~paulliu/unity8/reboot_140728

« back to all changes in this revision

Viewing changes to tests/qmltests/Dash/Apps/tst_RunningApplicationsGrid.qml

  • Committer: Ying-Chun Liu
  • Date: 2014-08-01 13:31:48 UTC
  • mfrom: (1089.1.18 unity8)
  • Revision ID: paul.liu@canonical.com-20140801133148-hwstkxij80hkhyol
Merge trunk

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 "../../../../qml/Dash/Apps"
20
 
import Unity.Test 0.1 as UT
21
 
import Unity.Application 0.1
22
 
import Ubuntu.Components 1.1
23
 
 
24
 
// Using Rectangle to have an opaque surface because AppManager paints app surfaces behind it.
25
 
Rectangle {
26
 
    width: units.gu(70)
27
 
    height: units.gu(40)
28
 
 
29
 
    function resetRunningApplications() {
30
 
        while (ApplicationManager.count > 0) {
31
 
            ApplicationManager.stopApplication(ApplicationManager.get(0).appId)
32
 
        }
33
 
 
34
 
        ApplicationManager.startApplication("dialer-app");
35
 
        ApplicationManager.startApplication("webbrowser-app");
36
 
    }
37
 
 
38
 
    Component.onCompleted: {
39
 
        resetRunningApplications()
40
 
    }
41
 
 
42
 
    // The component under test
43
 
    RunningApplicationsGrid {
44
 
        id: runningApplicationsGrid
45
 
        orientationAngle: orientationAngleSelector.selectedIndex * 90
46
 
        anchors.left: parent.left
47
 
        anchors.right: controlPanel.left
48
 
        anchors.top: parent.top
49
 
        anchors.bottom: parent.bottom
50
 
        model: ApplicationManager
51
 
    }
52
 
 
53
 
    Rectangle {
54
 
        id: controlPanel
55
 
        anchors.right: parent.right
56
 
        anchors.top: parent.top
57
 
        anchors.bottom: parent.bottom
58
 
        width: units.gu(20)
59
 
        color: "black"
60
 
 
61
 
        OptionSelector {
62
 
            id: orientationAngleSelector
63
 
            model: ["0","90","180","270"]
64
 
            text: "Orientation Angle"
65
 
            width: parent.width
66
 
        }
67
 
    }
68
 
 
69
 
    UT.UnityTestCase {
70
 
        name: "RunningApplicationsGrid"
71
 
        when: windowShown
72
 
 
73
 
        function init() {
74
 
            runningApplicationsGrid.terminationModeEnabled = false
75
 
            resetRunningApplications()
76
 
        }
77
 
 
78
 
        property var browserTile
79
 
        property var phoneTile
80
 
 
81
 
        property var isBrowserLongPressed: false
82
 
        function onBrowserLongPressed() {isBrowserLongPressed = true}
83
 
 
84
 
        property var isPhoneLongPressed: false
85
 
        function onPhoneLongPressed() {isPhoneLongPressed = true}
86
 
 
87
 
        // Tiles should go to termination mode when any one of them is long-pressed.
88
 
        // Long-pressing when they're in termination mode brings them back to activation mode
89
 
        function test_enterTerminationMode() {
90
 
            browserTile = findChild(runningApplicationsGrid, "runningAppTile Browser")
91
 
            verify(browserTile != undefined)
92
 
            browserTile.onPressAndHold.connect(onBrowserLongPressed)
93
 
 
94
 
            phoneTile = findChild(runningApplicationsGrid, "runningAppTile Dialer")
95
 
            verify(phoneTile != undefined)
96
 
            phoneTile.onPressAndHold.connect(onPhoneLongPressed)
97
 
 
98
 
            compare(browserTile.terminationModeEnabled, false)
99
 
            compare(phoneTile.terminationModeEnabled, false)
100
 
            compare(runningApplicationsGrid.terminationModeEnabled, false)
101
 
 
102
 
            isBrowserLongPressed = false
103
 
            mousePress(browserTile, browserTile.width/2, browserTile.height/2)
104
 
            tryCompareFunction(checkSwitchToTerminationModeAfterLongPress, true)
105
 
 
106
 
            mouseRelease(browserTile, browserTile.width/2, browserTile.height/2)
107
 
 
108
 
            compare(browserTile.terminationModeEnabled, true)
109
 
            compare(phoneTile.terminationModeEnabled, true)
110
 
            compare(runningApplicationsGrid.terminationModeEnabled, true)
111
 
 
112
 
            isPhoneLongPressed = false
113
 
            mousePress(phoneTile, phoneTile.width/2, phoneTile.height/2)
114
 
            tryCompareFunction(checkSwitchToActivationModeAfterLongPress, true)
115
 
 
116
 
            mouseRelease(phoneTile, phoneTile.width/2, phoneTile.height/2)
117
 
 
118
 
            compare(browserTile.terminationModeEnabled, false)
119
 
            compare(phoneTile.terminationModeEnabled, false)
120
 
            compare(runningApplicationsGrid.terminationModeEnabled, false)
121
 
 
122
 
            browserTile.onPressAndHold.disconnect(onBrowserLongPressed)
123
 
            phoneTile.onPressAndHold.disconnect(onPhoneLongPressed)
124
 
        }
125
 
 
126
 
        // Checks that components swicth to termination mode after (and only after) a long
127
 
        // press happens on Browser tile.
128
 
        function checkSwitchToTerminationModeAfterLongPress() {
129
 
            compare(browserTile.terminationModeEnabled, isBrowserLongPressed)
130
 
            compare(phoneTile.terminationModeEnabled, isBrowserLongPressed)
131
 
            compare(runningApplicationsGrid.terminationModeEnabled, isBrowserLongPressed)
132
 
 
133
 
            return isBrowserLongPressed &&
134
 
                browserTile.terminationModeEnabled &&
135
 
                phoneTile.terminationModeEnabled &&
136
 
                runningApplicationsGrid.terminationModeEnabled
137
 
        }
138
 
 
139
 
        // Checks that components swicth to activation mode after (and only after) a long
140
 
        // press happens on Phone tile.
141
 
        function checkSwitchToActivationModeAfterLongPress() {
142
 
            compare(browserTile.terminationModeEnabled, !isPhoneLongPressed)
143
 
            compare(phoneTile.terminationModeEnabled, !isPhoneLongPressed)
144
 
            compare(runningApplicationsGrid.terminationModeEnabled, !isPhoneLongPressed)
145
 
 
146
 
            return isPhoneLongPressed &&
147
 
                !browserTile.terminationModeEnabled &&
148
 
                !phoneTile.terminationModeEnabled &&
149
 
                !runningApplicationsGrid.terminationModeEnabled
150
 
        }
151
 
 
152
 
        // While on termination mode, clicking a running application tile, outside of
153
 
        // the close icon should do nothing
154
 
        function test_clickTileNotClose() {
155
 
            runningApplicationsGrid.terminationModeEnabled = true
156
 
 
157
 
            var browserTile = findChild(runningApplicationsGrid, "runningAppTile Browser")
158
 
            verify(browserTile != undefined)
159
 
 
160
 
            verify(ApplicationManager.findApplication("webbrowser-app") !== null)
161
 
 
162
 
            mouseClick(browserTile, browserTile.width/2, browserTile.height/2)
163
 
 
164
 
            verify(ApplicationManager.findApplication("webbrowser-app") !== null)
165
 
 
166
 
            // The tile for the Browser app should stay there
167
 
            tryCompareFunction(checkBrowserTileExists, true)
168
 
        }
169
 
 
170
 
        // While in termination mode, clicking on a running application tile's close icon
171
 
        // causes the corresponding application to be terminated
172
 
        function test_clickCloseIconToTerminateApp() {
173
 
            runningApplicationsGrid.terminationModeEnabled = true
174
 
 
175
 
            var browserTile = findChild(runningApplicationsGrid, "runningAppTile Browser")
176
 
            var browserTileCloseButton = findChild(runningApplicationsGrid, "closeIcon Browser")
177
 
 
178
 
            verify(browserTile != undefined)
179
 
            verify(browserTileCloseButton != undefined)
180
 
            verify(ApplicationManager.findApplication("webbrowser-app") !== 0)
181
 
 
182
 
            mouseClick(browserTileCloseButton, browserTileCloseButton.width/2, browserTileCloseButton.height/2)
183
 
            wait(0) // spin event loop to start any pending animation
184
 
 
185
 
            verify(ApplicationManager.findApplication("webbrowser-app") === null)
186
 
 
187
 
            // The tile for the Browser app should eventually vanish since the
188
 
            // application has been terminated.
189
 
            tryCompareFunction(checkBrowserTileExists, false)
190
 
        }
191
 
 
192
 
        function checkBrowserTileExists() {
193
 
            return findChild(runningApplicationsGrid, "runningAppTile Browser")
194
 
                    != undefined
195
 
        }
196
 
 
197
 
        // While in termination mode, if you click outside any of the tiles, the
198
 
        // termination mode is disabled (i.e. we switch back to activation mode).
199
 
        function test_clickOutsideTilesDisablesTerminationMode() {
200
 
            runningApplicationsGrid.terminationModeEnabled = true
201
 
 
202
 
            var browserTile = findChild(runningApplicationsGrid, "runningAppTile Browser")
203
 
            verify(browserTile != undefined)
204
 
 
205
 
            verify(runningApplicationsGrid.terminationModeEnabled);
206
 
 
207
 
            // Click on the bottom right corner of the grid, where there's no
208
 
            // RunningApplicationTile lying around
209
 
            mouseClick(runningApplicationsGrid,
210
 
                       runningApplicationsGrid.width - 1, runningApplicationsGrid.height - 1);
211
 
 
212
 
            wait(0) // spin event loop to ensure that any pending signal emission went through
213
 
 
214
 
            verify(!runningApplicationsGrid.terminationModeEnabled);
215
 
        }
216
 
    }
217
 
}