~unity-team/+junk/dashboard-playground

« back to all changes in this revision

Viewing changes to tests/qmltests/Panel/tst_Panel.qml

  • 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
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import QtTest 1.0
 
19
import Unity.Test 0.1 as UT
 
20
import ".."
 
21
import "../../../Panel"
 
22
import Ubuntu.ChewieUI 0.1 as ChewieUI
 
23
 
 
24
/*
 
25
  This tests the Panel component using a fake model to stage data in the indicators
 
26
  A view will show with indicators at the top, as does in the shell. This can be controlled
 
27
  as in the shell.
 
28
*/
 
29
Item {
 
30
    id: shell
 
31
    width: units.gu(40)
 
32
    height: units.gu(80)
 
33
 
 
34
    property bool search_clicked: false
 
35
 
 
36
    Connections {
 
37
        target: panel
 
38
        onSearchClicked: search_clicked = true
 
39
    }
 
40
 
 
41
    Panel {
 
42
        id: panel
 
43
        anchors.fill: parent
 
44
    }
 
45
 
 
46
    UT.UnityTestCase {
 
47
        name: "Panel"
 
48
        when: windowShown
 
49
 
 
50
        function get_window_data() {
 
51
            return [
 
52
            {tag: "pinned", fullscreenFlag: false },
 
53
            {tag: "fullscreen", fullscreenFlag: true }
 
54
        ]}
 
55
 
 
56
 
 
57
        function init() {
 
58
            search_clicked = false;
 
59
            panel.indicators.hide();
 
60
            tryCompare(panel.indicators.hideAnimation, "running", false);
 
61
            tryCompare(panel.indicators, "state", "initial");
 
62
        }
 
63
 
 
64
        function get_indicator_item(index) {
 
65
            var row_repeater = findChild(panel.indicators, "rowRepeater");
 
66
            verify(row_repeater != undefined)
 
67
            return row_repeater.itemAt(index);
 
68
        }
 
69
 
 
70
        function get_indicator_item_position(index) {
 
71
 
 
72
            var indicator_row = findChild(panel.indicators, "indicatorRow");
 
73
            verify(indicator_row != undefined)
 
74
 
 
75
            var indicator_item = get_indicator_item(index);
 
76
            verify(indicator_item != undefined);
 
77
 
 
78
            return panel.mapFromItem(indicator_item, indicator_item.width/2, indicator_item.height/2);
 
79
        }
 
80
 
 
81
        function test_hint_data() { return get_window_data() }
 
82
 
 
83
        // Pressing on the indicator panel should activate the indicator hints
 
84
        // and expose a portion of the conent.
 
85
        function test_hint(data) {
 
86
            panel.fullscreenMode = data.fullscreenFlag;
 
87
 
 
88
            var indicator_item_coord = get_indicator_item_position(0);
 
89
            var indicator_revealer = findChild(panel, "indicatorRevealer");
 
90
            verify(indicator_revealer != undefined)
 
91
 
 
92
            mousePress(panel,
 
93
                       indicator_item_coord.x, panel.panelHeight/2,
 
94
                       Qt.LeftButton, Qt.NoModifier , 0);
 
95
 
 
96
            if (!panel.fullscreenMode)
 
97
            {
 
98
                compare(indicator_revealer.hintingAnimation.running, true, "Indicator revealer hint animation should be running after mouse press on indicator panel in pinned mode");
 
99
                tryCompare(indicator_revealer.hintingAnimation, "running", false);
 
100
                tryCompare(panel.indicators, "partiallyOpened", true);
 
101
            }
 
102
            else
 
103
            {
 
104
                // nothing should happen
 
105
                compare(indicator_revealer.hintingAnimation.running, false, "Indicator revealer hint animation should not be running after mouse press on indicator panel in fullscreen mode");
 
106
                compare(panel.indicators.partiallyOpened, false, "Indicator should not be partially opened when panel is pressed in fullscreenmode");
 
107
                compare(panel.indicators.fullyOpened, false, "Indicator should not be partially opened when panel is pressed in fullscreenmode");
 
108
            }
 
109
 
 
110
            mouseRelease(panel,
 
111
                         indicator_item_coord.x, panel.panelHeight/2,
 
112
                         Qt.LeftButton, Qt.NoModifier , 0);
 
113
        }
 
114
 
 
115
        function test_show_click_data() { return get_window_data() }
 
116
 
 
117
        // Clicking the indicator panel should fully open the inidicators
 
118
        function test_show_click(data) {
 
119
            panel.fullscreenMode = data.fullscreenFlag;
 
120
 
 
121
            var indicator_item_coord = get_indicator_item_position(0);
 
122
 
 
123
            mouseClick(panel,
 
124
                       indicator_item_coord.x, panel.panelHeight/2,
 
125
                       Qt.LeftButton, Qt.NoModifier , 0);
 
126
 
 
127
            if (!panel.fullscreenMode)
 
128
            {
 
129
                compare(panel.indicators.showAnimation.running, true, "Show animation should run after panel is clicked in pinned mode.");
 
130
                tryCompare(panel.indicators, "fullyOpened", true);
 
131
 
 
132
                // click will activate device overview.
 
133
                compare(findChild(panel.indicators, "indicatorRow").overviewActive, true, "Overview indicator should be avtive when indicators clicked.")
 
134
            }
 
135
            else
 
136
            {
 
137
                compare(panel.indicators.showAnimation.running, false, "Indicators should not open when panel is clicked in pinned mode.");
 
138
            }
 
139
        }
 
140
 
 
141
        function test_show_press_release_data() { return get_window_data() }
 
142
 
 
143
        // Pressing and releasing on the indicator panel will fully open the indicators
 
144
        function test_show_press_release(data) {
 
145
            panel.fullscreenMode = data.fullscreenFlag;
 
146
 
 
147
            var indicator_item_coord = get_indicator_item_position(0);
 
148
 
 
149
            mousePress(panel,
 
150
                       indicator_item_coord.x, panel.panelHeight/2,
 
151
                       Qt.LeftButton, Qt.NoModifier , 0);
 
152
 
 
153
            mouseRelease(panel,
 
154
                         indicator_item_coord.x, panel.panelHeight/2,
 
155
                         Qt.LeftButton, Qt.NoModifier , 0);
 
156
 
 
157
            if (!panel.fullscreenMode)
 
158
            {
 
159
                compare(panel.indicators.showAnimation.running, true, "Show animation should run after panel is clicked in pinned mode.");
 
160
                tryCompare(panel.indicators, "fullyOpened", true);
 
161
            }
 
162
            else
 
163
            {
 
164
                // nothing should happen.
 
165
                compare(panel.indicators.showAnimation.running, false, "Indicators should not open when panel is clicked in pinned mode.");
 
166
            }
 
167
        }
 
168
 
 
169
        function test_drag_show_data() { return get_window_data() }
 
170
 
 
171
        // Dragging from a indicator item in the panel will gradually expose the
 
172
        // indicators, first by running the hint animation, then after dragging down will
 
173
        // expose more of the panel, binding it to the selected indicator and opening it's menu.
 
174
        function test_drag_show(data) {
 
175
            panel.fullscreenMode = data.fullscreenFlag;
 
176
 
 
177
            var indicator_revealer = findChild(panel, "indicatorRevealer");
 
178
            verify(indicator_revealer != undefined)
 
179
 
 
180
            var indicator_row = findChild(panel.indicators, "indicatorRow");
 
181
            verify(indicator_row != undefined)
 
182
 
 
183
            var row_repeater = findChild(panel.indicators, "rowRepeater");
 
184
            verify(indicator_row != undefined)
 
185
 
 
186
            var menu_content = findChild(panel.indicators, "menuContent");
 
187
            verify(indicator_row != undefined)
 
188
 
 
189
            // do this for each indicator item
 
190
            for (var i = 0; i < row_repeater.count; i++) {
 
191
 
 
192
                var indicator_item = get_indicator_item(i);
 
193
                verify(indicator_item != undefined)
 
194
 
 
195
                var indicator_item_coord = get_indicator_item_position(i);
 
196
 
 
197
                // 1) Press on the panel
 
198
                mousePress(panel,
 
199
                           indicator_item_coord.x, panel.panelHeight/2,
 
200
                           Qt.LeftButton, Qt.NoModifier , 0);
 
201
 
 
202
                if (!panel.fullscreenMode)
 
203
                {
 
204
                    // hint animation should be run, and panel will end in partiallyOpened state.
 
205
                    compare(indicator_revealer.hintingAnimation.running, true, "Indicator revealer hint animation should be running after mouse press on indicator panel");
 
206
                    tryCompare(indicator_revealer.hintingAnimation, "running", false);
 
207
                    tryCompare(panel.indicators, "partiallyOpened", true);
 
208
                }
 
209
 
 
210
                // 2) Drag the mouse down
 
211
                var old_progress = panel.indicators.progress
 
212
                mouseMove(panel,
 
213
                          indicator_item_coord.x, old_progress + (panel.height - old_progress)/2,
 
214
                          0, Qt.LeftButton);
 
215
 
 
216
                // progress should increase.
 
217
                var progress_increases = panel.indicators.progress > old_progress;
 
218
                compare(progress_increases, true, "Progress has not increased on dragging indicator.");
 
219
 
 
220
                mouseMove(panel,
 
221
                          indicator_item_coord.x, shell.y + shell.height,
 
222
                          0, Qt.LeftButton);
 
223
 
 
224
                tryCompare(panel.indicators, "fullyOpened", true);
 
225
 
 
226
                mouseRelease(panel,
 
227
                             indicator_item_coord.x, indicator_item_coord.y + panel.height/2,
 
228
                             Qt.LeftButton, Qt.NoModifier , 0);
 
229
 
 
230
                compare(indicator_row.currentItem, indicator_item, "Incorrect item activated at position " + i);
 
231
                compare(menu_content.__shown, true, "Menu conetent should be enabled for item at position " + i);
 
232
 
 
233
                // init for next indicator_item
 
234
                init();
 
235
            }
 
236
        }
 
237
 
 
238
        function test_search_click_when_visible() {
 
239
            panel.fullscreenMode = false;
 
240
            panel.searchVisible = true;
 
241
 
 
242
            var search_indicator = findChild(panel, "search");
 
243
            verify(search_indicator != undefined);
 
244
 
 
245
            mouseClick(search_indicator,
 
246
                       1, 1,
 
247
                       Qt.LeftButton, Qt.NoModifier , 0);
 
248
 
 
249
            compare(search_clicked, true, "Clicking search indicator while it was enabled did not emit searchClicked signal")
 
250
        }
 
251
 
 
252
        function test_search_click_when_not_visible() {
 
253
            panel.fullscreenMode = false;
 
254
            panel.searchVisible = false
 
255
 
 
256
            var search_indicator = findChild(panel, "search");
 
257
            verify(search_indicator != undefined);
 
258
 
 
259
            mouseClick(search_indicator,
 
260
                       1, 1,
 
261
                       Qt.LeftButton, Qt.NoModifier , 0);
 
262
 
 
263
            compare(search_clicked, false, "Clicking search indicator while it was not visible emitted searchClicked signal")
 
264
        }
 
265
    }
 
266
}