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 // TODO(robliao,vadimt): Determine the granularity of testing to perform. | 5 // TODO(robliao,vadimt): Determine the granularity of testing to perform. |
6 | 6 |
7 /** | 7 /** |
8 * Test fixture for background.js. | 8 * Test fixture for background.js. |
9 * @constructor | 9 * @constructor |
10 * @extends {testing.Test} | 10 * @extends {testing.Test} |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 assertFalse(thenCalled); | 329 assertFalse(thenCalled); |
330 assertTrue(catchCalled); | 330 assertTrue(catchCalled); |
331 }); | 331 }); |
332 | 332 |
333 /** | 333 /** |
334 * requestAndUpdateOptIn Tests | 334 * requestAndUpdateOptIn Tests |
335 */ | 335 */ |
336 TEST_F(TEST_NAME, 'RequestAndUpdateOptInOptedIn', function() { | 336 TEST_F(TEST_NAME, 'RequestAndUpdateOptInOptedIn', function() { |
337 this.makeAndRegisterMockApis([ | 337 this.makeAndRegisterMockApis([ |
338 'chrome.storage.local.set', | 338 'chrome.storage.local.set', |
339 'onStateChange', | 339 'requestFromServer' |
340 'requestFromServer', | |
341 'scheduleNextPoll' | |
342 ]); | 340 ]); |
343 | 341 |
344 this.mockApis.expects(once()).requestFromServer('GET', 'settings/optin') | 342 this.mockApis.expects(once()).requestFromServer('GET', 'settings/optin') |
345 .will(returnValue(Promise.resolve({ | 343 .will(returnValue(Promise.resolve({ |
346 status: 200, | 344 status: 200, |
347 responseText: '{"value": true}'}))); | 345 responseText: '{"value": true}'}))); |
348 | 346 |
349 this.mockApis.expects(once()) | 347 this.mockApis.expects(once()) |
350 .chrome_storage_local_set(eqJSON({googleNowEnabled: true})); | 348 .chrome_storage_local_set(eqJSON({googleNowEnabled: true})); |
351 | 349 |
352 this.mockApis.expects(once()).onStateChange(); | |
353 | |
354 this.mockApis.expects(never()).scheduleNextPoll(); | |
355 | |
356 var thenCalled = false; | 350 var thenCalled = false; |
357 var catchCalled = false; | 351 var catchCalled = false; |
358 requestAndUpdateOptedIn().then(function() { | 352 requestAndUpdateOptedIn().then(function(optedIn) { |
359 thenCalled = true; | 353 thenCalled = true; |
| 354 assertTrue(optedIn); |
360 }).catch(function() { | 355 }).catch(function() { |
361 catchCalled = true; | 356 catchCalled = true; |
362 }); | 357 }); |
363 assertTrue(thenCalled); | 358 assertTrue(thenCalled); |
364 assertFalse(catchCalled); | 359 assertFalse(catchCalled); |
365 }); | 360 }); |
366 | 361 |
367 TEST_F(TEST_NAME, 'RequestAndUpdateOptInOptedOut', function() { | 362 TEST_F(TEST_NAME, 'RequestAndUpdateOptInOptedOut', function() { |
368 this.makeAndRegisterMockApis([ | 363 this.makeAndRegisterMockApis([ |
369 'chrome.storage.local.set', | 364 'chrome.storage.local.set', |
370 'onStateChange', | 365 'requestFromServer' |
371 'requestFromServer', | |
372 'scheduleNextPoll' | |
373 ]); | 366 ]); |
374 | 367 |
375 this.mockApis.expects(once()).requestFromServer('GET', 'settings/optin') | 368 this.mockApis.expects(once()).requestFromServer('GET', 'settings/optin') |
376 .will(returnValue(Promise.resolve({ | 369 .will(returnValue(Promise.resolve({ |
377 status: 200, | 370 status: 200, |
378 responseText: '{"value": false}'}))); | 371 responseText: '{"value": false}'}))); |
379 | 372 |
380 this.mockApis.expects(never()).chrome_storage_local_set(); | 373 this.mockApis.expects(once()) |
381 | 374 .chrome_storage_local_set(eqJSON({googleNowEnabled: false})); |
382 this.mockApis.expects(never()).onStateChange(); | |
383 | |
384 this.mockApis.expects(once()).scheduleNextPoll(eqJSON({}), false); | |
385 | 375 |
386 var thenCalled = false; | 376 var thenCalled = false; |
387 var catchCalled = false; | 377 var catchCalled = false; |
388 requestAndUpdateOptedIn().then(function() { | 378 requestAndUpdateOptedIn().then(function(optedIn) { |
389 thenCalled = true; | 379 thenCalled = true; |
| 380 assertFalse(optedIn); |
390 }).catch(function() { | 381 }).catch(function() { |
391 catchCalled = true; | 382 catchCalled = true; |
392 }); | 383 }); |
393 assertFalse(thenCalled); | 384 assertTrue(thenCalled); |
394 assertTrue(catchCalled); | 385 assertFalse(catchCalled); |
395 }); | 386 }); |
396 | 387 |
397 TEST_F(TEST_NAME, 'RequestAndUpdateOptInFailure', function() { | 388 TEST_F(TEST_NAME, 'RequestAndUpdateOptInFailure', function() { |
398 this.makeAndRegisterMockApis([ | 389 this.makeAndRegisterMockApis([ |
399 'chrome.storage.local.set', | 390 'chrome.storage.local.set', |
400 'onStateChange', | 391 'requestFromServer' |
401 'requestFromServer', | |
402 'scheduleNextPoll' | |
403 ]); | 392 ]); |
404 | 393 |
405 this.mockApis.expects(once()).requestFromServer('GET', 'settings/optin') | 394 this.mockApis.expects(once()).requestFromServer('GET', 'settings/optin') |
406 .will(returnValue(Promise.reject({status: 404}))); | 395 .will(returnValue(Promise.reject({status: 404}))); |
407 | 396 |
408 this.mockApis.expects(never()).chrome_storage_local_set(); | 397 this.mockApis.expects(never()).chrome_storage_local_set(); |
409 | 398 |
410 this.mockApis.expects(never()).onStateChange(); | |
411 | |
412 this.mockApis.expects(never()).scheduleNextPoll(); | |
413 | |
414 var thenCalled = false; | 399 var thenCalled = false; |
415 var catchCalled = false; | 400 var catchCalled = false; |
416 requestAndUpdateOptedIn().then(function() { | 401 requestAndUpdateOptedIn().then(function() { |
417 thenCalled = true; | 402 thenCalled = true; |
418 }).catch(function() { | 403 }).catch(function() { |
419 catchCalled = true; | 404 catchCalled = true; |
420 }); | 405 }); |
421 assertFalse(thenCalled); | 406 assertFalse(thenCalled); |
422 assertTrue(catchCalled); | 407 assertTrue(catchCalled); |
423 }); | 408 }); |
424 | 409 |
425 /** | 410 /** |
| 411 * pollOptedInNoImmediateRecheck Tests |
| 412 */ |
| 413 TEST_F(TEST_NAME, 'pollOptedInNoImmediateRecheckOptedIn', function() { |
| 414 this.makeAndRegisterMockApis([ |
| 415 'requestAndUpdateOptedIn', |
| 416 'instrumented.metricsPrivate.getVariationParams', |
| 417 'optInPollAttempts.start' |
| 418 ]); |
| 419 |
| 420 this.mockApis.expects(once()).requestAndUpdateOptedIn() |
| 421 .will(returnValue(Promise.resolve(true))); |
| 422 |
| 423 this.mockApis.expects(never()) |
| 424 .instrumented_metricsPrivate_getVariationParams(); |
| 425 |
| 426 this.mockApis.expects(never()).optInPollAttempts_start(); |
| 427 |
| 428 pollOptedInNoImmediateRecheck(); |
| 429 }); |
| 430 |
| 431 TEST_F(TEST_NAME, 'pollOptedInNoImmediateRecheckOptedOut', function() { |
| 432 this.makeAndRegisterMockApis([ |
| 433 'requestAndUpdateOptedIn', |
| 434 'instrumented.metricsPrivate.getVariationParams', |
| 435 'optInPollAttempts.start' |
| 436 ]); |
| 437 |
| 438 this.mockApis.expects(once()).requestAndUpdateOptedIn() |
| 439 .will(returnValue(Promise.resolve(false))); |
| 440 |
| 441 var getVariationParamsSavedArgs = new SaveMockArguments(); |
| 442 this.mockApis.expects(once()) |
| 443 .instrumented_metricsPrivate_getVariationParams( |
| 444 getVariationParamsSavedArgs.match(eq('GoogleNow')), |
| 445 getVariationParamsSavedArgs.match(ANYTHING)) |
| 446 .will(invokeCallback(getVariationParamsSavedArgs, 1, {})); |
| 447 |
| 448 this.mockApis.expects(once()) |
| 449 .optInPollAttempts_start(DEFAULT_OPTIN_CHECK_PERIOD_SECONDS); |
| 450 |
| 451 pollOptedInNoImmediateRecheck(); |
| 452 }); |
| 453 |
| 454 TEST_F(TEST_NAME, 'pollOptedInNoImmediateRecheckFailure', function() { |
| 455 this.makeAndRegisterMockApis([ |
| 456 'requestAndUpdateOptedIn', |
| 457 'instrumented.metricsPrivate.getVariationParams', |
| 458 'optInPollAttempts.start' |
| 459 ]); |
| 460 |
| 461 this.mockApis.expects(once()).requestAndUpdateOptedIn() |
| 462 .will(returnValue(Promise.reject())); |
| 463 |
| 464 var getVariationParamsSavedArgs = new SaveMockArguments(); |
| 465 this.mockApis.expects(once()) |
| 466 .instrumented_metricsPrivate_getVariationParams( |
| 467 getVariationParamsSavedArgs.match(eq('GoogleNow')), |
| 468 getVariationParamsSavedArgs.match(ANYTHING)) |
| 469 .will(invokeCallback(getVariationParamsSavedArgs, 1, {})); |
| 470 |
| 471 this.mockApis.expects(once()) |
| 472 .optInPollAttempts_start(DEFAULT_OPTIN_CHECK_PERIOD_SECONDS); |
| 473 |
| 474 pollOptedInNoImmediateRecheck(); |
| 475 }); |
| 476 |
| 477 /** |
426 * getGroupsToRequest Tests | 478 * getGroupsToRequest Tests |
427 */ | 479 */ |
428 TEST_F(TEST_NAME, 'GetGroupsToRequestNone', function() { | 480 TEST_F(TEST_NAME, 'GetGroupsToRequestNone', function() { |
429 this.makeAndRegisterMockApis([ | 481 this.makeAndRegisterMockApis([ |
430 'fillFromChromeLocalStorage', | 482 'fillFromChromeLocalStorage', |
431 'Date.now' | 483 'Date.now' |
432 ]); | 484 ]); |
433 | 485 |
434 this.mockApis.expects(once()) | 486 this.mockApis.expects(once()) |
435 .fillFromChromeLocalStorage(eqJSON({notificationGroups: {}})) | 487 .fillFromChromeLocalStorage(eqJSON({notificationGroups: {}})) |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 JSON.stringify(expectedCombinedCards), | 576 JSON.stringify(expectedCombinedCards), |
525 JSON.stringify(combinedCards)); | 577 JSON.stringify(combinedCards)); |
526 }); | 578 }); |
527 | 579 |
528 /** | 580 /** |
529 * Mocks global functions and APIs that initialize() depends upon. | 581 * Mocks global functions and APIs that initialize() depends upon. |
530 * @param {Test} fixture Test fixture. | 582 * @param {Test} fixture Test fixture. |
531 */ | 583 */ |
532 function mockInitializeDependencies(fixture) { | 584 function mockInitializeDependencies(fixture) { |
533 fixture.makeAndRegisterMockGlobals([ | 585 fixture.makeAndRegisterMockGlobals([ |
| 586 'pollOptedInNoImmediateRecheck', |
534 'recordEvent', | 587 'recordEvent', |
535 'removeAllCards', | 588 'removeAllCards', |
536 'setBackgroundEnable', | 589 'setBackgroundEnable', |
537 'startPollingCards', | 590 'startPollingCards', |
538 'stopPollingCards' | 591 'stopPollingCards' |
539 ]); | 592 ]); |
540 fixture.makeAndRegisterMockApis([ | 593 fixture.makeAndRegisterMockApis([ |
541 'authenticationManager.isSignedIn', | 594 'authenticationManager.isSignedIn', |
542 'chrome.storage.local.remove', | 595 'chrome.storage.local.remove', |
543 'fillFromChromeLocalStorage', | 596 'fillFromChromeLocalStorage', |
544 'instrumented.metricsPrivate.getVariationParams', | 597 'instrumented.metricsPrivate.getVariationParams', |
545 'instrumented.notifications.getAll', | 598 'instrumented.notifications.getAll', |
546 'instrumented.notifications.getPermissionLevel', | 599 'instrumented.notifications.getPermissionLevel', |
547 'instrumented.webstorePrivate.getBrowserLogin', | 600 'instrumented.webstorePrivate.getBrowserLogin', |
| 601 'optInPollAttempts.isRunning', |
| 602 'optInPollAttempts.stop', |
548 'tasks.add', | 603 'tasks.add', |
549 'updateCardsAttempts.isRunning', | 604 'updateCardsAttempts.isRunning', |
550 'updateCardsAttempts.stop' | 605 'updateCardsAttempts.stop' |
551 ]); | 606 ]); |
552 } | 607 } |
553 | 608 |
554 /** | 609 /** |
555 * Sets up the test to expect the state machine calls and send | 610 * Sets up the test to expect the state machine calls and send |
556 * the specified state machine state. Currently used to test initialize(). | 611 * the specified state machine state. Currently used to test initialize(). |
557 * Note that this CAN NOT be used if any of the methods below are called | 612 * Note that this CAN NOT be used if any of the methods below are called |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 {googleNowEnabled: false}, | 655 {googleNowEnabled: false}, |
601 {googleNowEnabled: testGoogleNowEnabled}); | 656 {googleNowEnabled: testGoogleNowEnabled}); |
602 | 657 |
603 var updateCardsAttemptsIsRunningSavedArgs = new SaveMockArguments(); | 658 var updateCardsAttemptsIsRunningSavedArgs = new SaveMockArguments(); |
604 fixture.mockApis.expects(once()). | 659 fixture.mockApis.expects(once()). |
605 updateCardsAttempts_isRunning( | 660 updateCardsAttempts_isRunning( |
606 updateCardsAttemptsIsRunningSavedArgs.match(ANYTHING)). | 661 updateCardsAttemptsIsRunningSavedArgs.match(ANYTHING)). |
607 will( | 662 will( |
608 invokeCallback( | 663 invokeCallback( |
609 updateCardsAttemptsIsRunningSavedArgs, 0, undefined)); | 664 updateCardsAttemptsIsRunningSavedArgs, 0, undefined)); |
| 665 |
| 666 var optInPollAttemptsIsRunningSavedArgs = new SaveMockArguments(); |
| 667 fixture.mockApis.expects(once()). |
| 668 optInPollAttempts_isRunning( |
| 669 optInPollAttemptsIsRunningSavedArgs.match(ANYTHING)). |
| 670 will( |
| 671 invokeCallback( |
| 672 optInPollAttemptsIsRunningSavedArgs, 0, undefined)); |
610 } | 673 } |
611 | 674 |
612 /** | 675 /** |
613 * Sets up the test to expect the initialization calls that | 676 * Sets up the test to expect the initialization calls that |
614 * initialize() invokes. | 677 * initialize() invokes. |
615 * Note that this CAN NOT be used if any of the methods below are called | 678 * Note that this CAN NOT be used if any of the methods below are called |
616 * outside of this context with the same argument matchers. | 679 * outside of this context with the same argument matchers. |
617 * expects() calls cannot be chained with the same argument matchers. | 680 * expects() calls cannot be chained with the same argument matchers. |
618 */ | 681 */ |
619 function expectInitialization(fixture) { | 682 function expectInitialization(fixture) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 this, | 715 this, |
653 testIdentityToken, | 716 testIdentityToken, |
654 testExperimentVariationParams, | 717 testExperimentVariationParams, |
655 testNotificationPermissionLevel, | 718 testNotificationPermissionLevel, |
656 testGoogleNowEnabled); | 719 testGoogleNowEnabled); |
657 | 720 |
658 this.mockGlobals.expects(once()).setBackgroundEnable(false); | 721 this.mockGlobals.expects(once()).setBackgroundEnable(false); |
659 this.mockGlobals.expects(never()).startPollingCards(); | 722 this.mockGlobals.expects(never()).startPollingCards(); |
660 this.mockGlobals.expects(once()).stopPollingCards(); | 723 this.mockGlobals.expects(once()).stopPollingCards(); |
661 this.mockGlobals.expects(once()).removeAllCards(); | 724 this.mockGlobals.expects(once()).removeAllCards(); |
| 725 this.mockGlobals.expects(never()).pollOptedInNoImmediateRecheck(); |
| 726 this.mockApis.expects(once()).optInPollAttempts_stop(); |
662 | 727 |
663 // Invoking the tested function. | 728 // Invoking the tested function. |
664 initialize(); | 729 initialize(); |
665 }); | 730 }); |
666 | 731 |
667 TEST_F(TEST_NAME,'Initialize_NotificationDisabled', function() { | 732 TEST_F(TEST_NAME,'Initialize_NotificationDisabled', function() { |
668 // Tests the case when Google Now is disabled in the notifications center. | 733 // Tests the case when Google Now is disabled in the notifications center. |
669 | 734 |
670 // Setup and expectations. | 735 // Setup and expectations. |
671 var testIdentityToken = 'some identity token'; | 736 var testIdentityToken = 'some identity token'; |
672 var testExperimentVariationParams = {}; | 737 var testExperimentVariationParams = {}; |
673 var testNotificationPermissionLevel = 'denied'; | 738 var testNotificationPermissionLevel = 'denied'; |
674 var testGoogleNowEnabled = undefined; | 739 var testGoogleNowEnabled = undefined; |
675 | 740 |
676 mockInitializeDependencies(this); | 741 mockInitializeDependencies(this); |
677 | 742 |
678 expectInitialization(this); | 743 expectInitialization(this); |
679 | 744 |
680 expectStateMachineCalls( | 745 expectStateMachineCalls( |
681 this, | 746 this, |
682 testIdentityToken, | 747 testIdentityToken, |
683 testExperimentVariationParams, | 748 testExperimentVariationParams, |
684 testNotificationPermissionLevel, | 749 testNotificationPermissionLevel, |
685 testGoogleNowEnabled); | 750 testGoogleNowEnabled); |
686 | 751 |
687 this.mockGlobals.expects(once()).setBackgroundEnable(false); | 752 this.mockGlobals.expects(once()).setBackgroundEnable(false); |
688 this.mockGlobals.expects(never()).startPollingCards(); | 753 this.mockGlobals.expects(never()).startPollingCards(); |
689 this.mockGlobals.expects(once()).stopPollingCards(); | 754 this.mockGlobals.expects(once()).stopPollingCards(); |
690 this.mockGlobals.expects(once()).removeAllCards(); | 755 this.mockGlobals.expects(once()).removeAllCards(); |
| 756 this.mockGlobals.expects(never()).pollOptedInNoImmediateRecheck(); |
| 757 this.mockApis.expects(once()).optInPollAttempts_stop(); |
691 | 758 |
692 // Invoking the tested function. | 759 // Invoking the tested function. |
693 initialize(); | 760 initialize(); |
694 }); | 761 }); |
695 | 762 |
696 TEST_F(TEST_NAME, 'Initialize_NoBackground', function() { | 763 TEST_F(TEST_NAME, 'Initialize_NoBackground', function() { |
697 // Tests when the no background variation is received. | 764 // Tests when the no background variation is received. |
698 | 765 |
699 // Setup and expectations. | 766 // Setup and expectations. |
700 var testIdentityToken = 'some identity token'; | 767 var testIdentityToken = 'some identity token'; |
701 var testExperimentVariationParams = {canEnableBackground: 'false'}; | 768 var testExperimentVariationParams = {canEnableBackground: 'false'}; |
702 var testNotificationPermissionLevel = 'granted'; | 769 var testNotificationPermissionLevel = 'granted'; |
703 var testGoogleNowEnabled = true; | 770 var testGoogleNowEnabled = true; |
704 | 771 |
705 mockInitializeDependencies(this); | 772 mockInitializeDependencies(this); |
706 | 773 |
707 expectInitialization(this); | 774 expectInitialization(this); |
708 | 775 |
709 expectStateMachineCalls( | 776 expectStateMachineCalls( |
710 this, | 777 this, |
711 testIdentityToken, | 778 testIdentityToken, |
712 testExperimentVariationParams, | 779 testExperimentVariationParams, |
713 testNotificationPermissionLevel, | 780 testNotificationPermissionLevel, |
714 testGoogleNowEnabled); | 781 testGoogleNowEnabled); |
715 | 782 |
716 this.mockGlobals.expects(once()).setBackgroundEnable(false); | 783 this.mockGlobals.expects(once()).setBackgroundEnable(false); |
717 this.mockGlobals.expects(once()).startPollingCards(); | 784 this.mockGlobals.expects(once()).startPollingCards(); |
718 this.mockGlobals.expects(never()).stopPollingCards(); | 785 this.mockGlobals.expects(never()).stopPollingCards(); |
719 this.mockGlobals.expects(never()).removeAllCards(); | 786 this.mockGlobals.expects(never()).removeAllCards(); |
| 787 this.mockGlobals.expects(never()).pollOptedInNoImmediateRecheck(); |
| 788 this.mockApis.expects(once()).optInPollAttempts_stop(); |
720 | 789 |
721 // Invoking the tested function. | 790 // Invoking the tested function. |
722 initialize(); | 791 initialize(); |
723 }); | 792 }); |
724 | 793 |
725 TEST_F(TEST_NAME, 'Initialize_GoogleNowDisabled', function() { | 794 TEST_F(TEST_NAME, 'Initialize_GoogleNowDisabled', function() { |
726 // Tests when the user has Google Now disabled. | 795 // Tests when the user has Google Now disabled. |
727 | 796 |
728 // Setup and expectations. | 797 // Setup and expectations. |
729 var testIdentityToken = 'some identity token'; | 798 var testIdentityToken = 'some identity token'; |
730 var testExperimentVariationParams = {}; | 799 var testExperimentVariationParams = {}; |
731 var testNotificationPermissionLevel = 'granted'; | 800 var testNotificationPermissionLevel = 'granted'; |
732 var testGoogleNowEnabled = false; | 801 var testGoogleNowEnabled = false; |
733 | 802 |
734 mockInitializeDependencies(this); | 803 mockInitializeDependencies(this); |
735 | 804 |
736 expectInitialization(this); | 805 expectInitialization(this); |
737 | 806 |
738 expectStateMachineCalls( | 807 expectStateMachineCalls( |
739 this, | 808 this, |
740 testIdentityToken, | 809 testIdentityToken, |
741 testExperimentVariationParams, | 810 testExperimentVariationParams, |
742 testNotificationPermissionLevel, | 811 testNotificationPermissionLevel, |
743 testGoogleNowEnabled); | 812 testGoogleNowEnabled); |
744 | 813 |
745 this.mockGlobals.expects(once()).setBackgroundEnable(false); | 814 this.mockGlobals.expects(once()).setBackgroundEnable(false); |
746 this.mockGlobals.expects(once()).startPollingCards(); | 815 this.mockGlobals.expects(never()).startPollingCards(); |
747 this.mockGlobals.expects(never()).stopPollingCards(); | 816 this.mockGlobals.expects(once()).stopPollingCards(); |
748 this.mockGlobals.expects(once()).removeAllCards(); | 817 this.mockGlobals.expects(once()).removeAllCards(); |
| 818 this.mockGlobals.expects(once()).pollOptedInNoImmediateRecheck(); |
| 819 this.mockApis.expects(never()).optInPollAttempts_stop(); |
749 | 820 |
750 // Invoking the tested function. | 821 // Invoking the tested function. |
751 initialize(); | 822 initialize(); |
752 }); | 823 }); |
753 | 824 |
754 TEST_F(TEST_NAME, 'Initialize_RunGoogleNow', function() { | 825 TEST_F(TEST_NAME, 'Initialize_RunGoogleNow', function() { |
755 // Tests if Google Now will invoke startPollingCards when all | 826 // Tests if Google Now will invoke startPollingCards when all |
756 // of the required state is fulfilled. | 827 // of the required state is fulfilled. |
757 | 828 |
758 // Setup and expectations. | 829 // Setup and expectations. |
(...skipping 10 matching lines...) Expand all Loading... |
769 this, | 840 this, |
770 testIdentityToken, | 841 testIdentityToken, |
771 testExperimentVariationParams, | 842 testExperimentVariationParams, |
772 testNotificationPermissionLevel, | 843 testNotificationPermissionLevel, |
773 testGoogleNowEnabled); | 844 testGoogleNowEnabled); |
774 | 845 |
775 this.mockGlobals.expects(once()).setBackgroundEnable(true); | 846 this.mockGlobals.expects(once()).setBackgroundEnable(true); |
776 this.mockGlobals.expects(once()).startPollingCards(); | 847 this.mockGlobals.expects(once()).startPollingCards(); |
777 this.mockGlobals.expects(never()).stopPollingCards(); | 848 this.mockGlobals.expects(never()).stopPollingCards(); |
778 this.mockGlobals.expects(never()).removeAllCards(); | 849 this.mockGlobals.expects(never()).removeAllCards(); |
| 850 this.mockGlobals.expects(never()).pollOptedInNoImmediateRecheck(); |
| 851 this.mockApis.expects(once()).optInPollAttempts_stop(); |
779 | 852 |
780 // Invoking the tested function. | 853 // Invoking the tested function. |
781 initialize(); | 854 initialize(); |
782 }); | 855 }); |
783 | 856 |
784 /** | 857 /** |
785 * No Cards Event Recording Tests | 858 * No Cards Event Recording Tests |
786 */ | 859 */ |
787 TEST_F(TEST_NAME, 'NoCardsSignedOut', function() { | 860 TEST_F(TEST_NAME, 'NoCardsSignedOut', function() { |
788 var signedIn = false; | 861 var signedIn = false; |
789 var notificationEnabled = false; | 862 var notificationEnabled = false; |
790 var googleNowEnabled = false; | 863 var googleNowEnabled = false; |
791 this.makeAndRegisterMockGlobals([ | 864 this.makeAndRegisterMockGlobals([ |
792 'recordEvent', | 865 'recordEvent', |
793 'removeAllCards', | 866 'removeAllCards', |
794 'setBackgroundEnable', | 867 'setBackgroundEnable', |
795 'setShouldPollCards']); | 868 'setShouldPollCards', |
| 869 'setShouldPollOptInStatus']); |
796 | 870 |
797 this.mockGlobals.stubs().removeAllCards(); | 871 this.mockGlobals.stubs().removeAllCards(); |
798 this.mockGlobals.stubs().setBackgroundEnable(ANYTHING); | 872 this.mockGlobals.stubs().setBackgroundEnable(ANYTHING); |
799 this.mockGlobals.stubs().setShouldPollCards(ANYTHING); | 873 this.mockGlobals.stubs().setShouldPollCards(ANYTHING); |
| 874 this.mockGlobals.stubs().setShouldPollOptInStatus(ANYTHING); |
800 | 875 |
801 this.mockGlobals.expects(once()).recordEvent( | 876 this.mockGlobals.expects(once()).recordEvent( |
802 GoogleNowEvent.STOPPED); | 877 GoogleNowEvent.STOPPED); |
803 this.mockGlobals.expects(once()).recordEvent( | 878 this.mockGlobals.expects(once()).recordEvent( |
804 GoogleNowEvent.SIGNED_OUT); | 879 GoogleNowEvent.SIGNED_OUT); |
805 this.mockGlobals.expects(never()).recordEvent( | 880 this.mockGlobals.expects(never()).recordEvent( |
806 GoogleNowEvent.NOTIFICATION_DISABLED); | 881 GoogleNowEvent.NOTIFICATION_DISABLED); |
807 this.mockGlobals.expects(never()).recordEvent( | 882 this.mockGlobals.expects(never()).recordEvent( |
808 GoogleNowEvent.GOOGLE_NOW_DISABLED); | 883 GoogleNowEvent.GOOGLE_NOW_DISABLED); |
809 updateRunningState(signedIn, true, notificationEnabled, googleNowEnabled); | 884 updateRunningState(signedIn, true, notificationEnabled, googleNowEnabled); |
810 }); | 885 }); |
811 | 886 |
812 TEST_F(TEST_NAME, 'NoCardsNotificationsDisabled', function() { | 887 TEST_F(TEST_NAME, 'NoCardsNotificationsDisabled', function() { |
813 var signedIn = true; | 888 var signedIn = true; |
814 var notificationEnabled = false; | 889 var notificationEnabled = false; |
815 var googleNowEnabled = false; | 890 var googleNowEnabled = false; |
816 this.makeAndRegisterMockGlobals([ | 891 this.makeAndRegisterMockGlobals([ |
817 'recordEvent', | 892 'recordEvent', |
818 'removeAllCards', | 893 'removeAllCards', |
819 'setBackgroundEnable', | 894 'setBackgroundEnable', |
820 'setShouldPollCards']); | 895 'setShouldPollCards', |
| 896 'setShouldPollOptInStatus']); |
821 | 897 |
822 this.mockGlobals.stubs().removeAllCards(); | 898 this.mockGlobals.stubs().removeAllCards(); |
823 this.mockGlobals.stubs().setBackgroundEnable(ANYTHING); | 899 this.mockGlobals.stubs().setBackgroundEnable(ANYTHING); |
824 this.mockGlobals.stubs().setShouldPollCards(ANYTHING); | 900 this.mockGlobals.stubs().setShouldPollCards(ANYTHING); |
| 901 this.mockGlobals.stubs().setShouldPollOptInStatus(ANYTHING); |
825 | 902 |
826 this.mockGlobals.expects(once()).recordEvent( | 903 this.mockGlobals.expects(once()).recordEvent( |
827 GoogleNowEvent.STOPPED); | 904 GoogleNowEvent.STOPPED); |
828 this.mockGlobals.expects(never()).recordEvent( | 905 this.mockGlobals.expects(never()).recordEvent( |
829 GoogleNowEvent.SIGNED_OUT); | 906 GoogleNowEvent.SIGNED_OUT); |
830 this.mockGlobals.expects(once()).recordEvent( | 907 this.mockGlobals.expects(once()).recordEvent( |
831 GoogleNowEvent.NOTIFICATION_DISABLED); | 908 GoogleNowEvent.NOTIFICATION_DISABLED); |
832 this.mockGlobals.expects(never()).recordEvent( | 909 this.mockGlobals.expects(never()).recordEvent( |
833 GoogleNowEvent.GOOGLE_NOW_DISABLED); | 910 GoogleNowEvent.GOOGLE_NOW_DISABLED); |
834 updateRunningState(signedIn, true, notificationEnabled, googleNowEnabled); | 911 updateRunningState(signedIn, true, notificationEnabled, googleNowEnabled); |
835 }); | 912 }); |
836 | 913 |
837 TEST_F(TEST_NAME, 'NoCardsGoogleNowDisabled', function() { | 914 TEST_F(TEST_NAME, 'NoCardsGoogleNowDisabled', function() { |
838 var signedIn = true; | 915 var signedIn = true; |
839 var notificationEnabled = true; | 916 var notificationEnabled = true; |
840 var googleNowEnabled = false; | 917 var googleNowEnabled = false; |
841 this.makeAndRegisterMockGlobals([ | 918 this.makeAndRegisterMockGlobals([ |
842 'recordEvent', | 919 'recordEvent', |
843 'removeAllCards', | 920 'removeAllCards', |
844 'setBackgroundEnable', | 921 'setBackgroundEnable', |
845 'setShouldPollCards']); | 922 'setShouldPollCards', |
| 923 'setShouldPollOptInStatus']); |
846 | 924 |
847 this.mockGlobals.stubs().removeAllCards(); | 925 this.mockGlobals.stubs().removeAllCards(); |
848 this.mockGlobals.stubs().setBackgroundEnable(ANYTHING); | 926 this.mockGlobals.stubs().setBackgroundEnable(ANYTHING); |
849 this.mockGlobals.stubs().setShouldPollCards(ANYTHING); | 927 this.mockGlobals.stubs().setShouldPollCards(ANYTHING); |
| 928 this.mockGlobals.stubs().setShouldPollOptInStatus(ANYTHING); |
850 | 929 |
851 this.mockGlobals.expects(never()).recordEvent( | 930 this.mockGlobals.expects(never()).recordEvent( |
852 GoogleNowEvent.STOPPED); | 931 GoogleNowEvent.STOPPED); |
853 this.mockGlobals.expects(never()).recordEvent( | 932 this.mockGlobals.expects(never()).recordEvent( |
854 GoogleNowEvent.SIGNED_OUT); | 933 GoogleNowEvent.SIGNED_OUT); |
855 this.mockGlobals.expects(never()).recordEvent( | 934 this.mockGlobals.expects(never()).recordEvent( |
856 GoogleNowEvent.NOTIFICATION_DISABLED); | 935 GoogleNowEvent.NOTIFICATION_DISABLED); |
857 this.mockGlobals.expects(once()).recordEvent( | 936 this.mockGlobals.expects(once()).recordEvent( |
858 GoogleNowEvent.GOOGLE_NOW_DISABLED); | 937 GoogleNowEvent.GOOGLE_NOW_DISABLED); |
859 updateRunningState(signedIn, true, notificationEnabled, googleNowEnabled); | 938 updateRunningState(signedIn, true, notificationEnabled, googleNowEnabled); |
860 }); | 939 }); |
861 | 940 |
862 TEST_F(TEST_NAME, 'NoCardsEverythingEnabled', function() { | 941 TEST_F(TEST_NAME, 'NoCardsEverythingEnabled', function() { |
863 var signedIn = true; | 942 var signedIn = true; |
864 var notificationEnabled = true; | 943 var notificationEnabled = true; |
865 var googleNowEnabled = true; | 944 var googleNowEnabled = true; |
866 this.makeAndRegisterMockGlobals([ | 945 this.makeAndRegisterMockGlobals([ |
867 'recordEvent', | 946 'recordEvent', |
868 'removeAllCards', | 947 'removeAllCards', |
869 'setBackgroundEnable', | 948 'setBackgroundEnable', |
870 'setShouldPollCards']); | 949 'setShouldPollCards', |
| 950 'setShouldPollOptInStatus']); |
871 | 951 |
872 this.mockGlobals.stubs().removeAllCards(); | 952 this.mockGlobals.stubs().removeAllCards(); |
873 this.mockGlobals.stubs().setBackgroundEnable(ANYTHING); | 953 this.mockGlobals.stubs().setBackgroundEnable(ANYTHING); |
874 this.mockGlobals.stubs().setShouldPollCards(ANYTHING); | 954 this.mockGlobals.stubs().setShouldPollCards(ANYTHING); |
| 955 this.mockGlobals.stubs().setShouldPollOptInStatus(ANYTHING); |
875 | 956 |
876 this.mockGlobals.expects(never()).recordEvent( | 957 this.mockGlobals.expects(never()).recordEvent( |
877 GoogleNowEvent.STOPPED); | 958 GoogleNowEvent.STOPPED); |
878 this.mockGlobals.expects(never()).recordEvent( | 959 this.mockGlobals.expects(never()).recordEvent( |
879 GoogleNowEvent.SIGNED_OUT); | 960 GoogleNowEvent.SIGNED_OUT); |
880 this.mockGlobals.expects(never()).recordEvent( | 961 this.mockGlobals.expects(never()).recordEvent( |
881 GoogleNowEvent.NOTIFICATION_DISABLED); | 962 GoogleNowEvent.NOTIFICATION_DISABLED); |
882 this.mockGlobals.expects(never()).recordEvent( | 963 this.mockGlobals.expects(never()).recordEvent( |
883 GoogleNowEvent.GOOGLE_NOW_DISABLED); | 964 GoogleNowEvent.GOOGLE_NOW_DISABLED); |
884 updateRunningState(signedIn, true, notificationEnabled, googleNowEnabled); | 965 updateRunningState(signedIn, true, notificationEnabled, googleNowEnabled); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 cards: [], | 1269 cards: [], |
1189 cardsTimestamp: 3000000 | 1270 cardsTimestamp: 3000000 |
1190 } | 1271 } |
1191 }; | 1272 }; |
1192 | 1273 |
1193 var expectedUpdatedRecentDismissals = { | 1274 var expectedUpdatedRecentDismissals = { |
1194 c5: 1800001 | 1275 c5: 1800001 |
1195 }; | 1276 }; |
1196 | 1277 |
1197 this.makeAndRegisterMockGlobals([ | 1278 this.makeAndRegisterMockGlobals([ |
1198 'scheduleNextPoll' | 1279 'scheduleNextCardsPoll' |
1199 ]); | 1280 ]); |
1200 | 1281 |
1201 this.makeAndRegisterMockApis([ | 1282 this.makeAndRegisterMockApis([ |
1202 'fillFromChromeLocalStorage', | 1283 'fillFromChromeLocalStorage', |
1203 ]); | 1284 ]); |
1204 | 1285 |
1205 expectChromeLocalStorageGet( | 1286 expectChromeLocalStorageGet( |
1206 this, | 1287 this, |
1207 { | 1288 { |
1208 notificationGroups: {}, | 1289 notificationGroups: {}, |
1209 recentDismissals: {} | 1290 recentDismissals: {} |
1210 }, | 1291 }, |
1211 { | 1292 { |
1212 notificationGroups: storedGroups, | 1293 notificationGroups: storedGroups, |
1213 recentDismissals: recentDismissals | 1294 recentDismissals: recentDismissals |
1214 }); | 1295 }); |
1215 | 1296 |
1216 this.mockGlobals.expects(once()). | 1297 this.mockGlobals.expects(once()) |
1217 scheduleNextPoll(eqJSON(expectedUpdatedGroups), true); | 1298 .scheduleNextCardsPoll(eqJSON(expectedUpdatedGroups)); |
1218 | 1299 |
1219 // Invoking the tested function. | 1300 // Invoking the tested function. |
1220 processServerResponse(serverResponse); | 1301 processServerResponse(serverResponse); |
1221 }); | 1302 }); |
1222 | 1303 |
1223 TEST_F(TEST_NAME, 'ProcessServerResponseGoogleNowDisabled', function() { | 1304 TEST_F(TEST_NAME, 'ProcessServerResponseGoogleNowDisabled', function() { |
1224 // Tests processServerResponse function for the case when the response | 1305 // Tests processServerResponse function for the case when the response |
1225 // indicates that Google Now is disabled. | 1306 // indicates that Google Now is disabled. |
1226 | 1307 |
1227 // Setup and expectations. | 1308 // Setup and expectations. |
1228 var serverResponse = { | 1309 var serverResponse = { |
1229 googleNowDisabled: true, | 1310 googleNowDisabled: true, |
1230 groups: {} | 1311 groups: {} |
1231 }; | 1312 }; |
1232 | 1313 |
1233 this.makeAndRegisterMockGlobals([ | 1314 this.makeAndRegisterMockGlobals([ |
1234 'onStateChange', | 1315 'scheduleNextCardsPoll' |
1235 'scheduleNextPoll', | |
1236 ]); | 1316 ]); |
1237 | 1317 |
1238 this.makeAndRegisterMockApis([ | 1318 this.makeAndRegisterMockApis([ |
1239 'chrome.storage.local.set', | 1319 'chrome.storage.local.set', |
1240 'fillFromChromeLocalStorage' | 1320 'fillFromChromeLocalStorage' |
1241 ]); | 1321 ]); |
1242 | 1322 |
1243 this.mockApis.expects(once()). | 1323 this.mockApis.expects(once()). |
1244 chrome_storage_local_set(eqJSON({googleNowEnabled: false})); | 1324 chrome_storage_local_set(eqJSON({googleNowEnabled: false})); |
1245 | 1325 |
1246 this.mockGlobals.expects(once()).onStateChange(); | 1326 this.mockGlobals.expects(never()).scheduleNextCardsPoll(); |
1247 | |
1248 this.mockGlobals.expects(once()).scheduleNextPoll(eqJSON({}), false); | |
1249 | 1327 |
1250 // Invoking the tested function. | 1328 // Invoking the tested function. |
1251 processServerResponse(serverResponse); | 1329 processServerResponse(serverResponse); |
1252 }); | 1330 }); |
1253 | 1331 |
OLD | NEW |