~mhr3/unity8/fix-1297246

« back to all changes in this revision

Viewing changes to tests/qmltests/Dash/Apps/tst_RunningApplicationsGrid.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 Ubuntu.Application 0.1
 
20
import "../../../../Dash/Apps"
 
21
import Unity.Test 0.1 as UT
 
22
 
 
23
Item {
 
24
    width: units.gu(50)
 
25
    height: units.gu(40)
 
26
 
 
27
    QtObject {
 
28
        id: fakeApplicationManager
 
29
 
 
30
        property bool sideStageEnabled: false
 
31
 
 
32
        function stopProcess(application) {
 
33
            fakeRunningAppsModel.remove(application)
 
34
        }
 
35
    }
 
36
 
 
37
    QtObject {
 
38
        id: shell
 
39
        property bool dashShown: true
 
40
        property bool stageScreenshotsReady: false
 
41
        property var applicationManager: fakeApplicationManager
 
42
 
 
43
        function activateApplication(desktopFile) {
 
44
        }
 
45
    }
 
46
 
 
47
    ApplicationListModel { id: fakeRunningAppsModel }
 
48
 
 
49
    ApplicationInfo {
 
50
        id: phoneApp
 
51
        name: "Phone"
 
52
        icon: "phone-app"
 
53
        exec: "/usr/bin/phone-app"
 
54
        stage: ApplicationInfo.MainStage
 
55
        desktopFile: "phone.desktop"
 
56
        imageQml: "import QtQuick 2.0\n" +
 
57
                  "Rectangle { \n" +
 
58
                  "    anchors.fill:parent \n" +
 
59
                  "    color:'darkgreen' \n" +
 
60
                  "    Text { anchors.centerIn: parent; text: 'PHONE' } \n" +
 
61
                  "}"
 
62
    }
 
63
 
 
64
    ApplicationInfo {
 
65
        id: calendarApp
 
66
        name: "Calendar"
 
67
        icon: "calendar-app"
 
68
        exec: "/usr/bin/calendar-app"
 
69
        stage: ApplicationInfo.MainStage
 
70
        desktopFile: "calendar.desktop"
 
71
        imageQml: "import QtQuick 2.0\n" +
 
72
                  "Rectangle { \n" +
 
73
                  "    anchors.fill:parent \n" +
 
74
                  "    color:'darkblue' \n" +
 
75
                  "    Text { anchors.centerIn: parent; text: 'CALENDAR'\n" +
 
76
                  "           color:'white'} \n" +
 
77
                  "}"
 
78
    }
 
79
 
 
80
    function resetRunningApplications() {
 
81
        fakeRunningAppsModel.clear()
 
82
        fakeRunningAppsModel.add(phoneApp)
 
83
        fakeRunningAppsModel.add(calendarApp)
 
84
    }
 
85
 
 
86
    Component.onCompleted: {
 
87
        resetRunningApplications()
 
88
    }
 
89
 
 
90
    // The component under test
 
91
    RunningApplicationsGrid {
 
92
        id: runningApplicationsGrid
 
93
        anchors.fill: parent
 
94
        firstModel: fakeRunningAppsModel
 
95
    }
 
96
 
 
97
    UT.UnityTestCase {
 
98
        name: "RunningApplicationsGrid"
 
99
        when: windowShown
 
100
 
 
101
        function init() {
 
102
            runningApplicationsGrid.terminationModeEnabled = false
 
103
            resetRunningApplications()
 
104
        }
 
105
 
 
106
        property var calendarTile
 
107
        property var phoneTile
 
108
 
 
109
        property var isCalendarLongPressed: false
 
110
        function onCalendarLongPressed() {isCalendarLongPressed = true}
 
111
 
 
112
        property var isPhoneLongPressed: false
 
113
        function onPhoneLongPressed() {isPhoneLongPressed = true}
 
114
 
 
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)
 
121
 
 
122
            phoneTile = findChild(runningApplicationsGrid, "runningAppTile Phone")
 
123
            verify(phoneTile != undefined)
 
124
            phoneTile.onPressAndHold.connect(onPhoneLongPressed)
 
125
 
 
126
            compare(calendarTile.terminationModeEnabled, false)
 
127
            compare(phoneTile.terminationModeEnabled, false)
 
128
            compare(runningApplicationsGrid.terminationModeEnabled, false)
 
129
 
 
130
            isCalendarLongPressed = false
 
131
            mousePress(calendarTile, calendarTile.width/2, calendarTile.height/2)
 
132
            tryCompareFunction(checkSwitchToTerminationModeAfterLongPress, true)
 
133
 
 
134
            mouseRelease(calendarTile, calendarTile.width/2, calendarTile.height/2)
 
135
 
 
136
            compare(calendarTile.terminationModeEnabled, true)
 
137
            compare(phoneTile.terminationModeEnabled, true)
 
138
            compare(runningApplicationsGrid.terminationModeEnabled, true)
 
139
 
 
140
            isPhoneLongPressed = false
 
141
            mousePress(phoneTile, phoneTile.width/2, phoneTile.height/2)
 
142
            tryCompareFunction(checkSwitchToActivationModeAfterLongPress, true)
 
143
 
 
144
            mouseRelease(phoneTile, phoneTile.width/2, phoneTile.height/2)
 
145
 
 
146
            compare(calendarTile.terminationModeEnabled, false)
 
147
            compare(phoneTile.terminationModeEnabled, false)
 
148
            compare(runningApplicationsGrid.terminationModeEnabled, false)
 
149
 
 
150
            calendarTile.onPressAndHold.disconnect(onCalendarLongPressed)
 
151
            phoneTile.onPressAndHold.disconnect(onPhoneLongPressed)
 
152
        }
 
153
 
 
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)
 
160
 
 
161
            return isCalendarLongPressed &&
 
162
                calendarTile.terminationModeEnabled &&
 
163
                phoneTile.terminationModeEnabled &&
 
164
                runningApplicationsGrid.terminationModeEnabled
 
165
        }
 
166
 
 
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)
 
173
 
 
174
            return isPhoneLongPressed &&
 
175
                !calendarTile.terminationModeEnabled &&
 
176
                !phoneTile.terminationModeEnabled &&
 
177
                !runningApplicationsGrid.terminationModeEnabled
 
178
        }
 
179
 
 
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
 
184
 
 
185
            var calendarTile = findChild(runningApplicationsGrid, "runningAppTile Calendar")
 
186
            verify(calendarTile != undefined)
 
187
 
 
188
            verify(fakeRunningAppsModel.contains(calendarApp))
 
189
 
 
190
            mouseClick(calendarTile, calendarTile.width/2, calendarTile.height/2)
 
191
 
 
192
            verify(!fakeRunningAppsModel.contains(calendarApp))
 
193
 
 
194
            // The tile for the Calendar app should eventually vanish since the
 
195
            // application has been terminated
 
196
            tryCompareFunction(checkCalendarTileExists, false)
 
197
        }
 
198
 
 
199
        function checkCalendarTileExists() {
 
200
            return findChild(runningApplicationsGrid, "runningAppTile Calendar")
 
201
                    != undefined
 
202
        }
 
203
    }
 
204
}