~loic.molinari/ubuntu-ui-toolkit/ubuntu-ui-toolkit-private-shapes

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_toolbar.py

  • Committer: Christian Dywan
  • Date: 2014-04-30 10:22:44 UTC
  • mfrom: (1000.17.3 staging)
  • mto: (1000.41.5 staging)
  • mto: This revision was merged to the branch mainline in revision 1022.
  • Revision ID: christian.dywan@canonical.com-20140430102244-uti97msd0thmk31d
MergeĀ lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/staging

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
#
 
3
# Copyright (C) 2013, 2014 Canonical Ltd.
 
4
#
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU Lesser General Public License as published by
 
7
# the Free Software Foundation; version 3.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
12
# GNU Lesser General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU Lesser General Public License
 
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
16
 
 
17
try:
 
18
    from unittest import mock
 
19
except ImportError:
 
20
    import mock
 
21
 
 
22
import ubuntuuitoolkit
 
23
from ubuntuuitoolkit import tests
 
24
 
 
25
 
 
26
class ToolbarTestCase(tests.QMLStringAppTestCase):
 
27
 
 
28
    test_qml = ("""
 
29
import QtQuick 2.0
 
30
import Ubuntu.Components 0.1
 
31
 
 
32
MainView {
 
33
    width: units.gu(50)
 
34
    height: units.gu(50)
 
35
 
 
36
    // Make sure that for these tests the toolbar starts closed.
 
37
    Component.onCompleted: {
 
38
        __propagated.toolbar.close();
 
39
    }
 
40
 
 
41
    Page {
 
42
 
 
43
        Label {
 
44
            id: "label"
 
45
            objectName: "clicked_label"
 
46
            anchors.centerIn: parent
 
47
            text: "Button not clicked."
 
48
        }
 
49
 
 
50
        tools: ToolbarItems {
 
51
            ToolbarButton {
 
52
                objectName: "buttonName"
 
53
                action: Action {
 
54
                    text: "buttonText"
 
55
                    onTriggered: label.text = "Button clicked."
 
56
                }
 
57
            }
 
58
        }
 
59
    }
 
60
}
 
61
""")
 
62
 
 
63
    def setUp(self):
 
64
        super(ToolbarTestCase, self).setUp()
 
65
        self.toolbar = self.main_view.get_toolbar()
 
66
        # toolbar may be opened or closed now, depending on whether
 
67
        # the application has been deactivated and resumed already
 
68
 
 
69
    def test_open_toolbar(self):
 
70
        self.toolbar.open()
 
71
        self.assertTrue(self.toolbar.opened)
 
72
        self.assertFalse(self.toolbar.animating)
 
73
 
 
74
    def test_opened_toolbar_is_not_opened_again(self):
 
75
        self.toolbar.open()
 
76
        with mock.patch.object(
 
77
                self.main_view.pointing_device, 'drag') as mock_drag:
 
78
            self.toolbar.open()
 
79
 
 
80
        self.assertFalse(mock_drag.called)
 
81
        self.assertTrue(self.toolbar.opened)
 
82
 
 
83
    def test_close_toolbar(self):
 
84
        self.toolbar.open()
 
85
        self.toolbar.close()
 
86
        self.assertFalse(self.toolbar.opened)
 
87
        self.assertFalse(self.toolbar.animating)
 
88
 
 
89
    def test_closed_toolbar_is_not_closed_again(self):
 
90
        self.toolbar.close()
 
91
        with mock.patch.object(
 
92
                self.main_view.pointing_device, 'drag') as mock_drag:
 
93
            self.toolbar.close()
 
94
 
 
95
        self.assertFalse(mock_drag.called)
 
96
        self.assertFalse(self.toolbar.opened)
 
97
 
 
98
    def test_click_toolbar_button(self):
 
99
        self.toolbar.close()
 
100
        label = self.app.select_single('Label', objectName='clicked_label')
 
101
        self.assertNotEqual(label.text, 'Button clicked.')
 
102
        self.toolbar.open()
 
103
        self.toolbar.click_button('buttonName')
 
104
        self.assertEqual(label.text, 'Button clicked.')
 
105
 
 
106
    def test_click_unexisting_button(self):
 
107
        self.main_view.open_toolbar()
 
108
        error = self.assertRaises(
 
109
            ubuntuuitoolkit.ToolkitException, self.toolbar.click_button,
 
110
            'unexisting')
 
111
        self.assertEqual(
 
112
            str(error), 'Button with objectName "unexisting" not found.')
 
113
 
 
114
    def test_click_button_on_closed_toolbar(self):
 
115
        self.toolbar.close()
 
116
        error = self.assertRaises(
 
117
            ubuntuuitoolkit.ToolkitException, self.toolbar.click_button,
 
118
            'buttonName')
 
119
        self.assertEqual(
 
120
            str(error),
 
121
            'Toolbar must be opened before calling click_button().')