@@ -21,17 +21,13 @@
22from __future__ import absolute_import
22from __future__ import absolute_import
24−import logging
24+from autopilot.matchers import Eventually
25−from textwrap import dedent
27−from tempfile import mktemp
29from autopilot.platform import model
25from autopilot.platform import model
31−from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
27+import logging
33from testtools.matchers import Equals, NotEquals
29from testtools.matchers import Equals, NotEquals
34−
30+from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
36logger = logging.getLogger(__name__)
32logger = logging.getLogger(__name__)
@@ -46,139 +42,88 @@ class ApplicationLifecycleTests(UnityTestCase):
46 self.skipTest("Test must be run on a device.")
42 self.skipTest("Test must be run on a device.")
48 def swipe_from_right(self):
44 def swipe_from_right(self):
49− x, y, w, h = self.main_window.globalRect
45+ qml_view = self.main_window.get_qml_view()
46+ width = qml_view.width
47+ height = qml_view.height
50− start_x = w
48+ start_x = width
51− start_y = int(h / 2)
49+ start_y = int(height/2)
52− end_x = int(w / 2)
50+ end_x = int(width/2)
53 end_y = start_y
51 end_y = start_y
55 self.touch.drag(start_x, start_y, end_x, end_y)
53 self.touch.drag(start_x, start_y, end_x, end_y)
57− def _start_qml_script(self, script_contents):
58− """Launch a qml script."""
59− qml_path = mktemp(suffix='.qml')
60− open(qml_path, 'w').write(script_contents)
61− self.addCleanup(os.remove, qml_path)
63− desktop_file = self._get_dummy_desktop_file()
65− return self.launch_test_application(
68− "--desktop_file_hint=%s" % desktop_file,
72− def _get_dummy_desktop_file(self):
73− """Create a temp desktop file with app name *app_name*.
75− Returns the full path to the file.
78− file_path = mktemp(suffix='.desktop')
79− script_contents = dedent(
82−Comment=My project description
87−X-Ubuntu-Touch=true""")
88− open(file_path, 'w').write(script_contents)
89− self.addCleanup(os.remove, file_path)
91− print ">>> file path: ", file_path
94− # def _get_qml_script(self, title="Test App"):
97− # import Ubuntu.Components 0.1
101− # width: units.gu(48)
102− # height: units.gu(60)
105− def _get_qml_script(self, name="TestApp"):
108− import Ubuntu.Components 0.1
115− font.pixelSize: units.gu(8)
120 def test_can_launch_application(self):
55 def test_can_launch_application(self):
121 """must be able to launch and interact with an application."""
56 """must be able to launch and interact with an application."""
122− self.launch_unity()
57+ unity = self.launch_unity()
123 self.main_window.get_greeter().swipe()
58 self.main_window.get_greeter().swipe()
125− test_qml = self._get_qml_script("TestApp")
60+ app = self.launch_test_application(
126− app = self._start_qml_script(test_qml)
61+ "messaging-app",
127− main_window = app.select_single(
62+ "--desktop_file_hint="
128− "QQuickRectangle",
63+ "/usr/share/applications/messaging-app.desktop",
129− objectName="TestApp"
64+ "--stage_hint=main_stage",
67+ shell = unity.select_single("Shell")
132− self.assertThat(main_window, NotEquals(None))
69+ self.assertThat(app, NotEquals(None))
133− self.assertThat(main_window.visible, Equals(True))
70+ self.assertThat(shell.currentFocusedAppId, Equals("messaging-app"))
135 def test_can_launch_multiple_applications(self):
72 def test_can_launch_multiple_applications(self):
136 """A second application launched must be usable."""
73 """A second application launched must be usable."""
137− self.launch_unity()
74+ unity = self.launch_unity()
138 self.main_window.get_greeter().swipe()
75 self.main_window.get_greeter().swipe()
139− first_app = self._start_qml_script(self._get_qml_script("App1"))
140− second_app = self._start_qml_script(self._get_qml_script("App2"))
142− first_main_window = first_app.select_single(
77+ first_app = self.launch_test_application(
143− "QQuickRectangle",
78+ "messaging-app",
144− objectName="App1"
79+ "--desktop_file_hint="
80+ "/usr/share/applications/messaging-app.desktop",
81+ "--stage_hint=main_stage",
146− second_main_window = second_app.select_single(
84+
147− "QQuickRectangle",
85+ second_app = self.launch_test_application(
148− objectName="App2"
86+ "address-book-app",
87+ "--desktop_file_hint="
88+ "/usr/share/applications/address-book-app.desktop",
89+ "--stage_hint=main_stage",
151− import pdb; pdb.set_trace()
93+ shell = unity.select_single("Shell")
152− self.assertThat(first_main_window.visible, Equals(False))
154− self.assertThat(second_main_window.visible, Equals(True))
95+ # Required?
155− self.assertThat(
96+ self.assertThat(shell.currentFocusedAppId, NotEquals("messaging-app"))
156− second_main_window.select_single("Text").text,
97+ self.assertThat(shell.currentFocusedAppId, Equals("address-book-app"))
160 def test_app_moves_from_unfocused_to_focused(self):
99 def test_app_moves_from_unfocused_to_focused(self):
161 """An application that is in the unfocused state must be able to be
100 """An application that is in the unfocused state must be able to be
162 brought back to the focused state.
101 brought back to the focused state.
165− self.launch_unity()
104+ unity = self.launch_unity()
166 self.main_window.get_greeter().swipe()
105 self.main_window.get_greeter().swipe()
167− first_app = self._start_qml_script(self._get_qml_script("App1"))
168− self._start_qml_script(self._get_qml_script("App2"))
170− first_main_window = first_app.select_single(
107+ first_app = self.launch_test_application(
171− "QQuickRectangle",
108+ "messaging-app",
172− objectName="App1"
109+ "--desktop_file_hint="
110+ "/usr/share/applications/messaging-app.desktop",
111+ "--stage_hint=main_stage",
115+ second_app = self.launch_test_application(
117+ "--desktop_file_hint="
118+ "/usr/share/applications/address-book-app.desktop",
119+ "--stage_hint=main_stage",
175 self.swipe_from_right()
123 self.swipe_from_right()
177− self.assertThat(first_main_window.visible, Equals(True))
125+ shell = unity.select_single("Shell")
178 self.assertThat(
126 self.assertThat(
179− first_main_window.select_single("Text").text,
127+ shell.currentFocusedAppId,
180− Equals("App1")
128+ Eventually(Equals("messaging-app"))
183− # interact with it . . .
184− # self.assertThat(first_main_window.visible, Equals(True))