on xenial help sign in
Added a test for the demo edges.
commitee22cf861295908b10ee03608f9d551ea44563ab authorLeo Arias <leo.arias@canonical.com> dateTue 16 Dec 2014, 10:32 (12 years ago) parent10ced0c
3 files changed+229
tests/autopilot/unity8/shell/emulators/edges_demo.py+140 tests/autopilot/unity8/shell/fixture_setup.py+38 tests/autopilot/unity8/shell/tests/test_edges_demo.py+51
tests/autopilot/unity8/shell/emulators/edges_demo.pynew file+140
@@ -0,0 +1,140 @@
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2+#
3+# Unity Autopilot Test Suite
4+# Copyright (C) 2014 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+
20+import logging
21+import time
22+
23+import ubuntuuitoolkit
24+
25+import autopilot
26+from autopilot import introspection
27+
28+
29+logger = logging.getLogger(__name__)
30+
31+
32+class RightEdgeDemoOverlay(
33+ ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
34+
35+ @classmethod
36+ def validate_dbus_object(cls, path, state):
37+ name = introspection.get_classname_from_path(path)
38+ if name == b'EdgeDemoOverlay':
39+ if state['edge'][1] == 'right':
40+ return True
41+ return False
42+
43+ @autopilot.logging.log_action(logger.info)
44+ def swipe(self):
45+ """Swipe to the left to complete this demo step."""
46+ x, y, width, height = self.globalRect
47+ start_x = x + width
48+ stop_x = x
49+ start_y = stop_y = y + height // 2
50+ self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
51+ return self.get_root_instance().wait_select_single(
52+ edge='top', active=True)
53+
54+
55+class TopEdgeDemoOverlay(
56+ ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
57+
58+ @classmethod
59+ def validate_dbus_object(cls, path, state):
60+ name = introspection.get_classname_from_path(path)
61+ if name == b'EdgeDemoOverlay':
62+ if state['edge'][1] == 'top':
63+ return True
64+ return False
65+
66+ @autopilot.logging.log_action(logger.info)
67+ def swipe(self):
68+ """Swipe to the bottom to complete this demo step."""
69+ x, y, width, height = self.globalRect
70+ start_x = stop_x = x + width // 2
71+ start_y = y
72+ stop_y = y + height
73+ self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
74+ return self.get_root_instance().wait_select_single(
75+ edge='bottom', active=True)
76+
77+
78+class BottomEdgeDemoOverlay(
79+ ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
80+
81+ @classmethod
82+ def validate_dbus_object(cls, path, state):
83+ name = introspection.get_classname_from_path(path)
84+ if name == b'EdgeDemoOverlay':
85+ if state['edge'][1] == 'bottom':
86+ return True
87+ return False
88+
89+ @autopilot.logging.log_action(logger.info)
90+ def swipe(self):
91+ """Swipe to the top to complete this demo step."""
92+ x, y, width, height = self.globalRect
93+ start_x = stop_x = x + width // 2
94+ start_y = y + height
95+ stop_y = y
96+ self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
97+ return self.get_root_instance().wait_select_single(
98+ edge='left', active=True)
99+
100+
101+class LeftEdgeDemoOverlay(
102+ ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
103+
104+ @classmethod
105+ def validate_dbus_object(cls, path, state):
106+ name = introspection.get_classname_from_path(path)
107+ if name == b'EdgeDemoOverlay':
108+ if state['edge'][1] == 'left':
109+ return True
110+ return False
111+
112+ @autopilot.logging.log_action(logger.info)
113+ def swipe(self):
114+ """Swipe to the right to complete this demo step."""
115+ x, y, width, height = self.globalRect
116+ start_x = x
117+ stop_x = x + width
118+ start_y = stop_y = y + height // 2
119+ self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
120+ return self.get_root_instance().wait_select_single(
121+ edge='none', active=True)
122+
123+
124+class FinalEdgeDemoOverlay(
125+ ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
126+
127+ @classmethod
128+ def validate_dbus_object(cls, path, state):
129+ name = introspection.get_classname_from_path(path)
130+ if name == b'EdgeDemoOverlay':
131+ if state['edge'][1] == 'none':
132+ return True
133+ return False
134+
135+ @autopilot.logging.log_action(logger.info)
136+ def tap_to_start(self):
137+ """Tap to finish the demo and start using the Ubuntu Touch."""
138+ time.sleep(1)
139+ self.pointing_device.click_object(self)
140+ self.shown.wait_for(False)
tests/autopilot/unity8/shell/fixture_setup.py+38
@@ -20,6 +20,7 @@
2020"""Set up and clean up fixtures for the Unity acceptance tests."""
2121
2222import os
23+import subprocess
2324import sysconfig
2425
2526import fixtures
@@ -51,3 +52,40 @@ class FakeScopes(fixtures.Fixture):
5152 'Expected library path does not exists: %s.' % (
5253 ld_library_path))
5354 return ld_library_path
55+
56+
57+class EdgesDemo(fixtures.Fixture):
58+
59+ def __init__(self, enable):
60+ super().__init__()
61+ self.enable = enable
62+
63+ def setUp(self):
64+ super().setUp()
65+ original_state = self._is_edges_demo_enabled()
66+ if self.enable != original_state:
67+ self.addCleanup(self._set_edges_demo, original_state)
68+ self._set_edges_demo(self.enable)
69+
70+ def _is_edges_demo_enabled(self):
71+ command = [
72+ 'dbus-send', '--system', '--print-reply',
73+ '--dest=org.freedesktop.Accounts',
74+ '/org/freedesktop/Accounts/User32011',
75+ 'org.freedesktop.DBus.Properties.Get',
76+ 'string:com.canonical.unity.AccountsService',
77+ 'string:demo-edges'
78+ ]
79+ output = subprocess.check_output(command, universal_newlines=True)
80+ return True if output.count('true') else False
81+
82+ def _set_edges_demo(self, value):
83+ value_string = 'true' if value else 'false'
84+ command = [
85+ 'dbus-send', '--system', '--print-reply',
86+ '--dest=com.canonical.PropertyService',
87+ '/com/canonical/PropertyService',
88+ 'com.canonical.PropertyService.SetProperty',
89+ 'string:edge', 'boolean:{}'.format(value_string)
90+ ]
91+ subprocess.check_output(command)
tests/autopilot/unity8/shell/tests/test_edges_demo.pynew file+51
@@ -0,0 +1,51 @@
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2+#
3+# Unity Autopilot Test Suite
4+# Copyright (C) 2014 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+
20+from autopilot.matchers import Eventually
21+from testtools.matchers import Equals
22+
23+from unity8.shell import (
24+ emulators,
25+ fixture_setup,
26+ tests
27+)
28+
29+
30+class EdgesDemoTestCase(tests.UnityTestCase):
31+
32+ def setUp(self):
33+ super().setUp()
34+ self._qml_mock_enabled = False
35+ self._data_dirs_mock_enabled = False
36+ self._lightdm_mock_type = False
37+
38+ self.useFixture(fixture_setup.EdgesDemo(True))
39+ self.unity = self.launch_unity()
40+
41+ def test_complete_edge_demo(self):
42+ edge_demo = self.unity.select_single('EdgeDemo')
43+ self.assertThat(edge_demo.running, Eventually(Equals(True)))
44+ right_edge_overlay = self.unity.wait_select_single(
45+ edge='right', active=True)
46+ top_edge_overlay = right_edge_overlay.swipe()
47+ bottom_edge_overlay = top_edge_overlay.swipe()
48+ left_edge_overlay = bottom_edge_overlay.swipe()
49+ final_overlay = left_edge_overlay.swipe()
50+ final_overlay.tap_to_start()
51+ self.assertThat(edge_demo.running, Eventually(Equals(False)))