~macslow/unity8/fix-1475678

« back to all changes in this revision

Viewing changes to tests/autopilot/unity8/tests/testcases.py

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
# 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.
 
12
#
 
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:
 
15
#
 
16
#    test_testname.blacklist = (FormFactors.Tablet, FormFactors.Desktop,)
 
17
#
 
18
# Available form factors are:
 
19
# FormFactors.Phone
 
20
# FormFactors.Tablet
 
21
# FormFactors.Desktop
 
22
 
 
23
 
 
24
"""Tests for the Shell"""
 
25
 
 
26
from __future__ import absolute_import
 
27
 
 
28
from unity8.tests import ShellTestCase, FormFactors
 
29
from unity8.tests.helpers import TestShellHelpers
 
30
 
 
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
 
36
 
 
37
import unittest
 
38
import time
 
39
import os
 
40
from os import path
 
41
 
 
42
 
 
43
class TestShell(ShellTestCase, TestShellHelpers):
 
44
 
 
45
    """Tests the Shell"""
 
46
 
 
47
    # Scenarios:
 
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.
 
52
 
 
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(TestShell, 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.showLensOnLoaded, Eventually(Equals(""), timeout=30))
 
77
 
 
78
    def test_show_hud(self):
 
79
        hud = self.main_window.get_hud()
 
80
        self.unlock_greeter()
 
81
        self.show_hud()
 
82
        self.assertThat(hud.shown, Eventually(Equals(True)))
 
83
 
 
84
    def test_show_hud_button_dont_open(self):
 
85
        self.unlock_greeter()
 
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)))
 
107
        self.touch.release()
 
108
        self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
 
109
        self.assertThat(hud.shown, Eventually(Equals(False)))
 
110
 
 
111
    def test_hide_hud_click(self):
 
112
        hud = self.main_window.get_hud()
 
113
        self.unlock_greeter()
 
114
        self.show_hud()
 
115
        self.close_hud_click()
 
116
        self.assertThat(hud.shown, Eventually(Equals(False)))
 
117
 
 
118
    def test_hide_hud_click_outside_handle(self):
 
119
        hud = self.main_window.get_hud()
 
120
        self.unlock_greeter()
 
121
        self.show_hud()
 
122
        rect = hud.globalRect
 
123
        x = int(rect[0] + rect[2] / 2)
 
124
        y = rect[1] + hud.handleHeight + 1
 
125
        self.touch.tap(x, y)
 
126
        self.assertRaises(MismatchError, lambda: self.assertThat(hud.shown, Eventually(Equals(False), timeout=3)))
 
127
 
 
128
    def test_hide_hud_dragging(self):
 
129
        hud = self.main_window.get_hud()
 
130
        self.unlock_greeter()
 
131
        self.show_hud()
 
132
        rect = hud.globalRect
 
133
        start_x = rect[0] + (rect[2] - rect[0]) / 2
 
134
        start_y = rect[1] + 1
 
135
        stop_x = start_x
 
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)))
 
139
 
 
140
    def test_hide_hud_launcher(self):
 
141
        hud = self.main_window.get_hud()
 
142
        self.unlock_greeter()
 
143
        self.show_hud()
 
144
        self.show_launcher()
 
145
        self.assertThat(hud.shown, Eventually(Equals(False)))