on xenial help sign in
Initial implementation of veebers' comments, more to do.
4c919e5Allan LeSage
tests/autopilot/unity8/indicators/emulators/__init__.pynew file+17
@@ -0,0 +1,17 @@
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/>.
tests/autopilot/unity8/indicators/emulators/widget.pynew file+48
@@ -0,0 +1,48 @@
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2+#
3+# Unity Autopilot Test Suite
4+# Copyright (C) 2012-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 autopilot.introspection import CustomEmulatorBase
20+from autopilot.input import Touch
21+
22+
23+# TODO: submit to autopilot.introspection.types.Rectangle
24+def get_center(global_rect):
25+ """Returns (x, y) representing the center of a globalRect."""
26+ return (global_rect[0]+int(global_rect[2]/2),
27+ global_rect[1]+int(global_rect[3]/2))
28+
29+
30+class DefaultIndicatorWidget(CustomEmulatorBase):
31+
32+ def swipe_to_open_indicator(self, indicator_widget, window):
33+ """Swipe to open the indicator, wait until it's open."""
34+ start_x, start_y = get_center(indicator_widget.globalRect)
35+ end_x = start_x
36+ end_y = window.height
37+ self.pointer.drag(start_x, start_y,
38+ end_x, end_y)
39+ # TODO: assert that the indicator page opened
40+
41+ def swipe_to_close_indicator(self, indicator_widget, window):
42+ """Swipe to close the indicator, wait until it's closed."""
43+ end_x, end_y = get_center(indicator_widget.globalRect)
44+ start_x = end_x
45+ start_y = window.height
46+ self.pointer.drag(start_x, start_y,
47+ end_x, end_y)
48+ # TODO: assert that the indicator page closed
tests/autopilot/unity8/indicators/tests/__init__.py−48
@@ -15,51 +15,3 @@
15#
15#
16# You should have received a copy of the GNU General Public License
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/>.
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+13−12
@@ -20,13 +20,13 @@
20from __future__ import absolute_import
20from __future__ import absolute_import
21
21
22from autopilot import platform
22from autopilot import platform
23−from testtools import skipIf
24
23
24+from unity8.indicators.emulators.widget import DefaultIndicatorWidget
25from unity8.process_helpers import unlock_unity
25from unity8.process_helpers import unlock_unity
26−from unity8.indicators.tests import IndicatorBaseTestCase
26+from unity8.shell.tests import UnityTestCase
27
27
28
28
29−class IndicatorTestCase(IndicatorBaseTestCase):
29+class IndicatorTestCase(UnityTestCase):
30
30
31 scenarios = [
31 scenarios = [
32 ('Bluetooth', dict(indicator_name='indicator-bluetooth')),
32 ('Bluetooth', dict(indicator_name='indicator-bluetooth')),
@@ -38,9 +38,9 @@ class IndicatorTestCase(IndicatorBaseTestCase):
38 ('Sound', dict(indicator_name='indicator-sound')),
38 ('Sound', dict(indicator_name='indicator-sound')),
39 ]
39 ]
40
40
41− @skipIf(platform.image_codename() == 'Desktop',
42− "Unity8/phablet-only test!")
43 def setUp(self):
41 def setUp(self):
42+ if model() == "Desktop":
43+ self.skipTest("Test cannot be run on the desktop.")
44 super(IndicatorTestCase, self).setUp()
44 super(IndicatorTestCase, self).setUp()
45
45
46 def test_indicator_exists(self):
46 def test_indicator_exists(self):
@@ -53,7 +53,7 @@ class IndicatorTestCase(IndicatorBaseTestCase):
53 self.assertIsNotNone(widget)
53 self.assertIsNotNone(widget)
54
54
55
55
56−class IndicatorPageTitleMatchesWidgetTestCase(IndicatorBaseTestCase):
56+class IndicatorPageTitleMatchesWidgetTestCase(UnityTestCase):
57
57
58 scenarios = [
58 scenarios = [
59 ('Bluetooth', dict(indicator_name='indicator-bluetooth',
59 ('Bluetooth', dict(indicator_name='indicator-bluetooth',
@@ -72,24 +72,25 @@ class IndicatorPageTitleMatchesWidgetTestCase(IndicatorBaseTestCase):
72 title='Sound')),
72 title='Sound')),
73 ]
73 ]
74
74
75− @skipIf(platform.image_codename() == 'Desktop',
76− "Unity8/phablet-only test!")
77 def setUp(self):
75 def setUp(self):
76+ if model() == "Desktop":
77+ self.skipTest("Test cannot be run on the desktop.")
78 super(IndicatorPageTitleMatchesWidgetTestCase, self).setUp()
78 super(IndicatorPageTitleMatchesWidgetTestCase, self).setUp()
79
79
80 def test_indicator_page_title_matches_widget(self):
80 def test_indicator_page_title_matches_widget(self):
81− """When I swipe open an indicator, I should see its correct title.
81+ """Swiping open an indicator must show its correct title.
82
82
83 See https://bugs.launchpad.net/ubuntu-ux/+bug/1253804 .
83 See https://bugs.launchpad.net/ubuntu-ux/+bug/1253804 .
84 """
84 """
85 unity_proxy = self.launch_unity()
85 unity_proxy = self.launch_unity()
86 unlock_unity(unity_proxy)
86 unlock_unity(unity_proxy)
87 window = self.main_window.get_qml_view()
87 window = self.main_window.get_qml_view()
88+ widget = DefaultIndicatorWidget(
88− widget = self.main_window.get_indicator_widget(
89+ self.main_window.get_indicator_widget(
89− self.indicator_name
90+ self.indicator_name
91+ )
90 )
92 )
91 self.assertIsNotNone(widget)
93 self.assertIsNotNone(widget)
92 self.swipe_to_open_indicator(widget, window)
94 self.swipe_to_open_indicator(widget, window)
93 title = window.wait_select_single("IndicatorPage",
95 title = window.wait_select_single("IndicatorPage",
94 title=self.title)
96 title=self.title)
95− self.assertIsNotNone(title)