on xenial help sign in
Initial tests using default installed apps not qmlscene (as it's not showing up anymore).
536be7bChristopher Lee
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+55−110
@@ -21,17 +21,13 @@
21
21
22from __future__ import absolute_import
22from __future__ import absolute_import
23
23
24−import logging
24+from autopilot.matchers import Eventually
25−from textwrap import dedent
26−import os
27−from tempfile import mktemp
28−
29from autopilot.platform import model
25from autopilot.platform import model
30
26
31−from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
27+import logging
32
28
33from testtools.matchers import Equals, NotEquals
29from testtools.matchers import Equals, NotEquals
34−
30+from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
35
31
36logger = logging.getLogger(__name__)
32logger = logging.getLogger(__name__)
37
33
@@ -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.")
47
43
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
54
52
55 self.touch.drag(start_x, start_y, end_x, end_y)
53 self.touch.drag(start_x, start_y, end_x, end_y)
56
54
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)
62−
63− desktop_file = self._get_dummy_desktop_file()
64−
65− return self.launch_test_application(
66− "qmlscene",
67− qml_path,
68− "--desktop_file_hint=%s" % desktop_file,
69− app_type='qt',
70− )
71−
72− def _get_dummy_desktop_file(self):
73− """Create a temp desktop file with app name *app_name*.
74−
75− Returns the full path to the file.
76−
77− """
78− file_path = mktemp(suffix='.desktop')
79− script_contents = dedent(
80−"""[Desktop Entry]
81−Name=App1
82−Comment=My project description
83−Exec=true
84−Icon=qmlscene
85−Terminal=false
86−Type=Application
87−X-Ubuntu-Touch=true""")
88− open(file_path, 'w').write(script_contents)
89− self.addCleanup(os.remove, file_path)
90−
91− print ">>> file path: ", file_path
92− return file_path
93−
94− # def _get_qml_script(self, title="Test App"):
95− # return dedent("""
96− # import QtQuick 2.0
97− # import Ubuntu.Components 0.1
98−
99− # Page {
100− # title: "%s"
101− # width: units.gu(48)
102− # height: units.gu(60)
103− # }
104− # """ % title)
105− def _get_qml_script(self, name="TestApp"):
106− return dedent("""
107− import QtQuick 2.0
108− import Ubuntu.Components 0.1
109−
110− Rectangle {
111− objectName: "%s"
112− color: "lightblue"
113− Text {
114− text: "%s"
115− font.pixelSize: units.gu(8)
116− }
117− }
118− """ % (name, name))
119−
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()
124
59
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",
65+ app_type='qt'
130 )
66 )
67+ shell = unity.select_single("Shell")
131
68
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"))
134
71
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"))
141
76
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",
82+ app_type='qt'
145 )
83 )
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",
90+ app_type='qt'
149 )
91 )
150
92
151− import pdb; pdb.set_trace()
93+ shell = unity.select_single("Shell")
152− self.assertThat(first_main_window.visible, Equals(False))
153
94
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"))
157− Equals("App2")
158− )
159
98
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.
163
102
164 """
103 """
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"))
169
106
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",
112+ app_type='qt'
113+ )
114+
115+ second_app = self.launch_test_application(
116+ "address-book-app",
117+ "--desktop_file_hint="
118+ "/usr/share/applications/address-book-app.desktop",
119+ "--stage_hint=main_stage",
120+ app_type='qt'
173 )
121 )
174
122
175 self.swipe_from_right()
123 self.swipe_from_right()
176
124
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"))
181 )
129 )
182−
183− # interact with it . . .
184− # self.assertThat(first_main_window.visible, Equals(True))