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
3 // found in the LICENSE file.
6 * Test fixture for background.js.
8 * @extends {testing.Test}
10 function GoogleNowBackgroundUnitTest () {
11 testing.Test.call(this);
14 GoogleNowBackgroundUnitTest.prototype = {
15 __proto__: testing.Test.prototype,
19 'common_test_util.js',
20 'background_test_util.js',
25 TEST_F('GoogleNowBackgroundUnitTest', 'AreTasksConflicting', function() {
26 function testTaskPair(newTaskName, scheduledTaskName, expected) {
27 assertTrue(areTasksConflicting(newTaskName, scheduledTaskName) == expected,
28 '(' + newTaskName + ', ' + scheduledTaskName + ')');
31 testTaskPair(UPDATE_CARDS_TASK_NAME, UPDATE_CARDS_TASK_NAME, true);
32 testTaskPair(UPDATE_CARDS_TASK_NAME, DISMISS_CARD_TASK_NAME, false);
33 testTaskPair(UPDATE_CARDS_TASK_NAME, RETRY_DISMISS_TASK_NAME, false);
34 testTaskPair(UPDATE_CARDS_TASK_NAME, STATE_CHANGED_TASK_NAME, false);
36 testTaskPair(DISMISS_CARD_TASK_NAME, UPDATE_CARDS_TASK_NAME, false);
37 testTaskPair(DISMISS_CARD_TASK_NAME, DISMISS_CARD_TASK_NAME, false);
38 testTaskPair(DISMISS_CARD_TASK_NAME, RETRY_DISMISS_TASK_NAME, false);
39 testTaskPair(DISMISS_CARD_TASK_NAME, STATE_CHANGED_TASK_NAME, false);
41 testTaskPair(RETRY_DISMISS_TASK_NAME, UPDATE_CARDS_TASK_NAME, true);
42 testTaskPair(RETRY_DISMISS_TASK_NAME, DISMISS_CARD_TASK_NAME, true);
43 testTaskPair(RETRY_DISMISS_TASK_NAME, RETRY_DISMISS_TASK_NAME, true);
44 testTaskPair(RETRY_DISMISS_TASK_NAME, STATE_CHANGED_TASK_NAME, false);
46 testTaskPair(STATE_CHANGED_TASK_NAME, UPDATE_CARDS_TASK_NAME, false);
47 testTaskPair(STATE_CHANGED_TASK_NAME, DISMISS_CARD_TASK_NAME, false);
48 testTaskPair(STATE_CHANGED_TASK_NAME, RETRY_DISMISS_TASK_NAME, false);
49 testTaskPair(STATE_CHANGED_TASK_NAME, STATE_CHANGED_TASK_NAME, false);
52 var testNotificationId = 'TEST GROUP-SOME TEST ID';
53 var testChromeNotificationId = 'TEST CARD ID';
54 var testNotification1 =
55 {testNotificationField: 'TEST NOTIFICATION VALUE1', priority: -1};
56 var testNotification2 =
57 {testNotificationField: 'TEST NOTIFICATION VALUE2', priority: 0};
58 var testActionUrls1 = {testField: 'TEST VALUE1'};
59 var testActionUrls2 = {testField: 'TEST VALUE2'};
60 var testDismissal1 = {testDismissalField: 'TEST DISMISSAL VALUE 1'};
61 var testDismissal2 = {testDismissalField: 'TEST DISMISSAL VALUE 2'};
63 var testTimestamp1 = 300000;
64 var testTimestamp2 = 600000;
65 var testGroupRank1 = 19;
66 var testGroupRank2 = 23;
67 var testTriggerUnmerged = {showTimeSec: 100, hideTimeSec: 200};
68 var testTriggerMerged = {showTime: 300007, hideTime: 300011};
69 var testVersion1 = 29;
70 var testVersion2 = 31;
73 'GoogleNowBackgroundUnitTest',
74 'MergeCardsEmptyNoTrigger',
76 // Tests merging a card with an empty trigger into an 'undefined' merged
77 // card. This should start a new card.
79 // Invoking the tested function.
80 var resultingMergedCard = mergeCards(undefined, {
81 notificationId: testNotificationId,
82 chromeNotificationId: testChromeNotificationId,
83 version: testVersion1,
84 chromeNotificationOptions: testNotification1,
85 actionUrls: testActionUrls1,
86 dismissal: testDismissal1
87 }, testTimestamp1, testGroupRank1);
89 // Check the return value.
94 notificationId: testNotificationId,
95 parameters: testDismissal1
98 groupRank: testGroupRank1,
100 timestamp: testTimestamp1,
101 notification: testNotification1,
102 actionUrls: testActionUrls1,
103 version: testVersion1
105 JSON.stringify(resultingMergedCard));
109 'GoogleNowBackgroundUnitTest',
112 // Tests merging a unmerged card into a merged card.
113 // Unmerged card priority is greater than merged card one. Unmerged card
114 // rank is less than merged card one, and it's older.
118 trigger: testTriggerMerged,
119 version: testVersion1,
120 timestamp: testTimestamp2,
121 notification: testNotification1,
122 actionUrls: testActionUrls1,
123 groupRank: testGroupRank2,
125 [{notificationId: testNotificationId, parameters: testDismissal1}]
128 var unmergedNotification = {
129 notificationId: testNotificationId,
130 chromeNotificationId: testChromeNotificationId,
131 version: testVersion2,
132 chromeNotificationOptions: testNotification2,
133 actionUrls: testActionUrls2,
134 dismissal: testDismissal2,
135 trigger: testTriggerUnmerged
138 // Invoking the tested function.
139 var resultingMergedCard = mergeCards(
140 mergedCard, unmergedNotification, testTimestamp1, testGroupRank1);
142 // Check the return value.
145 trigger: testTriggerMerged,
146 version: testVersion1,
147 timestamp: testTimestamp2,
149 testNotificationField: 'TEST NOTIFICATION VALUE1',
152 actionUrls: testActionUrls1,
153 groupRank: testGroupRank2,
155 {notificationId: testNotificationId, parameters: testDismissal1},
156 {notificationId: testNotificationId, parameters: testDismissal2}
159 JSON.stringify(resultingMergedCard));
163 'GoogleNowBackgroundUnitTest',
166 // Tests merging a unmerged card into a merged card.
167 // Unmerged card priority is less than merged card one. Unmerged card rank
168 // is greater than merged card one, and it's older.
172 trigger: testTriggerMerged,
173 version: testVersion1,
174 timestamp: testTimestamp2,
175 notification: testNotification2,
176 actionUrls: testActionUrls1,
177 groupRank: testGroupRank1,
179 [{notificationId: testNotificationId, parameters: testDismissal1}]
182 var unmergedNotification = {
183 notificationId: testNotificationId,
184 chromeNotificationId: testChromeNotificationId,
185 version: testVersion2,
186 chromeNotificationOptions: testNotification1,
187 actionUrls: testActionUrls2,
188 dismissal: testDismissal2,
189 trigger: testTriggerUnmerged
192 // Invoking the tested function.
193 var resultingMergedCard = mergeCards(
194 mergedCard, unmergedNotification, testTimestamp1, testGroupRank2);
196 // Check the return value.
199 trigger: {showTime: 400000, hideTime: 500000},
200 version: testVersion1,
201 timestamp: testTimestamp2,
203 testNotificationField: 'TEST NOTIFICATION VALUE2',
206 actionUrls: testActionUrls1,
207 groupRank: testGroupRank2,
209 {notificationId: testNotificationId, parameters: testDismissal1},
210 {notificationId: testNotificationId, parameters: testDismissal2}
213 JSON.stringify(resultingMergedCard));
217 'GoogleNowBackgroundUnitTest',
220 // Tests merging a unmerged card into a merged card.
221 // Unmerged card priority is less than merged card one. Unmerged card rank
222 // is less than merged card one, and it's newer.
226 trigger: testTriggerMerged,
227 version: testVersion1,
228 timestamp: testTimestamp1,
229 notification: testNotification2,
230 actionUrls: testActionUrls1,
231 groupRank: testGroupRank2,
233 [{notificationId: testNotificationId, parameters: testDismissal1}]
236 var unmergedNotification = {
237 notificationId: testNotificationId,
238 chromeNotificationId: testChromeNotificationId,
239 version: testVersion2,
240 chromeNotificationOptions: testNotification1,
241 actionUrls: testActionUrls2,
242 dismissal: testDismissal2,
243 trigger: testTriggerUnmerged
246 // Invoking the tested function.
247 var resultingMergedCard = mergeCards(
248 mergedCard, unmergedNotification, testTimestamp2, testGroupRank1);
250 // Check the return value.
253 trigger: testTriggerMerged,
254 version: testVersion2,
255 timestamp: testTimestamp2,
257 testNotificationField: 'TEST NOTIFICATION VALUE1',
260 actionUrls: testActionUrls2,
261 groupRank: testGroupRank2,
263 {notificationId: testNotificationId, parameters: testDismissal1},
264 {notificationId: testNotificationId, parameters: testDismissal2}
267 JSON.stringify(resultingMergedCard));
271 'GoogleNowBackgroundUnitTest',
274 // Tests mergeGroup method.
277 this.makeAndRegisterMockGlobals(['mergeCards']);
279 this.mockGlobals.expects(once()).
282 eqJSON({chromeNotificationId: 'ID 1', testField: 'TEST_FIELD1'}),
285 will(returnValue({testField: 'RESULT 1'}));
286 this.mockGlobals.expects(once()).
288 eqJSON({testField: 'TEST_FIELD22'}),
289 eqJSON({chromeNotificationId: 'ID 2', testField: 'TEST_FIELD2'}),
292 will(returnValue({testField: 'RESULT 2'}));
296 {chromeNotificationId: 'ID 1', testField: 'TEST_FIELD1'},
297 {chromeNotificationId: 'ID 2', testField: 'TEST_FIELD2'}
299 cardsTimestamp: 300000,
300 nextPollTime: 600000,
305 'ID 2': { testField: 'TEST_FIELD22' },
306 'ID 3': { testField: 'TEST_FIELD3' }
309 // Invoking the tested function.
310 mergeGroup(mergedCards, group);
312 // Check the output parameter.
315 'ID 2': { testField: 'RESULT 2' },
316 'ID 3': { testField: 'TEST_FIELD3'},
317 'ID 1': { testField: 'RESULT 1' }}),
318 JSON.stringify(mergedCards));
322 * Mocks global functions and APIs that initialize() depends upon.
323 * @param {Test} fixture Test fixture.
325 function mockInitializeDependencies(fixture) {
326 fixture.makeAndRegisterMockGlobals([
328 'setBackgroundEnable',
332 fixture.makeAndRegisterMockApis([
333 'authenticationManager.isSignedIn',
334 'chrome.location.clearWatch',
335 'chrome.storage.local.remove',
336 'instrumented.metricsPrivate.getVariationParams',
337 'instrumented.notifications.getAll',
338 'instrumented.preferencesPrivate.googleGeolocationAccessEnabled.get',
339 'instrumented.storage.local.get',
341 'updateCardsAttempts.isRunning',
342 'updateCardsAttempts.stop'
347 * Sets up the test to expect the state machine calls and send
348 * the specified state machine state. Currently used to test initialize().
349 * Note that this CAN NOT be used if any of the methods below are called
350 * outside of this context with the same argument matchers.
351 * expects() calls cannot be chained with the same argument matchers.
352 * @param {object} fixture Test fixture.
353 * @param {string} testIdentityToken getAuthToken callback token.
354 * @param {boolean} testGeolocationPref Geolocation Preference callback value.
355 * @param {boolean} testUserRespondedToToast User Response to toast
357 * @param {object} testExperimentVariationParams Response of
358 * metricsPrivate.getVariationParams
360 function expectStateMachineCalls(
364 testUserRespondedToToast,
365 testExperimentVariationParams) {
366 var authenticationManagerIsSignedInSavedArgs = new SaveMockArguments();
367 fixture.mockApis.expects(once()).
368 authenticationManager_isSignedIn(
369 authenticationManagerIsSignedInSavedArgs.match(ANYTHING)).
371 authenticationManagerIsSignedInSavedArgs,
375 var getVariationParamsSavedArgs = new SaveMockArguments();
376 fixture.mockApis.expects(once()).
377 instrumented_metricsPrivate_getVariationParams(
378 getVariationParamsSavedArgs.match(ANYTHING),
379 getVariationParamsSavedArgs.match(ANYTHING)).
381 getVariationParamsSavedArgs, 1, testExperimentVariationParams));
383 var googleGeolocationPrefGetSavedArgs = new SaveMockArguments();
384 fixture.mockApis.expects(once()).
385 instrumented_preferencesPrivate_googleGeolocationAccessEnabled_get(
386 googleGeolocationPrefGetSavedArgs.match(eqJSON({})),
387 googleGeolocationPrefGetSavedArgs.match(ANYTHING)).
389 googleGeolocationPrefGetSavedArgs, 1, {value: testGeolocationPref}));
391 var storageGetSavedArgs = new SaveMockArguments();
392 fixture.mockApis.expects(once()).
393 instrumented_storage_local_get(
394 storageGetSavedArgs.match(eq('userRespondedToToast')),
395 storageGetSavedArgs.match(ANYTHING)).
396 will(invokeCallback(storageGetSavedArgs, 1, testUserRespondedToToast));
398 fixture.mockGlobals.expects(once()).
399 setBackgroundEnable(ANYTHING);
403 * Sets up the test to expect the initialization calls that
404 * initialize() invokes.
405 * Note that this CAN NOT be used if any of the methods below are called
406 * outside of this context with the same argument matchers.
407 * expects() calls cannot be chained with the same argument matchers.
409 function expectInitialization(mockApisObj) {
410 mockApisObj.expects(once()).
411 chrome_location_clearWatch(ANYTHING);
412 mockApisObj.expects(once()).
413 updateCardsAttempts_stop();
414 mockApisObj.expects(once()).
415 chrome_storage_local_remove(
416 eqJSON(['notificationsData', 'notificationGroups']));
417 var tasksAddSavedArgs = new SaveMockArguments();
418 mockApisObj.expects(once()).
420 tasksAddSavedArgs.match(ANYTHING),
421 tasksAddSavedArgs.match(ANYTHING)).
422 will(invokeCallback(tasksAddSavedArgs, 1, function() {}));
423 var updateCardsAttemptsIsRunningSavedArgs = new SaveMockArguments();
424 mockApisObj.expects(once()).
425 updateCardsAttempts_isRunning(
426 updateCardsAttemptsIsRunningSavedArgs.match(ANYTHING)).
429 updateCardsAttemptsIsRunningSavedArgs, 0, false));
433 'GoogleNowBackgroundUnitTest',
434 'Initialize_ToastStateEmpty1',
436 // Tests the case when the user isn't signed in and NOTIFICATION_CARDS_URL
437 // is not set. Since NOTIFICATION_CARDS_URL is empty,
438 // nothing should start.
440 // Setup and expectations.
441 NOTIFICATION_CARDS_URL = undefined;
442 var testIdentityToken = undefined;
443 var testGeolocationPref = false;
444 var testUserRespondedToToast = {};
445 var testExperimentVariationParams = {};
447 mockInitializeDependencies(this);
449 this.mockGlobals.expects(once()).recordEvent(
450 GoogleNowEvent.EXTENSION_START);
452 this.mockGlobals.expects(once()).recordEvent(
453 GoogleNowEvent.STOPPED);
455 expectInitialization(this.mockApis);
457 expectStateMachineCalls(
461 testUserRespondedToToast,
462 testExperimentVariationParams);
464 var chromeNotificationGetAllSavedArgs = new SaveMockArguments();
465 this.mockApis.expects(exactly(2)).
466 instrumented_notifications_getAll(
467 chromeNotificationGetAllSavedArgs.match(ANYTHING)).
469 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}),
470 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}));
472 // TODO(robliao,vadimt): Determine the granularity of testing to perform.
474 // Invoking the tested function.
479 'GoogleNowBackgroundUnitTest',
480 'Initialize_ToastStateEmpty2',
482 // Tests the case when NOTIFICATION_CARDS_URL is but getAuthToken fails
483 // most likely because the user is not signed in. In this case, the
484 // function should quietly exit after finding out that getAuthToken fails.
486 // Setup and expectations.
487 NOTIFICATION_CARDS_URL = 'https://some.server.url.com';
488 var testIdentityToken = undefined;
489 var testGeolocationPref = false;
490 var testUserRespondedToToast = {};
491 var testExperimentVariationParams = {};
493 mockInitializeDependencies(this);
495 this.mockGlobals.expects(once()).recordEvent(
496 GoogleNowEvent.EXTENSION_START);
498 this.mockGlobals.expects(once()).recordEvent(
499 GoogleNowEvent.STOPPED);
501 expectInitialization(this.mockApis);
503 expectStateMachineCalls(
507 testUserRespondedToToast,
508 testExperimentVariationParams);
510 var chromeNotificationGetAllSavedArgs = new SaveMockArguments();
511 this.mockApis.expects(exactly(2)).
512 instrumented_notifications_getAll(
513 chromeNotificationGetAllSavedArgs.match(ANYTHING)).
515 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}),
516 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}));
518 // Invoking the tested function.
523 'GoogleNowBackgroundUnitTest',
524 'DISABLED_Initialize_ToastStateEmpty3',
526 // Tests the case when NOTIFICATION_CARDS_URL is set, getAuthToken
527 // succeeds, and the user has never responded to the toast.
528 // In this case, the function should invoke showWelcomeToast().
530 // Setup and expectations.
531 NOTIFICATION_CARDS_URL = 'https://some.server.url.com';
532 var testIdentityToken = 'some identity token';
533 var testGeolocationPref = false;
534 var testUserRespondedToToast = {};
535 var testExperimentVariationParams = {};
537 mockInitializeDependencies(this);
539 this.mockGlobals.expects(once()).recordEvent(
540 GoogleNowEvent.EXTENSION_START);
542 expectInitialization(this.mockApis);
544 expectStateMachineCalls(
548 testUserRespondedToToast,
549 testExperimentVariationParams);
551 var chromeNotificationGetAllSavedArgs = new SaveMockArguments();
552 this.mockApis.expects(exactly(2)).
553 instrumented_notifications_getAll(
554 chromeNotificationGetAllSavedArgs.match(ANYTHING)).
556 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}),
557 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}));
559 this.mockGlobals.expects(once()).showWelcomeToast();
561 // Invoking the tested function.
565 TEST_F('GoogleNowBackgroundUnitTest', 'Initialize_RunGoogleNow', function() {
566 // Tests if Google Now will invoke startPollingCards when all
567 // of the required state is fulfilled.
569 // Setup and expectations.
570 NOTIFICATION_CARDS_URL = 'https://some.server.url.com';
571 var testIdentityToken = 'some identity token';
572 var testGeolocationPref = true;
573 var testUserRespondedToToast = {userRespondedToToast: true};
574 var testExperimentVariationParams = {};
576 mockInitializeDependencies(this);
578 this.mockGlobals.expects(once()).recordEvent(
579 GoogleNowEvent.EXTENSION_START);
581 expectInitialization(this.mockApis);
583 expectStateMachineCalls(
587 testUserRespondedToToast,
588 testExperimentVariationParams);
590 var chromeNotificationGetAllSavedArgs = new SaveMockArguments();
591 this.mockApis.expects(exactly(2)).
592 instrumented_notifications_getAll(
593 chromeNotificationGetAllSavedArgs.match(ANYTHING)).
595 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}),
596 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}));
598 this.mockGlobals.expects(once()).startPollingCards();
600 // Invoking the tested function.
605 'GoogleNowBackgroundUnitTest',
606 'DISABLED_Initialize_NoGeolocation',
608 // Tests the case where everything is in place except for the
609 // Geolocation Preference after the user responded to the toast.
611 // Setup and expectations.
612 NOTIFICATION_CARDS_URL = 'https://some.server.url.com';
613 var testIdentityToken = 'some identity token';
614 var testGeolocationPref = false;
615 var testUserRespondedToToast = {userRespondedToToast: true};
616 var testExperimentVariationParams = {};
618 mockInitializeDependencies(this);
620 this.mockGlobals.expects(once()).recordEvent(
621 GoogleNowEvent.EXTENSION_START);
623 this.mockGlobals.expects(once()).recordEvent(
624 GoogleNowEvent.USER_SUPPRESSED);
626 expectInitialization(this.mockApis);
628 expectStateMachineCalls(
632 testUserRespondedToToast,
633 testExperimentVariationParams);
635 var chromeNotificationGetAllSavedArgs = new SaveMockArguments();
636 this.mockApis.expects(exactly(2)).
637 instrumented_notifications_getAll(
638 chromeNotificationGetAllSavedArgs.match(ANYTHING)).
640 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}),
641 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}));
643 // Invoking the tested function.
648 * Mocks global functions and APIs that onNotificationClicked() depends upon.
649 * @param {Test} fixture Test fixture.
651 function mockOnNotificationClickedDependencies(fixture) {
652 fixture.makeAndRegisterMockApis([
653 'chrome.windows.create',
654 'chrome.windows.update',
655 'instrumented.storage.local.get',
656 'instrumented.tabs.create']);
660 'GoogleNowBackgroundUnitTest',
661 'OnNotificationClicked_NoData',
663 // Tests the case when there is no data associated with notification id.
664 // In this case, the function should do nothing.
666 // Setup and expectations.
667 var testNotificationId = 'TEST_ID';
668 var testNotificationData = {};
670 mockOnNotificationClickedDependencies(this);
671 this.makeMockLocalFunctions(['selector']);
673 var storageGetSavedArgs = new SaveMockArguments();
674 this.mockApis.expects(once()).
675 instrumented_storage_local_get(
676 storageGetSavedArgs.match(eq('notificationsData')),
677 storageGetSavedArgs.match(ANYTHING)).
678 will(invokeCallback(storageGetSavedArgs, 1, testNotificationData));
680 // Invoking the tested function.
681 onNotificationClicked(
682 testNotificationId, this.mockLocalFunctions.functions().selector);
686 'GoogleNowBackgroundUnitTest',
687 'OnNotificationClicked_ActionUrlsUndefined',
689 // Tests the case when the data associated with notification id is
691 // In this case, the function should do nothing.
693 // Setup and expectations.
694 var testActionUrls = undefined;
695 var testNotificationId = 'TEST_ID';
696 var testNotificationData = {
697 notificationsData: {'TEST_ID': {actionUrls: testActionUrls}}
700 mockOnNotificationClickedDependencies(this);
701 this.makeMockLocalFunctions(['selector']);
703 var storageGetSavedArgs = new SaveMockArguments();
704 this.mockApis.expects(once()).
705 instrumented_storage_local_get(
706 storageGetSavedArgs.match(eq('notificationsData')),
707 storageGetSavedArgs.match(ANYTHING)).
708 will(invokeCallback(storageGetSavedArgs, 1, testNotificationData));
709 this.mockLocalFunctions.expects(once()).selector(undefined).will(
710 returnValue(undefined));
712 // Invoking the tested function.
713 onNotificationClicked(
714 testNotificationId, this.mockLocalFunctions.functions().selector);
718 'GoogleNowBackgroundUnitTest',
719 'OnNotificationClicked_TabCreateSuccess',
721 // Tests the selected URL is OK and crome.tabs.create suceeds.
723 // Setup and expectations.
724 var testActionUrls = {testField: 'TEST VALUE'};
725 var testNotificationId = 'TEST_ID';
726 var testNotificationData = {
727 notificationsData: {'TEST_ID': {actionUrls: testActionUrls}}
729 var testActionUrl = 'http://testurl.com';
730 var testCreatedTab = {windowId: 239};
732 mockOnNotificationClickedDependencies(this);
733 this.makeMockLocalFunctions(['selector']);
735 var storageGetSavedArgs = new SaveMockArguments();
736 this.mockApis.expects(once()).
737 instrumented_storage_local_get(
738 storageGetSavedArgs.match(eq('notificationsData')),
739 storageGetSavedArgs.match(ANYTHING)).
740 will(invokeCallback(storageGetSavedArgs, 1, testNotificationData));
741 this.mockLocalFunctions.expects(once()).selector(testActionUrls).will(
742 returnValue(testActionUrl));
743 var chromeTabsCreateSavedArgs = new SaveMockArguments();
744 this.mockApis.expects(once()).
745 instrumented_tabs_create(
746 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})),
747 chromeTabsCreateSavedArgs.match(ANYTHING)).
748 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab));
749 this.mockApis.expects(once()).chrome_windows_update(
750 testCreatedTab.windowId,
751 eqJSON({focused: true}));
753 // Invoking the tested function.
754 onNotificationClicked(
755 testNotificationId, this.mockLocalFunctions.functions().selector);
759 'GoogleNowBackgroundUnitTest',
760 'OnNotificationClicked_TabCreateFail',
762 // Tests the selected URL is OK and crome.tabs.create fails.
763 // In this case, the function should invoke chrome.windows.create as a
766 // Setup and expectations.
767 var testActionUrls = {testField: 'TEST VALUE'};
768 var testNotificationId = 'TEST_ID';
769 var testNotificationData = {
770 notificationsData: {'TEST_ID': {actionUrls: testActionUrls}}
772 var testActionUrl = 'http://testurl.com';
773 var testCreatedTab = undefined; // chrome.tabs.create fails
775 mockOnNotificationClickedDependencies(this);
776 this.makeMockLocalFunctions(['selector']);
778 var storageGetSavedArgs = new SaveMockArguments();
779 this.mockApis.expects(once()).
780 instrumented_storage_local_get(
781 storageGetSavedArgs.match(eq('notificationsData')),
782 storageGetSavedArgs.match(ANYTHING)).
783 will(invokeCallback(storageGetSavedArgs, 1, testNotificationData));
784 this.mockLocalFunctions.expects(once()).selector(testActionUrls).will(
785 returnValue(testActionUrl));
786 var chromeTabsCreateSavedArgs = new SaveMockArguments();
787 this.mockApis.expects(once()).
788 instrumented_tabs_create(
789 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})),
790 chromeTabsCreateSavedArgs.match(ANYTHING)).
791 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab));
792 this.mockApis.expects(once()).chrome_windows_create(
793 eqJSON({url: testActionUrl, focused: true}));
795 // Invoking the tested function.
796 onNotificationClicked(
797 testNotificationId, this.mockLocalFunctions.functions().selector);