~mterry/+junk/u8

« back to all changes in this revision

Viewing changes to tests/qmltests/Stage/tst_WindowResizeArea.qml

Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import Unity.Test 0.1
21
21
import ".."
22
22
import "../../../qml/Components/PanelState"
23
 
import "../../../qml/Stages"
 
23
import "../../../qml/Stage"
24
24
import Ubuntu.Components 1.3
25
25
import Ubuntu.Components.ListItems 1.3 as ListItem
26
26
import Unity.Application 0.1
34
34
    Binding {
35
35
        target: PanelState
36
36
        property: "panelHeight"
37
 
        value: units.gu(2)
 
37
        value: units.gu(3)
38
38
    }
39
39
 
40
40
    Component {
44
44
            id: fakeWindow
45
45
            property alias resizeAreaMinWidth: windowResizeArea.minWidth
46
46
            property alias resizeAreaMinHeight: windowResizeArea.minHeight
47
 
            x: units.gu(20)
48
 
            y: units.gu(20)
 
47
            x: requestedX
 
48
            y: requestedY
 
49
            property real requestedX: windowedX
 
50
            property real requestedY: windowedY
49
51
            width: requestedWidth
50
52
            height: requestedHeight
51
 
            property real requestedWidth
52
 
            property real requestedHeight
 
53
            property real requestedWidth: windowedWidth
 
54
            property real requestedHeight: windowedHeight
 
55
            property real windowedX: units.gu(20)
 
56
            property real windowedY: units.gu(20)
 
57
            property real windowedWidth
 
58
            property real windowedHeight
53
59
            property real minimumWidth: 0
54
60
            property real minimumHeight: 0
55
61
            property real maximumWidth: 0
58
64
            property real heightIncrement: 0
59
65
 
60
66
            property int windowState: WindowStateStorage.WindowStateNormal
 
67
            property real restoredX
 
68
            property real restoredY
61
69
 
62
70
            states: [
63
71
                State { name: "normal"; when: windowState == WindowStateStorage.WindowStateNormal },
 
72
                State { name: "restored"; when: windowState == WindowStateStorage.WindowStateRestored },
64
73
                State { name: "maximized"; when: windowState == WindowStateStorage.WindowStateMaximized }
65
74
            ]
66
75
 
69
78
            }
70
79
 
71
80
            function restoreFromMaximized() {
72
 
                windowState = WindowStateStorage.WindowStateNormal
 
81
                windowState = WindowStateStorage.WindowStateRestored
 
82
            }
 
83
 
 
84
            function restore(animated,state) {
 
85
                windowState = state || WindowStateStorage.WindowStateRestored;
 
86
                windowState &= ~WindowStateStorage.WindowStateMinimized; // clear the minimized bit
73
87
            }
74
88
 
75
89
            WindowResizeArea {
226
240
        property var fakeWindow: windowLoader.item
227
241
 
228
242
        function init() {
229
 
            fakeWindow.x = units.gu(20)
230
 
            fakeWindow.y = units.gu(20)
231
 
            fakeWindow.requestedWidth = units.gu(20)
232
 
            fakeWindow.requestedHeight = units.gu(20)
 
243
            fakeWindow.windowedX = units.gu(20)
 
244
            fakeWindow.windowedY = units.gu(20)
 
245
            fakeWindow.windowedWidth = units.gu(20)
 
246
            fakeWindow.windowedHeight = units.gu(20)
233
247
            fakeWindow.resizeAreaMinWidth = units.gu(15);
234
248
            fakeWindow.resizeAreaMinHeight = units.gu(10);
235
249
            fakeWindow.minimumWidth = 0;
254
268
        }
255
269
 
256
270
        function test_resizeWindowRightBottom(data) {
257
 
            var initialWindowX = fakeWindow.x;
258
 
            var initialWindowY = fakeWindow.y;
 
271
            var initialWindowX = fakeWindow.windowedX;
 
272
            var initialWindowY = fakeWindow.windowedY;
259
273
            var initialWindowWidth = fakeWindow.width
260
274
            var initialWindowHeight = fakeWindow.height
261
275
 
266
280
            tryCompare(fakeWindow, "width", Math.max(initialWindowWidth + data.dx, fakeWindow.resizeAreaMinWidth));
267
281
            tryCompare(fakeWindow, "height", Math.max(initialWindowHeight + data.dy, fakeWindow.resizeAreaMinHeight));
268
282
 
269
 
            compare(fakeWindow.x, initialWindowX);
270
 
            compare(fakeWindow.y, initialWindowY);
 
283
            compare(fakeWindow.requestedX, initialWindowX);
 
284
            compare(fakeWindow.requestedY, initialWindowY);
271
285
        }
272
286
 
273
287
        function test_resizeWindowLeftTop_data() {
280
294
        }
281
295
 
282
296
        function test_resizeWindowLeftTop(data) {
283
 
            var initialWindowX = fakeWindow.x;
284
 
            var initialWindowY = fakeWindow.y;
 
297
            var initialWindowX = fakeWindow.windowedX;
 
298
            var initialWindowY = fakeWindow.windowedY;
285
299
            var initialWindowWidth = fakeWindow.width
286
300
            var initialWindowHeight = fakeWindow.height
287
301
 
294
308
 
295
309
            var maxMoveX = initialWindowWidth - fakeWindow.resizeAreaMinWidth;
296
310
            var maxMoveY = initialWindowHeight - fakeWindow.resizeAreaMinHeight;
297
 
            compare(fakeWindow.x, Math.min(initialWindowX + data.dx, initialWindowX + maxMoveX));
298
 
            compare(fakeWindow.y, Math.min(initialWindowY + data.dy, initialWindowY + maxMoveY));
 
311
            compare(fakeWindow.requestedX, Math.min(initialWindowX + data.dx, initialWindowX + maxMoveX));
 
312
            compare(fakeWindow.requestedY, Math.min(initialWindowY + data.dy, initialWindowY + maxMoveY));
299
313
        }
300
314
 
301
315
        function test_saveRestoreSize() {
302
 
            var initialWindowX = fakeWindow.x;
303
 
            var initialWindowY = fakeWindow.y;
 
316
            var initialWindowX = fakeWindow.windowedX;
 
317
            var initialWindowY = fakeWindow.windowedY;
304
318
            var initialWindowWidth = fakeWindow.width
305
319
            var initialWindowHeight = fakeWindow.height
306
320
 
332
346
        }
333
347
 
334
348
        function test_resizeSmallerAndLarger(data) {
335
 
            var initialWindowX = fakeWindow.x;
336
 
            var initialWindowY = fakeWindow.y;
 
349
            var initialWindowX = fakeWindow.windowedX;
 
350
            var initialWindowY = fakeWindow.windowedY;
337
351
            var initialWindowWidth = fakeWindow.width
338
352
            var initialWindowHeight = fakeWindow.height
339
353
 
348
362
        }
349
363
 
350
364
        function test_saveRestoreMaximized() {
351
 
            var initialWindowX = fakeWindow.x;
352
 
            var initialWindowY = fakeWindow.y;
 
365
            var initialWindowX = fakeWindow.windowedX;
 
366
            var initialWindowY = fakeWindow.windowedY;
353
367
 
354
368
            var moveDelta = units.gu(5);
355
369
 
356
 
            fakeWindow.x = initialWindowX + moveDelta
357
 
            fakeWindow.y = initialWindowY + moveDelta
 
370
            fakeWindow.windowedX = initialWindowX + moveDelta
 
371
            fakeWindow.windowedY = initialWindowY + moveDelta
358
372
 
359
373
            // Now change the state to maximized. The window should not keep updating the stored values
360
374
            fakeWindow.maximize()
361
 
            fakeWindow.x = 31415 // 0 is too risky to pass the test even when broken
362
 
            fakeWindow.y = 31415
 
375
            fakeWindow.windowedX = 31415 // 0 is too risky to pass the test even when broken
 
376
            fakeWindow.windowedY = 31415
363
377
 
364
378
            // This will destroy the window and recreate it
365
379
            windowLoader.active = false;
389
403
        }
390
404
 
391
405
        function test_restoreMovesIntoBounds(data) {
392
 
            fakeWindow.x = data.x;
393
 
            fakeWindow.y = data.y;
 
406
            fakeWindow.windowedX = data.x;
 
407
            fakeWindow.windowedY = data.y;
394
408
            fakeWindow.width = data.w;
395
409
            fakeWindow.height = data.h;
396
410
            waitForRendering(root);
402
416
            waitForRendering(root)
403
417
 
404
418
            // Make sure it's again where we left it in normal state before destroying
405
 
            compare(fakeWindow.x >= 0, true)
406
 
            compare(fakeWindow.y >= PanelState.panelHeight, true)
407
 
            compare(fakeWindow.x + fakeWindow.width <= root.width, true)
408
 
            compare(fakeWindow.y + fakeWindow.height <= root.height, true)
 
419
            compare(fakeWindow.requestedX >= 0, true)
 
420
            compare(fakeWindow.requestedY >= PanelState.panelHeight, true)
 
421
            compare(fakeWindow.requestedX + fakeWindow.width <= root.width, true)
 
422
            compare(fakeWindow.requestedY + fakeWindow.height <= root.height, true)
409
423
 
410
424
            waitForRendering(root)
411
425
        }
417
431
            and height) increment value.
418
432
         */
419
433
        function test_sizeIncrement() {
420
 
            var initialWindowX = fakeWindow.x;
421
 
            var initialWindowY = fakeWindow.y;
 
434
            var initialWindowX = fakeWindow.windowedX;
 
435
            var initialWindowY = fakeWindow.windowedY;
422
436
            var initialWindowWidth = fakeWindow.width
423
437
            var initialWindowHeight = fakeWindow.height
424
438
 
448
462
            Tests that when dragging a window border you cannot make it bigger than its maximum size
449
463
         */
450
464
        function test_maximumSize() {
451
 
            fakeWindow.x = units.gu(1);
452
 
            fakeWindow.y = units.gu(1);
 
465
            fakeWindow.windowedX = units.gu(1);
 
466
            fakeWindow.windowedY = units.gu(1);
453
467
            fakeWindow.resizeAreaMinWidth = 1; // so it does not interfere with anything
454
468
            fakeWindow.resizeAreaMinHeight = 1; // so it does not interfere with anything
455
 
            fakeWindow.requestedWidth = units.gu(10);
456
 
            fakeWindow.requestedHeight = units.gu(10);
 
469
            fakeWindow.windowedWidth = units.gu(10);
 
470
            fakeWindow.windowedHeight = units.gu(10);
457
471
 
458
472
            fakeWindow.maximumWidth = units.gu(20);
459
473
            fakeWindow.maximumHeight = units.gu(20);
478
492
            Tests that when dragging a window border you cannot make it smaller than its minimum size
479
493
         */
480
494
        function test_minimumSize() {
481
 
            fakeWindow.x = units.gu(1);
482
 
            fakeWindow.y = units.gu(1);
 
495
            fakeWindow.windowedX = units.gu(1);
 
496
            fakeWindow.windowedY = units.gu(1);
483
497
            fakeWindow.resizeAreaMinWidth = 1; // so it does not interfere with anything
484
498
            fakeWindow.resizeAreaMinHeight = 1; // so it does not interfere with anything
485
 
            fakeWindow.requestedWidth = units.gu(20);
486
 
            fakeWindow.requestedHeight = units.gu(20);
 
499
            fakeWindow.windowedWidth = units.gu(20);
 
500
            fakeWindow.windowedHeight = units.gu(20);
487
501
 
488
502
            fakeWindow.minimumWidth = units.gu(10);
489
503
            fakeWindow.minimumHeight = units.gu(10);