~mterry/+junk/u8

« back to all changes in this revision

Viewing changes to tests/qmltests/Notifications/tst_Notifications.qml

  • Committer: Michael Zanetti
  • Date: 2016-11-30 13:28:07 UTC
  • mfrom: (2704 unity8)
  • mto: This revision was merged to the branch mainline in revision 2739.
  • Revision ID: michael.zanetti@canonical.com-20161130132807-c314dqdxenzwy69c
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 2015 Canonical Ltd.
 
2
 * Copyright 2015-2016 Canonical Ltd.
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
5
5
 * it under the terms of the GNU Lesser General Public License as published by
31
31
    height: notificationsRect.height
32
32
    property int index: 0
33
33
 
34
 
    // add the default/PlaceHolder notification to the model
35
 
    Component.onCompleted: {
36
 
        var component = Qt.createComponent("Notification.qml")
37
 
        var n = component.createObject("notification", {"nid": index++,
38
 
                                                        "type": Notification.PlaceHolder,
39
 
                                                        "hints": {},
40
 
                                                        "summary": "",
41
 
                                                        "body": "",
42
 
                                                        "icon": "",
43
 
                                                        "secondaryIcon": "",
44
 
                                                        "rawActions": []})
45
 
        n.completed.connect(mockModel.onCompleted)
46
 
        mockModel.append(n)
47
 
    }
48
 
 
49
34
    Row {
50
35
        id: rootRow
51
36
 
156
141
            mockModel.append(n)
157
142
        }
158
143
 
 
144
        function addFullscreenNotification() {
 
145
            var component = Qt.createComponent("Notification.qml")
 
146
            var n = component.createObject("notification", {"nid": index++,
 
147
                                                            "type": Notification.SnapDecision,
 
148
                                                            "hints": {"x-canonical-private-affirmative-tint": "true"},
 
149
                                                            "summary": "SIM PIN screen",
 
150
                                                            "body": "Enter your PIN to unlock the SIM",
 
151
                                                            "fullscreen": true})
 
152
            n.completed.connect(mockModel.onCompleted)
 
153
            mockModel.append(n)
 
154
        }
 
155
 
159
156
        function clearNotifications() {
160
 
            while(mockModel.count > 1) {
161
 
                remove1stNotification()
 
157
            while(mockModel.count > 0) {
 
158
                remove1stNotification();
162
159
            }
163
160
        }
164
161
 
165
162
        function remove1stNotification() {
166
 
            if (mockModel.count > 1) {
167
 
                mockModel.removeSecond()
168
 
            }
 
163
            mockModel.removeFirst();
169
164
        }
170
165
 
171
166
        Rectangle {
247
242
 
248
243
                Button {
249
244
                    width: parent.width
 
245
                    text: "add a fullscreen notification"
 
246
                    onClicked: rootRow.addFullscreenNotification()
 
247
                }
 
248
 
 
249
                Button {
 
250
                    width: parent.width
250
251
                    text: "remove 1st notification"
251
252
                    onClicked: rootRow.remove1stNotification()
252
253
                }
388
389
                    rawActions: ["ok_id",     "Ok",
389
390
                                 "snooze_id", "Snooze",
390
391
                                 "view_id",   "View"]
 
392
                },
 
393
                Notification {
 
394
                    nid: 10
 
395
                    type: Notification.SnapDecision
 
396
                    hints: {"x-canonical-private-affirmative-tint": "true"}
 
397
                    summary: "SIM PIN screen"
 
398
                    body: "Enter your PIN to unlock the SIM"
 
399
                    fullscreen: true
391
400
                }
392
401
            ]
393
402
 
555
564
                signalName: "actionInvoked"
556
565
            }
557
566
 
558
 
            function init() {
559
 
                while (mockModel.count > 0) {
560
 
                    mockModel.remove(0);
561
 
                }
562
 
            }
563
 
 
564
567
            function cleanup() {
565
568
                clickThroughSpy.clear()
566
569
                actionSpy.clear()
 
570
                while (mockModel.count > 0) {
 
571
                    mockModel.removeFirst();
 
572
                }
567
573
            }
568
574
 
569
575
            function test_NotificationRenderer(data) {
791
797
                waitForRendering(notifications);
792
798
 
793
799
                // first one should be expanded by default
794
 
                var notification1 = findChild(notifications, "notification1") // 0 is placeholder...
 
800
                var notification1 = findChild(notifications, "notification0")
795
801
                verify(!!notification1, "notification wasn't found");
796
802
                waitForRendering(notification1);
797
803
                verify(notification1.expanded);
798
804
 
799
805
                // click the 2nd one, verify it's now expanded
800
 
                var notification2 = findChild(notifications, "notification2") // 0 is placeholder...
 
806
                var notification2 = findChild(notifications, "notification1")
801
807
                verify(!!notification2, "notification wasn't found");
802
808
                waitForRendering(notification2);
803
809
                mouseClick(notification2);
814
820
                tryCompareFunction(function() { return notification2.expanded; }, undefined);
815
821
            }
816
822
 
 
823
            function topmostIsFullscreen_data() {
 
824
                return [{
 
825
                            tag: "Confirmation notification with value",
 
826
                            n: nlist[6]
 
827
                        },
 
828
                        {
 
829
                            tag: "SIM PIN fullscreen notification",
 
830
                            n: nlist[9]
 
831
                        },
 
832
                        {
 
833
                            tag: "Snap Decision without secondary icon and no button-tint",
 
834
                            n: nlist[3]
 
835
                        }]
 
836
            }
 
837
 
 
838
            function test_topmostIsFullscreen() {
 
839
                var data = topmostIsFullscreen_data();
 
840
 
 
841
                // fill the model
 
842
                data.forEach(function(notification) {
 
843
                    mockModel.append(notification.n);
 
844
                    notification.n.completed.connect(mockModel.onCompleted);
 
845
                })
 
846
 
 
847
                // make sure the view is properly updated before going on
 
848
                notifications.forceLayout();
 
849
                waitForRendering(notifications);
 
850
 
 
851
                // initially, topmost is not fullscreen
 
852
                verify(!notifications.topmostIsFullscreen)
 
853
 
 
854
                // close the 1st one, 2nd one should be fullscreen
 
855
                var notification0 = findChild(notifications, "notification0")
 
856
                notification0.closeNotification();
 
857
                waitForRendering(notifications);
 
858
                verify(notifications.topmostIsFullscreen)
 
859
 
 
860
                // close the 1st one (SIM PIN) again, topmost should no longer be fullscreen
 
861
                notification0 = findChild(notifications, "notification0")
 
862
                notification0.closeNotification();
 
863
                waitForRendering(notifications);
 
864
                verify(!notifications.topmostIsFullscreen)
 
865
            }
 
866
 
817
867
            function cleanupTestCase() {
818
868
                notifications.hasMouse = false;
819
869
            }