| 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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 * Note that this CAN NOT be used if any of the methods below are called | 479 * Note that this CAN NOT be used if any of the methods below are called |
| 480 * outside of this context with the same argument matchers. | 480 * outside of this context with the same argument matchers. |
| 481 * expects() calls cannot be chained with the same argument matchers. | 481 * expects() calls cannot be chained with the same argument matchers. |
| 482 * @param {object} fixture Test fixture. | 482 * @param {object} fixture Test fixture. |
| 483 * @param {string} testIdentityToken getAuthToken callback token. | 483 * @param {string} testIdentityToken getAuthToken callback token. |
| 484 * @param {boolean} testGeolocationPref Geolocation Preference callback value. | 484 * @param {boolean} testGeolocationPref Geolocation Preference callback value. |
| 485 * @param {object} testExperimentVariationParams Response of | 485 * @param {object} testExperimentVariationParams Response of |
| 486 * metricsPrivate.getVariationParams. | 486 * metricsPrivate.getVariationParams. |
| 487 * @param {string} testExperimentVariationParams Response of | 487 * @param {string} testExperimentVariationParams Response of |
| 488 * notifications.getPermissionLevel. | 488 * notifications.getPermissionLevel. |
| 489 * @param {boolean} testGoogleNowEnabled True if the user is opted in to Google |
| 490 * Now. |
| 489 */ | 491 */ |
| 490 function expectStateMachineCalls( | 492 function expectStateMachineCalls( |
| 491 fixture, | 493 fixture, |
| 492 testIdentityToken, | 494 testIdentityToken, |
| 493 testGeolocationPref, | 495 testGeolocationPref, |
| 494 testExperimentVariationParams, | 496 testExperimentVariationParams, |
| 495 testNotificationPermissionLevel) { | 497 testNotificationPermissionLevel, |
| 498 testGoogleNowEnabled) { |
| 496 var authenticationManagerIsSignedInSavedArgs = new SaveMockArguments(); | 499 var authenticationManagerIsSignedInSavedArgs = new SaveMockArguments(); |
| 497 fixture.mockApis.expects(once()). | 500 fixture.mockApis.expects(once()). |
| 498 authenticationManager_isSignedIn( | 501 authenticationManager_isSignedIn( |
| 499 authenticationManagerIsSignedInSavedArgs.match(ANYTHING)). | 502 authenticationManagerIsSignedInSavedArgs.match(ANYTHING)). |
| 500 will(invokeCallback( | 503 will(invokeCallback( |
| 501 authenticationManagerIsSignedInSavedArgs, | 504 authenticationManagerIsSignedInSavedArgs, |
| 502 0, | 505 0, |
| 503 testIdentityToken)); | 506 testIdentityToken)); |
| 504 | 507 |
| 505 var getVariationParamsSavedArgs = new SaveMockArguments(); | 508 var getVariationParamsSavedArgs = new SaveMockArguments(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 520 | 523 |
| 521 var notificationGetPermissionLevelSavedArgs = new SaveMockArguments(); | 524 var notificationGetPermissionLevelSavedArgs = new SaveMockArguments(); |
| 522 fixture.mockApis.expects(once()). | 525 fixture.mockApis.expects(once()). |
| 523 instrumented_notifications_getPermissionLevel( | 526 instrumented_notifications_getPermissionLevel( |
| 524 notificationGetPermissionLevelSavedArgs.match(ANYTHING)). | 527 notificationGetPermissionLevelSavedArgs.match(ANYTHING)). |
| 525 will(invokeCallback( | 528 will(invokeCallback( |
| 526 notificationGetPermissionLevelSavedArgs, | 529 notificationGetPermissionLevelSavedArgs, |
| 527 0, | 530 0, |
| 528 testNotificationPermissionLevel)) | 531 testNotificationPermissionLevel)) |
| 529 | 532 |
| 533 var storageGetSavedArgs = new SaveMockArguments(); |
| 534 fixture.mockApis.expects(once()). |
| 535 instrumented_storage_local_get( |
| 536 storageGetSavedArgs.match(eq('googleNowEnabled')), |
| 537 storageGetSavedArgs.match(ANYTHING)). |
| 538 will(invokeCallback( |
| 539 storageGetSavedArgs, 1, {googleNowEnabled: testGoogleNowEnabled}));
|
| 540 |
| 530 fixture.mockGlobals.expects(once()). | 541 fixture.mockGlobals.expects(once()). |
| 531 setBackgroundEnable(ANYTHING); | 542 setBackgroundEnable(ANYTHING); |
| 532 } | 543 } |
| 533 | 544 |
| 534 /** | 545 /** |
| 535 * Sets up the test to expect the initialization calls that | 546 * Sets up the test to expect the initialization calls that |
| 536 * initialize() invokes. | 547 * initialize() invokes. |
| 537 * Note that this CAN NOT be used if any of the methods below are called | 548 * Note that this CAN NOT be used if any of the methods below are called |
| 538 * outside of this context with the same argument matchers. | 549 * outside of this context with the same argument matchers. |
| 539 * expects() calls cannot be chained with the same argument matchers. | 550 * expects() calls cannot be chained with the same argument matchers. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 560 function() { | 571 function() { |
| 561 // Tests the case when getAuthToken fails most likely because the user is | 572 // Tests the case when getAuthToken fails most likely because the user is |
| 562 // not signed in. In this case, the function should quietly exit after | 573 // not signed in. In this case, the function should quietly exit after |
| 563 // finding out that getAuthToken fails. | 574 // finding out that getAuthToken fails. |
| 564 | 575 |
| 565 // Setup and expectations. | 576 // Setup and expectations. |
| 566 var testIdentityToken = undefined; | 577 var testIdentityToken = undefined; |
| 567 var testGeolocationPref = false; | 578 var testGeolocationPref = false; |
| 568 var testExperimentVariationParams = {}; | 579 var testExperimentVariationParams = {}; |
| 569 var testNotificationPermissionLevel = 'denied'; | 580 var testNotificationPermissionLevel = 'denied'; |
| 581 var testGoogleNowEnabled = undefined; |
| 570 | 582 |
| 571 mockInitializeDependencies(this); | 583 mockInitializeDependencies(this); |
| 572 | 584 |
| 573 this.mockGlobals.expects(once()).recordEvent( | 585 this.mockGlobals.expects(once()).recordEvent( |
| 574 GoogleNowEvent.EXTENSION_START); | 586 GoogleNowEvent.EXTENSION_START); |
| 575 | 587 |
| 576 this.mockGlobals.expects(once()).recordEvent( | 588 this.mockGlobals.expects(once()).recordEvent( |
| 577 GoogleNowEvent.STOPPED); | 589 GoogleNowEvent.STOPPED); |
| 578 | 590 |
| 579 expectInitialization(this.mockApis); | 591 expectInitialization(this.mockApis); |
| 580 | 592 |
| 581 expectStateMachineCalls( | 593 expectStateMachineCalls( |
| 582 this, | 594 this, |
| 583 testIdentityToken, | 595 testIdentityToken, |
| 584 testGeolocationPref, | 596 testGeolocationPref, |
| 585 testExperimentVariationParams, | 597 testExperimentVariationParams, |
| 586 testNotificationPermissionLevel); | 598 testNotificationPermissionLevel, |
| 599 testGoogleNowEnabled); |
| 587 | 600 |
| 588 // Invoking the tested function. | 601 // Invoking the tested function. |
| 589 initialize(); | 602 initialize(); |
| 590 }); | 603 }); |
| 591 | 604 |
| 592 TEST_F( | 605 TEST_F( |
| 593 'GoogleNowBackgroundUnitTest', | 606 'GoogleNowBackgroundUnitTest', |
| 594 'DISABLED_Initialize_ToastStateEmpty2', | 607 'DISABLED_Initialize_ToastStateEmpty2', |
| 595 function() { | 608 function() { |
| 596 // Tests the case when getAuthToken succeeds, and the user has never | 609 // Tests the case when getAuthToken succeeds, and the user has never |
| 597 // responded to the toast. | 610 // responded to the toast. |
| 598 // In this case, the function should invoke showWelcomeToast(). | 611 // In this case, the function should invoke showWelcomeToast(). |
| 599 | 612 |
| 600 // Setup and expectations. | 613 // Setup and expectations. |
| 601 var testIdentityToken = 'some identity token'; | 614 var testIdentityToken = 'some identity token'; |
| 602 var testGeolocationPref = false; | 615 var testGeolocationPref = false; |
| 603 var testExperimentVariationParams = {}; | 616 var testExperimentVariationParams = {}; |
| 604 var testNotificationPermissionLevel = 'denied'; | 617 var testNotificationPermissionLevel = 'denied'; |
| 618 var testGoogleNowEnabled = undefined; |
| 605 | 619 |
| 606 mockInitializeDependencies(this); | 620 mockInitializeDependencies(this); |
| 607 | 621 |
| 608 this.mockGlobals.expects(once()).recordEvent( | 622 this.mockGlobals.expects(once()).recordEvent( |
| 609 GoogleNowEvent.EXTENSION_START); | 623 GoogleNowEvent.EXTENSION_START); |
| 610 | 624 |
| 611 expectInitialization(this.mockApis); | 625 expectInitialization(this.mockApis); |
| 612 | 626 |
| 613 expectStateMachineCalls( | 627 expectStateMachineCalls( |
| 614 this, | 628 this, |
| 615 testIdentityToken, | 629 testIdentityToken, |
| 616 testGeolocationPref, | 630 testGeolocationPref, |
| 617 testExperimentVariationParams, | 631 testExperimentVariationParams, |
| 618 testNotificationPermissionLevel); | 632 testNotificationPermissionLevel, |
| 633 testGoogleNowEnabled); |
| 619 | 634 |
| 620 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); | 635 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); |
| 621 this.mockApis.expects(exactly(1)). | 636 this.mockApis.expects(exactly(1)). |
| 622 instrumented_notifications_getAll( | 637 instrumented_notifications_getAll( |
| 623 chromeNotificationGetAllSavedArgs.match(ANYTHING)). | 638 chromeNotificationGetAllSavedArgs.match(ANYTHING)). |
| 624 will( | 639 will( |
| 625 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}), | 640 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}), |
| 626 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); | 641 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); |
| 627 | 642 |
| 628 // Invoking the tested function. | 643 // Invoking the tested function. |
| 629 initialize(); | 644 initialize(); |
| 630 }); | 645 }); |
| 631 | 646 |
| 632 TEST_F('GoogleNowBackgroundUnitTest', 'Initialize_RunGoogleNow', function() { | 647 TEST_F('GoogleNowBackgroundUnitTest', 'Initialize_RunGoogleNow', function() { |
| 633 // Tests if Google Now will invoke startPollingCards when all | 648 // Tests if Google Now will invoke startPollingCards when all |
| 634 // of the required state is fulfilled. | 649 // of the required state is fulfilled. |
| 635 | 650 |
| 636 // Setup and expectations. | 651 // Setup and expectations. |
| 637 var testIdentityToken = 'some identity token'; | 652 var testIdentityToken = 'some identity token'; |
| 638 var testGeolocationPref = true; | 653 var testGeolocationPref = true; |
| 639 var testExperimentVariationParams = {}; | 654 var testExperimentVariationParams = {}; |
| 640 var testNotificationPermissionLevel = 'granted'; | 655 var testNotificationPermissionLevel = 'granted'; |
| 656 var testGoogleNowEnabled = true; |
| 641 | 657 |
| 642 mockInitializeDependencies(this); | 658 mockInitializeDependencies(this); |
| 643 | 659 |
| 644 this.mockGlobals.expects(once()).recordEvent( | 660 this.mockGlobals.expects(once()).recordEvent( |
| 645 GoogleNowEvent.EXTENSION_START); | 661 GoogleNowEvent.EXTENSION_START); |
| 646 | 662 |
| 647 expectInitialization(this.mockApis); | 663 expectInitialization(this.mockApis); |
| 648 | 664 |
| 649 expectStateMachineCalls( | 665 expectStateMachineCalls( |
| 650 this, | 666 this, |
| 651 testIdentityToken, | 667 testIdentityToken, |
| 652 testGeolocationPref, | 668 testGeolocationPref, |
| 653 testExperimentVariationParams, | 669 testExperimentVariationParams, |
| 654 testNotificationPermissionLevel); | 670 testNotificationPermissionLevel, |
| 671 testGoogleNowEnabled); |
| 655 | 672 |
| 656 this.mockGlobals.expects(once()).startPollingCards(); | 673 this.mockGlobals.expects(once()).startPollingCards(); |
| 657 | 674 |
| 658 // Invoking the tested function. | 675 // Invoking the tested function. |
| 659 initialize(); | 676 initialize(); |
| 660 }); | 677 }); |
| 661 | 678 |
| 662 TEST_F( | 679 TEST_F( |
| 663 'GoogleNowBackgroundUnitTest', | 680 'GoogleNowBackgroundUnitTest', |
| 664 'DISABLED_Initialize_NoGeolocation', | 681 'DISABLED_Initialize_NoGeolocation', |
| 665 function() { | 682 function() { |
| 666 // Tests the case where everything is in place except for the | 683 // Tests the case where everything is in place except for the |
| 667 // Geolocation Preference after the user responded to the toast. | 684 // Geolocation Preference after the user responded to the toast. |
| 668 | 685 |
| 669 // Setup and expectations. | 686 // Setup and expectations. |
| 670 var testIdentityToken = 'some identity token'; | 687 var testIdentityToken = 'some identity token'; |
| 671 var testGeolocationPref = false; | 688 var testGeolocationPref = false; |
| 672 var testExperimentVariationParams = {}; | 689 var testExperimentVariationParams = {}; |
| 673 var testNotificationPermissionLevel = 'denied'; | 690 var testNotificationPermissionLevel = 'denied'; |
| 691 var testGoogleNowEnabled = undefined; |
| 692 |
| 674 | 693 |
| 675 mockInitializeDependencies(this); | 694 mockInitializeDependencies(this); |
| 676 | 695 |
| 677 this.mockGlobals.expects(once()).recordEvent( | 696 this.mockGlobals.expects(once()).recordEvent( |
| 678 GoogleNowEvent.EXTENSION_START); | 697 GoogleNowEvent.EXTENSION_START); |
| 679 | 698 |
| 680 this.mockGlobals.expects(once()).recordEvent( | 699 this.mockGlobals.expects(once()).recordEvent( |
| 681 GoogleNowEvent.USER_SUPPRESSED); | 700 GoogleNowEvent.USER_SUPPRESSED); |
| 682 | 701 |
| 683 expectInitialization(this.mockApis); | 702 expectInitialization(this.mockApis); |
| 684 | 703 |
| 685 expectStateMachineCalls( | 704 expectStateMachineCalls( |
| 686 this, | 705 this, |
| 687 testIdentityToken, | 706 testIdentityToken, |
| 688 testGeolocationPref, | 707 testGeolocationPref, |
| 689 testExperimentVariationParams, | 708 testExperimentVariationParams, |
| 690 testNotificationPermissionLevel, | 709 testNotificationPermissionLevel, |
| 691 testNotificationPermissionLevel); | 710 testNotificationPermissionLevel, |
| 711 testGoogleNowEnabled); |
| 692 | 712 |
| 693 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); | 713 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); |
| 694 this.mockApis.expects(exactly(2)). | 714 this.mockApis.expects(exactly(2)). |
| 695 instrumented_notifications_getAll( | 715 instrumented_notifications_getAll( |
| 696 chromeNotificationGetAllSavedArgs.match(ANYTHING)). | 716 chromeNotificationGetAllSavedArgs.match(ANYTHING)). |
| 697 will( | 717 will( |
| 698 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}), | 718 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}), |
| 699 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); | 719 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); |
| 700 | 720 |
| 701 // Invoking the tested function. | 721 // Invoking the tested function. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), | 867 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), |
| 848 chromeTabsCreateSavedArgs.match(ANYTHING)). | 868 chromeTabsCreateSavedArgs.match(ANYTHING)). |
| 849 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); | 869 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); |
| 850 this.mockApis.expects(once()).chrome_windows_create( | 870 this.mockApis.expects(once()).chrome_windows_create( |
| 851 eqJSON({url: testActionUrl, focused: true})); | 871 eqJSON({url: testActionUrl, focused: true})); |
| 852 | 872 |
| 853 // Invoking the tested function. | 873 // Invoking the tested function. |
| 854 onNotificationClicked( | 874 onNotificationClicked( |
| 855 testNotificationId, this.mockLocalFunctions.functions().selector); | 875 testNotificationId, this.mockLocalFunctions.functions().selector); |
| 856 }); | 876 }); |
| OLD | NEW |