1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2013 Canonical
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.
9
# This file contains general purpose test cases for Unity.
10
# Each test written in this file will be executed for a variety of
11
# configurations, such as Phone, Tablet or Desktop form factors.
13
# Sometimes there is the need to disable a certain test for a particular
14
# configuration. To do so, add this in a new line directly below your test:
16
# test_testname.blacklist = (FormFactors.Tablet, FormFactors.Desktop,)
18
# Available form factors are:
24
"""Tests for the Shell"""
26
from __future__ import absolute_import
28
from unity8.tests import ShellTestCase, FormFactors
29
from unity8.tests.helpers import TestShellHelpers
31
from autopilot.input import Mouse, Touch, Pointer
32
from testtools.matchers import Equals, NotEquals, GreaterThan, MismatchError
33
from autopilot.matchers import Eventually
34
from autopilot.display import Display
35
from autopilot.platform import model
43
class TestShell(ShellTestCase, TestShellHelpers):
48
# Fill in the scenarios to run the whole test suite with multiple configurations.
49
# Use app_width, app_height and grid_unit_px to set the apps geometry.
50
# Set app_width and app_height to 0 to use fullscreen.
51
# Set grid_unit_px to 0 to use the current system environment.
53
if model() == 'Desktop':
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")),
63
('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=0, lightdm_mock="single")),
67
self.touch = Touch.create()
69
sg = Display().create()
71
while (sg.get_screen_width() < self.app_width / divisor or sg.get_screen_height() < self.app_height / divisor):
73
super(TestShell, self).setUp("%sx%s" % (self.app_width / divisor, self.app_height / divisor), "%s" % (self.grid_unit_px / divisor))
75
dash = self.main_window.get_dash()
76
self.assertThat(dash.showLensOnLoaded, Eventually(Equals(""), timeout=30))
78
def test_show_hud(self):
79
hud = self.main_window.get_hud()
82
self.assertThat(hud.shown, Eventually(Equals(True)))
84
def test_show_hud_button_dont_open(self):
86
self.open_first_dash_home_app()
87
hud_show_button = self.main_window.get_hud_show_button()
88
hud = self.main_window.get_hud()
89
window = self.main_window.get_qml_view()
90
start_x = int(window.x + window.width / 2)
91
start_y = window.y + window.height - 2
92
self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
93
self.touch.press(start_x, start_y)
94
self.touch._finger_move(start_x, start_y - self.grid_size)
95
self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
96
self.touch._finger_move(start_x, start_y - self.grid_size * 2)
97
self.touch._finger_move(start_x, start_y - self.grid_size * 3)
98
self.touch._finger_move(start_x, start_y - self.grid_size * 4)
99
self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
100
self.assertThat(hud_show_button.mouseOver, Eventually(Equals(False)))
101
self.touch._finger_move(start_x, start_y - self.grid_size * 34)
102
self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
103
self.assertThat(hud_show_button.mouseOver, Eventually(Equals(True)))
104
self.touch._finger_move(start_x, start_y - self.grid_size)
105
self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
106
self.assertThat(hud_show_button.mouseOver, Eventually(Equals(False)))
108
self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
109
self.assertThat(hud.shown, Eventually(Equals(False)))
111
def test_hide_hud_click(self):
112
hud = self.main_window.get_hud()
113
self.unlock_greeter()
115
self.close_hud_click()
116
self.assertThat(hud.shown, Eventually(Equals(False)))
118
def test_hide_hud_click_outside_handle(self):
119
hud = self.main_window.get_hud()
120
self.unlock_greeter()
122
rect = hud.globalRect
123
x = int(rect[0] + rect[2] / 2)
124
y = rect[1] + hud.handleHeight + 1
126
self.assertRaises(MismatchError, lambda: self.assertThat(hud.shown, Eventually(Equals(False), timeout=3)))
128
def test_hide_hud_dragging(self):
129
hud = self.main_window.get_hud()
130
self.unlock_greeter()
132
rect = hud.globalRect
133
start_x = rect[0] + (rect[2] - rect[0]) / 2
134
start_y = rect[1] + 1
136
stop_y = start_y + (rect[3] - rect[1]) / 2
137
self.touch.drag(start_x, start_y, stop_x, stop_y)
138
self.assertThat(hud.shown, Eventually(Equals(False)))
140
def test_hide_hud_launcher(self):
141
hud = self.main_window.get_hud()
142
self.unlock_greeter()
145
self.assertThat(hud.shown, Eventually(Equals(False)))