on xenial help sign in
Test application life cycle with fake apps, instead of messaging and address book.
5b24052Leo Arias
tests/autopilot/unity8/application_lifecycle/tests/__init__.py+46
@@ -0,0 +1,46 @@
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+from ubuntuuitoolkit import fixture_setup
23+
24+from unity8 import process_helpers
25+from unity8.shell import tests
26+
27+
28+class ApplicationLifeCycleTestCase(tests.UnityTestCase):
29+
30+ def setUp(self):
31+ super(ApplicationLifeCycleTestCase, self).setUp()
32+ self._qml_mock_enabled = False
33+ self._data_dirs_mock_enabled = False
34+ unity_proxy = self.launch_unity()
35+ process_helpers.unlock_unity(unity_proxy)
36+
37+ def create_test_application(self):
38+ fake_application = fixture_setup.FakeApplication()
39+ self.useFixture(fake_application)
40+ return (
41+ fake_application.qml_file_path, fake_application.desktop_file_path)
42+
43+ def assert_current_focused_application(self, application_name):
44+ self.assertThat(
45+ self.main_window.get_current_focused_app_id,
46+ Eventually(Equals(application_name)))
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+28−73
@@ -21,27 +21,23 @@
21
21
22from __future__ import absolute_import
22from __future__ import absolute_import
23
23
24−from unity8.process_helpers import unlock_unity
24+import logging
25−from unity8.shell import disable_qml_mocking
25+import os
26−from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
27
26
28−from autopilot.matchers import Eventually
29from autopilot.platform import model
27from autopilot.platform import model
30−from testtools.matchers import Equals, NotEquals
31
28
32−import logging
29+from unity8.application_lifecycle import tests
33
30
34−logger = logging.getLogger(__name__)
35
31
32+logger = logging.getLogger(__name__)
36
33
37−class ApplicationLifecycleTests(UnityTestCase):
38
34
39− scenarios = _get_device_emulation_scenarios()
35+class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
40
36
41 def setUp(self):
37 def setUp(self):
38+ if model() == 'Desktop':
39+ self.skipTest('Test cannot be run on the desktop.')
42 super(ApplicationLifecycleTests, self).setUp()
40 super(ApplicationLifecycleTests, self).setUp()
43− if model() == "Desktop":
44− self.skipTest("Test cannot be run on the desktop.")
45
41
46 def swipe_screen_from_right(self):
42 def swipe_screen_from_right(self):
47 width = self.main_window.width
43 width = self.main_window.width
@@ -54,80 +50,39 @@ class ApplicationLifecycleTests(UnityTestCase):
54 logger.info("Swiping screen from the right edge")
50 logger.info("Swiping screen from the right edge")
55 self.touch.drag(start_x, start_y, end_x, end_y)
51 self.touch.drag(start_x, start_y, end_x, end_y)
56
52
57− def _launch_app(self, app_name):
53+ def launch_fake_app(self):
58− """Launches the application *app_name*
54+ _, desktop_file_path = self.create_test_application()
59−
55+ desktop_file_name = os.path.basename(desktop_file_path)
60− Assumes that the desktop file resides at:
56+ application_name, _ = os.path.splitext(desktop_file_name)
61− /usr/share/applications/{app_name}.desktop
57+ self.launch_upstart_application(application_name)
58+ return application_name
62
59
63− """
64− desktop_file = "--desktop_file_hint="\
65− "/usr/share/applications/{app_name}.desktop".format(
66− app_name=app_name
67− )
68− return self.launch_test_application(
69− app_name,
70− desktop_file,
71− "--stage_hint=main_stage",
72− app_type='qt'
73− )
74−
75− @disable_qml_mocking
76 def test_can_launch_application(self):
60 def test_can_launch_application(self):
77 """Must be able to launch an application."""
61 """Must be able to launch an application."""
78− unity_proxy = self.launch_unity()
62+ application_name = self.launch_fake_app()
79− unlock_unity(unity_proxy)
63+ self.assert_current_focused_application(application_name)
80
64
81− app = self._launch_app("messaging-app")
82−
83− self.assertThat(app, NotEquals(None))
84− self.assertThat(
85− self.main_window.get_current_focused_app_id(),
86− Eventually(Equals("messaging-app"))
87− )
88−
89− @disable_qml_mocking
90 def test_can_launch_multiple_applications(self):
65 def test_can_launch_multiple_applications(self):
91 """A second application launched must be focused."""
66 """A second application launched must be focused."""
92− unity_proxy = self.launch_unity()
67+ application1_name = self.launch_fake_app()
93− unlock_unity(unity_proxy)
68+ self.assert_current_focused_application(application1_name)
94−
69+
95− self._launch_app("messaging-app")
70+ application2_name = self.launch_fake_app()
96− self.assertThat(
71+ self.assertFalse(application1_name == application2_name)
97− self.main_window.get_current_focused_app_id(),
72+ self.assert_current_focused_application(application2_name)
98− Eventually(Equals("messaging-app"))
73+
99− )
100−
101− self._launch_app("address-book-app")
102− self.assertThat(
103− self.main_window.get_current_focused_app_id(),
104− Eventually(Equals("address-book-app"))
105− )
106−
107− @disable_qml_mocking
108 def test_app_moves_from_unfocused_to_focused(self):
74 def test_app_moves_from_unfocused_to_focused(self):
109 """An application that is in the unfocused state must be able to be
75 """An application that is in the unfocused state must be able to be
110 brought back to the focused state.
76 brought back to the focused state.
111
77
112 """
78 """
113− unity_proxy = self.launch_unity()
79+ application1_name = self.launch_fake_app()
114− unlock_unity(unity_proxy)
80+ self.assert_current_focused_application(application1_name)
115−
116− self._launch_app("messaging-app")
117− self.assertThat(
118− self.main_window.get_current_focused_app_id(),
119− Eventually(Equals("messaging-app"))
120− )
121
81
122− self._launch_app("address-book-app")
82+ application2_name = self.launch_fake_app()
123− self.assertThat(
83+ self.assertFalse(application1_name == application2_name)
124− self.main_window.get_current_focused_app_id(),
84+ self.assert_current_focused_application(application2_name)
125− Eventually(Equals("address-book-app"))
126− )
127
85
128 self.swipe_screen_from_right()
86 self.swipe_screen_from_right()
129
87
130− self.assertThat(
88+ self.assert_current_focused_application(application1_name)
131− self.main_window.get_current_focused_app_id(),
132− Eventually(Equals("messaging-app"))
133− )
tests/autopilot/unity8/application_lifecycle/tests/test_url_dispatcher.py+5−38
@@ -23,46 +23,16 @@ import os
23import subprocess
23import subprocess
24
24
25from autopilot import platform
25from autopilot import platform
26−from autopilot.matchers import Eventually
27−from testtools.matchers import Equals
28−from ubuntuuitoolkit import fixture_setup
29
26
30−from unity8 import process_helpers
27+from unity8.application_lifecycle import tests
31−from unity8.shell import tests
32
28
33
29
34−class URLDispatcherTestCase(tests.UnityTestCase):
30+class URLDispatcherTestCase(tests.ApplicationLifeCycleTestCase):
35−
36− scenarios = tests._get_device_emulation_scenarios()
37−
38− test_qml = ("""
39−import QtQuick 2.0
40−import Ubuntu.Components 0.1
41−
42−MainView {
43− width: units.gu(48)
44− height: units.gu(60)
45−
46− Label {
47− text: 'Test application.'
48− }
49−}
50−""")
51
31
52 def setUp(self):
32 def setUp(self):
53 if platform.model() == 'Desktop':
33 if platform.model() == 'Desktop':
54 self.skipTest("URL dispatcher doesn't work on the desktop.")
34 self.skipTest("URL dispatcher doesn't work on the desktop.")
55 super(URLDispatcherTestCase, self).setUp()
35 super(URLDispatcherTestCase, self).setUp()
56− self._qml_mock_enabled = False
57− self._data_dirs_mock_enabled = False
58− unity_proxy = self.launch_unity()
59− process_helpers.unlock_unity(unity_proxy)
60−
61− def create_test_application(self):
62− fake_application = fixture_setup.FakeApplication(self.test_qml)
63− self.useFixture(fake_application)
64− return (
65− fake_application.qml_file_path, fake_application.desktop_file_path)
66
36
67 def test_swipe_out_application_started_by_url_dispatcher(self):
37 def test_swipe_out_application_started_by_url_dispatcher(self):
68 _, desktop_file_path = self.create_test_application()
38 _, desktop_file_path = self.create_test_application()
@@ -71,13 +41,10 @@ MainView {
71
41
72 self.assertEqual('', self.main_window.get_current_focused_app_id())
42 self.assertEqual('', self.main_window.get_current_focused_app_id())
73 self.addCleanup(os.system, 'pkill qmlscene')
43 self.addCleanup(os.system, 'pkill qmlscene')
44+
74 subprocess.check_call(
45 subprocess.check_call(
75 ['url-dispatcher', 'application:///{}'.format(desktop_file_name)])
46 ['url-dispatcher', 'application:///{}'.format(desktop_file_name)])
76− self.assertThat(
47+ self.assert_current_focused_application(application_name)
77− self.main_window.get_current_focused_app_id,
78− Eventually(Equals(application_name)))
79
48
80 self.main_window.show_dash_swiping()
49 self.main_window.show_dash_swiping()
81− self.assertThat(
50+ self.assert_current_focused_application('')
82− self.main_window.get_current_focused_app_id,
83− Eventually(Equals('')))