Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: chrome/browser/resources/google_now/cards_unittest.gtestjs

Issue 166033010: Convert Google Now's use of chrome.local.storage.get to use Promises (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR Feedback Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 var testDismissalB = {testDismissalField: 'TEST DISMISSAL VALUE B'}; 46 var testDismissalB = {testDismissalField: 'TEST DISMISSAL VALUE B'};
47 var EXPLANATORY_CARDS_LINK_THRESHOLD = 4; 47 var EXPLANATORY_CARDS_LINK_THRESHOLD = 4;
48 var localStorage = {explanatoryCardsShown: 0}; 48 var localStorage = {explanatoryCardsShown: 0};
49 var notificationUpdateSuccessful = true; 49 var notificationUpdateSuccessful = true;
50 var notificationUpdateFailed = false; 50 var notificationUpdateFailed = false;
51 51
52 function setUpCardManagerTest(fixture) { 52 function setUpCardManagerTest(fixture) {
53 fixture.makeAndRegisterMockApis([ 53 fixture.makeAndRegisterMockApis([
54 'chrome.alarms.clear', 54 'chrome.alarms.clear',
55 'chrome.alarms.create', 55 'chrome.alarms.create',
56 'instrumented.notifications.clear',
57 'chrome.storage.local.set', 56 'chrome.storage.local.set',
58 'countExplanatoryCard', 57 'countExplanatoryCard',
58 'fillFromChromeLocalStorage',
59 'instrumented.alarms.onAlarm.addListener', 59 'instrumented.alarms.onAlarm.addListener',
60 'instrumented.notifications.clear',
60 'instrumented.notifications.create', 61 'instrumented.notifications.create',
61 'instrumented.notifications.update', 62 'instrumented.notifications.update',
62 'instrumented.storage.local.get',
63 'tasks.add' 63 'tasks.add'
64 ]); 64 ]);
65 65
66 chrome.runtime = {}; // No error. 66 chrome.runtime = {}; // No error.
67 67
68 var onAlarmSavedArgs = new SaveMockArguments(); 68 var onAlarmSavedArgs = new SaveMockArguments();
69 fixture.mockApis.expects(once()). 69 fixture.mockApis.expects(once()).
70 instrumented_alarms_onAlarm_addListener( 70 instrumented_alarms_onAlarm_addListener(
71 onAlarmSavedArgs.match(ANYTHING)); 71 onAlarmSavedArgs.match(ANYTHING));
72 72
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 }; 503 };
504 504
505 // Setup and expectations. 505 // Setup and expectations.
506 var test = setUpCardManagerTest(this); 506 var test = setUpCardManagerTest(this);
507 var tasksAddSavedArgs = new SaveMockArguments(); 507 var tasksAddSavedArgs = new SaveMockArguments();
508 this.mockApis.expects(once()). 508 this.mockApis.expects(once()).
509 tasks_add( 509 tasks_add(
510 tasksAddSavedArgs.match(eq(UPDATE_CARD_TASK_NAME)), 510 tasksAddSavedArgs.match(eq(UPDATE_CARD_TASK_NAME)),
511 tasksAddSavedArgs.match(ANYTHING)). 511 tasksAddSavedArgs.match(ANYTHING)).
512 will(invokeCallback(tasksAddSavedArgs,1)); 512 will(invokeCallback(tasksAddSavedArgs,1));
513 var storageGetSavedArgs = new SaveMockArguments(); 513 expectChromeLocalStorageGet(
514 this.mockApis.expects(once()). 514 this,
515 instrumented_storage_local_get( 515 {
516 storageGetSavedArgs.match( 516 notificationsData: {},
517 eqJSON(['notificationsData', 'notificationGroups'])), 517 notificationGroups: {}
518 storageGetSavedArgs.match(ANYTHING)). 518 },
519 will(invokeCallback( 519 {
520 storageGetSavedArgs, 520 notificationsData: {
521 1, 521 'TEST CARD ID': {
522 { 522 actionUrls: testActionUrlsA,
523 notificationsData: { 523 timestamp: 299998,
524 'TEST CARD ID': { 524 combinedCard: [testUncombinedNotification]
525 actionUrls: testActionUrlsA, 525 },
526 timestamp: 299998, 526 'TEST CARD ID 1': {testField: 'TEST VALUE 1'}
527 combinedCard: [testUncombinedNotification] 527 },
528 }, 528 notificationGroups: {
529 'TEST CARD ID 1': {testField: 'TEST VALUE 1'} 529 A: {
530 }, 530 cards: [
531 notificationGroups: { 531 {chromeNotificationId: 'ID1'},
532 A: { 532 {chromeNotificationId: testCardId}
533 cards: [ 533 ]
534 {chromeNotificationId: 'ID1'}, 534 },
535 {chromeNotificationId: testCardId} 535 B: {
536 ] 536 cards: [
537 }, 537 {chromeNotificationId: testCardId},
538 B: { 538 {chromeNotificationId: 'ID2'}
539 cards: [ 539 ]
540 {chromeNotificationId: testCardId}, 540 }}});
541 {chromeNotificationId: 'ID2'}
542 ]
543 }}}));
544 this.mockApis.expects(once()). 541 this.mockApis.expects(once()).
545 instrumented_notifications_clear(testCardId, ANYTHING); 542 instrumented_notifications_clear(testCardId, ANYTHING);
546 this.mockApis.expects(once()). 543 this.mockApis.expects(once()).
547 chrome_alarms_clear(expectedAlarmId); 544 chrome_alarms_clear(expectedAlarmId);
548 this.mockApis.expects(once()). 545 this.mockApis.expects(once()).
549 chrome_storage_local_set(eqJSON({ 546 chrome_storage_local_set(eqJSON({
550 notificationsData: { 547 notificationsData: {
551 'TEST CARD ID 1': {testField: 'TEST VALUE 1'} 548 'TEST CARD ID 1': {testField: 'TEST VALUE 1'}
552 }, 549 },
553 notificationGroups: { 550 notificationGroups: {
(...skipping 24 matching lines...) Expand all
578 }; 575 };
579 576
580 // Setup and expectations. 577 // Setup and expectations.
581 var test = setUpCardManagerTest(this); 578 var test = setUpCardManagerTest(this);
582 var tasksAddSavedArgs = new SaveMockArguments(); 579 var tasksAddSavedArgs = new SaveMockArguments();
583 this.mockApis.expects(once()). 580 this.mockApis.expects(once()).
584 tasks_add( 581 tasks_add(
585 tasksAddSavedArgs.match(eq(UPDATE_CARD_TASK_NAME)), 582 tasksAddSavedArgs.match(eq(UPDATE_CARD_TASK_NAME)),
586 tasksAddSavedArgs.match(ANYTHING)). 583 tasksAddSavedArgs.match(ANYTHING)).
587 will(invokeCallback(tasksAddSavedArgs,1)); 584 will(invokeCallback(tasksAddSavedArgs,1));
588 var storageGetSavedArgs = new SaveMockArguments(); 585 expectChromeLocalStorageGet(
589 this.mockApis.expects(once()). 586 this,
590 instrumented_storage_local_get( 587 {
591 storageGetSavedArgs.match( 588 notificationsData: {},
592 eqJSON(['notificationsData', 'notificationGroups'])), 589 notificationGroups: {}
593 storageGetSavedArgs.match(ANYTHING)). 590 },
594 will(invokeCallback( 591 {
595 storageGetSavedArgs, 592 notificationsData: {
596 1, 593 'TEST CARD ID': {
597 { 594 actionUrls: testActionUrlsA,
598 notificationsData: { 595 timestamp: 299998,
599 'TEST CARD ID': { 596 combinedCard: [testUncombinedNotification]
600 actionUrls: testActionUrlsA, 597 }},
601 timestamp: 299998, 598 notificationGroups: {}
602 combinedCard: [testUncombinedNotification] 599 });
603 }}}));
604 this.mockApis.expects(once()). 600 this.mockApis.expects(once()).
605 chrome_alarms_clear(expectedAlarmId); 601 chrome_alarms_clear(expectedAlarmId);
606 var chromeNotificationsUpdateSavedArgs = new SaveMockArguments(); 602 var chromeNotificationsUpdateSavedArgs = new SaveMockArguments();
607 this.mockApis.expects(once()). 603 this.mockApis.expects(once()).
608 instrumented_notifications_update( 604 instrumented_notifications_update(
609 chromeNotificationsUpdateSavedArgs.match(eq(testCardId)), 605 chromeNotificationsUpdateSavedArgs.match(eq(testCardId)),
610 chromeNotificationsUpdateSavedArgs.match(eqJSON(testNotificationA)), 606 chromeNotificationsUpdateSavedArgs.match(eqJSON(testNotificationA)),
611 chromeNotificationsUpdateSavedArgs.match(ANYTHING)). 607 chromeNotificationsUpdateSavedArgs.match(ANYTHING)).
612 will(invokeCallback( 608 will(invokeCallback(
613 chromeNotificationsUpdateSavedArgs, 2, notificationUpdateSuccessful)); 609 chromeNotificationsUpdateSavedArgs, 2, notificationUpdateSuccessful));
614 this.mockApis.expects(once()). 610 this.mockApis.expects(once()).
615 chrome_alarms_create(expectedAlarmId, eqJSON({when: 300001})); 611 chrome_alarms_create(expectedAlarmId, eqJSON({when: 300001}));
616 this.mockApis.expects(once()). 612 this.mockApis.expects(once()).
617 chrome_storage_local_set(eqJSON({ 613 chrome_storage_local_set(eqJSON({
618 notificationsData: { 614 notificationsData: {
619 'TEST CARD ID': { 615 'TEST CARD ID': {
620 actionUrls: testActionUrlsA, 616 actionUrls: testActionUrlsA,
621 timestamp: 300000, 617 timestamp: 300000,
622 combinedCard: [testUncombinedNotification] 618 combinedCard: [testUncombinedNotification]
623 } 619 }
624 }, 620 },
625 notificationGroups: { 621 notificationGroups: {
626 }})); 622 }}));
627 623
628 // Call tested method. 624 // Call tested method.
629 test.alarmCallback({name: expectedAlarmId}); 625 test.alarmCallback({name: expectedAlarmId});
630 }); 626 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/google_now/cards.js ('k') | chrome/browser/resources/google_now/common_test_util.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698