diff options
| author | Thomi Richards <thomi.richards@canonical.com> | 2012-07-11 08:41:57 +1200 |
|---|---|---|
| committer | Thomi Richards <thomi.richards@canonical.com> | 2012-07-11 08:41:57 +1200 |
| commit | e9d5bf496b9b0430062db47af933e22473c25c8b (patch) | |
| tree | ecc136c458a73baaa695114cc76006f090eac9e7 /tests/autopilot | |
| parent | 3bf370f522a450b8bf578877c24a2c1a967c623f (diff) | |
Pushed switcher icon selection code into the switcher emulator.
(bzr r2480.2.3)
Diffstat (limited to 'tests/autopilot')
| -rw-r--r-- | tests/autopilot/unity/emulators/switcher.py | 39 | ||||
| -rw-r--r-- | tests/autopilot/unity/tests/test_showdesktop.py | 14 |
2 files changed, 40 insertions, 13 deletions
diff --git a/tests/autopilot/unity/emulators/switcher.py b/tests/autopilot/unity/emulators/switcher.py index 7525f137b..16f6bdfc2 100644 --- a/tests/autopilot/unity/emulators/switcher.py +++ b/tests/autopilot/unity/emulators/switcher.py @@ -37,6 +37,9 @@ class Switcher(KeybindingsHelper): """ + DIRECTION_FORWARDS = 0 + DIRECTION_BACKWARDS = 1 + def __init__(self): super(Switcher, self).__init__() self._mouse = Mouse() @@ -107,6 +110,42 @@ class Switcher(KeybindingsHelper): logger.debug("Selecting previous item in switcher.") self.keybinding("switcher/prev") + def select_icon(self, direction, **kwargs): + """Select an icon in the switcher. + + direction must be one of Switcher.DIRECTION_FORWARDS or Switcher.DIRECTION_BACKWARDS. + + The keyword arguments are used to select an icon. For example, you might + do this to select the 'Show Desktop' icon: + + >>> self.switcher.select_icon(Switcher.DIRECTION_BACKWARDS, tooltip_text="Show Desktop") + + The switcher must be initiated already, and must be in normal mode when + this method is called, or a RuntimeError will be raised. + + If no icon matches, a ValueError will be raised. + + """ + if self.mode != SwitcherMode.NORMAL: + raise RuntimeError("Switcher must be initiated in normal mode before calling this method.") + + if direction not in (self.DIRECTION_BACKWARDS, self.DIRECTION_FORWARDS): + raise ValueError("direction must be one of Switcher.DIRECTION_BACKWARDS, Switcher.DIRECTION_FORWARDS") + + for i in self.controller.model.icons: + current_icon = self.current_icon + passed=True + for key,val in kwargs.iteritems(): + if not hasattr(current_icon, key) or getattr(current_icon, key) != val: + passed=False + if passed: + return + if direction == self.DIRECTION_FORWARDS: + self.next_icon() + elif direction == self.DIRECTION_BACKWARDS: + self.previous_icon() + raise ValueError("No icon found in switcher model that matches: %r" % kwargs) + def cancel(self): """Stop switcher without activating the selected icon and releasing the keys. diff --git a/tests/autopilot/unity/tests/test_showdesktop.py b/tests/autopilot/unity/tests/test_showdesktop.py index 1a845ec87..f134bbb6f 100644 --- a/tests/autopilot/unity/tests/test_showdesktop.py +++ b/tests/autopilot/unity/tests/test_showdesktop.py @@ -97,20 +97,8 @@ class ShowDesktopTests(UnityTestCase): # show desktop, verify all windows are hidden: self.switcher.initiate() - sleep(0.5) - found = False - switcher_model = self.switcher.controller.model - for i in switcher_model.icons: - current_icon = self.switcher.current_icon - self.assertIsNotNone(current_icon) - if isinstance(current_icon, DesktopLauncherIcon): - found = True - break - self.switcher.previous_icon() - sleep(0.25) - self.assertTrue(found, "Could not find 'Show Desktop' entry in switcher.") + self.switcher.select_icon(self.switcher.DIRECTION_BACKWARDS, tooltip_text="Show Desktop") self.addCleanup(self.window_manager.leave_show_desktop) - self.switcher.select() for win in test_windows: |
