2
* Copyright 2013 Canonical Ltd.
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.
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.
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/>.
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
24
// Using Rectangle to have an opaque surface because AppManager paints app surfaces behind it.
29
function resetRunningApplications() {
30
while (ApplicationManager.count > 0) {
31
ApplicationManager.stopApplication(ApplicationManager.get(0).appId)
34
ApplicationManager.startApplication("dialer-app");
35
ApplicationManager.startApplication("webbrowser-app");
38
Component.onCompleted: {
39
resetRunningApplications()
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
55
anchors.right: parent.right
56
anchors.top: parent.top
57
anchors.bottom: parent.bottom
62
id: orientationAngleSelector
63
model: ["0","90","180","270"]
64
text: "Orientation Angle"
70
name: "RunningApplicationsGrid"
74
runningApplicationsGrid.terminationModeEnabled = false
75
resetRunningApplications()
78
property var browserTile
79
property var phoneTile
81
property var isBrowserLongPressed: false
82
function onBrowserLongPressed() {isBrowserLongPressed = true}
84
property var isPhoneLongPressed: false
85
function onPhoneLongPressed() {isPhoneLongPressed = true}
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)
94
phoneTile = findChild(runningApplicationsGrid, "runningAppTile Dialer")
95
verify(phoneTile != undefined)
96
phoneTile.onPressAndHold.connect(onPhoneLongPressed)
98
compare(browserTile.terminationModeEnabled, false)
99
compare(phoneTile.terminationModeEnabled, false)
100
compare(runningApplicationsGrid.terminationModeEnabled, false)
102
isBrowserLongPressed = false
103
mousePress(browserTile, browserTile.width/2, browserTile.height/2)
104
tryCompareFunction(checkSwitchToTerminationModeAfterLongPress, true)
106
mouseRelease(browserTile, browserTile.width/2, browserTile.height/2)
108
compare(browserTile.terminationModeEnabled, true)
109
compare(phoneTile.terminationModeEnabled, true)
110
compare(runningApplicationsGrid.terminationModeEnabled, true)
112
isPhoneLongPressed = false
113
mousePress(phoneTile, phoneTile.width/2, phoneTile.height/2)
114
tryCompareFunction(checkSwitchToActivationModeAfterLongPress, true)
116
mouseRelease(phoneTile, phoneTile.width/2, phoneTile.height/2)
118
compare(browserTile.terminationModeEnabled, false)
119
compare(phoneTile.terminationModeEnabled, false)
120
compare(runningApplicationsGrid.terminationModeEnabled, false)
122
browserTile.onPressAndHold.disconnect(onBrowserLongPressed)
123
phoneTile.onPressAndHold.disconnect(onPhoneLongPressed)
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)
133
return isBrowserLongPressed &&
134
browserTile.terminationModeEnabled &&
135
phoneTile.terminationModeEnabled &&
136
runningApplicationsGrid.terminationModeEnabled
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)
146
return isPhoneLongPressed &&
147
!browserTile.terminationModeEnabled &&
148
!phoneTile.terminationModeEnabled &&
149
!runningApplicationsGrid.terminationModeEnabled
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
157
var browserTile = findChild(runningApplicationsGrid, "runningAppTile Browser")
158
verify(browserTile != undefined)
160
verify(ApplicationManager.findApplication("webbrowser-app") !== null)
162
mouseClick(browserTile, browserTile.width/2, browserTile.height/2)
164
verify(ApplicationManager.findApplication("webbrowser-app") !== null)
166
// The tile for the Browser app should stay there
167
tryCompareFunction(checkBrowserTileExists, true)
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
175
var browserTile = findChild(runningApplicationsGrid, "runningAppTile Browser")
176
var browserTileCloseButton = findChild(runningApplicationsGrid, "closeIcon Browser")
178
verify(browserTile != undefined)
179
verify(browserTileCloseButton != undefined)
180
verify(ApplicationManager.findApplication("webbrowser-app") !== 0)
182
mouseClick(browserTileCloseButton, browserTileCloseButton.width/2, browserTileCloseButton.height/2)
183
wait(0) // spin event loop to start any pending animation
185
verify(ApplicationManager.findApplication("webbrowser-app") === null)
187
// The tile for the Browser app should eventually vanish since the
188
// application has been terminated.
189
tryCompareFunction(checkBrowserTileExists, false)
192
function checkBrowserTileExists() {
193
return findChild(runningApplicationsGrid, "runningAppTile Browser")
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
202
var browserTile = findChild(runningApplicationsGrid, "runningAppTile Browser")
203
verify(browserTile != undefined)
205
verify(runningApplicationsGrid.terminationModeEnabled);
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);
212
wait(0) // spin event loop to ensure that any pending signal emission went through
214
verify(!runningApplicationsGrid.terminationModeEnabled);