| 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 background.js. | 6 * Test fixture for background.js. |
| 7 * @constructor | 7 * @constructor |
| 8 * @extends {testing.Test} | 8 * @extends {testing.Test} |
| 9 */ | 9 */ |
| 10 function GoogleNowBackgroundUnitTest () { | 10 function GoogleNowBackgroundUnitTest () { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 * Mocks global functions and APIs that initialize() depends upon. | 52 * Mocks global functions and APIs that initialize() depends upon. |
| 53 * @param {Test} fixture Test fixture. | 53 * @param {Test} fixture Test fixture. |
| 54 */ | 54 */ |
| 55 function mockInitializeDependencies(fixture) { | 55 function mockInitializeDependencies(fixture) { |
| 56 fixture.makeAndRegisterMockGlobals([ | 56 fixture.makeAndRegisterMockGlobals([ |
| 57 'recordEvent', | 57 'recordEvent', |
| 58 'showWelcomeToast', | 58 'showWelcomeToast', |
| 59 'startPollingCards' | 59 'startPollingCards' |
| 60 ]); | 60 ]); |
| 61 fixture.makeAndRegisterMockApis([ | 61 fixture.makeAndRegisterMockApis([ |
| 62 'chrome.identity.getAuthToken', | 62 'authenticationManager.isSignedIn', |
| 63 'chrome.location.clearWatch', | 63 'chrome.location.clearWatch', |
| 64 'chrome.notifications.getAll', | 64 'chrome.notifications.getAll', |
| 65 'chrome.preferencesPrivate.googleGeolocationAccessEnabled.get', | 65 'chrome.preferencesPrivate.googleGeolocationAccessEnabled.get', |
| 66 'storage.get', | 66 'storage.get', |
| 67 'storage.set', | 67 'storage.set', |
| 68 'tasks.add', | 68 'tasks.add', |
| 69 'updateCardsAttempts.isRunning', | 69 'updateCardsAttempts.isRunning', |
| 70 'updateCardsAttempts.stop' | 70 'updateCardsAttempts.stop' |
| 71 ]); | 71 ]); |
| 72 } | 72 } |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * Sets up the test to expect the state machine calls and send | 75 * Sets up the test to expect the state machine calls and send |
| 76 * the specified state machine state. Currently used to test initialize(). | 76 * the specified state machine state. Currently used to test initialize(). |
| 77 * Note that this CAN NOT be used if any of the methods below are called | 77 * Note that this CAN NOT be used if any of the methods below are called |
| 78 * outside of this context with the same argument matchers. | 78 * outside of this context with the same argument matchers. |
| 79 * expects() calls cannot be chained with the same argument matchers. | 79 * expects() calls cannot be chained with the same argument matchers. |
| 80 * @param {object} mockApisObj Mock APIs Object. | 80 * @param {object} mockApisObj Mock APIs Object. |
| 81 * @param {string} testIdentityToken getAuthToken callback token. | 81 * @param {string} testIdentityToken getAuthToken callback token. |
| 82 * @param {boolean} testGeolocationPref Geolocation Preference callback value. | 82 * @param {boolean} testGeolocationPref Geolocation Preference callback value. |
| 83 * @param {boolean} testUserRespondedToToast User Response to toast | 83 * @param {boolean} testUserRespondedToToast User Response to toast |
| 84 & callback value. | 84 & callback value. |
| 85 */ | 85 */ |
| 86 function expectStateMachineCalls( | 86 function expectStateMachineCalls( |
| 87 mockApisObj, | 87 mockApisObj, |
| 88 testIdentityToken, | 88 testIdentityToken, |
| 89 testGeolocationPref, | 89 testGeolocationPref, |
| 90 testUserRespondedToToast) { | 90 testUserRespondedToToast) { |
| 91 var chromeIdentityGetAuthTokenSavedArgs = new SaveMockArguments(); | 91 var authenticationManagerIsSignedInSavedArgs = new SaveMockArguments(); |
| 92 mockApisObj.expects(once()). | 92 mockApisObj.expects(once()). |
| 93 chrome_identity_getAuthToken( | 93 authenticationManager_isSignedIn( |
| 94 chromeIdentityGetAuthTokenSavedArgs.match( | 94 authenticationManagerIsSignedInSavedArgs.match(ANYTHING)). |
| 95 eqJSON({interactive: false})), | |
| 96 chromeIdentityGetAuthTokenSavedArgs.match(ANYTHING)). | |
| 97 will(invokeCallback( | 95 will(invokeCallback( |
| 98 chromeIdentityGetAuthTokenSavedArgs, 1, testIdentityToken)); | 96 authenticationManagerIsSignedInSavedArgs, |
| 97 0, |
| 98 testIdentityToken)); |
| 99 | 99 |
| 100 var googleGeolocationPrefGetSavedArgs = new SaveMockArguments(); | 100 var googleGeolocationPrefGetSavedArgs = new SaveMockArguments(); |
| 101 mockApisObj.expects(once()). | 101 mockApisObj.expects(once()). |
| 102 chrome_preferencesPrivate_googleGeolocationAccessEnabled_get( | 102 chrome_preferencesPrivate_googleGeolocationAccessEnabled_get( |
| 103 googleGeolocationPrefGetSavedArgs.match(eqJSON({})), | 103 googleGeolocationPrefGetSavedArgs.match(eqJSON({})), |
| 104 googleGeolocationPrefGetSavedArgs.match(ANYTHING)). | 104 googleGeolocationPrefGetSavedArgs.match(ANYTHING)). |
| 105 will(invokeCallback( | 105 will(invokeCallback( |
| 106 googleGeolocationPrefGetSavedArgs, 1, {value: testGeolocationPref})); | 106 googleGeolocationPrefGetSavedArgs, 1, {value: testGeolocationPref})); |
| 107 | 107 |
| 108 var storageGetSavedArgs = new SaveMockArguments(); | 108 var storageGetSavedArgs = new SaveMockArguments(); |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), | 516 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), |
| 517 chromeTabsCreateSavedArgs.match(ANYTHING)). | 517 chromeTabsCreateSavedArgs.match(ANYTHING)). |
| 518 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); | 518 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); |
| 519 this.mockApis.expects(once()).chrome_windows_create( | 519 this.mockApis.expects(once()).chrome_windows_create( |
| 520 eqJSON({url: testActionUrl})); | 520 eqJSON({url: testActionUrl})); |
| 521 | 521 |
| 522 // Invoking the tested function. | 522 // Invoking the tested function. |
| 523 onNotificationClicked( | 523 onNotificationClicked( |
| 524 testNotificationId, this.mockLocalFunctions.functions().selector); | 524 testNotificationId, this.mockLocalFunctions.functions().selector); |
| 525 }); | 525 }); |
| OLD | NEW |