on xenial help sign in
Initial tests using default installed apps not qmlscene (as it's not showing up anymore).
commit536be7bbdfd778fb401f4d6b10de005b18038e66 authorChristopher Lee <chris.lee@canonical.com> dateThu 12 Sep 2013, 16:41 (13 years ago) parentc468e0d
1 file changed+55−110
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+55−110
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+55−110
@@ -21,17 +21,13 @@
2121
2222from __future__ import absolute_import
2323
24−import logging
25−from textwrap import dedent
26−import os
27−from tempfile import mktemp
28−
24+from autopilot.matchers import Eventually
2925from autopilot.platform import model
3026
31−from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
27+import logging
3228
3329from testtools.matchers import Equals, NotEquals
34−
30+from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
3531
3632logger = logging.getLogger(__name__)
3733
@@ -46,139 +42,88 @@ class ApplicationLifecycleTests(UnityTestCase):
4642 self.skipTest("Test must be run on a device.")
4743
4844 def swipe_from_right(self):
49− x, y, w, h = self.main_window.globalRect
50− start_x = w
51− start_y = int(h / 2)
52− end_x = int(w / 2)
45+ qml_view = self.main_window.get_qml_view()
46+ width = qml_view.width
47+ height = qml_view.height
48+ start_x = width
49+ start_y = int(height/2)
50+ end_x = int(width/2)
5351 end_y = start_y
5452
5553 self.touch.drag(start_x, start_y, end_x, end_y)
5654
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−
12055 def test_can_launch_application(self):
12156 """must be able to launch and interact with an application."""
122− self.launch_unity()
57+ unity = self.launch_unity()
12358 self.main_window.get_greeter().swipe()
12459
125− test_qml = self._get_qml_script("TestApp")
126− app = self._start_qml_script(test_qml)
127− main_window = app.select_single(
128− "QQuickRectangle",
129− objectName="TestApp"
60+ app = self.launch_test_application(
61+ "messaging-app",
62+ "--desktop_file_hint="
63+ "/usr/share/applications/messaging-app.desktop",
64+ "--stage_hint=main_stage",
65+ app_type='qt'
13066 )
67+ shell = unity.select_single("Shell")
13168
132− self.assertThat(main_window, NotEquals(None))
133− self.assertThat(main_window.visible, Equals(True))
69+ self.assertThat(app, NotEquals(None))
70+ self.assertThat(shell.currentFocusedAppId, Equals("messaging-app"))
13471
13572 def test_can_launch_multiple_applications(self):
13673 """A second application launched must be usable."""
137− self.launch_unity()
74+ unity = self.launch_unity()
13875 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"))
14176
142− first_main_window = first_app.select_single(
143− "QQuickRectangle",
144− objectName="App1"
77+ first_app = self.launch_test_application(
78+ "messaging-app",
79+ "--desktop_file_hint="
80+ "/usr/share/applications/messaging-app.desktop",
81+ "--stage_hint=main_stage",
82+ app_type='qt'
14583 )
146− second_main_window = second_app.select_single(
147− "QQuickRectangle",
148− objectName="App2"
84+
85+ second_app = self.launch_test_application(
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'
14991 )
15092
151− import pdb; pdb.set_trace()
152− self.assertThat(first_main_window.visible, Equals(False))
93+ shell = unity.select_single("Shell")
15394
154− self.assertThat(second_main_window.visible, Equals(True))
155− self.assertThat(
156− second_main_window.select_single("Text").text,
157− Equals("App2")
158− )
95+ # Required?
96+ self.assertThat(shell.currentFocusedAppId, NotEquals("messaging-app"))
97+ self.assertThat(shell.currentFocusedAppId, Equals("address-book-app"))
15998
16099 def test_app_moves_from_unfocused_to_focused(self):
161100 """An application that is in the unfocused state must be able to be
162101 brought back to the focused state.
163102
164103 """
165− self.launch_unity()
104+ unity = self.launch_unity()
166105 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"))
169106
170− first_main_window = first_app.select_single(
171− "QQuickRectangle",
172− objectName="App1"
107+ first_app = self.launch_test_application(
108+ "messaging-app",
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'
173121 )
174122
175123 self.swipe_from_right()
176124
177− self.assertThat(first_main_window.visible, Equals(True))
125+ shell = unity.select_single("Shell")
178126 self.assertThat(
179− first_main_window.select_single("Text").text,
180− Equals("App1")
127+ shell.currentFocusedAppId,
128+ Eventually(Equals("messaging-app"))
181129 )
182−
183− # interact with it . . .
184− # self.assertThat(first_main_window.visible, Equals(True))