on xenial help sign in
moved greeter unlock code to a greeter emulator.
commitb928412a2104277e4420e5deabb805bf17e931ca authorThomi Richards <thomi.richards@canonical.com> dateMon 15 Jul 2013, 13:06 (13 years ago) parent2a00398
7 files changed+198−66
tests/autopilot/unity8/shell/emulators/__init__.py+7 tests/autopilot/unity8/shell/emulators/greeter.py+29 tests/autopilot/unity8/shell/emulators/main_window.py+5−1 tests/autopilot/unity8/shell/tests/__init__.py+3−1 tests/autopilot/unity8/shell/tests/test_hud.py+19−35 tests/autopilot/unity8/shell/tests/test_lock_screen.py+12−29 tests/autopilot/unity8/shell/tests/testhud.py+123
tests/autopilot/unity8/shell/emulators/__init__.py+7
@@ -4,3 +4,10 @@
44# This program is free software: you can redistribute it and/or modify it
55# under the terms of the GNU General Public License version 3, as published
66# by the Free Software Foundation.
7+
8+
9+from autopilot.introspection import CustomEmulatorBase
10+
11+
12+class Unity8EmulatorBase(CustomEmulatorBase):
13+ """A base class for all unity8 emulators."""
tests/autopilot/unity8/shell/emulators/greeter.pynew file+29
@@ -0,0 +1,29 @@
1+from unity8.shell.emulators import Unity8EmulatorBase
2+from autopilot.input import Touch
3+
4+
5+class Greeter(Unity8EmulatorBase):
6+
7+ """An emulator that understands the greeter screen."""
8+
9+ def unlock(self):
10+ """Swipe the greeter screen away."""
11+ self.created.wait_for(True)
12+ touch = Touch.create()
13+
14+ # TODO: Is this ever called? Find out, and maybe remove this branch:
15+ if self.multiUser:
16+ # this is borked!
17+ password_field = self.select_greeter_user("No Password")
18+ password_field.opacity.wait_for(1)
19+ touch.tap_object(password_field)
20+
21+ else:
22+ rect = self.globalRect
23+ start_x = rect[0] + rect[2] - 3
24+ start_y = int(rect[1] + rect[3] / 2)
25+ stop_x = int(rect[0] + rect[2] * 0.2)
26+ stop_y = start_y
27+ touch.drag(start_x, start_y, stop_x, stop_y)
28+
29+ self.created.wait_for(False)
tests/autopilot/unity8/shell/emulators/main_window.py+5−1
@@ -5,6 +5,10 @@
55# under the terms of the GNU General Public License version 3, as published
66# by the Free Software Foundation.
77
8+
9+from unity8.shell.emulators.greeter import Greeter
10+
11+
812class MainWindow(object):
913 """An emulator class that makes it easy to interact with the shell"""
1014
@@ -16,7 +20,7 @@ class MainWindow(object):
1620 return self.app.select_single("QQuickView")
1721
1822 def get_greeter(self):
19− return self.app.select_single("Greeter")
23+ return self.app.select_single(Greeter)
2024
2125 def get_greeter_content_loader(self):
2226 return self.app.select_single("QQuickLoader", objectName="greeterContentLoader")
tests/autopilot/unity8/shell/tests/__init__.py+3−1
@@ -18,6 +18,7 @@ import sysconfig
1818
1919from unity8 import get_lib_path, get_unity8_binary_path
2020from unity8.shell.emulators.main_window import MainWindow
21+from unity8.shell.emulators import Unity8EmulatorBase
2122
2223
2324logger = logging.getLogger(__name__)
@@ -57,7 +58,8 @@ class Unity8TestCase(AutopilotTestCase):
5758 app_proxy = self.launch_test_application(
5859 binary_path,
5960 "-fullscreen",
60− app_type='qt'
61+ app_type='qt',
62+ emulator_base=Unity8EmulatorBase,
6163 )
6264 logger.debug("Started unity8 shell, backend is: %r", app_proxy._Backend)
6365 self._set_proxy(app_proxy)
tests/autopilot/unity8/shell/tests/test_hud.py+19−35
@@ -25,24 +25,18 @@
2525
2626from __future__ import absolute_import
2727
28−from unity8.shell.tests import ShellTestCase, FormFactors
29−from unity8.shell.tests.helpers import TestShellHelpers
28+from unity8.shell.tests import Unity8TestCase
3029
31−from autopilot.input import Mouse, Touch, Pointer
32−from testtools.matchers import Equals, NotEquals, GreaterThan, MismatchError
30+from autopilot.input import Touch
31+from testtools.matchers import Equals, MismatchError
3332from autopilot.matchers import Eventually
3433from autopilot.display import Display
3534from autopilot.platform import model
3635
37−import unittest
38−import time
39−import os
40−from os import path
4136
37+class TestHud(Unity8TestCase):
4238
43−class TestHud(ShellTestCase, TestShellHelpers):
44−
45− """Tests the Shell"""
39+ """Tests the Shell HUD"""
4640
4741 # Scenarios:
4842 # Fill in the scenarios to run the whole test suite with multiple configurations.
@@ -50,32 +44,22 @@ class TestHud(ShellTestCase, TestShellHelpers):
5044 # Set app_width and app_height to 0 to use fullscreen.
5145 # Set grid_unit_px to 0 to use the current system environment.
5246
53− if model() == 'Desktop':
54− scenarios = [
55− ('Nexus 4', dict(app_width=768, app_height=1280, grid_unit_px=18, lightdm_mock="single")),
56− ('Nexus 10', dict(app_width=2560, app_height=1600, grid_unit_px=20, lightdm_mock="full")),
57−# TODO: don't run fullscreen tests just yet as the VM is performing too badly for that. Enable this once
58−# Autopilot tests are running on bear metal.
59−# ('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=10, lightdm_mock="full")),
60− ]
61− else:
62− scenarios = [
63− ('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=0, lightdm_mock="single")),
64− ]
65−
66− def setUp(self):
67− self.touch = Touch.create()
68−
69− sg = Display().create()
70− divisor = 1
71− while (sg.get_screen_width() < self.app_width / divisor or sg.get_screen_height() < self.app_height / divisor):
72− divisor = divisor * 2
73− super(TestHud, self).setUp("%sx%s" % (self.app_width / divisor, self.app_height / divisor), "%s" % (self.grid_unit_px / divisor))
74−
75− dash = self.main_window.get_dash()
76− self.assertThat(dash.showScopeOnLoaded, Eventually(Equals(""), timeout=30))
47+# if model() == 'Desktop':
48+# scenarios = [
49+# ('Nexus 4', dict(app_width=768, app_height=1280, grid_unit_px=18, lightdm_mock="single")),
50+# ('Nexus 10', dict(app_width=2560, app_height=1600, grid_unit_px=20, lightdm_mock="full")),
51+# # TODO: don't run fullscreen tests just yet as the VM is performing too badly for that. Enable this once
52+# # Autopilot tests are running on bear metal.
53+# # ('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=10, lightdm_mock="full")),
54+# ]
55+# else:
56+# scenarios = [
57+# ('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=0, lightdm_mock="single")),
58+# ]
59+
7760
7861 def test_show_hud(self):
62+ self.launch_unity()
7963 hud = self.main_window.get_hud()
8064 self.unlock_greeter()
8165 self.show_hud()
tests/autopilot/unity8/shell/tests/test_lock_screen.py+12−29
@@ -30,8 +30,9 @@ class TestLockscreen(Unity8TestCase):
3030 @with_lightdm_mock("single-pin")
3131 def test_can_unlock_pin_screen(self):
3232 """Must be able to unlock the PIN entry lock screen."""
33− self.app = self.launch_unity()
34− self._unlock_greeter()
33+ self.launch_unity()
34+ greeter = self.main_window.get_greeter()
35+ greeter.unlock()
3536
3637 lockscreen = self._wait_for_lockscreen()
3738 self._enter_pincode("1234")
@@ -42,8 +43,9 @@ class TestLockscreen(Unity8TestCase):
4243 @with_lightdm_mock("single-passphrase")
4344 def test_can_unlock_passphrase_screen(self):
4445 """Must be able to unlock the passphrase entry screen."""
45− self.app = self.launch_unity()
46− self._unlock_greeter()
46+ self.launch_unity()
47+ greeter = self.main_window.get_greeter()
48+ greeter.unlock()
4749
4850 lockscreen = self._wait_for_lockscreen()
4951 self._enter_passphrase("password")
@@ -53,8 +55,9 @@ class TestLockscreen(Unity8TestCase):
5355 @with_lightdm_mock("single-pin")
5456 def test_pin_screen_wrong_code(self):
5557 """Entering the wrong pin code must not dismiss the lock screen."""
56− self.app = self.launch_unity()
57− self._unlock_greeter()
58+ self.launch_unity()
59+ greeter = self.main_window.get_greeter()
60+ greeter.unlock()
5861
5962 lockscreen = self._wait_for_lockscreen()
6063 self._enter_pincode("4321")
@@ -67,8 +70,9 @@ class TestLockscreen(Unity8TestCase):
6770 @with_lightdm_mock("single-passphrase")
6871 def test_passphrase_screen_wrong_password(self):
6972 """Entering the wrong password must not dismiss the lock screen."""
70− self.app = self.launch_unity()
71− self._unlock_greeter()
73+ self.launch_unity()
74+ greeter = self.main_window.get_greeter()
75+ greeter.unlock()
7276
7377 lockscreen = self._wait_for_lockscreen()
7478 self._enter_passphrase("foobar")
@@ -77,27 +81,6 @@ class TestLockscreen(Unity8TestCase):
7781 self.assertThat(pinentryField.text, Eventually(Equals("")))
7882 self.assertThat(lockscreen.shown, Eventually(Equals(True)))
7983
80− def _unlock_greeter(self):
81− """Swipe the greeter out of the way."""
82− greeter = self.main_window.get_greeter()
83− self.assertThat(greeter.created, Eventually(Equals(True)))
84−
85− # TODO: Is this ever called? Find out, and maybe remove this branch:
86− if greeter.multiUser:
87− password_field = self.select_greeter_user("No Password")
88− self.assertThat(password_field.opacity, Eventually(Equals(1)))
89− self.touch.tap_object(password_field)
90−
91− else:
92− rect = greeter.globalRect
93− start_x = rect[0] + rect[2] - 3
94− start_y = int(rect[1] + rect[3] / 2)
95− stop_x = int(rect[0] + rect[2] * 0.2)
96− stop_y = start_y
97− self.touch.drag(start_x, start_y, stop_x, stop_y)
98−
99− self.assertThat(greeter.created, Eventually(Equals(False)))
100−
10184 def _wait_for_lockscreen(self):
10285 """Wait for the lock screen to load, and return it."""
10386 pinPadLoader = self.main_window.get_pinPadLoader();
tests/autopilot/unity8/shell/tests/testhud.pynew file+123
@@ -0,0 +1,123 @@
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2+# Copyright 2013 Canonical
3+#
4+# This program is free software: you can redistribute it and/or modify it
5+# under the terms of the GNU General Public License version 3, as published
6+# by the Free Software Foundation.
7+
8+
9+"""Tests for the Shell"""
10+
11+from __future__ import absolute_import
12+
13+from unity8.shell.tests import Unity8TestCase
14+
15+from autopilot.input import Touch
16+from testtools.matchers import Equals, MismatchError
17+from autopilot.matchers import Eventually
18+from autopilot.display import Display
19+
20+
21+class TestHud(Unity8TestCase):
22+
23+ """Tests the Shell HUD."""
24+
25+ # Scenarios:
26+ # Fill in the scenarios to run the whole test suite with multiple configurations.
27+ # Use app_width, app_height and grid_unit_px to set the apps geometry.
28+ # Set app_width and app_height to 0 to use fullscreen.
29+ # Set grid_unit_px to 0 to use the current system environment.
30+
31+# if model() == 'Desktop':
32+# scenarios = [
33+# ('Nexus 4', dict(app_width=768, app_height=1280, grid_unit_px=18, lightdm_mock="single")),
34+# ('Nexus 10', dict(app_width=2560, app_height=1600, grid_unit_px=20, lightdm_mock="full")),
35+# # TODO: don't run fullscreen tests just yet as the VM is performing too badly for that. Enable this once
36+# # Autopilot tests are running on bear metal.
37+# # ('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=10, lightdm_mock="full")),
38+# ]
39+# else:
40+# scenarios = [
41+# ('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=0, lightdm_mock="single")),
42+# ]
43+
44+ def setUp(self):
45+ self.touch = Touch.create()
46+
47+ sg = Display().create()
48+ divisor = 1
49+ while (sg.get_screen_width() < self.app_width / divisor or sg.get_screen_height() < self.app_height / divisor):
50+ divisor = divisor * 2
51+ super(TestHud, self).setUp("%sx%s" % (self.app_width / divisor, self.app_height / divisor), "%s" % (self.grid_unit_px / divisor))
52+
53+ dash = self.main_window.get_dash()
54+ self.assertThat(dash.showScopeOnLoaded, Eventually(Equals(""), timeout=30))
55+
56+ def test_show_hud(self):
57+ hud = self.main_window.get_hud()
58+ self.unlock_greeter()
59+ self.show_hud()
60+ self.assertThat(hud.shown, Eventually(Equals(True)))
61+
62+ def test_show_hud_button_dont_open(self):
63+ self.unlock_greeter()
64+ self.open_first_dash_home_app()
65+ hud_show_button = self.main_window.get_hud_show_button()
66+ hud = self.main_window.get_hud()
67+ window = self.main_window.get_qml_view()
68+ start_x = int(window.x + window.width / 2)
69+ start_y = window.y + window.height - 2
70+ self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
71+ self.touch.press(start_x, start_y)
72+ self.touch._finger_move(start_x, start_y - self.grid_size)
73+ self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
74+ self.touch._finger_move(start_x, start_y - self.grid_size * 2)
75+ self.touch._finger_move(start_x, start_y - self.grid_size * 3)
76+ self.touch._finger_move(start_x, start_y - self.grid_size * 4)
77+ self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
78+ self.assertThat(hud_show_button.mouseOver, Eventually(Equals(False)))
79+ self.touch._finger_move(start_x, start_y - self.grid_size * 34)
80+ self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
81+ self.assertThat(hud_show_button.mouseOver, Eventually(Equals(True)))
82+ self.touch._finger_move(start_x, start_y - self.grid_size)
83+ self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
84+ self.assertThat(hud_show_button.mouseOver, Eventually(Equals(False)))
85+ self.touch.release()
86+ self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
87+ self.assertThat(hud.shown, Eventually(Equals(False)))
88+
89+ def test_hide_hud_click(self):
90+ hud = self.main_window.get_hud()
91+ self.unlock_greeter()
92+ self.show_hud()
93+ self.close_hud_click()
94+ self.assertThat(hud.shown, Eventually(Equals(False)))
95+
96+ def test_hide_hud_click_outside_handle(self):
97+ hud = self.main_window.get_hud()
98+ self.unlock_greeter()
99+ self.show_hud()
100+ rect = hud.globalRect
101+ x = int(rect[0] + rect[2] / 2)
102+ y = rect[1] + hud.handleHeight + 1
103+ self.touch.tap(x, y)
104+ self.assertRaises(MismatchError, lambda: self.assertThat(hud.shown, Eventually(Equals(False), timeout=3)))
105+
106+ def test_hide_hud_dragging(self):
107+ hud = self.main_window.get_hud()
108+ self.unlock_greeter()
109+ self.show_hud()
110+ rect = hud.globalRect
111+ start_x = rect[0] + (rect[2] - rect[0]) / 2
112+ start_y = rect[1] + 1
113+ stop_x = start_x
114+ stop_y = start_y + (rect[3] - rect[1]) / 2
115+ self.touch.drag(start_x, start_y, stop_x, stop_y)
116+ self.assertThat(hud.shown, Eventually(Equals(False)))
117+
118+ def test_hide_hud_launcher(self):
119+ hud = self.main_window.get_hud()
120+ self.unlock_greeter()
121+ self.show_hud()
122+ self.show_launcher()
123+ self.assertThat(hud.shown, Eventually(Equals(False)))