on xenial help sign in
moved greeter unlock code to a greeter emulator.
b928412Thomi Richards
tests/autopilot/unity8/shell/emulators/__init__.py+7
@@ -4,3 +4,10 @@
4# This program is free software: you can redistribute it and/or modify it
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
5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.
6# 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 @@
5# under the terms of the GNU General Public License version 3, as published
5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.
6# by the Free Software Foundation.
7
7
8+
9+from unity8.shell.emulators.greeter import Greeter
10+
11+
8class MainWindow(object):
12class MainWindow(object):
9 """An emulator class that makes it easy to interact with the shell"""
13 """An emulator class that makes it easy to interact with the shell"""
10
14
@@ -16,7 +20,7 @@ class MainWindow(object):
16 return self.app.select_single("QQuickView")
20 return self.app.select_single("QQuickView")
17
21
18 def get_greeter(self):
22 def get_greeter(self):
19− return self.app.select_single("Greeter")
23+ return self.app.select_single(Greeter)
20
24
21 def get_greeter_content_loader(self):
25 def get_greeter_content_loader(self):
22 return self.app.select_single("QQuickLoader", objectName="greeterContentLoader")
26 return self.app.select_single("QQuickLoader", objectName="greeterContentLoader")
tests/autopilot/unity8/shell/tests/__init__.py+3−1
@@ -18,6 +18,7 @@ import sysconfig
18
18
19from unity8 import get_lib_path, get_unity8_binary_path
19from unity8 import get_lib_path, get_unity8_binary_path
20from unity8.shell.emulators.main_window import MainWindow
20from unity8.shell.emulators.main_window import MainWindow
21+from unity8.shell.emulators import Unity8EmulatorBase
21
22
22
23
23logger = logging.getLogger(__name__)
24logger = logging.getLogger(__name__)
@@ -57,7 +58,8 @@ class Unity8TestCase(AutopilotTestCase):
57 app_proxy = self.launch_test_application(
58 app_proxy = self.launch_test_application(
58 binary_path,
59 binary_path,
59 "-fullscreen",
60 "-fullscreen",
60− app_type='qt'
61+ app_type='qt',
62+ emulator_base=Unity8EmulatorBase,
61 )
63 )
62 logger.debug("Started unity8 shell, backend is: %r", app_proxy._Backend)
64 logger.debug("Started unity8 shell, backend is: %r", app_proxy._Backend)
63 self._set_proxy(app_proxy)
65 self._set_proxy(app_proxy)
tests/autopilot/unity8/shell/tests/test_hud.py+19−35
@@ -25,24 +25,18 @@
25
25
26from __future__ import absolute_import
26from __future__ import absolute_import
27
27
28−from unity8.shell.tests import ShellTestCase, FormFactors
28+from unity8.shell.tests import Unity8TestCase
29−from unity8.shell.tests.helpers import TestShellHelpers
30
29
31−from autopilot.input import Mouse, Touch, Pointer
30+from autopilot.input import Touch
32−from testtools.matchers import Equals, NotEquals, GreaterThan, MismatchError
31+from testtools.matchers import Equals, MismatchError
33from autopilot.matchers import Eventually
32from autopilot.matchers import Eventually
34from autopilot.display import Display
33from autopilot.display import Display
35from autopilot.platform import model
34from autopilot.platform import model
36
35
37−import unittest
38−import time
39−import os
40−from os import path
41
36
37+class TestHud(Unity8TestCase):
42
38
43−class TestHud(ShellTestCase, TestShellHelpers):
44−
45− """Tests the Shell"""
39+ """Tests the Shell HUD"""
46
40
47 # Scenarios:
41 # Scenarios:
48 # Fill in the scenarios to run the whole test suite with multiple configurations.
42 # Fill in the scenarios to run the whole test suite with multiple configurations.
@@ -50,32 +44,22 @@ class TestHud(ShellTestCase, TestShellHelpers):
50 # Set app_width and app_height to 0 to use fullscreen.
44 # Set app_width and app_height to 0 to use fullscreen.
51 # Set grid_unit_px to 0 to use the current system environment.
45 # Set grid_unit_px to 0 to use the current system environment.
52
46
53− if model() == 'Desktop':
47+# if model() == 'Desktop':
54− scenarios = [
48+# scenarios = [
55− ('Nexus 4', dict(app_width=768, app_height=1280, grid_unit_px=18, lightdm_mock="single")),
49+# ('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")),
50+# ('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
51+# # 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.
52+# # Autopilot tests are running on bear metal.
59−# ('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=10, lightdm_mock="full")),
53+# # ('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=10, lightdm_mock="full")),
60− ]
54+# ]
61− else:
55+# else:
62− scenarios = [
56+# scenarios = [
63− ('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=0, lightdm_mock="single")),
57+# ('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=0, lightdm_mock="single")),
64− ]
58+# ]
65−
59+
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))
77
60
78 def test_show_hud(self):
61 def test_show_hud(self):
62+ self.launch_unity()
79 hud = self.main_window.get_hud()
63 hud = self.main_window.get_hud()
80 self.unlock_greeter()
64 self.unlock_greeter()
81 self.show_hud()
65 self.show_hud()
tests/autopilot/unity8/shell/tests/test_lock_screen.py+12−29
@@ -30,8 +30,9 @@ class TestLockscreen(Unity8TestCase):
30 @with_lightdm_mock("single-pin")
30 @with_lightdm_mock("single-pin")
31 def test_can_unlock_pin_screen(self):
31 def test_can_unlock_pin_screen(self):
32 """Must be able to unlock the PIN entry lock screen."""
32 """Must be able to unlock the PIN entry lock screen."""
33− self.app = self.launch_unity()
33+ self.launch_unity()
34− self._unlock_greeter()
34+ greeter = self.main_window.get_greeter()
35+ greeter.unlock()
35
36
36 lockscreen = self._wait_for_lockscreen()
37 lockscreen = self._wait_for_lockscreen()
37 self._enter_pincode("1234")
38 self._enter_pincode("1234")
@@ -42,8 +43,9 @@ class TestLockscreen(Unity8TestCase):
42 @with_lightdm_mock("single-passphrase")
43 @with_lightdm_mock("single-passphrase")
43 def test_can_unlock_passphrase_screen(self):
44 def test_can_unlock_passphrase_screen(self):
44 """Must be able to unlock the passphrase entry screen."""
45 """Must be able to unlock the passphrase entry screen."""
45− self.app = self.launch_unity()
46+ self.launch_unity()
46− self._unlock_greeter()
47+ greeter = self.main_window.get_greeter()
48+ greeter.unlock()
47
49
48 lockscreen = self._wait_for_lockscreen()
50 lockscreen = self._wait_for_lockscreen()
49 self._enter_passphrase("password")
51 self._enter_passphrase("password")
@@ -53,8 +55,9 @@ class TestLockscreen(Unity8TestCase):
53 @with_lightdm_mock("single-pin")
55 @with_lightdm_mock("single-pin")
54 def test_pin_screen_wrong_code(self):
56 def test_pin_screen_wrong_code(self):
55 """Entering the wrong pin code must not dismiss the lock screen."""
57 """Entering the wrong pin code must not dismiss the lock screen."""
56− self.app = self.launch_unity()
58+ self.launch_unity()
57− self._unlock_greeter()
59+ greeter = self.main_window.get_greeter()
60+ greeter.unlock()
58
61
59 lockscreen = self._wait_for_lockscreen()
62 lockscreen = self._wait_for_lockscreen()
60 self._enter_pincode("4321")
63 self._enter_pincode("4321")
@@ -67,8 +70,9 @@ class TestLockscreen(Unity8TestCase):
67 @with_lightdm_mock("single-passphrase")
70 @with_lightdm_mock("single-passphrase")
68 def test_passphrase_screen_wrong_password(self):
71 def test_passphrase_screen_wrong_password(self):
69 """Entering the wrong password must not dismiss the lock screen."""
72 """Entering the wrong password must not dismiss the lock screen."""
70− self.app = self.launch_unity()
73+ self.launch_unity()
71− self._unlock_greeter()
74+ greeter = self.main_window.get_greeter()
75+ greeter.unlock()
72
76
73 lockscreen = self._wait_for_lockscreen()
77 lockscreen = self._wait_for_lockscreen()
74 self._enter_passphrase("foobar")
78 self._enter_passphrase("foobar")
@@ -77,27 +81,6 @@ class TestLockscreen(Unity8TestCase):
77 self.assertThat(pinentryField.text, Eventually(Equals("")))
81 self.assertThat(pinentryField.text, Eventually(Equals("")))
78 self.assertThat(lockscreen.shown, Eventually(Equals(True)))
82 self.assertThat(lockscreen.shown, Eventually(Equals(True)))
79
83
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−
101 def _wait_for_lockscreen(self):
84 def _wait_for_lockscreen(self):
102 """Wait for the lock screen to load, and return it."""
85 """Wait for the lock screen to load, and return it."""
103 pinPadLoader = self.main_window.get_pinPadLoader();
86 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)))