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 () { |
(...skipping 18 matching lines...) Expand all Loading... |
29 {testDismissalField: 'TEST DISMISSAL VALUE 1'}, | 29 {testDismissalField: 'TEST DISMISSAL VALUE 1'}, |
30 {testDismissalField: 'TEST DISMISSAL VALUE 2'} | 30 {testDismissalField: 'TEST DISMISSAL VALUE 2'} |
31 ]; | 31 ]; |
32 var testGroupRank = 271; | 32 var testGroupRank = 271; |
33 | 33 |
34 function setUpCardManagerTest(fixture) { | 34 function setUpCardManagerTest(fixture) { |
35 fixture.makeAndRegisterMockApis([ | 35 fixture.makeAndRegisterMockApis([ |
36 'chrome.alarms.clear', | 36 'chrome.alarms.clear', |
37 'chrome.alarms.create', | 37 'chrome.alarms.create', |
38 'chrome.notifications.clear', | 38 'chrome.notifications.clear', |
| 39 'chrome.storage.local.set', |
39 'instrumented.alarms.onAlarm.addListener', | 40 'instrumented.alarms.onAlarm.addListener', |
40 'instrumented.notifications.create', | 41 'instrumented.notifications.create', |
41 'instrumented.notifications.update', | 42 'instrumented.notifications.update', |
42 'instrumented.storage.local.get' | 43 'instrumented.storage.local.get', |
| 44 'tasks.add' |
43 ]); | 45 ]); |
44 | 46 |
45 chrome.runtime = {}; // No error. | 47 chrome.runtime = {}; // No error. |
46 | 48 |
47 var onAlarmSavedArgs = new SaveMockArguments(); | 49 var onAlarmSavedArgs = new SaveMockArguments(); |
48 fixture.mockApis.expects(once()). | 50 fixture.mockApis.expects(once()). |
49 instrumented_alarms_onAlarm_addListener( | 51 instrumented_alarms_onAlarm_addListener( |
50 onAlarmSavedArgs.match(ANYTHING)); | 52 onAlarmSavedArgs.match(ANYTHING)); |
51 | 53 |
52 var cardSet = buildCardSet(); | 54 var cardSet = buildCardSet(); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 // Setup and expectations. | 301 // Setup and expectations. |
300 var test = setUpCardManagerTest(this); | 302 var test = setUpCardManagerTest(this); |
301 this.mockApis.expects(once()). | 303 this.mockApis.expects(once()). |
302 chrome_notifications_clear(testCardId, ANYTHING); | 304 chrome_notifications_clear(testCardId, ANYTHING); |
303 this.mockApis.expects(once()). | 305 this.mockApis.expects(once()). |
304 chrome_alarms_clear(expectedShowAlarmId); | 306 chrome_alarms_clear(expectedShowAlarmId); |
305 this.mockApis.expects(once()). | 307 this.mockApis.expects(once()). |
306 chrome_alarms_clear(expectedHideAlarmId); | 308 chrome_alarms_clear(expectedHideAlarmId); |
307 | 309 |
308 // Call tested method. | 310 // Call tested method. |
309 test.cardSet.clear(testCardId); | 311 test.cardSet.clear(testCardId, false); |
310 }); | 312 }); |
311 | 313 |
312 TEST_F('GoogleNowCardsUnitTest', 'onAlarmUnrecognized', function() { | 314 TEST_F('GoogleNowCardsUnitTest', 'onAlarmUnrecognized', function() { |
313 // Tests onAlarm does nothing on an unrelated alarm. | 315 // Tests onAlarm does nothing on an unrelated alarm. |
314 var test = setUpCardManagerTest(this); | 316 var test = setUpCardManagerTest(this); |
315 | 317 |
316 // Call tested method. | 318 // Call tested method. |
317 test.alarmCallback({name: 'unrelated'}); | 319 test.alarmCallback({name: 'unrelated'}); |
318 }); | 320 }); |
319 | 321 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 instrumented_notifications_update( | 393 instrumented_notifications_update( |
392 testCardId, eqJSON(testNotification), ANYTHING); | 394 testCardId, eqJSON(testNotification), ANYTHING); |
393 | 395 |
394 // Call tested method. | 396 // Call tested method. |
395 test.alarmCallback({name: expectedShowAlarmId}); | 397 test.alarmCallback({name: expectedShowAlarmId}); |
396 }); | 398 }); |
397 | 399 |
398 TEST_F('GoogleNowCardsUnitTest', 'onAlarmHide', function() { | 400 TEST_F('GoogleNowCardsUnitTest', 'onAlarmHide', function() { |
399 // Tests onAlarm for the 'hide' alarm. | 401 // Tests onAlarm for the 'hide' alarm. |
400 var test = setUpCardManagerTest(this); | 402 var test = setUpCardManagerTest(this); |
| 403 var tasksAddSavedArgs = new SaveMockArguments(); |
| 404 this.mockApis.expects(once()). |
| 405 tasks_add( |
| 406 tasksAddSavedArgs.match(eq(CLEAR_CARD_TASK_NAME)), |
| 407 tasksAddSavedArgs.match(ANYTHING)). |
| 408 will(invokeCallback(tasksAddSavedArgs,1)); |
401 this.mockApis.expects(once()). | 409 this.mockApis.expects(once()). |
402 chrome_notifications_clear(testCardId, ANYTHING); | 410 chrome_notifications_clear(testCardId, ANYTHING); |
403 this.mockApis.expects(once()). | 411 this.mockApis.expects(once()). |
404 chrome_alarms_clear(expectedShowAlarmId); | 412 chrome_alarms_clear(expectedShowAlarmId); |
405 this.mockApis.expects(once()). | 413 this.mockApis.expects(once()). |
406 chrome_alarms_clear(expectedHideAlarmId); | 414 chrome_alarms_clear(expectedHideAlarmId); |
407 | 415 var storageGetSavedArgs = new SaveMockArguments(); |
| 416 this.mockApis.expects(once()). |
| 417 instrumented_storage_local_get( |
| 418 storageGetSavedArgs.match( |
| 419 eqJSON(['notificationsData', 'notificationGroups'])), |
| 420 storageGetSavedArgs.match(ANYTHING)). |
| 421 will(invokeCallback( |
| 422 storageGetSavedArgs, |
| 423 1, |
| 424 { |
| 425 notificationsData: { |
| 426 'TEST CARD ID': {testField: 'TEST VALUE'}, |
| 427 'TEST CARD ID 1': {testField: 'TEST VALUE 1'} |
| 428 }, |
| 429 notificationGroups: { |
| 430 groupA: { |
| 431 cards: [ |
| 432 { |
| 433 chromeNotificationId: 'TEST CARD ID', |
| 434 testField: 'TEST VALUE', |
| 435 }, |
| 436 { |
| 437 chromeNotificationId: 'TEST CARD ID 1', |
| 438 testField: 'TEST VALUE 1', |
| 439 } |
| 440 ] |
| 441 }, |
| 442 groupB: { |
| 443 cards: [ |
| 444 { |
| 445 chromeNotificationId: 'TEST CARD ID 0', |
| 446 testField: 'TEST VALUE 0', |
| 447 }, |
| 448 { |
| 449 chromeNotificationId: 'TEST CARD ID', |
| 450 testField: 'TEST VALUE', |
| 451 } |
| 452 ] |
| 453 } |
| 454 }})); |
| 455 this.mockApis.expects(once()). |
| 456 chrome_storage_local_set(eqJSON({ |
| 457 notificationsData: { |
| 458 'TEST CARD ID 1': {testField: 'TEST VALUE 1'} |
| 459 }, |
| 460 notificationGroups: { |
| 461 groupA: { |
| 462 cards: [ |
| 463 { |
| 464 chromeNotificationId: 'TEST CARD ID 1', |
| 465 testField: 'TEST VALUE 1', |
| 466 } |
| 467 ] |
| 468 }, |
| 469 groupB: { |
| 470 cards: [ |
| 471 { |
| 472 chromeNotificationId: 'TEST CARD ID 0', |
| 473 testField: 'TEST VALUE 0', |
| 474 } |
| 475 ] |
| 476 } |
| 477 } |
| 478 })); |
408 | 479 |
409 // Call tested method. | 480 // Call tested method. |
410 test.alarmCallback({name: expectedHideAlarmId}); | 481 test.alarmCallback({name: expectedHideAlarmId}); |
411 }); | 482 }); |
OLD | NEW |