@@ -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)))