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 Ubuntu.Application 0.1
20
import "../../../../Dash/Apps"
21
import Unity.Test 0.1 as UT
28
id: fakeApplicationManager
30
property bool sideStageEnabled: false
32
function stopProcess(application) {
33
fakeRunningAppsModel.remove(application)
39
property bool dashShown: true
40
property bool stageScreenshotsReady: false
41
property var applicationManager: fakeApplicationManager
43
function activateApplication(desktopFile) {
47
ApplicationListModel { id: fakeRunningAppsModel }
53
exec: "/usr/bin/phone-app"
54
stage: ApplicationInfo.MainStage
55
desktopFile: "phone.desktop"
56
imageQml: "import QtQuick 2.0\n" +
58
" anchors.fill:parent \n" +
59
" color:'darkgreen' \n" +
60
" Text { anchors.centerIn: parent; text: 'PHONE' } \n" +
68
exec: "/usr/bin/calendar-app"
69
stage: ApplicationInfo.MainStage
70
desktopFile: "calendar.desktop"
71
imageQml: "import QtQuick 2.0\n" +
73
" anchors.fill:parent \n" +
74
" color:'darkblue' \n" +
75
" Text { anchors.centerIn: parent; text: 'CALENDAR'\n" +
76
" color:'white'} \n" +
80
function resetRunningApplications() {
81
fakeRunningAppsModel.clear()
82
fakeRunningAppsModel.add(phoneApp)
83
fakeRunningAppsModel.add(calendarApp)
86
Component.onCompleted: {
87
resetRunningApplications()
90
// The component under test
91
RunningApplicationsGrid {
92
id: runningApplicationsGrid
94
firstModel: fakeRunningAppsModel
98
name: "RunningApplicationsGrid"
102
runningApplicationsGrid.terminationModeEnabled = false
103
resetRunningApplications()
106
property var calendarTile
107
property var phoneTile
109
property var isCalendarLongPressed: false
110
function onCalendarLongPressed() {isCalendarLongPressed = true}
112
property var isPhoneLongPressed: false
113
function onPhoneLongPressed() {isPhoneLongPressed = true}
115
// Tiles should go to termination mode when any one of them is long-pressed.
116
// Long-pressing when they're in termination mode brings them back to activation mode
117
function test_enterTerminationMode() {
118
calendarTile = findChild(runningApplicationsGrid, "runningAppTile Calendar")
119
verify(calendarTile != undefined)
120
calendarTile.onPressAndHold.connect(onCalendarLongPressed)
122
phoneTile = findChild(runningApplicationsGrid, "runningAppTile Phone")
123
verify(phoneTile != undefined)
124
phoneTile.onPressAndHold.connect(onPhoneLongPressed)
126
compare(calendarTile.terminationModeEnabled, false)
127
compare(phoneTile.terminationModeEnabled, false)
128
compare(runningApplicationsGrid.terminationModeEnabled, false)
130
isCalendarLongPressed = false
131
mousePress(calendarTile, calendarTile.width/2, calendarTile.height/2)
132
tryCompareFunction(checkSwitchToTerminationModeAfterLongPress, true)
134
mouseRelease(calendarTile, calendarTile.width/2, calendarTile.height/2)
136
compare(calendarTile.terminationModeEnabled, true)
137
compare(phoneTile.terminationModeEnabled, true)
138
compare(runningApplicationsGrid.terminationModeEnabled, true)
140
isPhoneLongPressed = false
141
mousePress(phoneTile, phoneTile.width/2, phoneTile.height/2)
142
tryCompareFunction(checkSwitchToActivationModeAfterLongPress, true)
144
mouseRelease(phoneTile, phoneTile.width/2, phoneTile.height/2)
146
compare(calendarTile.terminationModeEnabled, false)
147
compare(phoneTile.terminationModeEnabled, false)
148
compare(runningApplicationsGrid.terminationModeEnabled, false)
150
calendarTile.onPressAndHold.disconnect(onCalendarLongPressed)
151
phoneTile.onPressAndHold.disconnect(onPhoneLongPressed)
154
// Checks that components swicth to termination mode after (and only after) a long
155
// press happens on Calendar tile.
156
function checkSwitchToTerminationModeAfterLongPress() {
157
compare(calendarTile.terminationModeEnabled, isCalendarLongPressed)
158
compare(phoneTile.terminationModeEnabled, isCalendarLongPressed)
159
compare(runningApplicationsGrid.terminationModeEnabled, isCalendarLongPressed)
161
return isCalendarLongPressed &&
162
calendarTile.terminationModeEnabled &&
163
phoneTile.terminationModeEnabled &&
164
runningApplicationsGrid.terminationModeEnabled
167
// Checks that components swicth to activation mode after (and only after) a long
168
// press happens on Phone tile.
169
function checkSwitchToActivationModeAfterLongPress() {
170
compare(calendarTile.terminationModeEnabled, !isPhoneLongPressed)
171
compare(phoneTile.terminationModeEnabled, !isPhoneLongPressed)
172
compare(runningApplicationsGrid.terminationModeEnabled, !isPhoneLongPressed)
174
return isPhoneLongPressed &&
175
!calendarTile.terminationModeEnabled &&
176
!phoneTile.terminationModeEnabled &&
177
!runningApplicationsGrid.terminationModeEnabled
180
// While on termination mode, clicking a running application tile causes the
181
// corresponding application to be terminated.
182
function test_clickTileToTerminateApp() {
183
runningApplicationsGrid.terminationModeEnabled = true
185
var calendarTile = findChild(runningApplicationsGrid, "runningAppTile Calendar")
186
verify(calendarTile != undefined)
188
verify(fakeRunningAppsModel.contains(calendarApp))
190
mouseClick(calendarTile, calendarTile.width/2, calendarTile.height/2)
192
verify(!fakeRunningAppsModel.contains(calendarApp))
194
// The tile for the Calendar app should eventually vanish since the
195
// application has been terminated
196
tryCompareFunction(checkCalendarTileExists, false)
199
function checkCalendarTileExists() {
200
return findChild(runningApplicationsGrid, "runningAppTile Calendar")