summaryrefslogtreecommitdiff
diff options
-rw-r--r--tests/autopilot/unity/tests/test_switcher.py177
1 files changed, 79 insertions, 98 deletions
diff --git a/tests/autopilot/unity/tests/test_switcher.py b/tests/autopilot/unity/tests/test_switcher.py
index 52254ea2d..f3a301959 100644
--- a/tests/autopilot/unity/tests/test_switcher.py
+++ b/tests/autopilot/unity/tests/test_switcher.py
@@ -25,6 +25,28 @@ class SwitcherTestCase(UnityTestCase):
self.set_unity_option("alt_tab_timeout", state)
sleep(1)
+ def start_applications(self, *args):
+ """Start some applications, returning their windows.
+
+ If no applications are specified, the following will be started:
+ * Character Map
+ * Calculator
+ * Calculator
+
+ Windows are always started in the order that they are specified (which
+ means the last specified application will *probably* be at the top of the
+ window stack after calling this method). Windows are returned in the same
+ order they are specified in.
+
+ """
+ if len(args) == 0:
+ args = ('Character Map', 'Calculator', 'Calculator')
+ windows = []
+ for app in args:
+ windows.append(self.start_app_window(app))
+
+ return windows
+
class SwitcherTests(SwitcherTestCase):
"""Test the switcher."""
@@ -32,9 +54,6 @@ class SwitcherTests(SwitcherTestCase):
def setUp(self):
super(SwitcherTests, self).setUp()
self.set_timeout_setting(False)
- self.char_map = self.start_app('Character Map')
- self.calc = self.start_app('Calculator')
- self.mahjongg = self.start_app('Mahjongg')
def tearDown(self):
super(SwitcherTests, self).tearDown()
@@ -42,18 +61,16 @@ class SwitcherTests(SwitcherTestCase):
def test_witcher_starts_in_normal_mode(self):
"""Switcher must start in normal (i.e.- not details) mode."""
self.start_app("Character Map")
- sleep(1)
self.switcher.initiate()
self.addCleanup(self.switcher.terminate)
- self.assertThat(self.switcher.mode, Equals(SwitcherMode.NORMAL))
+ self.assertProperty(self.switcher, mode=SwitcherMode.NORMAL)
def test_first_detail_mode_has_correct_label(self):
"""Starting switcher in details mode must show the focused window title."""
- app = self.start_app("Text Editor")
- sleep(1)
+ window = self.start_app_window("Text Editor")
+ title = window.title
- [title] = [w.title for w in app.get_windows() if w.is_focused]
self.switcher.initiate(SwitcherMode.DETAIL)
self.addCleanup(self.switcher.terminate)
@@ -61,44 +78,47 @@ class SwitcherTests(SwitcherTestCase):
def test_switcher_move_next(self):
"""Test that pressing the next icon binding moves to the next icon"""
+ self.start_applications()
self.switcher.initiate()
self.addCleanup(self.switcher.terminate)
start = self.switcher.selection_index
self.switcher.next_icon()
- self.assertThat(self.switcher.selection_index, Equals(start + 1))
+
+ self.assertThat(self.switcher.selection_index, Eventually(Equals(start + 1)))
def test_switcher_move_prev(self):
"""Test that pressing the previous icon binding moves to the previous icon"""
+ self.start_applications()
self.switcher.initiate()
self.addCleanup(self.switcher.terminate)
start = self.switcher.selection_index
self.switcher.previous_icon()
- self.assertThat(self.switcher.selection_index, Equals(start - 1))
+
+ self.assertThat(self.switcher.selection_index, Eventually(Equals(start - 1)))
def test_switcher_scroll_next(self):
"""Test that scrolling the mouse wheel down moves to the next icon"""
+ self.start_applications()
self.switcher.initiate()
self.addCleanup(self.switcher.terminate)
start = self.switcher.selection_index
self.switcher.next_via_mouse()
- self.assertThat(self.switcher.selection_index, Equals(start + 1))
+ self.assertThat(self.switcher.selection_index, Eventually(Equals(start + 1)))
def test_switcher_scroll_prev(self):
"""Test that scrolling the mouse wheel up moves to the previous icon"""
+ self.start_applications()
self.switcher.initiate()
self.addCleanup(self.switcher.terminate)
start = self.switcher.selection_index
self.switcher.previous_via_mouse()
- end = self.switcher.selection_index
- self.assertThat(end, Equals(start - 1))
-
- self.switcher.terminate()
+ self.assertThat(self.switcher.selection_index, Eventually(Equals(start - 1)))
def test_switcher_arrow_key_does_not_init(self):
"""Ensure that Alt+Right does not initiate switcher.
@@ -106,21 +126,24 @@ class SwitcherTests(SwitcherTestCase):
Regression test for LP:??????
"""
- self.keyboard.press('Alt')
- self.addCleanup(self.keyboard.release, 'Alt')
- self.keyboard.press_and_release('Right')
+ self.keyboard.press_and_release('Alt+Right')
self.assertThat(self.switcher.visible, Equals(False))
def test_lazy_switcher_initiate(self):
+ """Inserting a long delay between the Alt press and the Tab tab must still
+ open the switcher.
+
+ """
self.keybinding_hold("switcher/reveal_normal")
self.addCleanup(self.keybinding_release, "switcher/reveal_normal")
self.assertThat(self.switcher.visible, Eventually(Equals(False)))
-
+ sleep(5)
self.keybinding_tap("switcher/reveal_normal")
self.addCleanup(self.keybinding, "switcher/cancel")
self.assertThat(self.switcher.visible, Eventually(Equals(True)))
def test_switcher_cancel(self):
+ """Pressing the switcher cancel keystroke must cancel the switcher."""
self.switcher.initiate()
self.addCleanup(self.switcher.terminate)
@@ -129,9 +152,11 @@ class SwitcherTests(SwitcherTestCase):
self.assertThat(self.switcher.visible, Eventually(Equals(False)))
def test_lazy_switcher_cancel(self):
+ """Must be able to cancel the switcher after a 'lazy' initiation."""
self.keybinding_hold("switcher/reveal_normal")
self.addCleanup(self.keybinding_release, "switcher/reveal_normal")
self.assertThat(self.switcher.visible, Eventually(Equals(False)))
+ sleep(5)
self.keybinding_tap("switcher/reveal_normal")
self.assertThat(self.switcher.visible, Eventually(Equals(True)))
self.switcher.cancel()
@@ -143,13 +168,17 @@ class SwitcherTests(SwitcherTestCase):
This is defined as the monitor with a focused window.
"""
+ # TODO - this test fails in multi-monitor setups. You can't use addCleanup
+ # a better way would be to have a scenario'd class for multi-monitor
+ # switcher tests.
num_monitors = self.screen_geo.get_num_monitors()
if num_monitors == 1:
self.skip("No point testing this on one monitor")
- [calc_win] = self.calc.get_windows()
+ charmap, calc, mahjongg = self.start_applications()
+
for monitor in range(num_monitors):
- self.screen_geo.drag_window_to_monitor(calc_win, monitor)
+ self.screen_geo.drag_window_to_monitor(calc, monitor)
self.switcher.initiate()
self.addCleanup(self.switcher.terminate)
self.assertThat(self.switcher.controller.monitor, Eventually(Equals(monitor)))
@@ -157,18 +186,15 @@ class SwitcherTests(SwitcherTestCase):
def test_switcher_alt_f4_is_disabled(self):
"""Tests that alt+f4 does not work while switcher is active."""
- app = self.start_app("Text Editor")
- sleep(1)
+ win = self.start_app_window("Text Editor")
self.switcher.initiate(SwitcherMode.DETAIL)
self.addCleanup(self.switcher.terminate)
self.keyboard.press_and_release("Alt+F4")
- [win] = [w for w in app.get_windows()]
-
# Need the sleep to allow the window time to close, for jenkins!
sleep(10)
- self.assertThat(win.is_valid, Equals(True))
+ self.assertProperty(win, is_valid=True)
class SwitcherWindowsManagementTests(SwitcherTestCase):
@@ -182,22 +208,19 @@ class SwitcherWindowsManagementTests(SwitcherTestCase):
Then we close the currently focused window.
"""
- mah_win1 = self.start_app_window("Mahjongg")
- calc_win = self.start_app_window("Calculator")
- mah_win2 = self.start_app_window("Mahjongg")
-
+ mah_win1, calc_win, mah_win2 = self.start_applications("Mahjongg", "Calculator", "Mahjongg")
self.assertVisibleWindowStack([mah_win2, calc_win, mah_win1])
self.keybinding("switcher/reveal_normal")
- self.assertThat(lambda: calc_win.is_focused, Eventually(Equals(True)))
+ self.assertProperty(calc_win, is_focused=True)
self.assertVisibleWindowStack([calc_win, mah_win2, mah_win1])
self.keybinding("switcher/reveal_normal")
- self.assertThat(lambda: mah_win2.is_focused, Eventually(Equals(True)))
+ self.assertProperty(mah_win2, is_focused=True)
self.assertVisibleWindowStack([mah_win2, calc_win, mah_win1])
self.keybinding("window/close")
- self.assertThat(lambda: calc_win.is_focused, Eventually(Equals(True)))
+ self.assertProperty(calc_win, is_focused=True)
self.assertVisibleWindowStack([calc_win, mah_win1])
@@ -211,25 +234,14 @@ class SwitcherDetailsTests(SwitcherTestCase):
"""Test that details mode activates on a timeout."""
initial_workspace = self.workspace.current_workspace
self.addCleanup(self.workspace.switch_to, initial_workspace)
- #FIXME: Setup
- self.close_all_app('Character Map')
self.workspace.switch_to(1)
- self.start_app("Character Map")
- sleep(1)
- self.start_app("Character Map")
- sleep(1)
-
- # Need to start a different app, so it has focus, so alt-tab goes to
- # the character map.
- self.start_app('Mahjongg')
- sleep(1)
- # end setup
+ self.start_applications("Character Map", "Character Map", "Mahjongg")
self.switcher.initiate()
self.addCleanup(self.switcher.terminate)
# Wait longer than details mode.
sleep(3)
- self.assertThat(self.switcher.mode, Equals(SwitcherMode.DETAIL))
+ self.assertProperty(self.switcher, mode=SwitcherMode.DETAIL)
def test_no_details_for_apps_on_different_workspace(self):
"""Tests that details mode does not initiates when there are multiple windows
@@ -238,27 +250,18 @@ class SwitcherDetailsTests(SwitcherTestCase):
Regression test for LP:933406.
"""
- #Fixme: setup
initial_workspace = self.workspace.current_workspace
self.addCleanup(self.workspace.switch_to, initial_workspace)
- self.close_all_app('Character Map')
self.workspace.switch_to(1)
- self.start_app("Character Map")
- sleep(1)
+ self.start_app_window("Character Map")
self.workspace.switch_to(2)
- self.start_app("Character Map")
- sleep(1)
- # Need to start a different app, so it has focus, so alt-tab goes to
- # the character map.
- self.start_app('Mahjongg')
- sleep(1)
- # end setup
+ self.start_applications("Character Map", "Mahjongg")
self.switcher.initiate()
self.addCleanup(self.switcher.terminate)
# Wait longer than details mode.
sleep(3)
- self.assertThat(self.switcher.mode, Equals(SwitcherMode.NORMAL))
+ self.assertProperty(self.switcher, mode=SwitcherMode.NORMAL)
class SwitcherDetailsModeTests(SwitcherTestCase):
@@ -274,14 +277,16 @@ class SwitcherDetailsModeTests(SwitcherTestCase):
]
def test_can_start_details_mode(self):
- """Must be able to initiate details mode using selected scenario keycode.
+ """Must be able to switch to details mode using selected scenario keycode.
"""
- self.start_app("Character Map")
+ self.start_app_window("Character Map")
self.switcher.initiate()
self.addCleanup(self.switcher.terminate)
+
self.keyboard.press_and_release(self.initiate_keycode)
- self.assertThat(self.switcher.mode, Equals(SwitcherMode.DETAIL))
+
+ self.assertProperty(self.switcher, mode=SwitcherMode.DETAIL)
def test_next_icon_from_last_detail_works(self):
"""Pressing next while showing last switcher item in details mode
@@ -301,7 +306,7 @@ class SwitcherDetailsModeTests(SwitcherTestCase):
self.switcher.next_detail()
self.switcher.next_icon()
- self.assertThat(self.switcher.selection_index, Equals(0))
+ self.assertThat(self.switcher.selection_index, Eventually(Equals(0)))
class SwitcherWorkspaceTests(SwitcherTestCase):
@@ -311,47 +316,36 @@ class SwitcherWorkspaceTests(SwitcherTestCase):
"""Switcher must show apps from the current workspace only."""
initial_workspace = self.workspace.current_workspace
self.addCleanup(self.workspace.switch_to, initial_workspace)
- #FIXME: SETUP
- self.close_all_app('Calculator')
- self.close_all_app('Character Map')
self.workspace.switch_to(1)
calc = self.start_app("Calculator")
- sleep(1)
self.workspace.switch_to(2)
char_map = self.start_app("Character Map")
- sleep(1)
- # END SETUP
self.switcher.initiate()
self.addCleanup(self.switcher.terminate)
- icon_names = [i.tooltip_text for i in self.switcher.icons]
- self.assertThat(icon_names, Contains(char_map.name))
- self.assertThat(icon_names, Not(Contains(calc.name)))
+ get_icon_names = lambda: [i.tooltip_text for i in self.switcher.icons]
+ self.assertThat(get_icon_names, Eventually(Contains(char_map.name)))
+ self.assertThat(get_icon_names, Eventually(Not(Contains(calc.name))))
def test_switcher_all_mode_shows_all_apps(self):
"""Test switcher 'show_all' mode shows apps from all workspaces."""
initial_workspace = self.workspace.current_workspace
self.addCleanup(self.workspace.switch_to, initial_workspace)
- self.close_all_app('Calculator')
- self.close_all_app('Character Map')
- #FIXME: this is setup
self.workspace.switch_to(1)
calc = self.start_app("Calculator")
- sleep(1)
self.workspace.switch_to(2)
char_map = self.start_app("Character Map")
- sleep(1)
- # END SETUP
+
self.switcher.initiate(SwitcherMode.ALL)
self.addCleanup(self.switcher.terminate)
- icon_names = [i.tooltip_text for i in self.switcher.icons]
- self.assertThat(icon_names, Contains(calc.name))
- self.assertThat(icon_names, Contains(char_map.name))
+ get_icon_names = lambda: [i.tooltip_text for i in self.switcher.icons]
+ self.assertThat(get_icon_names, Eventually(Contains(calc.name)))
+ self.assertThat(get_icon_names, Eventually(Contains(char_map.name)))
def test_switcher_can_switch_to_minimised_window(self):
"""Switcher must be able to switch to a minimised window when there's
@@ -361,37 +355,24 @@ class SwitcherWorkspaceTests(SwitcherTestCase):
"""
initial_workspace = self.workspace.current_workspace
self.addCleanup(self.workspace.switch_to, initial_workspace)
- #FIXME this is setup.
+
# disable automatic gridding of the switcher after a timeout, since it makes
# it harder to write the tests.
self.set_unity_option("alt_tab_timeout", False)
- self.close_all_app("Calculator")
- self.close_all_app("Mahjongg")
self.workspace.switch_to(1)
self.start_app("Mahjongg")
self.workspace.switch_to(3)
- mahjongg = self.start_app("Mahjongg")
- sleep(1)
+ mah_win2 = self.start_app_window("Mahjongg")
self.keybinding("window/minimize")
- sleep(1)
+ self.assertProperty(mah_win2, is_hidden=True)
self.start_app("Calculator")
- sleep(1)
- # END SETUP
self.switcher.initiate()
- while self.switcher.current_icon.tooltip_text != mahjongg.name:
- logger.debug("%s -> %s" % (self.switcher.current_icon.tooltip_text, mahjongg.name))
+ while self.switcher.current_icon.tooltip_text != mah_win2.application.name:
self.switcher.next_icon()
- sleep(1)
self.switcher.select()
- #get mahjongg windows - there should be two:
- wins = mahjongg.get_windows()
- self.assertThat(len(wins), Equals(2))
- # Ideally we should be able to find the instance that is on the
- # current workspace and ask that one if it is hidden.
- self.assertFalse(wins[0].is_hidden)
- self.assertFalse(wins[1].is_hidden)
+ self.assertProperty(mah_win2, is_hidden=False)