summaryrefslogtreecommitdiff
path: root/tests
diff options
authorThomi Richards <thomi.richards@canonical.com>2012-04-18 03:02:40 -0400
committerTarmac <>2012-04-18 03:02:40 -0400
commit11239ef7eea78ea23d9705fed73b2fade226649b (patch)
treed61fe41a7546364e6a783f352ca17d3b159b6d30 /tests
parentae8cad17b34ce2d1780767344aadff74de8cd728 (diff)
parent2929089b98f4ced411c575daa83b9b86d7f31038 (diff)
Dash autopilot tests use the new autopilot wait_for feature.. Fixes: . Approved by Brandon Schaefer, Tim Penhey.
(bzr r2296)
Diffstat (limited to 'tests')
-rw-r--r--tests/autopilot/autopilot/tests/test_dash.py180
1 files changed, 51 insertions, 129 deletions
diff --git a/tests/autopilot/autopilot/tests/test_dash.py b/tests/autopilot/autopilot/tests/test_dash.py
index bcf9f6607..678e3f440 100644
--- a/tests/autopilot/autopilot/tests/test_dash.py
+++ b/tests/autopilot/autopilot/tests/test_dash.py
@@ -9,15 +9,15 @@
from time import sleep
from gtk import Clipboard
-from testtools.matchers import Equals
+from testtools.matchers import Equals, NotEquals
+from autopilot.matchers import Eventually
from autopilot.tests import AutopilotTestCase
class DashTestCase(AutopilotTestCase):
def setUp(self):
super(DashTestCase, self).setUp()
- self.set_unity_log_level("unity", "DEBUG")
self.set_unity_log_level("unity.shell", "DEBUG")
self.set_unity_log_level("unity.launcher", "DEBUG")
self.dash.ensure_hidden()
@@ -37,37 +37,35 @@ class DashRevealTests(DashTestCase):
def test_application_lens_shortcut(self):
"""Application lense must reveal when Super+a is pressed."""
self.dash.reveal_application_lens()
- self.assertThat(self.dash.active_lens, Equals('applications.lens'))
+ self.assertThat(self.dash.active_lens, Eventually(Equals('applications.lens')))
def test_music_lens_shortcut(self):
"""Music lense must reveal when Super+w is pressed."""
self.dash.reveal_music_lens()
- self.assertThat(self.dash.active_lens, Equals('music.lens'))
+ self.assertThat(self.dash.active_lens, Eventually(Equals('music.lens')))
def test_file_lens_shortcut(self):
"""File lense must reveal when Super+f is pressed."""
self.dash.reveal_file_lens()
- self.assertThat(self.dash.active_lens, Equals('files.lens'))
+ self.assertThat(self.dash.active_lens, Eventually(Equals('files.lens')))
def test_command_lens_shortcut(self):
"""Run Command lens must reveat on alt+F2."""
self.dash.reveal_command_lens()
- self.assertThat(self.dash.active_lens, Equals('commands.lens'))
+ self.assertThat(self.dash.active_lens, Eventually(Equals('commands.lens')))
def test_alt_f4_close_dash(self):
"""Dash must close on alt+F4."""
self.dash.ensure_visible()
self.keyboard.press_and_release("Alt+F4")
- sleep(0.5)
- self.assertFalse(self.dash.visible)
+ self.assertThat(self.dash.visible, Eventually(Equals(False)))
class DashSearchInputTests(DashTestCase):
"""Test features involving input to the dash search"""
def assertSearchText(self, text):
- sleep(0.5)
- self.assertThat(self.dash.search_string, Equals(text))
+ self.assertThat(self.dash.search_string, Eventually(Equals(text)))
def test_search_keyboard_focus(self):
"""Dash must put keyboard focus on the search bar at all times."""
@@ -75,6 +73,7 @@ class DashSearchInputTests(DashTestCase):
self.keyboard.type("Hello")
self.assertSearchText("Hello")
+
class DashMultiKeyTests(DashSearchInputTests):
def setUp(self):
# set the multi key first so that we're not getting a new _DISPLAY while keys are held down.
@@ -126,7 +125,7 @@ class DashKeyNavTests(DashTestCase):
for i in range(self.dash.get_num_rows()):
self.keyboard.press_and_release("Down")
lensbar = self.dash.view.get_lensbar()
- self.assertIsNot(lensbar.focused_lens_icon, '')
+ self.assertThat(lensbar.focused_lens_icon, Eventually(NotEquals('')))
def test_lensbar_focus_changes(self):
"""Lensbar focused icon should change with Left and Right keypresses."""
@@ -135,13 +134,14 @@ class DashKeyNavTests(DashTestCase):
for i in range(self.dash.get_num_rows()):
self.keyboard.press_and_release("Down")
lensbar = self.dash.view.get_lensbar()
+
current_focused_icon = lensbar.focused_lens_icon
+
self.keyboard.press_and_release("Right");
- lensbar.refresh_state()
- self.assertNotEqual(lensbar.focused_lens_icon, current_focused_icon)
+ self.assertThat(lensbar.focused_lens_icon, Eventually(NotEquals(current_focused_icon)))
+
self.keyboard.press_and_release("Left")
- lensbar.refresh_state()
- self.assertEqual(lensbar.focused_lens_icon, current_focused_icon)
+ self.assertThat(lensbar.focused_lens_icon, Eventually(Equals(current_focused_icon)))
def test_lensbar_enter_activation(self):
"""Must be able to activate LensBar icons that have focus with an Enter keypress."""
@@ -153,64 +153,13 @@ class DashKeyNavTests(DashTestCase):
lensbar = self.dash.view.get_lensbar()
focused_icon = lensbar.focused_lens_icon
self.keyboard.press_and_release("Enter");
- lensbar.refresh_state()
- self.assertEqual(lensbar.active_lens, focused_icon)
+
+ self.assertThat(lensbar.active_lens, Eventually(Equals(focused_icon)))
# lensbar should lose focus after activation.
# TODO this should be a different test to make sure focus
# returns to the correct place.
- self.assertEqual(lensbar.focused_lens_icon, "")
-
- def test_category_header_keynav_autoscroll(self):
- """Tests that the dash scrolls a category header into view when scrolling via
- the keyboard.
-
- Test for lp:919563
- """
-
- reason = """
- False assumptions. Expanding the first category will not necessarily expand enough
- to force the next category header off screen.
- """
- self.skipTest(reason)
-
- self.dash.ensure_visible()
- lens = self.dash.get_current_lens()
-
- # Expand the first category
- self.keyboard.press_and_release("Down")
- self.keyboard.press_and_release("Enter")
- category = app_lens.get_focused_category()
-
- # Get the geometry of that category header.
- x = category.header_x
- y = category.header_y
- w = category.header_width
-
- # Manually scroll the dash.
- mouse.move(x+w+10, y+w+10, True)
- mouse.click(5)
- mouse.click(5)
- mouse.click(5)
-
- cached_y = y
-
- # Focus the search bar with the mouse
- searchbar = self.dash.get_searchbar()
- mouse.move(searchbar.x + 100,
- searchbar.y + searchbar.height / 2,
- True)
- mouse.click()
- sleep(2)
-
- # Then focus again the first category header
- self.keyboard.press_and_release("Down")
- self.keyboard.press_and_release("Enter")
- category = app_lens.get_focused_category()
- y = category.header_y
-
- # Make sure the dash autoscroll
- self.assertTrue(abs(y - cached_y) < 30)
+ self.assertThat(lensbar.focused_lens_icon, Eventually(Equals("")))
def test_category_header_keynav(self):
""" Tests that a category header gets focus when 'down' is pressed after the
@@ -229,28 +178,8 @@ class DashKeyNavTests(DashTestCase):
# Make sure that the category is highlighted.
self.assertTrue(category.header_is_highlighted)
- def test_maintain_highlight(self):
- # Get the geometry of that category header.
- self.skipTest('Not implemented at all. Broken out of another test but not reworked')
- mouse = Mouse()
-
- x = category.header_x
- y = category.header_y
- w = category.header_width
- h = category.header_height
-
- # Move the mouse close the view, and press down.
- mouse.move(x + w + 10,
- y + h / 2,
- True)
- sleep(1)
- self.keyboard.press_and_release("Down")
- lens = self.dash.get_current_lens()
- category = lens.get_focused_category()
- self.assertEqual(category, None)
-
def test_control_tab_lens_cycle(self):
- """ This test makes sure that Ctlr + Tab cycles lenses."""
+ """This test makes sure that Ctrl+Tab cycles lenses."""
self.dash.ensure_visible()
self.keyboard.press('Control')
@@ -266,8 +195,7 @@ class DashKeyNavTests(DashTestCase):
self.keyboard.release('Control')
self.keyboard.release('Shift')
- lensbar.refresh_state()
- self.assertEqual(lensbar.active_lens, u'home.lens')
+ self.assertThat(lensbar.active_lens, Eventually(Equals('home.lens')))
def test_tab_cycle_category_headers(self):
""" Makes sure that pressing tab cycles through the category headers"""
@@ -292,12 +220,12 @@ class DashKeyNavTests(DashTestCase):
self.keyboard.press_and_release('Tab')
searchbar = self.dash.get_searchbar()
- self.assertTrue(searchbar.expander_has_focus)
+ self.assertThat(searchbar.expander_has_focus, Eventually(Equals(True)))
filter_bar = lens.get_filterbar()
if not searchbar.showing_filters:
self.keyboard.press_and_release('Enter')
- self.assertTrue(searchbar.showing_filters)
+ self.assertThat(searchbar.showing_filters, Eventually(Equals(True)))
self.addCleanup(filter_bar.ensure_collapsed)
for i in range(filter_bar.get_num_filters()):
@@ -328,41 +256,35 @@ class DashClipboardTests(DashTestCase):
self.dash.ensure_visible()
self.keyboard.type("SelectAll")
- sleep(1)
- self.assertThat(self.dash.search_string, Equals('SelectAll'))
+ self.assertThat(self.dash.search_string, Eventually(Equals("SelectAll")))
self.keyboard.press_and_release("Ctrl+a")
self.keyboard.press_and_release("Delete")
- self.assertThat(self.dash.search_string, Equals(''))
+ self.assertThat(self.dash.search_string, Eventually(Equals('')))
def test_ctrl_c(self):
""" This test if ctrl+c copies text into the clipboard """
self.dash.ensure_visible()
self.keyboard.type("Copy")
- sleep(1)
+ self.assertThat(self.dash.search_string, Eventually(Equals("Copy")))
self.keyboard.press_and_release("Ctrl+a")
self.keyboard.press_and_release("Ctrl+c")
cb = Clipboard(selection="CLIPBOARD")
-
- searchbar = self.dash.get_searchbar()
- self.assertEqual(searchbar.search_string, cb.wait_for_text())
+ self.assertThat(self.dash.search_string, Eventually(Equals(cb.wait_for_text())))
def test_ctrl_x(self):
""" This test if ctrl+x deletes all text and copys it """
self.dash.ensure_visible()
self.keyboard.type("Cut")
- sleep(1)
+ self.assertThat(self.dash.search_string, Eventually(Equals("Cut")))
self.keyboard.press_and_release("Ctrl+a")
self.keyboard.press_and_release("Ctrl+x")
- sleep(1)
-
- searchbar = self.dash.get_searchbar()
- self.assertEqual(searchbar.search_string, u'')
+ self.assertThat(self.dash.search_string, Eventually(Equals("")))
cb = Clipboard(selection="CLIPBOARD")
self.assertEqual(cb.wait_for_text(), u'Cut')
@@ -372,30 +294,28 @@ class DashClipboardTests(DashTestCase):
self.dash.ensure_visible()
self.keyboard.type("CopyPaste")
- sleep(1)
+ self.assertThat(self.dash.search_string, Eventually(Equals("CopyPaste")))
self.keyboard.press_and_release("Ctrl+a")
self.keyboard.press_and_release("Ctrl+c")
self.keyboard.press_and_release("Ctrl+v")
self.keyboard.press_and_release("Ctrl+v")
- searchbar = self.dash.get_searchbar()
- self.assertEqual(searchbar.search_string, u'CopyPasteCopyPaste')
+ self.assertThat(self.dash.search_string, Eventually(Equals('CopyPasteCopyPaste')))
def test_ctrl_x_v(self):
""" This test if ctrl+x and ctrl+v cuts and pastes text"""
self.dash.ensure_visible()
self.keyboard.type("CutPaste")
- sleep(1)
+ self.assertThat(self.dash.search_string, Eventually(Equals("CutPaste")))
self.keyboard.press_and_release("Ctrl+a")
self.keyboard.press_and_release("Ctrl+x")
self.keyboard.press_and_release("Ctrl+v")
self.keyboard.press_and_release("Ctrl+v")
- searchbar = self.dash.get_searchbar()
- self.assertEqual(searchbar.search_string, u'CutPasteCutPaste')
+ self.assertThat(self.dash.search_string, Eventually(Equals('CutPasteCutPaste')))
class DashKeyboardFocusTests(DashTestCase):
@@ -413,7 +333,7 @@ class DashKeyboardFocusTests(DashTestCase):
filter_bar.ensure_expanded()
self.addCleanup(filter_bar.ensure_collapsed)
self.keyboard.type(" world")
- self.assertThat(self.dash.search_string, Equals("hello world"))
+ self.assertThat(self.dash.search_string, Eventually(Equals("hello world")))
class DashLensResultsTests(DashTestCase):
@@ -423,34 +343,36 @@ class DashLensResultsTests(DashTestCase):
"""This tests a message is not shown when there is no text."""
self.dash.reveal_application_lens()
lens = self.dash.get_current_lens()
- self.assertFalse(lens.no_results_active)
+ self.assertThat(lens.no_results_active, Eventually(Equals(False)))
def test_results_message(self):
"""This test no mesage will be shown when results are there."""
self.dash.reveal_application_lens()
self.keyboard.type("Terminal")
- sleep(1)
+ self.assertThat(self.dash.search_string, Eventually(Equals("Terminal")))
lens = self.dash.get_current_lens()
- self.assertFalse(lens.no_results_active)
+ self.assertThat(lens.no_results_active, Eventually(Equals(False)))
def test_no_results_message(self):
"""This test shows a message will appear in the lens."""
self.dash.reveal_application_lens()
self.keyboard.type("qwerlkjzvxc")
- sleep(1)
+ self.assertThat(self.dash.search_string, Eventually(Equals("qwerlkjzvxc")))
lens = self.dash.get_current_lens()
- self.assertTrue(lens.no_results_active)
+ self.assertThat(lens.no_results_active, Eventually(Equals(True)))
def test_results_update_on_filter_changed(self):
"""This test makes sure the results change when filters change."""
self.dash.reveal_application_lens()
lens = self.dash.get_current_lens()
self.keyboard.type(" ")
- sleep(1)
+ self.assertThat(self.dash.search_string, Eventually(Equals(" ")))
results_category = lens.get_category_by_name("Installed")
old_results = results_category.get_results()
-
+ # FIXME: This should be a method on the dash emulator perhaps, or
+ # maybe a proper method of this class. It should NOT be an inline
+ # function that is only called once!
def activate_filter(add_cleanup = False):
# Tabs to last category
for i in range(lens.get_num_visible_categories()):
@@ -458,13 +380,14 @@ class DashLensResultsTests(DashTestCase):
self.keyboard.press_and_release('Tab')
searchbar = self.dash.get_searchbar()
- self.assertTrue(searchbar.expander_has_focus)
+ self.assertThat(searchbar.expander_has_focus, Eventually(Equals(True)))
filter_bar = lens.get_filterbar()
if not searchbar.showing_filters:
self.keyboard.press_and_release('Enter')
- self.assertTrue(searchbar.showing_filters)
- if add_cleanup: self.addCleanup(filter_bar.ensure_collapsed)
+ self.assertThat(searchbar.showing_filters, Eventually(Equals(True)))
+ if add_cleanup:
+ self.addCleanup(filter_bar.ensure_collapsed)
# Tab to the "Type" filter in apps lens
self.keyboard.press_and_release('Tab')
@@ -480,7 +403,6 @@ class DashLensResultsTests(DashTestCase):
activate_filter(True)
self.addCleanup(activate_filter)
- sleep(1)
results_category = lens.get_category_by_name("Installed")
results = results_category.get_results()
self.assertIsNot(results, old_results)
@@ -507,8 +429,10 @@ class DashVisualTests(DashTestCase):
name_label_y = group.name_label_y + group.name_label_baseline
self.assertThat(expand_label_y, Equals(name_label_y))
+
class DashLensBarTests(DashTestCase):
"""Tests that the lensbar works well."""
+
def setUp(self):
super(DashLensBarTests, self).setUp()
self.dash.ensure_visible()
@@ -520,9 +444,7 @@ class DashLensBarTests(DashTestCase):
"""
app_icon = self.lensbar.get_icon_by_name(u'applications.lens')
- self.mouse.move(app_icon.x, app_icon.y)
+ self.mouse.move(app_icon.x + (app_icon.width / 2),
+ app_icon.y + (app_icon.height / 2))
self.mouse.click()
-
- sleep(1)
-
- self.assertEqual(self.lensbar.active_lens, u'applications.lens')
+ self.assertThat(self.lensbar.active_lens, Eventually(Equals('applications.lens')))