on xenial help sign in
Test application life cycle with fake apps, instead of messaging and address book.
commit5b24052827d7c67ac512ba132ee143fb8d331a5a authorLeo Arias <leo.arias@canonical.com> dateTue 15 Apr 2014, 12:46 (13 years ago) parentc5cc48e46e08ae
3 files changed+79−111
tests/autopilot/unity8/application_lifecycle/tests/__init__.py+46 tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+28−73 tests/autopilot/unity8/application_lifecycle/tests/test_url_dispatcher.py+5−38
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 @@
2121
2222from __future__ import absolute_import
2323
24−from unity8.process_helpers import unlock_unity
25−from unity8.shell import disable_qml_mocking
26−from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
24+import logging
25+import os
2726
28−from autopilot.matchers import Eventually
2927from autopilot.platform import model
30−from testtools.matchers import Equals, NotEquals
3128
32−import logging
29+from unity8.application_lifecycle import tests
3330
34−logger = logging.getLogger(__name__)
3531
32+logger = logging.getLogger(__name__)
3633
37−class ApplicationLifecycleTests(UnityTestCase):
3834
39− scenarios = _get_device_emulation_scenarios()
35+class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
4036
4137 def setUp(self):
38+ if model() == 'Desktop':
39+ self.skipTest('Test cannot be run on the desktop.')
4240 super(ApplicationLifecycleTests, self).setUp()
43− if model() == "Desktop":
44− self.skipTest("Test cannot be run on the desktop.")
4541
4642 def swipe_screen_from_right(self):
4743 width = self.main_window.width
@@ -54,80 +50,39 @@ class ApplicationLifecycleTests(UnityTestCase):
5450 logger.info("Swiping screen from the right edge")
5551 self.touch.drag(start_x, start_y, end_x, end_y)
5652
57− def _launch_app(self, app_name):
58− """Launches the application *app_name*
59−
60− Assumes that the desktop file resides at:
61− /usr/share/applications/{app_name}.desktop
53+ def launch_fake_app(self):
54+ _, desktop_file_path = self.create_test_application()
55+ desktop_file_name = os.path.basename(desktop_file_path)
56+ application_name, _ = os.path.splitext(desktop_file_name)
57+ self.launch_upstart_application(application_name)
58+ return application_name
6259
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
7660 def test_can_launch_application(self):
7761 """Must be able to launch an application."""
78− unity_proxy = self.launch_unity()
79− unlock_unity(unity_proxy)
62+ application_name = self.launch_fake_app()
63+ self.assert_current_focused_application(application_name)
8064
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
9065 def test_can_launch_multiple_applications(self):
9166 """A second application launched must be focused."""
92− unity_proxy = self.launch_unity()
93− unlock_unity(unity_proxy)
94−
95− self._launch_app("messaging-app")
96− self.assertThat(
97− self.main_window.get_current_focused_app_id(),
98− Eventually(Equals("messaging-app"))
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
67+ application1_name = self.launch_fake_app()
68+ self.assert_current_focused_application(application1_name)
69+
70+ application2_name = self.launch_fake_app()
71+ self.assertFalse(application1_name == application2_name)
72+ self.assert_current_focused_application(application2_name)
73+
10874 def test_app_moves_from_unfocused_to_focused(self):
10975 """An application that is in the unfocused state must be able to be
11076 brought back to the focused state.
11177
11278 """
113− unity_proxy = self.launch_unity()
114− unlock_unity(unity_proxy)
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− )
79+ application1_name = self.launch_fake_app()
80+ self.assert_current_focused_application(application1_name)
12181
122− self._launch_app("address-book-app")
123− self.assertThat(
124− self.main_window.get_current_focused_app_id(),
125− Eventually(Equals("address-book-app"))
126− )
82+ application2_name = self.launch_fake_app()
83+ self.assertFalse(application1_name == application2_name)
84+ self.assert_current_focused_application(application2_name)
12785
12886 self.swipe_screen_from_right()
12987
130− self.assertThat(
131− self.main_window.get_current_focused_app_id(),
132− Eventually(Equals("messaging-app"))
133− )
88+ self.assert_current_focused_application(application1_name)
tests/autopilot/unity8/application_lifecycle/tests/test_url_dispatcher.py+5−38
@@ -23,46 +23,16 @@ import os
2323import subprocess
2424
2525from autopilot import platform
26−from autopilot.matchers import Eventually
27−from testtools.matchers import Equals
28−from ubuntuuitoolkit import fixture_setup
2926
30−from unity8 import process_helpers
31−from unity8.shell import tests
27+from unity8.application_lifecycle import tests
3228
3329
34−class URLDispatcherTestCase(tests.UnityTestCase):
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−""")
30+class URLDispatcherTestCase(tests.ApplicationLifeCycleTestCase):
5131
5232 def setUp(self):
5333 if platform.model() == 'Desktop':
5434 self.skipTest("URL dispatcher doesn't work on the desktop.")
5535 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)
6636
6737 def test_swipe_out_application_started_by_url_dispatcher(self):
6838 _, desktop_file_path = self.create_test_application()
@@ -71,13 +41,10 @@ MainView {
7141
7242 self.assertEqual('', self.main_window.get_current_focused_app_id())
7343 self.addCleanup(os.system, 'pkill qmlscene')
44+
7445 subprocess.check_call(
7546 ['url-dispatcher', 'application:///{}'.format(desktop_file_name)])
76− self.assertThat(
77− self.main_window.get_current_focused_app_id,
78− Eventually(Equals(application_name)))
47+ self.assert_current_focused_application(application_name)
7948
8049 self.main_window.show_dash_swiping()
81− self.assertThat(
82− self.main_window.get_current_focused_app_id,
83− Eventually(Equals('')))
50+ self.assert_current_focused_application('')