88
// wait until unity8-dash is up and running.
89
// it's started automatically by ApplicationManager mock implementation
90
tryCompare(ApplicationManager, "count", 1);
91
var dashApp = ApplicationManager.findApplication("unity8-dash");
93
tryCompare(dashApp, "state", ApplicationInfoInterface.Running);
97
ApplicationManager.requestFocusApplication("unity8-dash");
98
tryCompare(ApplicationManager, "focusedApplicationId", "unity8-dash");
99
tryCompare(stage, "state", "staged");
100
waitForRendering(stage);
103
// wait for Stage to stabilize back into its initial state
104
var appRepeater = findChild(stage, "appRepeater");
105
tryCompare(appRepeater, "count", 1);
106
tryCompare(appRepeater.itemAt(0), "x", 0);
108
stage.shellOrientationAngle = 0;
110
waitForRendering(stage)
87
113
function findAppWindowForSurfaceId(surfaceId) {
88
var delegateObjectName = "spreadDelegate_" + surfaceId;
89
var spreadDelegate = findChild(phoneStage, delegateObjectName);
114
var delegateObjectName = "appDelegate_" + surfaceId;
115
var spreadDelegate = findChild(stage, delegateObjectName);
90
116
if (!spreadDelegate) {
91
console.warn("Failed to find " + delegateObjectName + " in phoneStage ("+phoneStage+")");
117
console.warn("Failed to find " + delegateObjectName + " in stage");
94
120
var appWindow = findChild(spreadDelegate, "appWindow");
108
134
function addApps(count) {
109
135
if (count == undefined) count = 1;
110
136
for (var i = 0; i < count; i++) {
137
var startingAppId = ApplicationManager.availableApplications[ApplicationManager.count];
111
138
var appSurfaceId = topLevelSurfaceList.nextId;
112
var app = ApplicationManager.startApplication(ApplicationManager.availableApplications[ApplicationManager.count])
139
var app = ApplicationManager.startApplication(startingAppId)
113
140
tryCompare(app, "state", ApplicationInfoInterface.Running)
114
var spreadView = findChild(phoneStage, "spreadView");
115
tryCompare(spreadView, "contentX", -spreadView.shift);
116
141
waitUntilAppSurfaceShowsUp(appSurfaceId);
117
waitForRendering(phoneStage)
142
waitForRendering(stage)
143
tryCompare(ApplicationManager, "focusedApplicationId", startingAppId)
121
147
function performEdgeSwipeToShowAppSpread() {
122
var spreadView = findChild(phoneStage, "spreadView");
124
// Keep it inside the PhoneStage otherwise the controls on the right side will
148
// Keep it inside the Stage otherwise the controls on the right side will
125
149
// capture the press thus the "- 2" on startX.
126
var startX = phoneStage.width - 2;
127
var startY = phoneStage.height / 2;
150
var startX = stage.width - 2;
151
var startY = stage.height / 2;
128
152
var endY = startY;
129
var endX = phoneStage.width / 2;
153
var endX = stage.width / 2;
131
touchFlick(phoneStage, startX, startY, endX, endY,
155
touchFlick(stage, startX, startY, endX, endY,
132
156
true /* beginTouch */, true /* endTouch */, units.gu(10), 50);
134
tryCompare(spreadView, "phase", 2);
135
tryCompare(spreadView, "flicking", false);
136
tryCompare(spreadView, "moving", false);
137
waitForRendering(phoneStage);
158
tryCompare(stage, "state", "spread");
159
// Make sure all the transitions have finished
160
var appRepeater = findChild(stage, "appRepeater");
161
for (var i = 0; i < appRepeater.count; i++) {
162
waitUntilTransitionsEnd(appRepeater.itemAt(i));
164
waitForRendering(stage);
140
167
function swipeSurfaceUpwards(surfaceId) {
172
199
} while (lastValue != targetAppDelegate.animatedProgress);
175
function test_shortFlick() {
177
var startX = phoneStage.width - units.gu(1);
178
var startY = phoneStage.height / 2;
179
var endX = startX - units.gu(4);
182
var activeApp = ApplicationManager.get(0);
183
var inactiveApp = ApplicationManager.get(1);
185
touchFlick(phoneStage, startX, startY, endX, endY,
186
true /* beginTouch */, true /* endTouch */, units.gu(10), 50);
188
tryCompare(ApplicationManager, "focusedApplicationId", inactiveApp.appId)
190
touchFlick(phoneStage, startX, startY, endX, endY,
191
true /* beginTouch */, true /* endTouch */, units.gu(10), 50);
193
tryCompare(ApplicationManager, "focusedApplicationId", activeApp.appId)
196
202
function test_enterSpread_data() {
198
{tag: "<position1 (linear movement)", positionMarker: "positionMarker1", linear: true, offset: 0, endPhase: 0, targetPhase: 0, newFocusedIndex: 1 },
199
{tag: "<position1 (non-linear movement)", positionMarker: "positionMarker1", linear: false, offset: 0, endPhase: 0, targetPhase: 0, newFocusedIndex: 0 },
200
{tag: ">position1", positionMarker: "positionMarker1", linear: true, offset: +5, endPhase: 0, targetPhase: 0, newFocusedIndex: 1 },
201
{tag: "<position2 (linear)", positionMarker: "positionMarker2", linear: true, offset: 0, endPhase: 0, targetPhase: 0, newFocusedIndex: 1 },
202
{tag: "<position2 (non-linear)", positionMarker: "positionMarker2", linear: false, offset: 0, endPhase: 0, targetPhase: 0, newFocusedIndex: 1 },
203
{tag: ">position2", positionMarker: "positionMarker2", linear: true, offset: +5, endPhase: 1, targetPhase: 0, newFocusedIndex: 1 },
204
{tag: "<position3", positionMarker: "positionMarker3", linear: true, offset: 0, endPhase: 1, targetPhase: 0, newFocusedIndex: 1 },
205
{tag: ">position3", positionMarker: "positionMarker3", linear: true, offset: +5, endPhase: 1, targetPhase: 2, newFocusedIndex: 2 },
204
{tag: "<breakPoint (trigger)", progress: .2, cancel: false, endState: "staged", newFocusedIndex: 1 },
205
{tag: "<breakPoint (cancel)", progress: .2, cancel: true, endState: "staged", newFocusedIndex: 0 },
206
{tag: ">breakPoint (trigger)", progress: .5, cancel: false, endState: "spread", newFocusedIndex: 0 },
207
{tag: ">breakPoint (cancel)", progress: .8, cancel: true, endState: "staged", newFocusedIndex: 0 },
209
211
function test_enterSpread(data) {
212
var spreadView = findChild(phoneStage, "spreadView");
214
// Keep it inside the PhoneStage otherwise the controls on the right side will
214
// Keep it inside the Stage otherwise the controls on the right side will
215
215
// capture the press thus the "- 2" on startX.
216
var startX = phoneStage.width - 2;
217
var startY = phoneStage.height / 2;
216
var startX = stage.width - 2;
217
var startY = stage.height / 2;
218
218
var endY = startY;
219
var endX = spreadView.width - (spreadView.width * spreadView[data.positionMarker]) - data.offset
220
- phoneStage.dragAreaWidth;
219
var endX = stage.width - (stage.width * data.progress) - stage.dragAreaWidth;
222
221
var oldFocusedApp = ApplicationManager.get(0);
223
222
var newFocusedApp = ApplicationManager.get(data.newFocusedIndex);
225
touchFlick(phoneStage, startX, startY, endX, endY,
224
touchFlick(stage, startX, startY, endX, endY,
226
225
true /* beginTouch */, false /* endTouch */, units.gu(10), 50);
228
tryCompare(spreadView, "phase", data.endPhase)
231
touchFlick(phoneStage, endX, endY, endX + units.gu(.5), endY,
232
false /* beginTouch */, false /* endTouch */, units.gu(10), 50);
233
touchFlick(phoneStage, endY + units.gu(.5), endY, endX, endY,
234
false /* beginTouch */, false /* endTouch */, units.gu(10), 50);
237
touchRelease(phoneStage, endX, endY);
239
tryCompare(spreadView, "phase", data.targetPhase)
241
if (data.targetPhase == 2) {
242
var app2 = findChild(spreadView, "spreadDelegate_" + topLevelSurfaceList.idAt(2));
243
tryCompare(app2, "swipeToCloseEnabled", true);
244
mouseClick(app2, units.gu(1), units.gu(1));
247
tryCompare(ApplicationManager, "focusedApplicationId", newFocusedApp.appId);
228
touchFlick(stage, endX, endY, endX + units.gu(5), endY,
229
false /* beginTouch */, true /* endTouch */, units.gu(10), 50);
231
touchRelease(stage, endX, endY); }
233
tryCompare(stage, "state", data.endState);
234
tryCompare(ApplicationManager, "focusedApplicationId", data.endState == "spread" ? oldFocusedApp.appId : newFocusedApp.appId);
250
237
function test_selectAppFromSpread_data() {
263
250
function test_selectAppFromSpread(data) {
264
251
addApps(data.total)
266
var spreadView = findChild(phoneStage, "spreadView");
268
253
performEdgeSwipeToShowAppSpread();
270
tryCompare(spreadView, "phase", 2);
272
var tile = findChild(spreadView, "spreadDelegate_" + topLevelSurfaceList.idAt(data.index));
255
var tile = findChild(stage, "appDelegate_" + topLevelSurfaceList.idAt(data.index));
273
256
var appId = ApplicationManager.get(data.index).appId;
275
if (tile.mapToItem(spreadView, 0, 0).x > spreadView.width) {
258
if (tile.mapToItem(stage, 0, 0).x > stage.width - units.gu(3)) {
276
259
// Item is not visible... Need to flick the spread
277
var startX = phoneStage.width - units.gu(1);
278
var startY = phoneStage.height / 2;
260
var startX = stage.width - units.gu(1);
261
var startY = stage.height / 2;
279
262
var endY = startY;
280
263
var endX = units.gu(2);
281
touchFlick(phoneStage, startX, startY, endX, endY, true, true, units.gu(10), 50)
282
tryCompare(spreadView, "flicking", false);
283
tryCompare(spreadView, "moving", false);
284
// waitForRendering(phoneStage);
264
touchFlick(stage, startX, startY, endX, endY, true, true, units.gu(10), 50)
287
267
console.log("clicking app", data.index, "(", appId, ")")
288
tryCompare(tile, "swipeToCloseEnabled", true);
289
mouseClick(spreadView, tile.mapToItem(spreadView, 0, 0).x + units.gu(1), spreadView.height / 2)
268
var dragArea = findChild(tile, "dragArea");
269
tryCompare(dragArea, "closeable", true);
270
mouseClick(stage, tile.mapToItem(stage, 0, 0).x + units.gu(1), stage.height / 2)
290
271
tryCompare(ApplicationManager, "focusedApplicationId", appId);
291
tryCompare(spreadView, "phase", 0);
272
tryCompare(stage, "state", "staged");
294
275
function test_select_data() {
302
283
function test_select(data) {
305
var spreadView = findChild(phoneStage, "spreadView");
306
286
var selectedApp = ApplicationManager.get(data.index);
287
var appRepeater = findChild(stage, "appRepeater");
288
var selectedAppDeleage = appRepeater.itemAt(data.index);
308
290
performEdgeSwipeToShowAppSpread();
310
phoneStage.select(selectedApp.appId);
312
tryCompare(spreadView, "contentX", -spreadView.shift);
314
compare(ApplicationManager.focusedApplicationId, selectedApp.appId);
292
print("tapping", selectedAppDeleage.appId, selectedAppDeleage.visible)
293
if (selectedAppDeleage.x > stage.width - units.gu(5)) {
294
touchFlick(stage, stage.width - units.gu(2), stage.height / 2, units.gu(2), stage.height / 2, true, true, units.gu(2), 10)
297
tap(selectedAppDeleage, 1, 1);
299
tryCompare(stage, "state", "staged");
301
tryCompare(ApplicationManager, "focusedApplicationId", selectedApp.appId);
317
304
function test_backgroundClickCancelsSpread() {
320
307
var focusedAppId = ApplicationManager.focusedApplicationId;
322
309
performEdgeSwipeToShowAppSpread();
324
mouseClick(phoneStage, units.gu(1), units.gu(1));
326
// Make sure the spread is in the idle position
327
var spreadView = findChild(phoneStage, "spreadView");
328
tryCompare(spreadView, "contentX", -spreadView.shift);
310
tryCompare(stage, "state", "spread");
312
mouseClick(stage, units.gu(1), units.gu(1));
314
tryCompare(stage, "state", "staged");
330
316
// Make sure the same app is still focused
331
compare(focusedAppId, ApplicationManager.focusedApplicationId);
335
// wait until unity8-dash is up and running.
336
// it's started automatically by ApplicationManager mock implementation
337
tryCompare(ApplicationManager, "count", 1);
338
var dashApp = ApplicationManager.findApplication("unity8-dash");
340
tryCompare(dashApp, "state", ApplicationInfoInterface.Running);
346
phoneStage.shellOrientationAngle = 0;
347
phoneStage.select(ApplicationManager.get(0).appId);
349
// wait for PhoneStage to stabilize back into its initial state
350
var spreadView = findChild(phoneStage, "spreadView");
351
while (spreadView.phase !== 0 || spreadView.contentX !== -spreadView.shift || spreadView.selectedIndex != -1) {
317
tryCompare(ApplicationManager, "focusedApplicationId", focusedAppId);
356
320
function test_focusNewTopMostAppAfterFocusedOneClosesItself() {
370
334
tryCompare(firstApp, "focused", true);
373
function test_cantCloseWhileSnapping() {
376
performEdgeSwipeToShowAppSpread();
378
var spreadView = findChild(phoneStage, "spreadView");
379
var selectedApp = ApplicationManager.get(2);
381
performEdgeSwipeToShowAppSpread();
383
var app0 = findChild(spreadView, "spreadDelegate_" + topLevelSurfaceList.idAt(0));
384
var app1 = findChild(spreadView, "spreadDelegate_" + topLevelSurfaceList.idAt(1));
385
var app2 = findChild(spreadView, "spreadDelegate_" + topLevelSurfaceList.idAt(2));
387
var dragArea0 = findChild(app0, "dragArea");
388
var dragArea1 = findChild(app1, "dragArea");
389
var dragArea2 = findChild(app2, "dragArea");
391
compare(dragArea0.enabled, true);
392
compare(dragArea1.enabled, true);
393
compare(dragArea2.enabled, true);
395
phoneStage.select(selectedApp.appId);
397
// Make sure all drag areas are disabled instantly. Don't use tryCompare here!
398
compare(dragArea0.enabled, false);
399
compare(dragArea1.enabled, false);
400
compare(dragArea2.enabled, false);
402
tryCompare(spreadView, "contentX", -spreadView.shift)
405
function test_cantAccessPhoneStageWhileRightEdgeGesture() {
406
var spreadView = findChild(phoneStage, "spreadView");
407
var eventEaterArea = findChild(phoneStage, "eventEaterArea")
409
var startX = phoneStage.width - 2;
410
var startY = phoneStage.height / 2;
412
var endX = phoneStage.width / 2;
414
touchFlick(phoneStage, startX, startY, endX, endY,
415
true /* beginTouch */, false /* endTouch */, units.gu(10), 50);
417
compare(eventEaterArea.enabled, true);
419
touchRelease(phoneStage, endX, endY);
421
compare(eventEaterArea.enabled, false);
424
337
function test_leftEdge_data() {
426
{ tag: "normal", inSpread: false, leftEdgeDragWidth: units.gu(5), shouldMoveApp: true },
339
{ tag: "normal", inSpread: false, leftEdgeDragWidth: units.gu(20), shouldMoveApp: true },
427
340
{ tag: "inSpread", inSpread: true, leftEdgeDragWidth: units.gu(5), shouldMoveApp: false }
435
348
performEdgeSwipeToShowAppSpread();
438
var focusedDelegate = findChild(phoneStage, "spreadDelegate_" + topLevelSurfaceList.idAt(0));
439
phoneStage.inverseProgress = data.leftEdgeDragWidth;
441
tryCompare(focusedDelegate, "x", data.shouldMoveApp ? data.leftEdgeDragWidth : 0);
443
phoneStage.inverseProgress = 0;
445
tryCompare(focusedDelegate, "x", 0);
351
var focusedDelegate = findChild(stage, "appDelegate_" + topLevelSurfaceList.idAt(0));
352
var currentX = focusedDelegate.x;
354
stage.leftEdgeDragProgress = data.leftEdgeDragWidth;
356
tryCompare(focusedDelegate, "x", data.shouldMoveApp ? data.leftEdgeDragWidth : currentX);
358
stage.leftEdgeDragProgress = 0;
360
tryCompare(focusedDelegate, "x", currentX);
448
363
function test_focusedAppIsTheOnlyRunningApp() {
451
var delegateA = findChild(phoneStage, "spreadDelegate_" + topLevelSurfaceList.idAt(0));
366
var delegateA = findChild(stage, "appDelegate_" + topLevelSurfaceList.idAt(0));
452
367
verify(delegateA);
453
var delegateB = findChild(phoneStage, "spreadDelegate_" + topLevelSurfaceList.idAt(1));
368
var delegateB = findChild(stage, "appDelegate_" + topLevelSurfaceList.idAt(1));
454
369
verify(delegateB);
456
371
// A is focused and running, B is unfocused and suspended
490
405
compare(delegateOther.application.requestedState, ApplicationInfoInterface.RequestedSuspended);
492
407
performEdgeSwipeToShowAppSpread();
493
phoneStage.select(delegateOther.application.appId);
408
tap(delegateOther, 1, 1);
495
409
// The other app gets focused and running but dash is kept running despite being unfocused
410
tryCompare(delegateOther, "focus", true);
411
tryCompare(delegateOther.application, "requestedState", ApplicationInfoInterface.RequestedRunning);
496
412
tryCompare(delegateDash, "focus", false);
497
413
tryCompare(delegateDash.application, "requestedState", ApplicationInfoInterface.RequestedRunning);
498
compare(delegateOther.focus, true);
499
compare(delegateOther.application.requestedState, ApplicationInfoInterface.RequestedRunning);
502
416
function test_foregroundAppIsSuspendedWhenStageIsSuspended() {
505
var delegate = findChild(phoneStage, "spreadDelegate_" + topLevelSurfaceList.idAt(0));
419
var delegate = findChild(stage, "appDelegate_" + topLevelSurfaceList.idAt(0));
506
420
verify(delegate);
508
422
compare(delegate.focus, true);
509
423
compare(delegate.application.requestedState, ApplicationInfoInterface.RequestedRunning);
511
phoneStage.suspended = true;
425
stage.suspended = true;
513
427
tryCompare(delegate.application, "requestedState", ApplicationInfoInterface.RequestedSuspended);
515
phoneStage.suspended = false;
429
stage.suspended = false;
517
431
tryCompare(delegate.application, "requestedState", ApplicationInfoInterface.RequestedRunning);
520
434
function test_mouseEdgePush() {
521
var spreadView = findChild(phoneStage, "spreadView")
523
mouseMove(phoneStage, phoneStage.width - 1, units.gu(10));
436
mouseMove(stage, stage.width - 1, units.gu(10));
524
437
for (var i = 0; i < units.gu(10); i++) {
525
phoneStage.pushRightEdge(1);
438
stage.pushRightEdge(1);
527
tryCompare(spreadView, "phase", 2);
440
mouseMove(stage, stage.width - units.gu(5), units.gu(10));
441
compare(stage.state, "spread");
530
444
function test_closeSurfaceOfMultiSurfaceApp() {
540
454
performEdgeSwipeToShowAppSpread();
542
var appDelegate = findChild(phoneStage, "spreadDelegate_" + surface1Id);
544
tryCompare(appDelegate, "swipeToCloseEnabled", true);
456
var appDelegate = findChild(stage, "appDelegate_" + surface1Id);
457
var dragArea = findChild(appDelegate, "dragArea")
459
tryCompare(dragArea, "closeable", true);
546
461
compare(webbrowserApp.surfaceList.count, 2);
547
compare(webbrowserApp.state, ApplicationInfoInterface.Running);
549
463
swipeSurfaceUpwards(surface1Id);
551
465
// Surface must eventually be gone
552
466
tryCompareFunction(function() { return topLevelSurfaceList.indexForId(surface1Id); }, -1);
553
467
tryCompare(webbrowserApp.surfaceList, "count", 1);
554
compare(webbrowserApp.state, ApplicationInfoInterface.Running);
470
function test_swipeToClose_data() {
472
{ tag: "closeable", closeable: true },
473
{ tag: "not closeable", closeable: false }
477
function test_swipeToClose(data) {
478
var surface1Id = topLevelSurfaceList.nextId;
479
var webbrowserApp = ApplicationManager.startApplication("webbrowser-app");
480
waitUntilAppSurfaceShowsUp(surface1Id);
482
performEdgeSwipeToShowAppSpread();
484
var appDelegate = findChild(stage, "appDelegate_" + surface1Id);
485
var dragArea = findChild(appDelegate, "dragArea")
487
dragArea.closeable = data.closeable;
489
var oldCount = ApplicationManager.count;
491
swipeSurfaceUpwards(surface1Id);
493
tryCompare(ApplicationManager, "count", data.closeable ? oldCount - 1 : oldCount);