~aacid/unity8/moreAsyncAudioCard

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
/*
 * Copyright (C) 2014 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 QtTest 1.0
import ".."
import "../../../qml/Notifications"
import Ubuntu.Components 1.3
import Unity.Test 0.1
import Unity.Notifications 1.0

Row {
    id: rootRow

    Component {
        id: mockNotification

        QtObject {
            function invokeAction(actionId) {
                mockModel.actionInvoked(actionId)
            }
        }
    }

    ListModel {
        id: mockModel

        signal actionInvoked(string actionId)

        function getRaw(id) {
            return mockNotification.createObject(mockModel)
        }

        // add the default/PlaceHolder notification to the model
        Component.onCompleted: {
            var n = {
                type: Notification.PlaceHolder,
                hints: {},
                summary: "",
                body: "",
                icon: "",
                secondaryIcon: "",
                actions: []
            }

            append(n)
        }
    }

    function addSomeSnapDecisionNotifications() {
        var n = [{
            type: Notification.SnapDecision,
            hints: {"x-canonical-private-button-tint": "true"},
            summary: "Incoming call",
            body: "Frank Zappa\n+44 (0)7736 027340",
            icon: "../../tests/graphics/avatars/funky.png",
            secondaryIcon: "../../tests/graphics/applicationIcons/dialer-app.png",
            actions: [{ id: "pickup_id", label: "Pick up"},
                      { id: "decline_1_id", label: "Decline"},
                      { id: "decline_2_id", label: "Can't talk now, what's up?"},
                      { id: "decline_3_id", label: "I call you back."},
                      { id: "decline_4_id", label: "Send custom message..."}]
        },
        {
            type: Notification.SnapDecision,
            hints: {"x-canonical-private-button-tint": "true",
                    "x-canonical-non-shaped-icon": "true"},
            summary: "Incoming file",
            body: "Frank would like to send you the file: essay.pdf.",
            icon: "image://theme/search",
            actions: [{ id: "accept_id", label: "Accept"},
                      { id: "reject_id", label: "Reject"}]
        },
        {
            type: Notification.SnapDecision,
            hints: {"x-canonical-private-button-tint": "true",
                    "x-canonical-non-shaped-icon": "true"},
            summary: "Authentication error",
            body: "Please authorise Ubuntu to access your Google account.",
            icon: "image://theme/search",
            actions: [{ id: "settings_id", label: "Settings..."},
                      { id: "cancel_id", label: "Cancel"}]
        },
        {
            type: Notification.SnapDecision,
            hints: {"x-canonical-private-button-tint": "true",
                    "x-canonical-non-shaped-icon": "true"},
            summary: "Morning alarm",
            body: "It's 6:30... time to get up!",
            icon: "image://theme/search",
            actions: [{ id: "ok_reply", label: "Ok"},
                      { id: "snooze_id", label: "Snooze"}]
        },
        {
            type: Notification.SnapDecision,
            hints: {"x-canonical-private-button-tint": "true"},
            summary: "Jenny Sample",
            body: "Hey there! Have you been watching the latest episode of that TV-show I told you about last week?",
            icon: "../../tests/graphics/avatars/amanda.png",
            secondaryIcon: "../../tests/graphics/applicationIcons/messages-app.png",
            actions: [{ id: "reply_id", label: "Reply"},
                      { id: "ignore_id", label: "Ignore"}]
        }]

        mockModel.append(n)
    }

    function clearNotifications() {
        // remove all but the first (PlaceHolder) notification
        mockModel.remove(1, mockModel.count - 1)
    }

    function removeTopMostNotification() {
        // leave real/first (PlaceHolder) notification untouched
        if (mockModel.count > 1)
            mockModel.remove(1)
    }

    Rectangle {
        id: notificationsRect

        width: units.gu(40)
        height: units.gu(71)

        MouseArea{
            id: clickThroughCatcher

            anchors.fill: parent
        }

        Notifications {
            id: notifications

            margin: units.gu(1)

            anchors.fill: parent
            model: mockModel
        }
    }

    Rectangle {
        id: interactiveControls

        width: units.gu(30)
        height: units.gu(81)
        color: "grey"

        Column {
            spacing: units.gu(1)
            anchors.fill: parent
            anchors.margins: units.gu(1)

            Button {
                width: parent.width
                text: "add some snap-decisions"
                onClicked: addSomeSnapDecisionNotifications()
            }

            Button {
                width: parent.width
                text: "remove top-most notification"
                onClicked: removeTopMostNotification()
            }

            Button {
                width: parent.width
                text: "clear model"
                onClicked: clearNotifications()
            }
        }
    }

    UnityTestCase {
        id: root
        name: "VisualQueueTest"
        when: windowShown

        function test_VisualSnapDecisionsQueue() {
            // populate model with some mock notifications
            addSomeSnapDecisionNotifications();

            // make sure the view is properly updated before going on
            notifications.forceLayout();
            waitForRendering(notifications);

            var snap_decision = [findChild(notifications, "notification1"),
                                 findChild(notifications, "notification2"),
                                 findChild(notifications, "notification3"),
                                 findChild(notifications, "notification4"),
                                 findChild(notifications, "notification5")]

            for (var index = 0; index < snap_decision.length; index++) {
                verify(snap_decision[index] !== undefined, index + ". snap-decision wasn't found");
            }

            // check initial states once all five snap-decisions were appended to the model
            compare(snap_decision[0].state, "expanded", "state of first snap-decision is not expanded");
            for (var index = 1; index < snap_decision.length; index++) {
                compare(snap_decision[index].state, "contracted", "state of "+ index + ".snap-decision is not contracted");
            }

            // click/tap on each snap-decision and verify only one is in expanded-state at any time
            for (var index = 0; index < snap_decision.length; index++) {
                mouseClick(snap_decision[index])
                for (var kindex = 0; kindex < snap_decision.length; kindex++) {
                    if (kindex == index) {
                        compare(snap_decision[kindex].state, "expanded", "state of "+ kindex + ".snap-decision is not expanded");
                    } else {
                        compare(snap_decision[kindex].state, "contracted", "state of "+ kindex + ".snap-decision is not contracted");
                    }
                }
            }

            // remove top-most and verify one of the remaining ones is still getting expanded

            waitForRendering(notifications);
            // make first snap-decision expand
            mouseClick(snap_decision[0]);

            for (var index = 1; index < snap_decision.length; index++) {
                removeTopMostNotification();
                compare(snap_decision[index].state, "expanded", "state of " + index + ". snap-decision is not expanded");
            }
        }
    }
}