on xenial help sign in
fix testRunningApplicationsGrid
commitfcd72d081a6d4fc8b2f3a6e51a0c20f1427ed5be authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 6 Feb 2014, 20:12 (13 years ago) parent45716b3
1 file changed+50−117
tests/qmltests/Dash/Apps/tst_RunningApplicationsGrid.qml+50−117
tests/qmltests/Dash/Apps/tst_RunningApplicationsGrid.qml+50−117
@@ -18,87 +18,20 @@ import QtQuick 2.0
1818import QtTest 1.0
1919import "../../../../qml/Dash/Apps"
2020import Unity.Test 0.1 as UT
21+import Unity.Application 0.1
2122
22−Item {
23+// Using Rectangle to have an opaque surface because AppManager paints app surfaces behind it.
24+Rectangle {
2325 width: units.gu(50)
2426 height: units.gu(40)
2527
26− QtObject {
27− id: fakeApplicationManager
28−
29− property bool sideStageEnabled: false
30−
31− function stopApplication(appId) {
32− for (var i=0, len=fakeRunningAppsModel.count; i<len; i++) {
33− if (appId == fakeRunningAppsModel.get(i).appId) {
34− fakeRunningAppsModel.remove(i)
35− }
36− }
37− }
38− }
39−
40− QtObject {
41− id: shell
42− property bool dashShown: true
43− property bool stageScreenshotsReady: false
44− property var applicationManager: fakeApplicationManager
45−
46− function activateApplication(appId) {
47− }
48− }
49−
50− ListModel {
51− id: fakeRunningAppsModel
52−
53− function contains(appId) {
54− for (var i=0, len=fakeRunningAppsModel.count; i<len; i++) {
55− if (appId == fakeRunningAppsModel.get(i).appId) {
56− return true;
57− }
58− }
59− return false;
60− }
61−
62− function rePopulate() {
63− for (var i=0, len=availableAppsModel.count; i<len; i++) {
64− fakeRunningAppsModel.append(availableAppsModel.get(i));
65− }
66− }
67− }
68−
69− ListModel {
70− id: availableAppsModel
71− ListElement {
72− name: "Phone"
73− icon: "phone-app"
74− exec: "/usr/bin/phone-app"
75− appId: "phone"
76− imageQml: "import QtQuick 2.0\n \
77− Rectangle { \n \
78− anchors.fill:parent \n \
79− color:'darkgreen' \n \
80− Text { anchors.centerIn: parent; text: 'PHONE' } \n \
81− }"
28+ function resetRunningApplications() {
29+ while (ApplicationManager.count > 0) {
30+ ApplicationManager.stopApplication(ApplicationManager.get(0).appId)
8231 }
8332
84− ListElement {
85− name: "Calendar"
86− icon: "calendar-app"
87− exec: "/usr/bin/calendar-app"
88− appId: "calendar"
89− imageQml: "import QtQuick 2.0\n \
90− Rectangle { \n \
91− anchors.fill:parent \n \
92− color:'darkblue' \n \
93− Text { anchors.centerIn: parent; text: 'CALENDAR'\n \
94− color:'white'} \n \
95− }"
96− }
97− }
98−
99− function resetRunningApplications() {
100− fakeRunningAppsModel.clear()
101− fakeRunningAppsModel.rePopulate()
33+ ApplicationManager.startApplication("phone-app");
34+ ApplicationManager.startApplication("webbrowser-app");
10235 }
10336
10437 Component.onCompleted: {
@@ -109,7 +42,7 @@ Item {
10942 RunningApplicationsGrid {
11043 id: runningApplicationsGrid
11144 anchors.fill: parent
112− firstModel: fakeRunningAppsModel
45+ model: ApplicationManager
11346 }
11447
11548 UT.UnityTestCase {
@@ -121,11 +54,11 @@ Item {
12154 resetRunningApplications()
12255 }
12356
124− property var calendarTile
57+ property var browserTile
12558 property var phoneTile
12659
127− property var isCalendarLongPressed: false
128− function onCalendarLongPressed() {isCalendarLongPressed = true}
60+ property var isBrowserLongPressed: false
61+ function onBrowserLongPressed() {isBrowserLongPressed = true}
12962
13063 property var isPhoneLongPressed: false
13164 function onPhoneLongPressed() {isPhoneLongPressed = true}
@@ -133,25 +66,25 @@ Item {
13366 // Tiles should go to termination mode when any one of them is long-pressed.
13467 // Long-pressing when they're in termination mode brings them back to activation mode
13568 function test_enterTerminationMode() {
136− calendarTile = findChild(runningApplicationsGrid, "runningAppTile Calendar")
137− verify(calendarTile != undefined)
138− calendarTile.onPressAndHold.connect(onCalendarLongPressed)
69+ browserTile = findChild(runningApplicationsGrid, "runningAppTile Browser")
70+ verify(browserTile != undefined)
71+ browserTile.onPressAndHold.connect(onBrowserLongPressed)
13972
14073 phoneTile = findChild(runningApplicationsGrid, "runningAppTile Phone")
14174 verify(phoneTile != undefined)
14275 phoneTile.onPressAndHold.connect(onPhoneLongPressed)
14376
144− compare(calendarTile.terminationModeEnabled, false)
77+ compare(browserTile.terminationModeEnabled, false)
14578 compare(phoneTile.terminationModeEnabled, false)
14679 compare(runningApplicationsGrid.terminationModeEnabled, false)
14780
148− isCalendarLongPressed = false
149− mousePress(calendarTile, calendarTile.width/2, calendarTile.height/2)
81+ isBrowserLongPressed = false
82+ mousePress(browserTile, browserTile.width/2, browserTile.height/2)
15083 tryCompareFunction(checkSwitchToTerminationModeAfterLongPress, true)
15184
152− mouseRelease(calendarTile, calendarTile.width/2, calendarTile.height/2)
85+ mouseRelease(browserTile, browserTile.width/2, browserTile.height/2)
15386
154− compare(calendarTile.terminationModeEnabled, true)
87+ compare(browserTile.terminationModeEnabled, true)
15588 compare(phoneTile.terminationModeEnabled, true)
15689 compare(runningApplicationsGrid.terminationModeEnabled, true)
15790
@@ -161,23 +94,23 @@ Item {
16194
16295 mouseRelease(phoneTile, phoneTile.width/2, phoneTile.height/2)
16396
164− compare(calendarTile.terminationModeEnabled, false)
97+ compare(browserTile.terminationModeEnabled, false)
16598 compare(phoneTile.terminationModeEnabled, false)
16699 compare(runningApplicationsGrid.terminationModeEnabled, false)
167100
168− calendarTile.onPressAndHold.disconnect(onCalendarLongPressed)
101+ browserTile.onPressAndHold.disconnect(onBrowserLongPressed)
169102 phoneTile.onPressAndHold.disconnect(onPhoneLongPressed)
170103 }
171104
172105 // Checks that components swicth to termination mode after (and only after) a long
173− // press happens on Calendar tile.
106+ // press happens on Browser tile.
174107 function checkSwitchToTerminationModeAfterLongPress() {
175− compare(calendarTile.terminationModeEnabled, isCalendarLongPressed)
176− compare(phoneTile.terminationModeEnabled, isCalendarLongPressed)
177− compare(runningApplicationsGrid.terminationModeEnabled, isCalendarLongPressed)
108+ compare(browserTile.terminationModeEnabled, isBrowserLongPressed)
109+ compare(phoneTile.terminationModeEnabled, isBrowserLongPressed)
110+ compare(runningApplicationsGrid.terminationModeEnabled, isBrowserLongPressed)
178111
179− return isCalendarLongPressed &&
180− calendarTile.terminationModeEnabled &&
112+ return isBrowserLongPressed &&
113+ browserTile.terminationModeEnabled &&
181114 phoneTile.terminationModeEnabled &&
182115 runningApplicationsGrid.terminationModeEnabled
183116 }
@@ -185,12 +118,12 @@ Item {
185118 // Checks that components swicth to activation mode after (and only after) a long
186119 // press happens on Phone tile.
187120 function checkSwitchToActivationModeAfterLongPress() {
188− compare(calendarTile.terminationModeEnabled, !isPhoneLongPressed)
121+ compare(browserTile.terminationModeEnabled, !isPhoneLongPressed)
189122 compare(phoneTile.terminationModeEnabled, !isPhoneLongPressed)
190123 compare(runningApplicationsGrid.terminationModeEnabled, !isPhoneLongPressed)
191124
192125 return isPhoneLongPressed &&
193− !calendarTile.terminationModeEnabled &&
126+ !browserTile.terminationModeEnabled &&
194127 !phoneTile.terminationModeEnabled &&
195128 !runningApplicationsGrid.terminationModeEnabled
196129 }
@@ -200,17 +133,17 @@ Item {
200133 function test_clickTileNotClose() {
201134 runningApplicationsGrid.terminationModeEnabled = true
202135
203− var calendarTile = findChild(runningApplicationsGrid, "runningAppTile Calendar")
204− verify(calendarTile != undefined)
136+ var browserTile = findChild(runningApplicationsGrid, "runningAppTile Browser")
137+ verify(browserTile != undefined)
205138
206− verify(fakeRunningAppsModel.contains("calendar"))
139+ verify(ApplicationManager.findApplication("webbrowser-app") !== null)
207140
208− mouseClick(calendarTile, calendarTile.width/2, calendarTile.height/2)
141+ mouseClick(browserTile, browserTile.width/2, browserTile.height/2)
209142
210− verify(fakeRunningAppsModel.contains("calendar"))
143+ verify(ApplicationManager.findApplication("webbrowser-app") !== null)
211144
212− // The tile for the Calendar app should stay there
213− tryCompareFunction(checkCalendarTileExists, true)
145+ // The tile for the Browser app should stay there
146+ tryCompareFunction(checkBrowserTileExists, true)
214147 }
215148
216149 // While in termination mode, clicking on a running application tile's close icon
@@ -218,25 +151,25 @@ Item {
218151 function test_clickCloseIconToTerminateApp() {
219152 runningApplicationsGrid.terminationModeEnabled = true
220153
221− var calendarTile = findChild(runningApplicationsGrid, "runningAppTile Calendar")
222− var calendarTileCloseButton = findChild(runningApplicationsGrid, "closeIcon Calendar")
154+ var browserTile = findChild(runningApplicationsGrid, "runningAppTile Browser")
155+ var browserTileCloseButton = findChild(runningApplicationsGrid, "closeIcon Browser")
223156
224− verify(calendarTile != undefined)
225− verify(calendarTileCloseButton != undefined)
226− verify(fakeRunningAppsModel.contains("calendar"))
157+ verify(browserTile != undefined)
158+ verify(browserTileCloseButton != undefined)
159+ verify(ApplicationManager.findApplication("webbrowser-app") !== 0)
227160
228− mouseClick(calendarTileCloseButton, calendarTileCloseButton.width/2, calendarTileCloseButton.height/2)
161+ mouseClick(browserTileCloseButton, browserTileCloseButton.width/2, browserTileCloseButton.height/2)
229162 wait(0) // spin event loop to start any pending animation
230163
231− verify(!fakeRunningAppsModel.contains("calendar"))
164+ verify(ApplicationManager.findApplication("webbrowser-app") === null)
232165
233− // The tile for the Calendar app should eventually vanish since the
166+ // The tile for the Browser app should eventually vanish since the
234167 // application has been terminated.
235− tryCompareFunction(checkCalendarTileExists, false)
168+ tryCompareFunction(checkBrowserTileExists, false)
236169 }
237170
238− function checkCalendarTileExists() {
239− return findChild(runningApplicationsGrid, "runningAppTile Calendar")
171+ function checkBrowserTileExists() {
172+ return findChild(runningApplicationsGrid, "runningAppTile Browser")
240173 != undefined
241174 }
242175
@@ -245,8 +178,8 @@ Item {
245178 function test_clickOutsideTilesDisablesTerminationMode() {
246179 runningApplicationsGrid.terminationModeEnabled = true
247180
248− var calendarTile = findChild(runningApplicationsGrid, "runningAppTile Calendar")
249− verify(calendarTile != undefined)
181+ var browserTile = findChild(runningApplicationsGrid, "runningAppTile Browser")
182+ verify(browserTile != undefined)
250183
251184 verify(runningApplicationsGrid.terminationModeEnabled);
252185