~unity-api-team/unity8/scopes-active-depends-on-screen-rtm

« back to all changes in this revision

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

  • Committer: CI bot
  • Author(s): Michael Terry, Michael Zanetti, Michał Sawicz, Daniel d'Andrada, Albert Astals, Nick Dedekind, Mirco Müller, Alberto Aguirre
  • Date: 2014-11-05 14:39:26 UTC
  • mfrom: (1396.3.14 rtm-1104-sync)
  • Revision ID: ps-jenkins@lists.canonical.com-20141105143926-gnigtgarofubbip2
[ Albert Astals ]
* Fix i18n (LP: #1389165)

[ Michael Zanetti ]
* Fix DBusVariant conversion for launcher emblems (LP: #1387261)
* Fix desktop file encoding in launcher (LP: #1387083)

[ Alberto Aguirre ]
* Add audioRole to QtMultimedia mock
* Add a plugin to take screenshots on vol up + vol down

[ Nick Dedekind ]
* Reset current item selection on deleted. (LP: #1378462)
* Added timer to re-assert server value after indicator menu item
  activation. (LP: #1336715)

[ Mirco Müller ]
* Added dedicated swipe-to-act button for snap-decisions, which avoids
  accidental taps/button-presses. (LP: #1358343)

[ Michael Terry ]
* Don't lock phone if user tries to switch back to an active call.
  (LP: #1388156)

[ Daniel d'Andrada ]
* TouchDispatcher: synthesize MouseButtonDblClick events (LP: #1388359) Fixes: 1336715, 1358343, 1378462, 1387083, 1387261, 1388156, 1388359, 1389165

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2014 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import QtTest 1.0
 
19
import ".."
 
20
import "../../../qml/Notifications"
 
21
import Ubuntu.Components 0.1
 
22
import Unity.Test 0.1
 
23
import Unity.Notifications 1.0
 
24
 
 
25
Item {
 
26
    width: notificationsRect.width + interactiveControls.width
 
27
    height: notificationsRect.height
 
28
 
 
29
    Row {
 
30
        id: rootRow
 
31
 
 
32
        Component {
 
33
            id: mockNotification
 
34
 
 
35
            QtObject {
 
36
                function invokeAction(actionId) {
 
37
                    mockModel.actionInvoked(actionId)
 
38
                }
 
39
            }
 
40
        }
 
41
 
 
42
        ListModel {
 
43
            id: mockModel
 
44
            dynamicRoles: true
 
45
 
 
46
            signal actionInvoked(string actionId)
 
47
 
 
48
            function getRaw(id) {
 
49
                return mockNotification.createObject(mockModel)
 
50
            }
 
51
 
 
52
            // add the default/PlaceHolder notification to the model
 
53
            Component.onCompleted: {
 
54
                var n = {
 
55
                    type: Notification.PlaceHolder,
 
56
                    hints: {},
 
57
                    summary: "",
 
58
                    body: "",
 
59
                    icon: "",
 
60
                    secondaryIcon: "",
 
61
                    actions: []
 
62
                }
 
63
 
 
64
                append(n)
 
65
            }
 
66
        }
 
67
 
 
68
        function addSwipeToActNotification() {
 
69
            var n = {
 
70
                type: Notification.SnapDecision,
 
71
                hints: {"x-canonical-snap-decisions-swipe": "true"},
 
72
                summary: "Incoming call",
 
73
                body: "Frank Zappa\n+44 (0)7736 027340",
 
74
                icon: "../graphics/avatars/amanda.png",
 
75
                secondaryIcon: "incoming-call",
 
76
                actions: [{ id: "ok_id", label: "Ok"},
 
77
                    { id: "cancel_id", label: "Cancel"}]
 
78
            }
 
79
 
 
80
            mockModel.append(n)
 
81
        }
 
82
 
 
83
        function clearNotifications() {
 
84
            mockModel.clear()
 
85
        }
 
86
 
 
87
        function remove1stNotification() {
 
88
            if (mockModel.count > 0)
 
89
                mockModel.remove(0)
 
90
        }
 
91
 
 
92
        Rectangle {
 
93
            id: notificationsRect
 
94
 
 
95
            width: units.gu(40)
 
96
            height: units.gu(71)
 
97
 
 
98
            MouseArea{
 
99
                id: clickThroughCatcher
 
100
 
 
101
                anchors.fill: parent
 
102
            }
 
103
 
 
104
            Notifications {
 
105
                id: notifications
 
106
 
 
107
                margin: units.gu(1)
 
108
 
 
109
                anchors.fill: parent
 
110
                model: mockModel
 
111
            }
 
112
        }
 
113
 
 
114
        Rectangle {
 
115
            id: interactiveControls
 
116
 
 
117
            width: units.gu(30)
 
118
            height: units.gu(81)
 
119
            color: "grey"
 
120
 
 
121
            Column {
 
122
                spacing: units.gu(1)
 
123
                anchors.fill: parent
 
124
                anchors.margins: units.gu(1)
 
125
 
 
126
                Button {
 
127
                    width: parent.width
 
128
                    text: "add a SwipeToAct snap-decision"
 
129
                    onClicked: rootRow.addSwipeToActNotification()
 
130
                }
 
131
 
 
132
                Button {
 
133
                    width: parent.width
 
134
                    text: "remove 1st notification"
 
135
                    onClicked: rootRow.remove1stNotification()
 
136
                }
 
137
 
 
138
                Button {
 
139
                    width: parent.width
 
140
                    text: "clear model"
 
141
                    onClicked: rootRow.clearNotifications()
 
142
                }
 
143
            }
 
144
        }
 
145
 
 
146
        ActionModel {
 
147
            id: myActionModel
 
148
        }
 
149
 
 
150
        UnityTestCase {
 
151
            id: root
 
152
            name: "NotificationRendererTest"
 
153
            when: windowShown
 
154
 
 
155
            function test_NotificationRenderer_data() {
 
156
                return [
 
157
                {
 
158
                    tag: "Snap Decision with SwipeToAct-widget (accept)",
 
159
                    type: Notification.SnapDecision,
 
160
                    hints: {"x-canonical-snap-decisions-swipe": "true"},
 
161
                    summary: "Incoming call",
 
162
                    body: "Frank Zappa\n+44 (0)7736 027340",
 
163
                    icon: "../graphics/avatars/amanda.png",
 
164
                    secondaryIcon: "../graphics/applicationIcons/facebook.png",
 
165
                    actions: myActionModel,
 
166
                    summaryVisible: true,
 
167
                    bodyVisible: true,
 
168
                    iconVisible: true,
 
169
                    shaped: true,
 
170
                    secondaryIconVisible: true,
 
171
                    buttonRowVisible: true,
 
172
                    buttonTinted: false,
 
173
                    checkSwipeToActAccept: true,
 
174
                    checkSwipeToActReject: false
 
175
                },
 
176
                {
 
177
                    tag: "Snap Decision with SwipeToAct-widget (reject)",
 
178
                    type: Notification.SnapDecision,
 
179
                    hints: {"x-canonical-snap-decisions-swipe": "true"},
 
180
                    summary: "Incoming call",
 
181
                    body: "Bro Coly\n+49 (0)221 426973",
 
182
                    icon: "../graphics/avatars/funky.png",
 
183
                    secondaryIcon: "../graphics/applicationIcons/facebook.png",
 
184
                    actions: myActionModel,
 
185
                    summaryVisible: true,
 
186
                    bodyVisible: true,
 
187
                    iconVisible: true,
 
188
                    shaped: true,
 
189
                    secondaryIconVisible: true,
 
190
                    buttonRowVisible: true,
 
191
                    buttonTinted: false,
 
192
                    checkSwipeToActAccept: false,
 
193
                    checkSwipeToActReject: true
 
194
                }
 
195
                ]
 
196
            }
 
197
 
 
198
            SignalSpy {
 
199
                id: clickThroughSpy
 
200
 
 
201
                target: clickThroughCatcher
 
202
                signalName: "clicked"
 
203
            }
 
204
 
 
205
            SignalSpy {
 
206
                id: actionSpy
 
207
 
 
208
                target: mockModel
 
209
                signalName: "actionInvoked"
 
210
            }
 
211
 
 
212
            function cleanup() {
 
213
                clickThroughSpy.clear()
 
214
                actionSpy.clear()
 
215
            }
 
216
 
 
217
            function test_NotificationRenderer(data) {
 
218
                // populate model with some mock notifications
 
219
                mockModel.append(data)
 
220
 
 
221
                // make sure the view is properly updated before going on
 
222
                notifications.forceLayout();
 
223
                waitForRendering(notifications);
 
224
 
 
225
                var notification = findChild(notifications, "notification" + (mockModel.count - 1))
 
226
                verify(notification !== undefined, "notification wasn't found");
 
227
 
 
228
                waitForRendering(notification);
 
229
 
 
230
                var icon = findChild(notification, "icon")
 
231
                var interactiveArea = findChild(notification, "interactiveArea")
 
232
                var secondaryIcon = findChild(notification, "secondaryIcon")
 
233
                var summaryLabel = findChild(notification, "summaryLabel")
 
234
                var bodyLabel = findChild(notification, "bodyLabel")
 
235
                var buttonRow = findChild(notification, "buttonRow")
 
236
 
 
237
                compare(icon.visible, data.iconVisible, "avatar-icon visibility is incorrect")
 
238
                if (icon.visible) {
 
239
                    compare(icon.shaped, data.shaped, "shaped-status is incorrect")
 
240
                }
 
241
 
 
242
                // test input does not fall through
 
243
                mouseClick(notification, notification.width / 2, notification.height / 2)
 
244
                if(data.type == Notification.Interactive) {
 
245
                    actionSpy.wait()
 
246
                    compare(actionSpy.signalArguments[0][0], data.actions[0]["id"], "got wrong id for interactive action")
 
247
                }
 
248
                compare(clickThroughSpy.count, 0, "click on notification fell through")
 
249
 
 
250
                compare(secondaryIcon.visible, data.secondaryIconVisible, "secondary-icon visibility is incorrect")
 
251
                compare(summaryLabel.visible, data.summaryVisible, "summary-text visibility is incorrect")
 
252
                compare(bodyLabel.visible, data.bodyVisible, "body-text visibility is incorrect")
 
253
                compare(buttonRow.visible, data.buttonRowVisible, "button visibility is incorrect")
 
254
 
 
255
                if(data.buttonRowVisible) {
 
256
                    var swipeButton = findChild(buttonRow, "notify_swipe_button")
 
257
                    var slider = findChild(swipeButton, "slider")
 
258
                    var swipeMouseArea = findChild(swipeButton, "swipeMouseArea")
 
259
                    var x = swipeMouseArea.width / 2
 
260
                    var y = swipeMouseArea.height / 2
 
261
 
 
262
                    if(data.checkSwipeToActAccept) {
 
263
                        tryCompareFunction(function() { mouseDrag(slider, x, y, (swipeMouseArea.width / 2) - slider.width, 0); return actionSpy.signalArguments.length > 0; }, true);
 
264
                        compare(actionSpy.signalArguments[0][0], data.actions.data(0, ActionModel.RoleActionId), "got wrong id for positive action")
 
265
                        actionSpy.clear()
 
266
                    }
 
267
                    if(data.checkSwipeToActReject) {
 
268
                        tryCompareFunction(function() { mouseDrag(slider, x, y, -(swipeMouseArea.width / 2), 0); return actionSpy.signalArguments.length > 0; }, true);
 
269
                        compare(actionSpy.signalArguments[0][0], data.actions.data(1, ActionModel.RoleActionId), "got wrong id for negative action")
 
270
                        actionSpy.clear()
 
271
                    }
 
272
                }
 
273
            }
 
274
        }
 
275
    }
 
276
}