OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Test fixture for cards.js. | 6 * Test fixture for cards.js. |
7 * @constructor | 7 * @constructor |
8 * @extends {testing.Test} | 8 * @extends {testing.Test} |
9 */ | 9 */ |
10 function GoogleNowCardsUnitTest () { | 10 function GoogleNowCardsUnitTest () { |
11 testing.Test.call(this); | 11 testing.Test.call(this); |
12 } | 12 } |
13 | 13 |
14 GoogleNowCardsUnitTest.prototype = { | 14 GoogleNowCardsUnitTest.prototype = { |
15 __proto__: testing.Test.prototype, | 15 __proto__: testing.Test.prototype, |
16 | 16 |
17 /** @override */ | 17 /** @override */ |
18 extraLibraries: [ | 18 extraLibraries: [ |
19 'cards.js' | 19 'cards.js' |
20 ] | 20 ] |
21 }; | 21 }; |
22 | 22 |
23 // Test implementation of a function provided by utility.js. | |
24 function verify(condition, message) { | |
25 assertTrue(condition, message); | |
26 } | |
27 | |
23 var testCardId = 'TEST CARD ID'; | 28 var testCardId = 'TEST CARD ID'; |
24 var testNotification = {testNotificationField: 'TEST NOTIFICATION VALUE'}; | 29 var testNotificationIdA = 'TEST CARD ID-A'; |
25 var expectedShowAlarmId = 'card-show-TEST CARD ID'; | 30 var testNotificationIdB = 'TEST CARD ID-B'; |
26 var expectedHideAlarmId = 'card-hide-TEST CARD ID'; | 31 var testNotificationA = { |
robliao
2013/12/30 01:59:49
Including the priority in the name would be useful
vadimt
2014/01/02 21:46:04
There are not so many tests that care about priori
| |
27 var testActionUrls = {testField: 'TEST VALUE'}; | 32 testNotificationField: 'TEST NOTIFICATION VALUE A', |
28 var testDismissals = [ | 33 priority: 1 |
29 {testDismissalField: 'TEST DISMISSAL VALUE 1'}, | 34 }; |
30 {testDismissalField: 'TEST DISMISSAL VALUE 2'} | 35 var testNotificationB = { |
31 ]; | 36 testNotificationField: 'TEST NOTIFICATION VALUE B', |
32 var testGroupRank = 271; | 37 priority: 2 |
38 }; | |
39 var groupNameA = 'A'; | |
40 var groupNameB = 'B'; | |
41 var expectedAlarmId = 'card-TEST CARD ID'; | |
42 var testActionUrlsA = {testField: 'TEST VALUE A'}; | |
43 var testActionUrlsB = {testField: 'TEST VALUE B'}; | |
44 var testDismissalA = {testDismissalField: 'TEST DISMISSAL VALUE A'}; | |
45 var testDismissalB = {testDismissalField: 'TEST DISMISSAL VALUE B'}; | |
33 var LOCATION_CARDS_LINK_THRESHOLD = 10; | 46 var LOCATION_CARDS_LINK_THRESHOLD = 10; |
34 var localStorage = {locationCardsShown: 0}; | 47 var localStorage = {locationCardsShown: 0}; |
35 | 48 |
36 function setUpCardManagerTest(fixture) { | 49 function setUpCardManagerTest(fixture) { |
37 fixture.makeAndRegisterMockApis([ | 50 fixture.makeAndRegisterMockApis([ |
38 'chrome.alarms.clear', | 51 'chrome.alarms.clear', |
39 'chrome.alarms.create', | 52 'chrome.alarms.create', |
40 'chrome.notifications.clear', | 53 'instrumented.notifications.clear', |
41 'chrome.storage.local.set', | 54 'chrome.storage.local.set', |
42 'countLocationCard', | 55 'countLocationCard', |
43 'instrumented.alarms.onAlarm.addListener', | 56 'instrumented.alarms.onAlarm.addListener', |
44 'instrumented.notifications.create', | 57 'instrumented.notifications.create', |
45 'instrumented.notifications.update', | 58 'instrumented.notifications.update', |
46 'instrumented.storage.local.get', | 59 'instrumented.storage.local.get', |
47 'tasks.add' | 60 'tasks.add' |
48 ]); | 61 ]); |
49 | 62 |
50 chrome.runtime = {}; // No error. | 63 chrome.runtime = {}; // No error. |
(...skipping 18 matching lines...) Expand all Loading... | |
69 } | 82 } |
70 | 83 |
71 TEST_F('GoogleNowCardsUnitTest', 'BuildCardManager', function() { | 84 TEST_F('GoogleNowCardsUnitTest', 'BuildCardManager', function() { |
72 // Tests that buildCardSet() call completes with no problems. | 85 // Tests that buildCardSet() call completes with no problems. |
73 var test = setUpCardManagerTest(this); | 86 var test = setUpCardManagerTest(this); |
74 | 87 |
75 assertEquals('object', typeof test.cardSet); | 88 assertEquals('object', typeof test.cardSet); |
76 assertEquals('function', typeof test.alarmCallback); | 89 assertEquals('function', typeof test.alarmCallback); |
77 }); | 90 }); |
78 | 91 |
92 TEST_F('GoogleNowCardsUnitTest', 'UpdateSimpleHideFuture', function() { | |
93 // Update a simple card with the hide event in future. | |
94 | |
95 var testUncombinedNotification = { | |
96 receivedNotification: { | |
97 notificationId: testNotificationIdA, | |
robliao
2013/12/30 01:59:49
Add a few tests that vary the optional arguments i
vadimt
2014/01/02 21:46:04
See the above comment about detailness of testing.
| |
98 chromeNotificationId: testCardId, | |
99 chromeNotificationOptions: testNotificationA, | |
100 actionUrls: testActionUrlsA, | |
101 dismissal: testDismissalA, | |
102 groupName: groupNameA | |
103 }, | |
104 hideTime: 300001 | |
105 }; | |
106 | |
107 // Setup and expectations. | |
108 var test = setUpCardManagerTest(this); | |
109 this.mockApis.expects(once()). | |
110 chrome_alarms_clear(expectedAlarmId); | |
111 var chromeNotificationsCreateSavedArgs = new SaveMockArguments(); | |
112 this.mockApis.expects(once()). | |
113 instrumented_notifications_update( | |
114 chromeNotificationsCreateSavedArgs.match(eq(testCardId)), | |
115 chromeNotificationsCreateSavedArgs.match(eqJSON(testNotificationA)), | |
116 chromeNotificationsCreateSavedArgs.match(ANYTHING)). | |
117 will(invokeCallback(chromeNotificationsCreateSavedArgs, 2, true)); | |
robliao
2013/12/30 01:59:49
Useful comment here: the true here indicates that
vadimt
2014/01/02 21:46:04
I added the constant for 'true', hope this will wo
robliao
2014/01/03 09:09:34
Even better!
On 2014/01/02 21:46:04, vadimt wrote:
| |
118 this.mockApis.expects(once()). | |
119 chrome_alarms_create(expectedAlarmId, eqJSON({when: 300001})); | |
120 | |
121 // Call tested method. | |
122 var notificationData = test.cardSet.update( | |
123 testCardId, [testUncombinedNotification], {}); | |
124 | |
125 // Check the return value. | |
126 assertEquals( | |
127 JSON.stringify({ | |
128 actionUrls: testActionUrlsA, | |
129 timestamp: 300000, | |
130 combinedCard: [testUncombinedNotification] | |
131 }), | |
132 JSON.stringify(notificationData)); | |
133 }); | |
134 | |
135 TEST_F('GoogleNowCardsUnitTest', 'CreateSimpleHideFuture', function() { | |
136 // Create a simple card with the hide event in future. | |
137 | |
138 var testUncombinedNotification = { | |
139 receivedNotification: { | |
140 notificationId: testNotificationIdA, | |
141 chromeNotificationId: testCardId, | |
142 chromeNotificationOptions: testNotificationA, | |
143 actionUrls: testActionUrlsA, | |
144 dismissal: testDismissalA, | |
145 groupName: groupNameA | |
146 }, | |
147 hideTime: 300001 | |
148 }; | |
149 | |
150 // Setup and expectations. | |
151 var test = setUpCardManagerTest(this); | |
152 this.makeMockLocalFunctions(['onCardShown']); | |
153 | |
154 this.mockApis.expects(once()). | |
155 chrome_alarms_clear(expectedAlarmId); | |
156 | |
157 // notifications.update will return false, which will trigger | |
158 // notifications.create. | |
159 var chromeNotificationsUpdateSavedArgs = new SaveMockArguments(); | |
160 this.mockApis.expects(once()). | |
161 instrumented_notifications_update( | |
162 chromeNotificationsUpdateSavedArgs.match(eq(testCardId)), | |
163 chromeNotificationsUpdateSavedArgs.match(eqJSON(testNotificationA)), | |
164 chromeNotificationsUpdateSavedArgs.match(ANYTHING)). | |
165 will(invokeCallback(chromeNotificationsUpdateSavedArgs, 2, false)); | |
166 var chromeNotificationsCreateSavedArgs = new SaveMockArguments(); | |
167 this.mockApis.expects(once()). | |
168 instrumented_notifications_create( | |
169 chromeNotificationsCreateSavedArgs.match(eq(testCardId)), | |
170 chromeNotificationsCreateSavedArgs.match(eqJSON(testNotificationA)), | |
171 chromeNotificationsCreateSavedArgs.match(ANYTHING)). | |
172 will(invokeCallback(chromeNotificationsCreateSavedArgs, 2, testCardId)); | |
173 | |
174 this.mockLocalFunctions.expects(once()). | |
175 onCardShown(eqJSON(testUncombinedNotification.receivedNotification)); | |
176 | |
177 this.mockApis.expects(once()). | |
178 chrome_alarms_create(expectedAlarmId, eqJSON({when: 300001})); | |
179 | |
180 // Call tested method. | |
181 var notificationData = test.cardSet.update( | |
182 testCardId, | |
183 [testUncombinedNotification], | |
184 {}, | |
185 this.mockLocalFunctions.functions().onCardShown); | |
186 | |
187 // Check the return value. | |
188 assertEquals( | |
189 JSON.stringify({ | |
190 actionUrls: testActionUrlsA, | |
191 timestamp: 300000, | |
192 combinedCard: [testUncombinedNotification] | |
193 }), | |
194 JSON.stringify(notificationData)); | |
195 }); | |
196 | |
197 TEST_F('GoogleNowCardsUnitTest', 'CreateSimpleShowFuture', function() { | |
198 // Create a simple card with the show event in future. Should create an alarm | |
199 // to fire at the show time. | |
200 | |
201 var testUncombinedNotification = { | |
202 receivedNotification: { | |
203 notificationId: testNotificationIdA, | |
204 chromeNotificationId: testCardId, | |
205 chromeNotificationOptions: testNotificationA, | |
206 actionUrls: testActionUrlsA, | |
207 dismissal: testDismissalA, | |
208 groupName: groupNameA | |
209 }, | |
210 showTime: 300001, | |
211 hideTime: 300002 | |
212 }; | |
213 | |
214 // Setup and expectations. | |
215 var test = setUpCardManagerTest(this); | |
216 | |
217 this.mockApis.expects(once()). | |
218 chrome_alarms_clear(expectedAlarmId); | |
219 this.mockApis.expects(once()). | |
220 instrumented_notifications_clear(testCardId, ANYTHING); | |
221 this.mockApis.expects(once()). | |
222 chrome_alarms_create(expectedAlarmId, eqJSON({when: 300001})); | |
223 | |
224 // Call tested method. | |
225 var notificationData = test.cardSet.update( | |
226 testCardId, [testUncombinedNotification], {}); | |
227 | |
228 // Check the return value. | |
229 assertEquals( | |
230 JSON.stringify({ | |
231 timestamp: 300000, | |
232 combinedCard: [testUncombinedNotification] | |
233 }), | |
234 JSON.stringify(notificationData)); | |
235 }); | |
236 | |
237 TEST_F('GoogleNowCardsUnitTest', 'UpdateSimpleHidePast', function() { | |
238 // Update a simple card with the hide event in the past (actually, present). | |
239 // Should clear the notification. | |
240 | |
241 var testUncombinedNotification = { | |
242 receivedNotification: { | |
243 notificationId: testNotificationIdA, | |
244 chromeNotificationId: testCardId, | |
245 chromeNotificationOptions: testNotificationA, | |
246 actionUrls: testActionUrlsA, | |
247 dismissal: testDismissalA, | |
248 groupName: groupNameA | |
249 }, | |
250 hideTime: 300000 | |
251 }; | |
252 | |
253 // Setup and expectations. | |
254 var test = setUpCardManagerTest(this); | |
255 this.mockApis.expects(once()). | |
256 chrome_alarms_clear(expectedAlarmId); | |
257 this.mockApis.expects(once()). | |
258 instrumented_notifications_clear(testCardId, ANYTHING); | |
259 | |
260 var groups = { | |
261 A: { | |
262 cards: [{chromeNotificationId: 'ID1'}, {chromeNotificationId: testCardId}] | |
263 }, | |
264 B: { | |
265 cards: [{chromeNotificationId: testCardId}, {chromeNotificationId: 'ID2'}] | |
266 } | |
267 }; | |
268 | |
269 // Call tested method. | |
270 var notificationData = test.cardSet.update( | |
271 testCardId, [testUncombinedNotification], groups); | |
272 | |
273 // Check the return value. | |
274 assertEquals(undefined, notificationData); | |
275 | |
276 // Check that groups were cleaned up. | |
277 var expectedCleanedGroups = { | |
278 A: { | |
279 cards: [{chromeNotificationId: 'ID1'}] | |
280 }, | |
281 B: { | |
282 cards: [{chromeNotificationId: 'ID2'}] | |
283 } | |
284 }; | |
285 | |
286 assertEquals(JSON.stringify(expectedCleanedGroups), JSON.stringify(groups)); | |
287 }); | |
288 | |
289 TEST_F('GoogleNowCardsUnitTest', 'UpdateComplex', function() { | |
290 // Update a combined card that contains 2 uncombined cards. The card from | |
291 // group B has higher priority and wins. | |
292 | |
293 var testUncombinedNotificationA = { | |
294 receivedNotification: { | |
295 notificationId: testNotificationIdA, | |
296 chromeNotificationId: testCardId, | |
297 chromeNotificationOptions: testNotificationA, | |
298 actionUrls: testActionUrlsA, | |
299 dismissal: testDismissalA, | |
300 groupName: groupNameA | |
301 }, | |
302 hideTime: 300001 | |
303 }; | |
304 | |
305 var testUncombinedNotificationB = { | |
306 receivedNotification: { | |
307 notificationId: testNotificationIdB, | |
308 chromeNotificationId: testCardId, | |
309 chromeNotificationOptions: testNotificationB, | |
310 actionUrls: testActionUrlsB, | |
311 dismissal: testDismissalB, | |
312 groupName: groupNameB | |
313 }, | |
314 hideTime: 300002 | |
315 }; | |
316 | |
317 // Setup and expectations. | |
318 var test = setUpCardManagerTest(this); | |
319 this.mockApis.expects(once()). | |
320 chrome_alarms_clear(expectedAlarmId); | |
321 var chromeNotificationsCreateSavedArgs = new SaveMockArguments(); | |
322 this.mockApis.expects(once()). | |
323 instrumented_notifications_update( | |
324 chromeNotificationsCreateSavedArgs.match(eq(testCardId)), | |
325 chromeNotificationsCreateSavedArgs.match(eqJSON(testNotificationB)), | |
326 chromeNotificationsCreateSavedArgs.match(ANYTHING)). | |
327 will(invokeCallback(chromeNotificationsCreateSavedArgs, 2, true)); | |
328 this.mockApis.expects(once()). | |
329 chrome_alarms_create(expectedAlarmId, eqJSON({when: 300001})); | |
330 | |
331 // Call tested method. | |
332 var notificationData = test.cardSet.update( | |
333 testCardId, | |
334 [testUncombinedNotificationA, testUncombinedNotificationB], | |
335 {}); | |
336 | |
337 // Check the return value. | |
338 assertEquals( | |
339 JSON.stringify({ | |
340 actionUrls: testActionUrlsB, | |
341 timestamp: 300000, | |
342 combinedCard: [testUncombinedNotificationA, testUncombinedNotificationB] | |
343 }), | |
344 JSON.stringify(notificationData)); | |
345 }); | |
346 | |
347 TEST_F('GoogleNowCardsUnitTest', 'DismissSimple', function() { | |
348 // Dismiss a combined card that contains 1 uncombined currently visible card. | |
349 // The notification should be deleted, and the card data should be cleared. | |
350 // showTime in future, and it doesn't get dismissed. | |
robliao
2013/12/30 01:59:49
What do you mean in the third line?
vadimt
2014/01/02 21:46:04
Nothing ;-)
| |
351 | |
352 var testUncombinedNotificationA = { | |
353 receivedNotification: { | |
354 notificationId: testNotificationIdA, | |
355 chromeNotificationId: testCardId, | |
356 chromeNotificationOptions: testNotificationA, | |
357 actionUrls: testActionUrlsA, | |
358 dismissal: testDismissalA, | |
359 groupName: groupNameA | |
360 }, | |
361 showTime: 299995, | |
362 hideTime: 300005 | |
363 }; | |
364 | |
365 // Setup and expectations. | |
366 var test = setUpCardManagerTest(this); | |
367 this.mockApis.expects(once()). | |
368 chrome_alarms_clear(expectedAlarmId); | |
369 this.mockApis.expects(once()). | |
370 instrumented_notifications_clear(testCardId, ANYTHING); | |
371 | |
372 var groups = { | |
373 A: { | |
374 cards: [{chromeNotificationId: 'ID1'}, {chromeNotificationId: testCardId}] | |
375 }, | |
376 B: { | |
377 cards: [{chromeNotificationId: testCardId}, {chromeNotificationId: 'ID2'}] | |
378 } | |
379 }; | |
380 | |
381 // Call tested method. | |
382 var dismissalResult = test.cardSet.onDismissal( | |
383 testCardId, | |
384 { | |
385 actionUrls: testActionUrlsA, | |
386 timestamp: 299999, | |
387 combinedCard: [testUncombinedNotificationA] | |
388 }, | |
389 groups); | |
390 | |
391 // Check the return value. | |
392 assertEquals( | |
393 JSON.stringify({ | |
394 dismissals: [ | |
395 {notificationId: testNotificationIdA, parameters: testDismissalA} | |
396 ], | |
397 notificationData: undefined | |
398 }), | |
399 JSON.stringify(dismissalResult)); | |
400 | |
401 // Check that groups were cleaned up. | |
402 var expectedCleanedGroups = { | |
403 A: { | |
404 cards: [{chromeNotificationId: 'ID1'}] | |
405 }, | |
406 B: { | |
407 cards: [{chromeNotificationId: 'ID2'}] | |
408 } | |
409 }; | |
410 | |
411 assertEquals(JSON.stringify(expectedCleanedGroups), JSON.stringify(groups)); | |
412 }); | |
413 | |
414 TEST_F('GoogleNowCardsUnitTest', 'DismissComplex', function() { | |
415 // Dismiss a combined card that contains 2 uncombined cards. One of them (B), | |
416 // is currently shown, and it should be dismissed. The other one (A) has | |
417 // showTime in future, and it doesn't get dismissed. | |
robliao
2013/12/30 01:59:49
should not be dismissed.
vadimt
2014/01/02 21:46:04
Done.
| |
418 | |
419 var testUncombinedNotificationA = { | |
420 receivedNotification: { | |
421 notificationId: testNotificationIdA, | |
422 chromeNotificationId: testCardId, | |
423 chromeNotificationOptions: testNotificationA, | |
424 actionUrls: testActionUrlsA, | |
425 dismissal: testDismissalA, | |
426 groupName: groupNameA | |
427 }, | |
428 showTime: 300010, | |
429 hideTime: 300011 | |
430 }; | |
431 | |
432 var testUncombinedNotificationB = { | |
433 receivedNotification: { | |
434 notificationId: testNotificationIdB, | |
435 chromeNotificationId: testCardId, | |
436 chromeNotificationOptions: testNotificationB, | |
437 actionUrls: testActionUrlsB, | |
438 dismissal: testDismissalB, | |
439 groupName: groupNameB | |
440 }, | |
441 showTime: 299995, | |
442 hideTime: 300005 | |
443 }; | |
444 | |
445 // Setup and expectations. | |
446 var test = setUpCardManagerTest(this); | |
447 this.mockApis.expects(once()). | |
448 chrome_alarms_clear(expectedAlarmId); | |
449 this.mockApis.expects(once()). | |
450 instrumented_notifications_clear(testCardId, ANYTHING); | |
451 this.mockApis.expects(once()). | |
452 chrome_alarms_create(expectedAlarmId, eqJSON({when: 300010})); | |
453 | |
454 // Call tested method. | |
455 var dismissalResult = test.cardSet.onDismissal( | |
456 testCardId, | |
457 { | |
458 actionUrls: testActionUrlsB, | |
459 timestamp: 299999, | |
460 combinedCard: [testUncombinedNotificationA, testUncombinedNotificationB] | |
461 }, | |
462 {}); | |
463 | |
464 // Check the return value. | |
465 assertEquals( | |
466 JSON.stringify({ | |
467 dismissals: [ | |
468 {notificationId: testNotificationIdB, parameters: testDismissalB} | |
469 ], | |
470 notificationData: { | |
471 timestamp: 300000, | |
472 combinedCard: [testUncombinedNotificationA] | |
473 }}), | |
474 JSON.stringify(dismissalResult)); | |
475 }); | |
476 | |
79 TEST_F('GoogleNowCardsUnitTest', 'onAlarmUnrecognized', function() { | 477 TEST_F('GoogleNowCardsUnitTest', 'onAlarmUnrecognized', function() { |
80 // Tests onAlarm does nothing on an unrelated alarm. | 478 // Tests onAlarm does nothing on an unrelated alarm. |
81 var test = setUpCardManagerTest(this); | 479 var test = setUpCardManagerTest(this); |
82 | 480 |
83 // Call tested method. | 481 // Call tested method. |
84 test.alarmCallback({name: 'unrelated'}); | 482 test.alarmCallback({name: 'unrelated'}); |
85 }); | 483 }); |
484 | |
485 TEST_F('GoogleNowCardsUnitTest', 'onAlarmClear', function() { | |
486 // Tests onAlarm fired at a moment past all card's events. The card should be | |
487 // cleaned. | |
488 var testUncombinedNotification = { | |
489 receivedNotification: { | |
490 notificationId: testNotificationIdA, | |
491 chromeNotificationId: testCardId, | |
492 chromeNotificationOptions: testNotificationA, | |
493 actionUrls: testActionUrlsA, | |
494 dismissal: testDismissalA, | |
495 groupName: groupNameA | |
496 }, | |
497 hideTime: 299999 | |
498 }; | |
499 | |
500 // Setup and expectations. | |
501 var test = setUpCardManagerTest(this); | |
502 var tasksAddSavedArgs = new SaveMockArguments(); | |
503 this.mockApis.expects(once()). | |
504 tasks_add( | |
505 tasksAddSavedArgs.match(eq(UPDATE_CARD_TASK_NAME)), | |
506 tasksAddSavedArgs.match(ANYTHING)). | |
507 will(invokeCallback(tasksAddSavedArgs,1)); | |
508 var storageGetSavedArgs = new SaveMockArguments(); | |
509 this.mockApis.expects(once()). | |
510 instrumented_storage_local_get( | |
511 storageGetSavedArgs.match( | |
512 eqJSON(['notificationsData', 'notificationGroups'])), | |
513 storageGetSavedArgs.match(ANYTHING)). | |
514 will(invokeCallback( | |
515 storageGetSavedArgs, | |
516 1, | |
517 { | |
518 notificationsData: { | |
519 'TEST CARD ID': { | |
520 actionUrls: testActionUrlsA, | |
521 timestamp: 299998, | |
522 combinedCard: [testUncombinedNotification] | |
523 }, | |
524 'TEST CARD ID 1': {testField: 'TEST VALUE 1'} | |
525 }, | |
526 notificationGroups: { | |
527 A: { | |
528 cards: [ | |
529 {chromeNotificationId: 'ID1'}, | |
530 {chromeNotificationId: testCardId} | |
531 ] | |
532 }, | |
533 B: { | |
534 cards: [ | |
535 {chromeNotificationId: testCardId}, | |
536 {chromeNotificationId: 'ID2'} | |
537 ] | |
538 }}})); | |
539 this.mockApis.expects(once()). | |
540 instrumented_notifications_clear(testCardId, ANYTHING); | |
541 this.mockApis.expects(once()). | |
542 chrome_alarms_clear(expectedAlarmId); | |
543 this.mockApis.expects(once()). | |
544 chrome_storage_local_set(eqJSON({ | |
545 notificationsData: { | |
546 'TEST CARD ID 1': {testField: 'TEST VALUE 1'} | |
547 }, | |
548 notificationGroups: { | |
549 A: { | |
550 cards: [{chromeNotificationId: 'ID1'}] | |
551 }, | |
552 B: { | |
553 cards: [{chromeNotificationId: 'ID2'}] | |
554 }}})); | |
555 | |
556 // Call tested method. | |
557 test.alarmCallback({name: expectedAlarmId}); | |
558 }); | |
559 | |
560 TEST_F('GoogleNowCardsUnitTest', 'onAlarmUpdate', function() { | |
561 // Tests onAlarm fired at a moment when there are future card's events. The | |
562 // card needs to be updated. | |
563 var testUncombinedNotification = { | |
564 receivedNotification: { | |
565 notificationId: testNotificationIdA, | |
566 chromeNotificationId: testCardId, | |
567 chromeNotificationOptions: testNotificationA, | |
568 actionUrls: testActionUrlsA, | |
569 dismissal: testDismissalA, | |
570 groupName: groupNameA | |
571 }, | |
572 hideTime: 300001 | |
573 }; | |
574 | |
575 // Setup and expectations. | |
576 var test = setUpCardManagerTest(this); | |
577 var tasksAddSavedArgs = new SaveMockArguments(); | |
578 this.mockApis.expects(once()). | |
579 tasks_add( | |
580 tasksAddSavedArgs.match(eq(UPDATE_CARD_TASK_NAME)), | |
581 tasksAddSavedArgs.match(ANYTHING)). | |
582 will(invokeCallback(tasksAddSavedArgs,1)); | |
583 var storageGetSavedArgs = new SaveMockArguments(); | |
584 this.mockApis.expects(once()). | |
585 instrumented_storage_local_get( | |
586 storageGetSavedArgs.match( | |
587 eqJSON(['notificationsData', 'notificationGroups'])), | |
588 storageGetSavedArgs.match(ANYTHING)). | |
589 will(invokeCallback( | |
590 storageGetSavedArgs, | |
591 1, | |
592 { | |
593 notificationsData: { | |
594 'TEST CARD ID': { | |
595 actionUrls: testActionUrlsA, | |
596 timestamp: 299998, | |
597 combinedCard: [testUncombinedNotification] | |
598 }}})); | |
599 this.mockApis.expects(once()). | |
600 chrome_alarms_clear(expectedAlarmId); | |
601 var chromeNotificationsCreateSavedArgs = new SaveMockArguments(); | |
602 this.mockApis.expects(once()). | |
603 instrumented_notifications_update( | |
604 chromeNotificationsCreateSavedArgs.match(eq(testCardId)), | |
605 chromeNotificationsCreateSavedArgs.match(eqJSON(testNotificationA)), | |
606 chromeNotificationsCreateSavedArgs.match(ANYTHING)). | |
607 will(invokeCallback(chromeNotificationsCreateSavedArgs, 2, true)); | |
608 this.mockApis.expects(once()). | |
609 chrome_alarms_create(expectedAlarmId, eqJSON({when: 300001})); | |
610 this.mockApis.expects(once()). | |
611 chrome_storage_local_set(eqJSON({ | |
612 notificationsData: { | |
613 'TEST CARD ID': { | |
614 actionUrls: testActionUrlsA, | |
615 timestamp: 300000, | |
616 combinedCard: [testUncombinedNotification] | |
617 } | |
618 }, | |
619 notificationGroups: { | |
620 }})); | |
621 | |
622 // Call tested method. | |
623 test.alarmCallback({name: expectedAlarmId}); | |
624 }); | |
OLD | NEW |