| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 ]); | 63 ]); |
| 64 fixture.makeAndRegisterMockApis([ | 64 fixture.makeAndRegisterMockApis([ |
| 65 'authenticationManager.isSignedIn', | 65 'authenticationManager.isSignedIn', |
| 66 'chrome.location.clearWatch', | 66 'chrome.location.clearWatch', |
| 67 'chrome.storage.local.remove', | 67 'chrome.storage.local.remove', |
| 68 'instrumented.metricsPrivate.getVariationParams', | 68 'instrumented.metricsPrivate.getVariationParams', |
| 69 'instrumented.notifications.getAll', | 69 'instrumented.notifications.getAll', |
| 70 'instrumented.notifications.getPermissionLevel', | 70 'instrumented.notifications.getPermissionLevel', |
| 71 'instrumented.preferencesPrivate.googleGeolocationAccessEnabled.get', | 71 'instrumented.preferencesPrivate.googleGeolocationAccessEnabled.get', |
| 72 'instrumented.storage.local.get', | 72 'instrumented.storage.local.get', |
| 73 'instrumented.webstorePrivate.getBrowserLogin', |
| 73 'tasks.add', | 74 'tasks.add', |
| 74 'updateCardsAttempts.isRunning', | 75 'updateCardsAttempts.isRunning', |
| 75 'updateCardsAttempts.stop' | 76 'updateCardsAttempts.stop' |
| 76 ]); | 77 ]); |
| 77 } | 78 } |
| 78 | 79 |
| 79 /** | 80 /** |
| 80 * Sets up the test to expect the state machine calls and send | 81 * Sets up the test to expect the state machine calls and send |
| 81 * the specified state machine state. Currently used to test initialize(). | 82 * the specified state machine state. Currently used to test initialize(). |
| 82 * Note that this CAN NOT be used if any of the methods below are called | 83 * Note that this CAN NOT be used if any of the methods below are called |
| 83 * outside of this context with the same argument matchers. | 84 * outside of this context with the same argument matchers. |
| 84 * expects() calls cannot be chained with the same argument matchers. | 85 * expects() calls cannot be chained with the same argument matchers. |
| 85 * @param {object} fixture Test fixture. | 86 * @param {object} fixture Test fixture. |
| 86 * @param {string} testIdentityToken getAuthToken callback token. | 87 * @param {string} testIdentityToken getAuthToken callback token. |
| 87 * @param {boolean} testGeolocationPref Geolocation Preference callback value. | 88 * @param {boolean} testGeolocationPref Geolocation Preference callback value. |
| 88 * @param {object} testExperimentVariationParams Response of | 89 * @param {object} testExperimentVariationParams Response of |
| 89 * metricsPrivate.getVariationParams. | 90 * metricsPrivate.getVariationParams. |
| 90 * @param {string} testExperimentVariationParams Response of | 91 * @param {string} testExperimentVariationParams Response of |
| 91 * notifications.getPermissionLevel. | 92 * notifications.getPermissionLevel. |
| 92 * @param {boolean} testGoogleNowEnabled True if the user is opted in to Google | 93 * @param {boolean} testGoogleNowEnabled True if the user is opted in to Google |
| 93 * Now. | 94 * Now. |
| 94 */ | 95 */ |
| 95 function expectStateMachineCalls( | 96 function expectStateMachineCalls( |
| 96 fixture, | 97 fixture, |
| 97 testIdentityToken, | 98 testIdentityToken, |
| 98 testGeolocationPref, | 99 testGeolocationPref, |
| 99 testExperimentVariationParams, | 100 testExperimentVariationParams, |
| 100 testNotificationPermissionLevel, | 101 testNotificationPermissionLevel, |
| 101 testGoogleNowEnabled) { | 102 testGoogleNowEnabled) { |
| 102 var authenticationManagerIsSignedInSavedArgs = new SaveMockArguments(); | |
| 103 fixture.mockApis.expects(once()). | 103 fixture.mockApis.expects(once()). |
| 104 authenticationManager_isSignedIn( | 104 authenticationManager_isSignedIn(). |
| 105 authenticationManagerIsSignedInSavedArgs.match(ANYTHING)). | 105 will(returnValue(new Promise(function(resolve) { |
| 106 will(invokeCallback( | 106 resolve(!!testIdentityToken); |
| 107 authenticationManagerIsSignedInSavedArgs, | 107 }))); |
| 108 0, | |
| 109 testIdentityToken)); | |
| 110 | 108 |
| 111 var getVariationParamsSavedArgs = new SaveMockArguments(); | 109 var getVariationParamsSavedArgs = new SaveMockArguments(); |
| 112 fixture.mockApis.expects(once()). | 110 fixture.mockApis.expects(once()). |
| 113 instrumented_metricsPrivate_getVariationParams( | 111 instrumented_metricsPrivate_getVariationParams( |
| 114 getVariationParamsSavedArgs.match(ANYTHING), | 112 getVariationParamsSavedArgs.match(ANYTHING), |
| 115 getVariationParamsSavedArgs.match(ANYTHING)). | 113 getVariationParamsSavedArgs.match(ANYTHING)). |
| 116 will(invokeCallback( | 114 will(invokeCallback( |
| 117 getVariationParamsSavedArgs, 1, testExperimentVariationParams)); | 115 getVariationParamsSavedArgs, 1, testExperimentVariationParams)); |
| 118 | 116 |
| 119 var googleGeolocationPrefGetSavedArgs = new SaveMockArguments(); | 117 var googleGeolocationPrefGetSavedArgs = new SaveMockArguments(); |
| 120 fixture.mockApis.expects(once()). | 118 fixture.mockApis.expects(once()). |
| 121 instrumented_preferencesPrivate_googleGeolocationAccessEnabled_get( | 119 instrumented_preferencesPrivate_googleGeolocationAccessEnabled_get( |
| 122 googleGeolocationPrefGetSavedArgs.match(eqJSON({})), | 120 googleGeolocationPrefGetSavedArgs.match(eqJSON({})), |
| 123 googleGeolocationPrefGetSavedArgs.match(ANYTHING)). | 121 googleGeolocationPrefGetSavedArgs.match(ANYTHING)). |
| 124 will(invokeCallback( | 122 will(invokeCallback( |
| 125 googleGeolocationPrefGetSavedArgs, 1, {value: testGeolocationPref})); | 123 googleGeolocationPrefGetSavedArgs, 1, {value: testGeolocationPref})); |
| 126 | 124 |
| 127 var notificationGetPermissionLevelSavedArgs = new SaveMockArguments(); | 125 var notificationGetPermissionLevelSavedArgs = new SaveMockArguments(); |
| 128 fixture.mockApis.expects(once()). | 126 fixture.mockApis.expects(once()). |
| 129 instrumented_notifications_getPermissionLevel( | 127 instrumented_notifications_getPermissionLevel( |
| 130 notificationGetPermissionLevelSavedArgs.match(ANYTHING)). | 128 notificationGetPermissionLevelSavedArgs.match(ANYTHING)). |
| 131 will(invokeCallback( | 129 will(invokeCallback( |
| 132 notificationGetPermissionLevelSavedArgs, | 130 notificationGetPermissionLevelSavedArgs, |
| 133 0, | 131 0, |
| 134 testNotificationPermissionLevel)) | 132 testNotificationPermissionLevel)) |
| 135 | 133 |
| 136 var storageGetSavedArgs = new SaveMockArguments();» | 134 var storageGetSavedArgs = new SaveMockArguments(); |
| 137 fixture.mockApis.expects(once()).» | 135 fixture.mockApis.expects(once()). |
| 138 instrumented_storage_local_get(» | 136 instrumented_storage_local_get( |
| 139 storageGetSavedArgs.match(eq('googleNowEnabled')),» | 137 storageGetSavedArgs.match(eq('googleNowEnabled')), |
| 140 storageGetSavedArgs.match(ANYTHING)).» | 138 storageGetSavedArgs.match(ANYTHING)). |
| 141 will(invokeCallback( | 139 will(invokeCallback( |
| 142 storageGetSavedArgs, 1, {googleNowEnabled: testGoogleNowEnabled}));»
| 140 storageGetSavedArgs, 1, {googleNowEnabled: testGoogleNowEnabled})); |
| 143 | 141 |
| 144 fixture.mockGlobals.expects(once()). | 142 fixture.mockGlobals.expects(once()). |
| 145 setBackgroundEnable(ANYTHING); | 143 setBackgroundEnable(ANYTHING); |
| 146 } | 144 } |
| 147 | 145 |
| 148 /** | 146 /** |
| 149 * Sets up the test to expect the initialization calls that | 147 * Sets up the test to expect the initialization calls that |
| 150 * initialize() invokes. | 148 * initialize() invokes. |
| 151 * Note that this CAN NOT be used if any of the methods below are called | 149 * Note that this CAN NOT be used if any of the methods below are called |
| 152 * outside of this context with the same argument matchers. | 150 * outside of this context with the same argument matchers. |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 receivedNotificationWithShowTime | 588 receivedNotificationWithShowTime |
| 591 ] | 589 ] |
| 592 }; | 590 }; |
| 593 | 591 |
| 594 // Invoking the tested function. | 592 // Invoking the tested function. |
| 595 combineGroup(combinedCards, storedGroup); | 593 combineGroup(combinedCards, storedGroup); |
| 596 | 594 |
| 597 // Check the output value. | 595 // Check the output value. |
| 598 var expectedCombinedCards = { | 596 var expectedCombinedCards = { |
| 599 'EXISTING CARD': [ | 597 'EXISTING CARD': [ |
| 600 1, | 598 1, |
| 601 { | 599 { |
| 602 receivedNotification: receivedNotificationNoShowTime, | 600 receivedNotification: receivedNotificationNoShowTime, |
| 603 hideTime: 11000 | 601 hideTime: 11000 |
| 604 } | 602 } |
| 605 ], | 603 ], |
| 606 'NEW CARD': [ | 604 'NEW CARD': [ |
| 607 { | 605 { |
| 608 receivedNotification: receivedNotificationWithShowTime, | 606 receivedNotification: receivedNotificationWithShowTime, |
| 609 showTime: 12000, | 607 showTime: 12000, |
| 610 hideTime: 13000 | 608 hideTime: 13000 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 eqJSON({ | 887 eqJSON({ |
| 890 notificationGroups: expectedUpdatedGroups, | 888 notificationGroups: expectedUpdatedGroups, |
| 891 recentDismissals: {}})); | 889 recentDismissals: {}})); |
| 892 | 890 |
| 893 this.mockGlobals.expects(once()). | 891 this.mockGlobals.expects(once()). |
| 894 recordEvent(GoogleNowEvent.CARDS_PARSE_SUCCESS); | 892 recordEvent(GoogleNowEvent.CARDS_PARSE_SUCCESS); |
| 895 | 893 |
| 896 // Invoking the tested function. | 894 // Invoking the tested function. |
| 897 processServerResponse(serverResponse, fakeOnCardShownFunction); | 895 processServerResponse(serverResponse, fakeOnCardShownFunction); |
| 898 }); | 896 }); |
| OLD | NEW |