This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
notification_get_test.js
216 lines (194 loc) · 7.41 KB
/
notification_get_test.js
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
'use strict';
var assert = require('assert');
var CALENDAR_APP = 'app://calendar.gaiamobile.org';
var CALENDAR_APP_MANIFEST = CALENDAR_APP + '/manifest.webapp';
marionette('Notification.get():', function() {
var client = marionette.client({
settings: {
'ftu.manifestURL': null,
'lockscreen.enabled': false
}
});
test('promise is fulfilled', function(done) {
var error = client.executeAsyncScript(function() {
if (!Notification.get) {
return marionetteScriptFinished('no .get memeber');
}
var promise = Notification.get();
if (!promise || !promise.then) {
return marionetteScriptFinished('no promise returned');
}
promise.then(
function(notifications) {
marionetteScriptFinished(false);
},
function(err) {
marionetteScriptFinished('promise errored');
});
});
assert.equal(error, false, 'Notification.get fulfilled promise');
done();
});
test('promise returns a new notification', function(done) {
var error = client.executeAsyncScript(function() {
try {
var title = 'test title';
var notification = new Notification(title);
var promise = Notification.get();
promise.then(function(notifications) {
if (!notifications || !notifications.length) {
marionetteScriptFinished('get returned no notifications');
}
var found = notifications.some(function(notification) {
return notification.title === title;
});
if (!found) {
marionetteScriptFinished('new notification not returned');
}
// success, return no error
marionetteScriptFinished(false);
}, function(error) {
marionetteScriptFinished('promise.then error :' + error);
});
} catch (error) {
marionetteScriptFinished('uncaught error: ' + error);
}
});
assert.equal(error, false, 'new notification error: ' + error);
done();
});
test('get works with tag option', function(done) {
var error = client.executeAsyncScript(function() {
try {
var title = 'test title, tag';
var options = {
tag: 'my tag:' + Date.now()
};
var notification = new Notification(title, options);
var promise = Notification.get({tag: options.tag});
promise.then(function(notifications) {
if (!notifications) {
marionetteScriptFinished('promise return no notifications');
}
if (notifications.length !== 1) {
marionetteScriptFinished('tag filter did not give us 1 result');
}
var n = notifications[0];
if (n.title !== title || n.tag !== options.tag) {
marionetteScriptFinished(
'tag filter returned wrong notification');
}
// success, return no error
marionetteScriptFinished(false);
}, function(error) {
marionetteScriptFinished('promise.then error: ' + error);
});
} catch (error) {
marionetteScriptFinished('uncaught error: ' + error);
}
});
assert.equal(error, false, 'get with tag error: ' + error);
done();
});
test('should work across domains', function(done) {
var sharedTag = 'shared tag:' + Date.now();
var emailTitle = 'email title:' + Date.now();
var systemTitle = 'system tite:' + Date.now();
// switch to email app and send notification
client.apps.launch(CALENDAR_APP);
client.apps.switchToApp(CALENDAR_APP);
client.executeScript(function(title, tag) {
var notification = new Notification(title, {tag: tag});
}, [emailTitle, sharedTag]);
// switch to system app and send system notification
client.switchToFrame();
client.executeScript(function(title, tag) {
var notification = new Notification(title, {tag: tag});
}, [systemTitle, sharedTag]);
// switch back to email, and fetch notification by tag
client.apps.launch(CALENDAR_APP);
client.apps.switchToApp(CALENDAR_APP);
var error = client.executeAsyncScript(function(title, tag) {
var promise = Notification.get({tag: tag});
promise.then(function(notifications) {
if (!notifications || notifications.length !== 1) {
marionetteScriptFinished('no notifications returned');
}
var notification = notifications[0];
if (notification.tag !== tag || notification.title !== title) {
marionetteScriptFinished('incorrent notification data returned');
}
// success, return no error
marionetteScriptFinished(false);
}, function(error) {
marionetteScriptFinished('promise.then error: ' + error);
});
}, [emailTitle, sharedTag]);
assert.equal(error, false, 'email domain error: ' + error);
// switch to system app, fetch it's notifications by tag
client.switchToFrame();
error = client.executeAsyncScript(function(title, tag) {
var promise = Notification.get({tag: tag});
promise.then(function(notifications) {
if (!notifications || notifications.length !== 1) {
marionetteScriptFinished('no notifications returned');
}
var notification = notifications[0];
if (notification.tag !== tag || notification.title !== title) {
marionetteScriptFinished('incorrent notification data returned');
}
// success, return no error
marionetteScriptFinished(false);
}, function(error) {
marionetteScriptFinished('promise.then error: ' + error);
});
}, [systemTitle, sharedTag]);
assert.equal(error, false, 'system domain error: ' + error);
done();
});
test('notifications should persist even after closing app',
function(done) {
var title = 'test title:' + Date.now();
var tag = 'test tag:' + Date.now();
client.apps.launch(CALENDAR_APP);
client.apps.switchToApp(CALENDAR_APP);
client.executeScript(function(title, tag) {
var notification = new Notification(title, {tag: tag});
}, [title, tag]);
client.switchToFrame();
client.apps.close(CALENDAR_APP);
client.apps.launch(CALENDAR_APP);
client.apps.switchToApp(CALENDAR_APP);
var error = client.executeAsyncScript(function(title, tag) {
var promise = Notification.get({tag: tag});
promise.then(function(notifications) {
if (!notifications || notifications.length !== 1) {
marionetteScriptFinished('no notifications returned');
}
var notification = notifications[0];
if (notification.tag !== tag || notification.title !== title) {
marionetteScriptFinished('incorrent notification data returned');
}
// success, return no error
marionetteScriptFinished(false);
}, function(error) {
marionetteScriptFinished('promise.then error: ' + error);
});
}, [title, tag]);
assert.equal(error, false, 'notification persist error: ' + error);
done();
});
test('bug 931307, empty title should not cause crash', function(done) {
var error = client.executeAsyncScript(function() {
var notification = new Notification('');
var promise = Notification.get();
promise.then(function() {
marionetteScriptFinished(false);
}, function() {
marionetteScriptFinished('promise returned an error');
});
});
assert.equal(error, false, 'empty title returned error: ' + error);
done();
});
});