Lomiri
Loading...
Searching...
No Matches
test_application_lifecycle.py
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
3# Lomiri Autopilot Test Suite
4# Copyright (C) 2013, 2014, 2015 Canonical Ltd.
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"""Tests for the application lifecycle."""
21
22import logging
23import os
24import threading
25
26from autopilot.platform import model
27from autopilot.application import _launcher
28
29from lomiri import process_helpers
30from lomiri.application_lifecycle import tests
31
32
33logger = logging.getLogger(__name__)
34
35
36class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
37
38 def setUp(self):
39 if model() == 'Desktop':
40 self.skipTest('Test cannot be run on the desktop.')
41 super().setUp()
42
43 def swipe_screen_from_right(self):
44 width = self.main_window.width
45 height = self.main_window.height
46 start_x = width
47 start_y = int(height/2)
48 end_x = int(width*3/4)
49 end_y = start_y
50
51 logger.info("Swiping screen from the right edge")
52 self.main_window.pointing_device.drag(start_x, start_y, end_x, end_y)
53
54 def launch_fake_app(self):
55 _, desktop_file_path = self.create_test_application()
56 desktop_file_name = os.path.basename(desktop_file_path)
57 application_name, _ = os.path.splitext(desktop_file_name)
58 self.launch_upstart_application(application_name)
59 return application_name
60
61 def test_can_launch_application(self):
62 """Must be able to launch an application."""
63 application_name = self.launch_fake_app()
64 self.assert_current_focused_application(application_name)
65
66 def test_can_launch_multiple_applications(self):
67 """A second application launched must be focused."""
68 application1_name = self.launch_fake_app()
69 self.assert_current_focused_application(application1_name)
70
71 application2_name = self.launch_fake_app()
72 self.assertFalse(application1_name == application2_name)
73 self.assert_current_focused_application(application2_name)
74
75 def test_app_moves_from_unfocused_to_focused(self):
76 """An application that is in the unfocused state must be able to be
77 brought back to the focused state.
78
79 """
80 application1_name = self.launch_fake_app()
81 self.assert_current_focused_application(application1_name)
82
83 application2_name = self.launch_fake_app()
84 self.assertFalse(application1_name == application2_name)
85 self.assert_current_focused_application(application2_name)
86
87 self.swipe_screen_from_right()
88
89 self.assert_current_focused_application(application1_name)
90
91 def test_greeter_hides_on_app_open(self):
92 """Greeter should hide when an app is opened"""
93 process_helpers.lock_lomiri()
94
95 # FIXME - this is because the device greeter uses a password.
96 # Need to be able to selectively enable mocks so that we can use the
97 # fake greeter.
98 def unlock_thread_worker(greeter):
99 greeter.wait_swiped_away()
100 process_helpers.unlock_lomiri()
101 greeter.created.wait_for(False)
102
103 greeter = self.main_window.get_greeter()
104 unlock_thread = threading.Thread(
105 target=unlock_thread_worker, args=(greeter,))
106 unlock_thread.start()
107 application_name = self.launch_fake_app()
108 unlock_thread.join(10)
109
110 self.assert_current_focused_application(application_name)
111
112 def test_greeter_hides_on_app_focus(self):
113 """Greeter should hide when an app is re-focused"""
114 application_name = self.launch_fake_app()
115 self.assert_current_focused_application(application_name)
116
117 self.main_window.show_dash_swiping()
118 self.assert_current_focused_application('lomiri-dash')
119
120 process_helpers.lock_lomiri()
121
122 self.launch_upstart_application(application_name, [], _launcher.AlreadyLaunchedUpstartLauncher)
123 greeter = self.main_window.get_greeter()
124 greeter.wait_swiped_away()
125 process_helpers.unlock_lomiri()
126 self.assert_current_focused_application(application_name)
127
128 def test_click_dash_icon_must_unfocus_application(self):
129 application_name = self.launch_fake_app()
130 self.assert_current_focused_application(application_name)
131
132 self.main_window.show_dash_from_launcher()
133
134 self.assert_current_focused_application('lomiri-dash')
135
136 def test_click_app_icon_on_dash_must_focus_it(self):
137 application_name = self.launch_fake_app()
138 self.main_window.show_dash_from_launcher()
139
140 self.main_window.launch_application(application_name)
141 self.assert_current_focused_application(application_name)