~verzegnassi-stefano/+junk/ubuntu-terminal-app-uitk13

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntu_terminal_app/tests/test_terminal.py

  • Committer: Filippo Scognamiglio
  • Date: 2014-10-25 04:42:31 UTC
  • Revision ID: flscogna@gmail.com-20141025044231-javjhusbqa171127
Initial reboot commit.

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
"""Terminal app autopilot tests."""
 
9
 
 
10
from __future__ import absolute_import
 
11
 
 
12
from autopilot.matchers import Eventually
 
13
from testtools.matchers import Equals
 
14
 
 
15
from ubuntu_terminal_app.tests import TerminalTestCase
 
16
from ubuntu_terminal_app import DbMan
 
17
from ubuntuuitoolkit import ToolkitException
 
18
from testscenarios import TestWithScenarios
 
19
 
 
20
from time import sleep
 
21
import random
 
22
 
 
23
 
 
24
class TestMainWindow(TerminalTestCase):
 
25
 
 
26
    def test_circle_menu_shows(self):
 
27
        """Make sure that Circle Menu is visible
 
28
        on long tap"""
 
29
        self.app.main_view.long_tap_terminal_center()
 
30
        menu = self.app.main_view.get_circle_menu()
 
31
        self.assertThat(menu.visible, Eventually(Equals(True)))
 
32
 
 
33
    def test_header(self):
 
34
        """Make sure that Header is visible
 
35
        in Portrait Mode and not visible in landscape mode"""
 
36
        kterm = self.app.main_view.get_terminal_page()
 
37
        header = self.app.main_view.get_header()
 
38
        if kterm.width > kterm.height:
 
39
            self.assertThat(header.visible, Equals(False))
 
40
        else:
 
41
            self.assertThat(header.visible, Equals(True))
 
42
 
 
43
 
 
44
class TestPanel(TerminalTestCase, TestWithScenarios):
 
45
 
 
46
    scenarios = [
 
47
        ('controlpanel',
 
48
            {'button': 'controlkeysaction',
 
49
             'helper_method': 'get_control_panel'
 
50
             }),
 
51
 
 
52
        ('functionpanel',
 
53
            {'button': 'functionkeysaction',
 
54
             'helper_method': 'get_function_panel'
 
55
             }),
 
56
 
 
57
        ('textpanel',
 
58
            {'button': 'textkeysaction',
 
59
             'helper_method': 'get_text_panel'
 
60
             })
 
61
    ]
 
62
 
 
63
    def open_panel(self, button, helper_method):
 
64
        """Open named panel"""
 
65
        header = self.app.main_view.get_header()
 
66
        header.click_action_button(button)
 
67
        get_panel = getattr(self.app.main_view, helper_method)
 
68
        return get_panel()
 
69
 
 
70
    def hide_panel(self):
 
71
        """Close any open panel"""
 
72
        header = self.app.main_view.get_header()
 
73
 
 
74
        # the overflow panel can be left open, so we need to try again
 
75
        # https://bugs.launchpad.net/ubuntu-terminal-app/+bug/1363233
 
76
        try:
 
77
            header.click_action_button('hidepanelaction')
 
78
            try:
 
79
                sleep(2)
 
80
                header.click_action_button('hidepanelaction')
 
81
            except ToolkitException:
 
82
                pass
 
83
        except ToolkitException:
 
84
            pass
 
85
 
 
86
    def test_panels(self):
 
87
        """Make sure that Panel is visible
 
88
        when clicking the toolbar popup items and hides properly."""
 
89
        panel = self.open_panel(self.button, self.helper_method)
 
90
        self.assertThat(panel.visible, Eventually(Equals(True)))
 
91
        self.hide_panel()
 
92
        self.assertThat(panel.visible, Eventually(Equals(False)))
 
93
 
 
94
 
 
95
class TestSettings(TerminalTestCase, DbMan):
 
96
 
 
97
    def click_item_selector_item(self, selector, value):
 
98
        """Clicks item from item selector"""
 
99
        # This needs a toolkit helper
 
100
        # https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1272345
 
101
        select = self.app.main_view.wait_select_single('ItemSelector',
 
102
                                                       objectName=selector)
 
103
        container = select.wait_select_single('Standard',
 
104
                                              objectName='listContainer')
 
105
        self.app.pointing_device.click_object(container)
 
106
        select.currentlyExpanded.wait_for(True)
 
107
        # waiting for currentlyExpanded is not enough
 
108
        # some animation is not accounted for and thus we sleep
 
109
        sleep(2)
 
110
        item = container.wait_select_single('Label', text=value)
 
111
        self.app.pointing_device.click_object(item)
 
112
        select.currentlyExpanded.wait_for(False)
 
113
        # waiting for currentlyExpanded is not enough
 
114
        # some animation is not accounted for and thus we sleep
 
115
        sleep(1)
 
116
 
 
117
    def test_color_scheme_changes(self):
 
118
        """Make sure that color scheme is set correctly"""
 
119
 
 
120
        # are these string translatable?
 
121
        # if so, we need to do this another way
 
122
        schemeList = ("BlackOnRandomLight",
 
123
                      "BlackOnWhite",
 
124
                      "BlackOnLightYellow",
 
125
                      "DarkPastels",
 
126
                      "GreenOnBlack",
 
127
                      "Linux",
 
128
                      "WhiteOnBlack")
 
129
 
 
130
        colorScheme = self.get_color_scheme_from_storage
 
131
        for scheme in schemeList:
 
132
            header = self.app.main_view.get_header()
 
133
            header.click_action_button('SettingsButton')
 
134
            self.click_item_selector_item("liSchemes", scheme)
 
135
            self.app.main_view.go_back()
 
136
            self.assertThat(colorScheme, Eventually(Equals(scheme)))
 
137
 
 
138
    def test_font_size_changes(self):
 
139
        """Make sure that font size is set correctly"""
 
140
        header = self.app.main_view.get_header()
 
141
        header.click_action_button('SettingsButton')
 
142
 
 
143
        font_size = self.get_font_size_from_storage
 
144
 
 
145
        # change font size to min
 
146
        self.app.main_view.drag_horizontal_slider("slFont", 8)
 
147
        self.assertThat(font_size, Eventually(Equals(8)))
 
148
 
 
149
        # change font size to max
 
150
        self.app.main_view.drag_horizontal_slider("slFont", 32)
 
151
        self.assertThat(font_size, Eventually(Equals(32)))
 
152
 
 
153
        # change font size to random sizes
 
154
        for loop in range(1, 3):
 
155
            randSize = random.randrange(9, 31, 1)
 
156
            self.app.main_view.drag_horizontal_slider("slFont", randSize)
 
157
            self.assertThat(font_size, Eventually(Equals(randSize)))