~ci-train-bot/unity8/unity8-ubuntu-zesty-2663

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
/*
 * Copyright 2013-2015 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.4
import QtQuick.Layouts 1.1
import QtTest 1.0
import Unity.Test 0.1
import Ubuntu.Components 1.3
import Ubuntu.Components.ListItems 1.3 as ListItem
import Unity.Application 0.1
import QMenuModel 0.1
import Ubuntu.Telephony 0.1 as Telephony
import AccountsService 0.1
import Unity.InputInfo 0.1
import "../../../qml/Panel"
import "../../../qml/Components/PanelState"
import "../Stage"
import ".."

PanelTest {
    id: root
    width: units.gu(120)
    height: units.gu(71)
    color: "black"

    Binding {
        target: QuickUtils
        property: "keyboardAttached"
        value: keyboardAttached.checked
    }

    readonly property alias panelState: panel.panelState

    SurfaceManager { id: sMgr }
    ApplicationMenuDataLoader {
        id: appMenuData
        surfaceManager: sMgr
    }

    Component.onCompleted: {
        theme.name = "Ubuntu.Components.Themes.SuruDark"
    }

    Rectangle {
        anchors.fill: parent
        color: "darkgrey"
    }

    RowLayout {
        anchors.fill: parent
        anchors.margins: units.gu(1)
        clip: true

        Rectangle {
            Layout.fillWidth: true
            Layout.fillHeight: true

            id: itemArea
            color: backgroundMouseArea.pressed ? "red" : "blue"

            MouseArea {
                id: backgroundMouseArea
                anchors.fill: parent
                hoverEnabled: true

                Panel {
                    id: panel
                    anchors.fill: parent
                    mode: modeSelector.model[modeSelector.selectedIndex]

                    indicatorMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
                    applicationMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width

                    applicationMenus {
                        model: UnityMenuModel {
                            modelData: appMenuData.generateTestData(5, 4, 2, 3, "menu")
                        }

                        hides: [ panel.indicators ]
                    }

                    indicators {
                        model: root.indicatorsModel
                        hides: [ panel.applicationMenus ]
                    }
                }
            }
        }

        ColumnLayout {
            Layout.alignment: Qt.AlignTop
            Layout.fillWidth: false

            ListItem.ItemSelector {
                id: modeSelector
                anchors { left: parent.left; right: parent.right }
                activeFocusOnPress: false
                text: "Mode"
                model: ["staged", "windowed" ]
                onSelectedIndexChanged: {
                    panel.mode = model[selectedIndex];
                    keyboardAttached.checked = panel.mode == "windowed"
                }
            }

            Button {
                Layout.fillWidth: true
                text: panel.indicators.shown ? "Hide" : "Show"
                onClicked: {
                    if (panel.indicators.shown) {
                        panel.indicators.hide();
                    } else {
                        panel.indicators.show();
                    }
                }
            }

            Button {
                text: panel.fullscreenMode ? "Maximize" : "FullScreen"
                Layout.fillWidth: true
                onClicked: panel.fullscreenMode = !panel.fullscreenMode
            }

            Button {
                Layout.fillWidth: true
                text: callManager.hasCalls ? "Called" : "No Calls"
                onClicked: {
                    if (callManager.foregroundCall) {
                        callManager.foregroundCall = null;
                    } else {
                        callManager.foregroundCall = phoneCall;
                    }
                }
            }

            RowLayout {
                Layout.fillWidth: true
                CheckBox {
                    id: windowControlsCB
                    onClicked: panelState.decorationsVisible = checked
                }
                Label {
                    text: "Show window decorations"
                    color: "white"
                }
            }

            RowLayout {
                Layout.fillWidth: true
                CheckBox {
                    onClicked: panelState.title = checked ? "Fake window title" : ""
                }
                Label {
                    text: "Show fake window title"
                    color: "white"
                }
            }

            Rectangle {
                Layout.preferredHeight: units.dp(1);
                Layout.fillWidth: true;
                color: "black"
            }

            Rectangle {
                Layout.preferredHeight: units.dp(1);
                Layout.fillWidth: true;
                color: "black"
            }

            Repeater {
                model: root.originalModelData
                RowLayout {
                    CheckBox {
                        checked: true
                        onCheckedChanged: checked ? insertIndicator(index) : removeIndicator(index);
                    }
                    Label {
                        Layout.fillWidth: true
                        text: modelData["identifier"]
                        color: "white"
                    }

                    CheckBox {
                        checked: true
                        onCheckedChanged: setIndicatorVisible(index, checked);
                    }
                    Label {
                        text: "visible"
                        color: "white"
                    }
                }
            }

            Rectangle {
                Layout.preferredHeight: units.dp(1);
                Layout.fillWidth: true;
                color: "black"
            }

            MouseTouchEmulationCheckbox {
                id: mouseEmulation
                color: "white"
                checked: panel.mode == "staged"
            }

            RowLayout {
                Layout.fillWidth: true
                CheckBox {
                    id: keyboardAttached
                }
                Label {
                    text: "Keyboard Attached"
                    color: "white"
                }
            }
        }
    }

    Telephony.CallEntry {
        id: phoneCall
        phoneNumber: "+447812221111"
    }

    UnityTestCase {
        name: "Panel"
        when: windowShown

        SignalSpy {
            id: backgroundPressedSpy
            target: backgroundMouseArea
            signalName: "pressedChanged"
        }

        SignalSpy {
            id: windowControlButtonsSpy
            target: panelState
            signalName: "closeClicked"
        }

        function init() {
            panel.mode = "staged";
            mouseEmulation.checked = true;
            panel.fullscreenMode = false;
            callManager.foregroundCall = null;

            panelState.title = "";
            panelState.decorationsVisible = false;

            // Wait for the indicators to get into position.
            // (switches between normal and fullscreen modes are animated)
            var panelArea = findChild(panel, "panelArea");
            tryCompare(panelArea, "y", 0);

            backgroundPressedSpy.clear();
            compare(backgroundPressedSpy.valid, true);
            windowControlButtonsSpy.clear();
            compare(windowControlButtonsSpy.valid, true);

            waitForRendering(panel);
        }

        function cleanup() {
            panel.hasKeyboard = false;
            panel.indicators.hide();
            panel.applicationMenus.hide();
            waitForAllAnimationToComplete("initial");
        }

        function get_indicator_item(index) {
            var indicatorItem = findChild(panel, root.originalModelData[index]["identifier"]+"-panelItem");
            verify(indicatorItem !== null);

            return indicatorItem;
        }

        function waitForAllAnimationToComplete(state) {

            waitUntilTransitionsEnd(panel);
            tryCompare(panel.indicators.hideAnimation, "running", false);
            tryCompare(panel.indicators.showAnimation, "running", false);
            tryCompare(panel.indicators, "state", state);

            for (var i = 0; i < root.originalModelData.length; i++) {
                var indicatorItem = get_indicator_item(i);

                var itemState = findInvisibleChild(indicatorItem, "indicatorItemState");
                verify(itemState !== null);

                waitUntilTransitionsEnd(itemState);
            }

            tryCompare(panel.applicationMenus.hideAnimation, "running", false);
            tryCompare(panel.applicationMenus, "state", state);
        }

        function pullDownIndicatorsMenu() {
            var showDragHandle = findChild(panel.indicators, "showDragHandle");
            touchFlick(showDragHandle,
                       showDragHandle.width / 2,
                       showDragHandle.height / 2,
                       showDragHandle.width / 2,
                       showDragHandle.height / 2 + (showDragHandle.autoCompleteDragThreshold * 1.1));
            tryCompare(panel.indicators, "fullyOpened", true);
        }

        function pullDownApplicationsMenu() {
            var showDragHandle = findChild(panel.applicationMenus, "showDragHandle");
            touchFlick(showDragHandle,
                       showDragHandle.width / 2,
                       showDragHandle.height / 2,
                       showDragHandle.width / 2,
                       showDragHandle.height / 2 + (showDragHandle.autoCompleteDragThreshold * 1.1));
            tryCompare(panel.applicationMenus, "fullyOpened", true);
        }

        function test_drag_indicator_item_down_shows_menu_data() {
            return [
                { tag: "pinned", fullscreen: false, call: null, y: 0 },
                { tag: "fullscreen", fullscreen: true, call: null, y: -panel.minimizedPanelHeight },
                { tag: "pinned-callActive", fullscreen: false, call: phoneCall, y: 0},
                { tag: "fullscreen-callActive", fullscreen: true, call: phoneCall, y: -panel.minimizedPanelHeight }
            ];
        }

        // Dragging from a indicator item in the panel will gradually expose the
        // indicators, first by running the hint animation, then after dragging down will
        // expose more of the panel, binding it to the selected indicator and opening it's menu.
        // Tested from first Y pixel to check for swipe from offscreen.
        function test_drag_indicator_item_down_shows_menu(data) {
            skip("Unstable test; panel expansion refactor may be required");

            panel.fullscreenMode = data.fullscreen;
            callManager.foregroundCall = data.call;

            var panelRow = findChild(panel.indicators, "panelItemRow");
            verify(panelRow !== null);

            var menuContent = findChild(panel.indicators, "menuContent");
            verify(menuContent !== null);

            var panelArea = findChild(panel, "panelArea");
            verify(panelArea !== null);

            // Wait for the indicators to get into position.
            // (switches between normal and fullscreen modes are animated)
            tryCompareFunction(function() { return panelArea.y }, data.y);

            for (var i = 0; i < root.originalModelData.length; i++) {
                waitForAllAnimationToComplete("initial");

                var indicatorItem = get_indicator_item(i);

                var startXPosition = panel.mapFromItem(indicatorItem, indicatorItem.width / 2, 0).x;

                touchFlick(panel,
                           startXPosition, 0,
                           startXPosition, panel.height,
                           true /* beginTouch */, false /* endTouch */, 1, 15);

                // Indicators height should follow the drag, and therefore increase accordingly.
                // They should be at least half-way through the screen
                tryCompareFunction(
                    function() {return panel.indicators.height >= panel.height * 0.5},
                    true);

                touchRelease(panel, startXPosition, panel.height);

                tryCompare(panelRow, "currentItemIndex", i, undefined, "Indicator item should be activated at position " + i);
                compare(menuContent.currentMenuIndex, i, "Menu conetent should be activated for item at position " + i);

                // init for next indicatorItem
                panel.indicators.hide();
            }
        }

        function test_drag_panel_handle_up_hides_menu_data() {
            return [
                { tag: "indicators-pinned", section: panel.indicators, fullscreen: false, call: null },
                { tag: "indicators-fullscreen", section: panel.indicators, fullscreen: true, call: null },
                { tag: "indicators-pinned-callActive", section: panel.indicators, fullscreen: false, call: phoneCall },
                { tag: "indicators-fullscreen-callActive", section: panel.indicators, fullscreen: true, call: phoneCall },
                { tag: "appMenus-pinned", section: panel.applicationMenus, fullscreen: false, call: null },
                { tag: "appMenus-fullscreen", section: panel.applicationMenus, fullscreen: true, call: null },
                { tag: "appMenus-pinned-callActive", section: panel.applicationMenus, fullscreen: false, call: phoneCall },
                { tag: "appMenus-fullscreen-callActive", section: panel.applicationMenus, fullscreen: true, call: phoneCall }
            ];
        }

        // Dragging the shown indicators up from bottom of panel will hide the indicators
        // Tested from last Y pixel to check for swipe from offscreen.
        function test_drag_panel_handle_up_hides_menu(data) {
            panel.fullscreenMode = data.fullscreen;
            callManager.foregroundCall = data.call;

            var panelRow = findChild(data.section, "panelItemRow");
            verify(panelRow !== null);

            var panelArea = findChild(panel, "panelArea");
            verify(panelArea !== null);

            // Wait for the indicators to get into position.
            // (switches between normal and fullscreen modes are animated)
            tryCompareFunction(function() { return panelArea.y }, data.fullscreen ? -panel.minimizedPanelHeight : 0);

            data.section.show();
            tryCompare(data.section.showAnimation, "running", false);
            tryCompare(data.section, "unitProgress", 1);

            touchFlick(data.section,
                       data.section.width / 2, panel.height,
                       data.section.width / 2, 0,
                       true /* beginTouch */, false /* endTouch */, units.gu(5), 15);

            // Indicators height should follow the drag, and therefore increase accordingly.
            // They should be at least half-way through the screen
            tryCompareFunction(
                function() {return data.section.height <= panel.height * 0.5},
                true);

            touchRelease(data.section, data.section.width / 2, 0);

            tryCompare(data.section.hideAnimation, "running", true);
            tryCompare(data.section.hideAnimation, "running", false);
            tryCompare(data.section, "state", "initial");
        }

        function test_hint_data() {
            return [
                { tag: "indicators-normal", section: panel.indicators, fullscreen: false, call: null, hintExpected: true},
                { tag: "indicators-fullscreen", section: panel.indicators, fullscreen: true, call: null, hintExpected: false},
                { tag: "indicators-callActive", section: panel.indicators, fullscreen: false, call: phoneCall, hintExpected: false},
                { tag: "appMenus-normal", section: panel.applicationMenus, fullscreen: false, call: null, hintExpected: true},
                { tag: "appMenus-fullscreen", section: panel.applicationMenus, fullscreen: true, call: null, hintExpected: false},
                { tag: "appMenus-callActive", section: panel.applicationMenus, fullscreen: false, call: phoneCall, hintExpected: false},
            ];
        }

        function test_hint(data) {
            panelState.title = "Fake Title"
            panel.fullscreenMode = data.fullscreen;
            callManager.foregroundCall = data.call;

            if (data.fullscreen) {
                // Wait for the indicators to get into position.
                // (switches between normal and fullscreen modes are animated)
                var panelArea = findChild(panel, "panelArea");
                tryCompare(panelArea, "y", -panel.minimizedPanelHeight);
            }

            var mappedPosition = root.mapFromItem(data.section,
                                                  data.section.barWidth / 2, data.section.minimizedPanelHeight / 2);

            touchPress(panel, mappedPosition.x, panel.minimizedPanelHeight / 2);

            var showDragHandle = findChild(data.section, "showDragHandle")
            var hintingAnimation = findInvisibleChild(showDragHandle, "hintingAnimation");
            verify(hintingAnimation);

            compare(hintingAnimation.running, data.hintExpected)
            tryCompare(hintingAnimation, "running", false); // wait till animation completes

            // no hint animation when fullscreen
            compare(data.section.partiallyOpened, data.hintExpected, "Indicator should be partialy opened");
            compare(data.section.fullyOpened, false, "Indicator should not be fully opened");

            touchRelease(panel, mappedPosition.x, panel.minimizedPanelHeight / 2);
        }

        function test_drag_applicationMenu_down_shows_menu_data() {
            return [
                { tag: "normal", fullscreen: false, call: null, hintExpected: true},
                { tag: "fullscreen", fullscreen: true, call: null, hintExpected: false},
                { tag: "callActive", fullscreen: false, call: phoneCall, hintExpected: false}
            ];
        }

        // Dragging the application menu will gradually expose the
        // menus, first by running the hint animation, then after dragging down will
        // expose more of the panel. Releasing the touch will complete the show.
        function test_drag_applicationMenu_down_shows_menu(data) {
            panelState.title = "Fake Title";
            panel.fullscreenMode = data.fullscreen;
            callManager.foregroundCall = data.call;

            var panelRow = findChild(panel.indicators, "panelItemRow");
            verify(panelRow !== null);

            var menuContent = findChild(panel.indicators, "menuContent");
            verify(menuContent !== null);

            var panelArea = findChild(panel, "panelArea");
            verify(panelArea !== null);

            // Wait for the indicators to get into position.
            // (switches between normal and fullscreen modes are animated)
            tryCompareFunction(function() { return panelArea.y }, data.fullscreen ? -panel.minimizedPanelHeight : 0);

            touchFlick(panel,
                       units.gu(1), 0,
                       units.gu(1), panel.height,
                       true /* beginTouch */, false /* endTouch */, units.gu(5), 15);

            // Indicators height should follow the drag, and therefore increase accordingly.
            // They should be at least half-way through the screen
            tryCompareFunction(
                function() {return panel.applicationMenus.height >= panel.height * 0.5},
                true);

            touchRelease(panel, units.gu(1), panel.height);

            tryCompare(panel.applicationMenus, "fullyOpened", true)
        }

        /* Checks that no input reaches items behind the indicator bar.
           Ie., the indicator bar should eat all input events that hit it.
         */
        function test_indicatorBarEatsAllEvents() {
            // Perform several taps throughout the length of the indicator bar to ensure
            // that it doesn't have a "weak spot" from where taps pass through.
            var numTaps = 5;
            var stepLength = (panel.width / (numTaps + 1));
            var tapY = panel.minimizedPanelHeight / 2;
            for (var i = 1; i <= numTaps; ++i) {
                tap(panel, stepLength * i, tapY);
                tryCompare(panel.indicators, "fullyClosed", true);
            }
        }

        function test_darkenedAreaEatsAllIndicatorEvents() {

            // The center of the area not covered by the indicators menu
            // Ie, the visible darkened area behind the menu
            var touchPosX = (panel.width - panel.indicators.width) / 2
            var touchPosY = panel.minimizedPanelHeight +
                    ((panel.height - panel.minimizedPanelHeight) / 2)

            // input goes through while the indicators menu is closed
            tryCompare(panel.indicators, "fullyClosed", true);
            compare(backgroundPressedSpy.count, 0);
            tap(panel, touchPosX, touchPosY);
            compare(backgroundPressedSpy.count, 2);

            pullDownIndicatorsMenu();

            // Darkened area eats input when the indicators menu is fully opened
            tap(panel, touchPosX, touchPosY);
            compare(backgroundPressedSpy.count, 2);
            backgroundPressedSpy.clear();

            // And should continue to eat inpunt until the indicators menu is fully closed
            wait(10);
            while (!panel.indicators.fullyClosed) {
                tap(panel, touchPosX, touchPosY);

                // it could have got fully closed during the tap
                // so we have to double check here
                if (!panel.indicators.fullyClosed) {
                    compare(backgroundPressedSpy.count, 0);
                }

                // let the animation go a bit further
                wait(50);
            }

            // Now that's fully closed, input should go through again
            backgroundPressedSpy.clear();
            tap(panel, touchPosX, touchPosY);
            compare(backgroundPressedSpy.count, 2);
        }

        function test_darkenedAreaEatsAllApplicationMenuEvents() {
            panelState.title = "Fake Title"

            // The center of the area not covered by the indicators menu
            // Ie, the visible darkened area behind the menu
            var touchPosX = panel.applicationMenus.width + (panel.width - panel.applicationMenus.width) / 2
            var touchPosY = panel.minimizedPanelHeight +
                    ((panel.height - panel.minimizedPanelHeight) / 2)

            // input goes through while the indicators menu is closed
            tryCompare(panel.applicationMenus, "fullyClosed", true);
            compare(backgroundPressedSpy.count, 0);
            tap(panel, touchPosX, touchPosY);
            compare(backgroundPressedSpy.count, 2);

            pullDownApplicationsMenu();

            // Darkened area eats input when the indicators menu is fully opened
            tap(panel, touchPosX, touchPosY);
            compare(backgroundPressedSpy.count, 2);
            backgroundPressedSpy.clear();

            // And should continue to eat inpunt until the indicators menu is fully closed
            wait(10);
            while (!panel.applicationMenus.fullyClosed) {
                tap(panel, touchPosX, touchPosY);

                // it could have got fully closed during the tap
                // so we have to double check here
                if (!panel.applicationMenus.fullyClosed) {
                    compare(backgroundPressedSpy.count, 0);
                }

                // let the animation go a bit further
                wait(50);
            }

            // Now that's fully closed, input should go through again
            backgroundPressedSpy.clear();
            tap(panel, touchPosX, touchPosY);
            compare(backgroundPressedSpy.count, 2);
        }


        /*
          Regression test for https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1439318
          When the panel is in fullscreen mode and the user taps near the top edge,
          the panel should take no action and the tap should reach the item behind the
          panel.
         */
        function test_tapNearTopEdgeWithPanelInFullscreenMode() {
            var panelArea = findChild(panel, "panelArea");
            verify(panelArea);

            panel.fullscreenMode = true;
            // wait until if finishes hiding itself
            tryCompare(panelArea, "y", -panel.minimizedPanelHeight);

            compare(panel.indicators.shown, false);
            verify(panel.indicators.fullyClosed);

            // tap near the very top of the screen
            tap(itemArea, itemArea.width / 2, 2);

            // the tap should have reached the item behind the panel
            compare(backgroundPressedSpy.count, 2);

            // give it a couple of event loop iterations for any animations etc to kick in
            wait(50);

            compare(panel.indicators.shown, false);
            verify(panel.indicators.fullyClosed);
        }

        function test_tapToReturnCallDoesntExpandIndicators() {
            compare(panel.indicators.shown, false);
            verify(panel.indicators.fullyClosed);

            callManager.foregroundCall = phoneCall;

            var dashApp = ApplicationManager.startApplication("unity8-dash");
            tryCompare(dashApp.surfaceList, "count", 1);
            dashApp.surfaceList.get(0).activate();
            tryCompare(ApplicationManager, "focusedApplicationId", "unity8-dash");

            mouseClick(panel.indicators,
                       panel.indicators.width / 2,
                       panel.minimizedPanelHeight / 2);

            compare(panel.indicators.shown, false);
            verify(panel.indicators.fullyClosed);

            // clean up
            ApplicationManager.stopApplication("unity8-dash");
        }

        function test_openAndClosePanelWithMouseClicks() {
            compare(panel.indicators.shown, false);
            verify(panel.indicators.fullyClosed);

            mouseClick(panel.indicators,
                    panel.indicators.width / 2,
                    panel.minimizedPanelHeight / 2);

            compare(panel.indicators.shown, true);
            tryCompare(panel.indicators, "fullyOpened", true);

            var handle = findChild(panel.indicators, "handle");
            verify(handle);

            mouseClick(handle);

            compare(panel.indicators.shown, false);
            tryCompare(panel.indicators, "fullyClosed", true);
        }

        // https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1611959
        function test_windowControlButtonsFittsLaw() {
            panel.mode = "windowed";
            var windowControlArea = findChild(panel, "windowControlArea");
            verify(windowControlArea, "Window control area should have been created in windowed mode")

            panelState.decorationsVisible = true;
            // click in very topleft corner and verify the close button got clicked too
            mouseMove(panel, 0, 0);
            mouseClick(panel, 0, 0, undefined /*button*/, undefined /*modifiers*/, 100 /*short delay*/);
            compare(windowControlButtonsSpy.count, 1);
        }

        function test_hidingKeyboardIndicator_data() {
            return [
                { tag: "No keyboard, no keymap", keyboard: false, keymaps: [], hidden: true },
                { tag: "No keyboard, one keymap", keyboard: false, keymaps: ["us"], hidden: true },
                { tag: "No keyboard, 2 keymaps", keyboard: false, keymaps: ["us", "cs"], hidden: true },
                { tag: "Keyboard, no keymap", keyboard: true, keymaps: [], hidden: false },
                { tag: "Keyboard, one keymap", keyboard: true, keymaps: ["us"], hidden: false },
                { tag: "Keyboard, 2 keymaps", keyboard: true, keymaps: ["us", "cs"], hidden: false }
            ];
        }

        function test_hidingKeyboardIndicator(data) {
            var item = findChild(panel, "indicator-keyboard-panelItem");
            AccountsService.keymaps = data.keymaps;
            panel.hasKeyboard = data.keyboard;
            if (data.keyboard) {
                MockInputDeviceBackend.addMockDevice("/indicator_kbd0", InputInfo.Keyboard);
            } else {
                MockInputDeviceBackend.removeDevice("/indicator_kbd0");
            }

            compare(item.hidden, data.hidden);
        }

        function test_visibleIndicators_data() {
            return [
                { visible: [true, false, true, false, true, true, false, true] },
                { visible: [true, false, false, false, false, false, true, false] }
            ];
        }

        function test_visibleIndicators(data) {
            panel.hasKeyboard = true;
            for (var i = 0; i < data.visible.length; i++) {
                var visible = data.visible[i];
                root.setIndicatorVisible(i, visible);

                var dataItem = findChild(panel, root.originalModelData[i]["identifier"] + "-panelItem");
                tryCompare(dataItem, "opacity", visible ? 1.0 : 0.0);
                tryCompareFunction(function() { return dataItem.width > 0.0; }, visible);
            }

            panel.indicators.show();
            tryCompare(panel.indicators.showAnimation, "running", false);
            tryCompare(panel.indicators, "unitProgress", 1);

            for (var i = 0; i < data.visible.length; i++) {
                root.setIndicatorVisible(i, data.visible[i]);

                var dataItem = findChild(panel, root.originalModelData[i]["identifier"] + "-panelItem");
                tryCompareFunction(function() { return dataItem.opacity > 0.0; }, true);
                tryCompareFunction(function() { return dataItem.width > 0.0; }, true);
            }
        }

        function test_stagedApplicationMenuBarShowOnMouseHover() {
            panelState.title = "Fake Title";
            panel.mode = "staged";
            mouseEmulation.checked = false;

            var appTitle = findChild(panel.applicationMenus, "panelTitle"); verify(appTitle);
            var appMenuRow = findChild(panel.applicationMenus, "panelRow"); verify(appMenuRow);
            var appMenuBar = findChild(panel, "menuBar"); verify(appMenuBar);

            tryCompare(appTitle, "visible", true, undefined, "App title should be visible");
            tryCompare(appMenuBar, "visible", false, undefined, "App menu bar should not be visible");

            mouseMove(panel, panel.width/2, panel.panelHeight);

            tryCompare(appTitle, "visible", false, undefined, "App title should not be visible on mouse hover");
            tryCompare(appMenuBar, "visible", true, undefined, "App menu bar should be visible on mouse hover");
        }

        function test_windowedApplicationMenuShowOnMouseHoverWhenDecorationsShown() {
            panelState.title = "Fake Title";
            panel.mode = "windowed";
            mouseEmulation.checked = false;

            var appTitle = findChild(panel.applicationMenus, "panelTitle"); verify(appTitle);
            var appMenuRow = findChild(panel.applicationMenus, "panelRow"); verify(appMenuRow);
            var appMenuBar = findChild(panel, "menuBar"); verify(appMenuBar);

            tryCompare(appTitle, "visible", true, undefined, "App title should be visible");
            tryCompare(appMenuBar, "visible", false, undefined, "App menu bar should not be visible");

            mouseMove(panel, panel.width/2, panel.panelHeight);

            tryCompare(appTitle, "visible", true, undefined, "App title should still be visible on mouse hover when panel decorations are not visible");
            tryCompare(appMenuBar, "visible", false, undefined, "App menu bar should be visible on mouse hover when panel decorations are not visible");

            panelState.decorationsVisible = true;

            tryCompare(appTitle, "visible", false, undefined, "App title should still be visible on mouse hover when panel decorations are visible");
            tryCompare(appMenuBar, "visible", true, undefined, "App menu bar should be visible on mouse hover when panel decorations not visible");
        }

        function test_keyboardNavigation_data() {
            return [
                {tag: "tab to start", doTab: false},
                {tag: "no tab to start", doTab: true}
            ]
        }

        function test_keyboardNavigation(data) {
            var indicatorsBar = findChild(panel.indicators, "indicatorsBar");

            pullDownIndicatorsMenu();

            indicatorsBar.setCurrentItemIndex(0);

            if (data.doTab) {
                keyClick(Qt.Key_Tab);
            }

            keyClick(Qt.Key_Right);
            tryCompare(indicatorsBar, "currentItemIndex", 1);

            keyClick(Qt.Key_Right);
            tryCompare(indicatorsBar, "currentItemIndex", 2);

            keyClick(Qt.Key_Left);
            tryCompare(indicatorsBar, "currentItemIndex", 1);

            keyClick(Qt.Key_Left);
            tryCompare(indicatorsBar, "currentItemIndex", 0);

            keyClick(Qt.Key_Escape);
            tryCompare(panel.indicators, "fullyClosed", true);
        }
    }
}