~marcobiscaro2112/unity/custom-bg

« back to all changes in this revision

Viewing changes to tests/autopilot/unity/tests/test_showdesktop.py

  • Committer: Marco Biscaro
  • Date: 2012-07-12 12:05:07 UTC
  • mfrom: (2353.2.144 unity)
  • Revision ID: marcobiscaro2112@gmail.com-20120712120507-7u9sb43bqon88ifl
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
from __future__ import absolute_import
10
10
 
 
11
from autopilot.matchers import Eventually
 
12
from testtools.matchers import NotEquals
11
13
from time import sleep
12
14
 
13
15
from unity.emulators.icons import DesktopLauncherIcon
25
27
        sleep(2)
26
28
 
27
29
    def launch_test_apps(self):
28
 
        """Launch character map and calculator apps."""
29
 
        self.start_app('Character Map', locale='C')
30
 
        self.start_app('Calculator', locale='C')
31
 
        sleep(1)
 
30
        """Launch character map and calculator apps, and return their windows."""
 
31
        char_win = self.start_app_window('Character Map', locale='C')
 
32
        calc_win = self.start_app_window('Calculator', locale='C')
 
33
        return (char_win, calc_win)
32
34
 
33
35
    def test_showdesktop_hides_apps(self):
34
36
        """Show Desktop keyboard shortcut must hide applications."""
35
 
        self.launch_test_apps()
 
37
        test_windows = self.launch_test_apps()
36
38
 
37
39
        # show desktop, verify all windows are hidden:
38
40
        self.window_manager.enter_show_desktop()
39
41
        self.addCleanup(self.window_manager.leave_show_desktop)
40
42
 
41
 
        open_wins = self.bamf.get_open_windows()
42
 
        self.assertGreaterEqual(len(open_wins), 2)
43
 
        for win in open_wins:
44
 
            self.assertTrue(win.is_valid)
45
 
            self.assertTrue(win.is_hidden, "Window '%s' is not hidden after show desktop activated." % (win.title))
 
43
        for win in test_windows:
 
44
            self.assertProperty(win, is_valid=True)
 
45
            self.assertProperty(win, is_hidden=True)
46
46
 
47
47
    def test_showdesktop_unhides_apps(self):
48
48
        """Show desktop shortcut must re-show all hidden apps."""
49
 
        self.launch_test_apps()
 
49
        test_windows = self.launch_test_apps()
50
50
 
51
51
        # show desktop, verify all windows are hidden:
52
52
        self.window_manager.enter_show_desktop()
53
53
        self.addCleanup(self.window_manager.leave_show_desktop)
54
54
 
55
 
        open_wins = self.bamf.get_open_windows()
56
 
        self.assertGreaterEqual(len(open_wins), 2)
57
 
        for win in open_wins:
58
 
            self.assertTrue(win.is_valid)
59
 
            self.assertTrue(win.is_hidden, "Window '%s' is not hidden after show desktop activated." % (win.title))
 
55
        for win in test_windows:
 
56
            self.assertProperty(win, is_valid=True)
 
57
            self.assertProperty(win, is_hidden=True)
60
58
 
61
59
        # un-show desktop, verify all windows are shown:
62
60
        self.window_manager.leave_show_desktop()
63
61
 
64
 
        for win in self.bamf.get_open_windows():
65
 
            self.assertTrue(win.is_valid)
66
 
            self.assertFalse(win.is_hidden, "Window '%s' is shown after show desktop deactivated." % (win.title))
 
62
        for win in test_windows:
 
63
            self.assertProperty(win, is_valid=True)
 
64
            self.assertProperty(win, is_hidden=False)
67
65
 
68
66
    def test_unhide_single_app(self):
69
67
        """Un-hide a single app from launcher after hiding all apps."""
70
 
        self.launch_test_apps()
 
68
        test_windows = self.launch_test_apps()
71
69
 
72
70
        # show desktop, verify all windows are hidden:
73
71
        self.window_manager.enter_show_desktop()
74
72
        self.addCleanup(self.window_manager.leave_show_desktop)
75
73
 
76
 
        open_wins = self.bamf.get_open_windows()
77
 
        self.assertGreaterEqual(len(open_wins), 2)
78
 
        for win in open_wins:
79
 
            self.assertTrue(win.is_valid)
80
 
            self.assertTrue(win.is_hidden, "Window '%s' is not hidden after show desktop activated." % (win.title))
 
74
        for win in test_windows:
 
75
            self.assertProperty(win, is_valid=True)
 
76
            self.assertProperty(win, is_hidden=True)
81
77
 
82
78
        # We'll un-minimise the character map - find it's launcherIcon in the launcher:
83
 
        charmap_icon = self.launcher.model.get_icon_by_desktop_id("gucharmap.desktop")
 
79
        charmap_icon = self.launcher.model.get_icon(desktop_id="gucharmap.desktop")
84
80
        if charmap_icon:
85
81
            self.launcher.get_launcher_for_monitor(0).click_launcher_icon(charmap_icon)
86
82
        else:
87
83
            self.fail("Could not find launcher icon in launcher.")
88
84
 
89
 
        sleep(3)
90
 
        for win in self.bamf.get_open_windows():
91
 
            if win.is_valid:
92
 
                if win.title == 'Character Map':
93
 
                    self.assertFalse(win.is_hidden, "Character map did not un-hide from launcher.")
94
 
                else:
95
 
                    self.assertTrue(win.is_hidden, "Window '%s' should still be hidden." % (win.title))
 
85
        self.assertProperty(charmap, is_hidden=False)
 
86
        self.assertProperty(calc, is_hidden=True)
96
87
 
97
88
        # hide desktop - now all windows should be visible:
98
89
        self.window_manager.leave_show_desktop()
99
90
 
100
 
        for win in self.bamf.get_open_windows():
101
 
            if win.is_valid:
102
 
                self.assertFalse(win.is_hidden, "Window '%s' is not shown after show desktop deactivated." % (win.title))
 
91
        for win in test_windows:
 
92
            self.assertProperty(win, is_hidden=False)
103
93
 
104
94
    def test_showdesktop_switcher(self):
105
95
        """Show desktop item in switcher should hide all hidden apps."""
106
 
        self.launch_test_apps()
 
96
        test_windows = self.launch_test_apps()
107
97
 
108
98
        # show desktop, verify all windows are hidden:
109
99
        self.switcher.initiate()
110
 
        sleep(0.5)
111
 
        found = False
112
 
        switcher_model = self.switcher.controller.model
113
 
        for i in switcher_model.icons:
114
 
            current_icon = self.switcher.current_icon
115
 
            self.assertIsNotNone(current_icon)
116
 
            if isinstance(current_icon, DesktopLauncherIcon):
117
 
                found = True
118
 
                break
119
 
            self.switcher.previous_icon()
120
 
            sleep(0.25)
121
 
        self.assertTrue(found, "Could not find 'Show Desktop' entry in switcher.")
 
100
        self.switcher.select_icon(self.switcher.DIRECTION_BACKWARDS, tooltip_text="Show Desktop")
122
101
        self.addCleanup(self.window_manager.leave_show_desktop)
123
 
 
124
102
        self.switcher.select()
125
103
 
126
 
        sleep(3)
127
 
        open_wins = self.bamf.get_open_windows()
128
 
        self.assertGreaterEqual(len(open_wins), 2)
129
 
        for win in open_wins:
130
 
            self.assertTrue(win.is_valid)
131
 
            self.assertTrue(win.is_hidden, "Window '%s' is not hidden after show desktop activated." % (win.title))
 
104
        for win in test_windows:
 
105
            self.assertProperty(win, is_valid=True)
 
106
            self.assertProperty(win, is_hidden=True)