on xenial help sign in
Add autopilot tests to assert indicator page title matches widget.
commit29047e4805070811db9f61cce900d811790595c8 authorAllan LeSage <allan.lesage@canonical.com> dateWed 27 Nov 2013, 17:09 (13 years ago) parent17b6350
3 files changed+114−5
tests/autopilot/unity8/indicators/tests/__init__.py+65 tests/autopilot/unity8/indicators/tests/test_indicators.py+48−4 tests/autopilot/unity8/shell/emulators/main_window.py+1−1
tests/autopilot/unity8/indicators/tests/__init__.py+65
@@ -0,0 +1,65 @@
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2+#
3+# Unity - Indicators Autopilot Test Suite
4+# Copyright (C) 2013 Canonical
5+#
6+# This program is free software: you can redistribute it and/or modify
7+# it under the terms of the GNU General Public License as published by
8+# the Free Software Foundation, either version 3 of the License, or
9+# (at your option) any later version.
10+#
11+# This program is distributed in the hope that it will be useful,
12+# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+# GNU General Public License for more details.
15+#
16+# You should have received a copy of the GNU General Public License
17+# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+from __future__ import absolute_import
20+
21+from autopilot.input import Pointer, Touch
22+
23+from unity8.shell.tests import UnityTestCase
24+
25+
26+# TODO: submit to autopilot.introspection.types.Rectangle
27+def get_center(global_rect):
28+ """Returns (x, y) representing the center of a globalRect."""
29+ return (global_rect[0]+int(global_rect[2]/2),
30+ global_rect[1]+int(global_rect[3]/2))
31+
32+
33+class IndicatorBaseTestCase(UnityTestCase):
34+
35+ def setUp(self):
36+ super(IndicatorBaseTestCase, self).setUp()
37+ self.pointer = Pointer(Touch.create())
38+
39+ # Because some tests are manually manipulating the finger, we want to
40+ # cleanup if the test fails, but we don't want to fail with an exception if
41+ # we don't.
42+ def _maybe_release_finger(self):
43+ """Only release the finger if it is in fact down."""
44+ if self.touch._touch_finger is not None:
45+ self.touch.release()
46+
47+ def swipe_to_open_indicator(self, indicator_widget, window):
48+ """Swipe to open the indicator, wait until it's open."""
49+ start_x, start_y = get_center(indicator_widget.globalRect)
50+ end_x = start_x
51+ end_y = window.height
52+ self.pointer.drag(start_x, start_y,
53+ end_x, end_y)
54+ self.addCleanup(self._maybe_release_finger)
55+ # TODO: assert that the indicator page opened
56+
57+ def swipe_to_close_indicator(self, indicator_widget, window):
58+ """Swipe to close the indicator, wait until it's closed."""
59+ end_x, end_y = get_center(indicator_widget.globalRect)
60+ start_x = end_x
61+ start_y = window.height
62+ self.pointer.drag(start_x, start_y,
63+ end_x, end_y)
64+ self.addCleanup(self._maybe_release_finger)
65+ # TODO: assert that the indicator page closed
tests/autopilot/unity8/indicators/tests/test_indicators.py+48−4
@@ -23,10 +23,10 @@ from autopilot import platform
2323from testtools import skipIf
2424
2525from unity8.process_helpers import unlock_unity
26−from unity8.shell.tests import UnityTestCase
26+from unity8.indicators.tests import IndicatorBaseTestCase
2727
2828
29−class IndicatorTestCase(UnityTestCase):
29+class IndicatorTestCase(IndicatorBaseTestCase):
3030
3131 scenarios = [
3232 ('Bluetooth', dict(indicator_name='indicator-bluetooth')),
@@ -47,5 +47,49 @@ class IndicatorTestCase(UnityTestCase):
4747 """The tab of a given indicator can be found."""
4848 unity_proxy = self.launch_unity()
4949 unlock_unity(unity_proxy)
50− indicator = self.main_window.get_indicator(self.indicator_name)
51− self.assertIsNotNone(indicator)
50+ widget = self.main_window.get_indicator_widget(
51+ self.indicator_name
52+ )
53+ self.assertIsNotNone(widget)
54+
55+
56+class IndicatorPageTitleMatchesWidgetTestCase(IndicatorBaseTestCase):
57+
58+ scenarios = [
59+ ('Bluetooth', dict(indicator_name='indicator-bluetooth',
60+ title='Bluetooth')),
61+ ('Datetime', dict(indicator_name='indicator-datetime',
62+ title='Upcoming')),
63+ ('Location', dict(indicator_name='indicator-location',
64+ title='Location')),
65+ ('Messaging', dict(indicator_name='indicator-messages',
66+ title='Incoming')),
67+ ('Network', dict(indicator_name='indicator-network',
68+ title='Network')),
69+ ('Power', dict(indicator_name='indicator-power',
70+ title='Battery')),
71+ ('Sound', dict(indicator_name='indicator-sound',
72+ title='Sound')),
73+ ]
74+
75+ @skipIf(platform.image_codename() == 'Desktop',
76+ "Unity8/phablet-only test!")
77+ def setUp(self):
78+ super(IndicatorPageTitleMatchesWidgetTestCase, self).setUp()
79+
80+ def test_indicator_page_title_matches_widget(self):
81+ """When I swipe open an indicator, I should see its correct title.
82+
83+ See https://bugs.launchpad.net/ubuntu-ux/+bug/1253804 .
84+ """
85+ unity_proxy = self.launch_unity()
86+ unlock_unity(unity_proxy)
87+ window = self.main_window.get_qml_view()
88+ widget = self.main_window.get_indicator_widget(
89+ self.indicator_name
90+ )
91+ self.assertIsNotNone(widget)
92+ self.swipe_to_open_indicator(widget, window)
93+ title = window.wait_select_single("IndicatorPage",
94+ title=self.title)
95+ self.assertIsNotNone(title)
tests/autopilot/unity8/shell/emulators/main_window.py+1−1
@@ -91,7 +91,7 @@ class MainWindow(object):
9191 def get_pinentryField(self):
9292 return self.app.select_single(objectName="pinentryField")
9393
94− def get_indicator(self, indicator_name):
94+ def get_indicator_widget(self, indicator_name):
9595 return self.app.select_single(
9696 'DefaultIndicatorWidget',
9797 objectName=indicator_name+'-widget'