Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 23 | 23 |
| 24 TEST_F('GoogleNowBackgroundUnitTest', 'AreTasksConflicting', function() { | 24 TEST_F('GoogleNowBackgroundUnitTest', 'AreTasksConflicting', function() { |
| 25 function testTaskPair(newTaskName, scheduledTaskName, expected) { | 25 function testTaskPair(newTaskName, scheduledTaskName, expected) { |
| 26 assertTrue(areTasksConflicting(newTaskName, scheduledTaskName) == expected, | 26 assertTrue(areTasksConflicting(newTaskName, scheduledTaskName) == expected, |
| 27 '(' + newTaskName + ', ' + scheduledTaskName + ')'); | 27 '(' + newTaskName + ', ' + scheduledTaskName + ')'); |
| 28 } | 28 } |
| 29 | 29 |
| 30 testTaskPair(UPDATE_CARDS_TASK_NAME, UPDATE_CARDS_TASK_NAME, true); | 30 testTaskPair(UPDATE_CARDS_TASK_NAME, UPDATE_CARDS_TASK_NAME, true); |
| 31 testTaskPair(UPDATE_CARDS_TASK_NAME, DISMISS_CARD_TASK_NAME, false); | 31 testTaskPair(UPDATE_CARDS_TASK_NAME, DISMISS_CARD_TASK_NAME, false); |
| 32 testTaskPair(UPDATE_CARDS_TASK_NAME, RETRY_DISMISS_TASK_NAME, false); | 32 testTaskPair(UPDATE_CARDS_TASK_NAME, RETRY_DISMISS_TASK_NAME, false); |
| 33 testTaskPair(UPDATE_CARDS_TASK_NAME, STATE_CHANGED_TASK_NAME, false); | |
| 33 | 34 |
| 34 testTaskPair(DISMISS_CARD_TASK_NAME, UPDATE_CARDS_TASK_NAME, false); | 35 testTaskPair(DISMISS_CARD_TASK_NAME, UPDATE_CARDS_TASK_NAME, false); |
| 35 testTaskPair(DISMISS_CARD_TASK_NAME, DISMISS_CARD_TASK_NAME, false); | 36 testTaskPair(DISMISS_CARD_TASK_NAME, DISMISS_CARD_TASK_NAME, false); |
| 36 testTaskPair(DISMISS_CARD_TASK_NAME, RETRY_DISMISS_TASK_NAME, false); | 37 testTaskPair(DISMISS_CARD_TASK_NAME, RETRY_DISMISS_TASK_NAME, false); |
| 38 testTaskPair(DISMISS_CARD_TASK_NAME, STATE_CHANGED_TASK_NAME, false); | |
| 37 | 39 |
| 38 testTaskPair(RETRY_DISMISS_TASK_NAME, UPDATE_CARDS_TASK_NAME, true); | 40 testTaskPair(RETRY_DISMISS_TASK_NAME, UPDATE_CARDS_TASK_NAME, true); |
| 39 testTaskPair(RETRY_DISMISS_TASK_NAME, DISMISS_CARD_TASK_NAME, true); | 41 testTaskPair(RETRY_DISMISS_TASK_NAME, DISMISS_CARD_TASK_NAME, true); |
| 40 testTaskPair(RETRY_DISMISS_TASK_NAME, RETRY_DISMISS_TASK_NAME, true); | 42 testTaskPair(RETRY_DISMISS_TASK_NAME, RETRY_DISMISS_TASK_NAME, true); |
| 43 testTaskPair(RETRY_DISMISS_TASK_NAME, STATE_CHANGED_TASK_NAME, false); | |
| 44 | |
| 45 testTaskPair(STATE_CHANGED_TASK_NAME, UPDATE_CARDS_TASK_NAME, false); | |
| 46 testTaskPair(STATE_CHANGED_TASK_NAME, DISMISS_CARD_TASK_NAME, false); | |
| 47 testTaskPair(STATE_CHANGED_TASK_NAME, RETRY_DISMISS_TASK_NAME, false); | |
| 48 testTaskPair(STATE_CHANGED_TASK_NAME, STATE_CHANGED_TASK_NAME, false); | |
| 41 }); | 49 }); |
| 42 | 50 |
| 43 /** | 51 /** |
| 44 * Mocks global functions and APIs that initialize() depends upon. | 52 * Mocks global functions and APIs that initialize() depends upon. |
| 45 * @param {Test} fixture Test fixture. | 53 * @param {Test} fixture Test fixture. |
| 46 */ | 54 */ |
| 47 function mockInitializeDependencies(fixture) { | 55 function mockInitializeDependencies(fixture) { |
| 48 fixture.makeAndRegisterMockGlobals([ | 56 fixture.makeAndRegisterMockGlobals([ |
| 49 'recordEvent', | 57 'recordEvent', |
| 50 'showWelcomeToast', | 58 'showWelcomeToast', |
| 51 'startPollingCards']); | 59 'startPollingCards']); |
| 52 fixture.makeAndRegisterMockApis( | 60 fixture.makeAndRegisterMockApis([ |
| 53 ['storage.get', 'chrome.identity.getAuthToken']); | 61 'chrome.identity.getAuthToken', |
|
vadimt
2013/07/26 01:54:01
Should be indented by 2, I guess.
robliao
2013/07/26 08:11:23
Yup, per the style guide. Fixed the one above too.
| |
| 62 'chrome.location.clearWatch', | |
| 63 'chrome.notifications.getAll', | |
| 64 'chrome.preferencesPrivate.googleGeolocationAccessEnabled.get', | |
| 65 'storage.get', | |
| 66 'storage.set', | |
| 67 'tasks.add', | |
| 68 'updateCardsAttempts.isRunning', | |
| 69 'updateCardsAttempts.stop' | |
| 70 ]); | |
| 71 } | |
| 72 | |
| 73 /** | |
| 74 * Sets up the test to expect the state machine calls and send | |
| 75 * the specified state machine state. Currently used to test initialize(). | |
| 76 * Note that this CAN NOT be used if any of the methods below are called | |
| 77 * outside of this context with the same argument matchers. | |
| 78 * expects() calls cannot be chained with the same argument matchers. | |
| 79 * @param {object} mockApisObj Mock APIs Object. | |
| 80 * @param {string} testIdentityToken getAuthToken callback token. | |
| 81 * @param {boolean} testGeolocationPref Geolocation Preference callback value. | |
| 82 * @param {boolean} testUserRespondedToToast User Response to toast | |
| 83 & callback value. | |
| 84 */ | |
| 85 function expectStateMachineCalls( | |
| 86 mockApisObj, | |
| 87 testIdentityToken, | |
| 88 testGeolocationPref, | |
| 89 testUserRespondedToToast) { | |
| 90 var chromeIdentityGetAuthTokenSavedArgs = new SaveMockArguments(); | |
| 91 mockApisObj.expects(once()). | |
| 92 chrome_identity_getAuthToken( | |
| 93 chromeIdentityGetAuthTokenSavedArgs.match( | |
| 94 eqJSON({interactive: false})), | |
| 95 chromeIdentityGetAuthTokenSavedArgs.match(ANYTHING)). | |
| 96 will(invokeCallback( | |
| 97 chromeIdentityGetAuthTokenSavedArgs, 1, testIdentityToken)); | |
| 98 | |
| 99 var googleGeolocationPrefGetSavedArgs = new SaveMockArguments(); | |
| 100 mockApisObj.expects(once()). | |
| 101 chrome_preferencesPrivate_googleGeolocationAccessEnabled_get( | |
| 102 googleGeolocationPrefGetSavedArgs.match(eqJSON({})), | |
| 103 googleGeolocationPrefGetSavedArgs.match(ANYTHING)). | |
| 104 will(invokeCallback( | |
| 105 googleGeolocationPrefGetSavedArgs, 1, {value: testGeolocationPref})); | |
| 106 | |
| 107 var storageGetSavedArgs = new SaveMockArguments(); | |
| 108 mockApisObj.expects(once()). | |
| 109 storage_get( | |
| 110 storageGetSavedArgs.match(eq('userRespondedToToast')), | |
| 111 storageGetSavedArgs.match(ANYTHING)). | |
| 112 will(invokeCallback(storageGetSavedArgs, 1, testUserRespondedToToast)); | |
| 113 } | |
| 114 | |
| 115 /** | |
| 116 * Sets up the test to expect the initialization calls that | |
| 117 * initialize() invokes. | |
| 118 * Note that this CAN NOT be used if any of the methods below are called | |
| 119 * outside of this context with the same argument matchers. | |
| 120 * expects() calls cannot be chained with the same argument matchers. | |
| 121 */ | |
| 122 function expectInitialization(mockApisObj) { | |
| 123 mockApisObj.expects(once()). | |
| 124 chrome_location_clearWatch(ANYTHING); | |
| 125 mockApisObj.expects(once()). | |
| 126 updateCardsAttempts_stop(); | |
| 127 mockApisObj.expects(once()). | |
| 128 storage_set(eqJSON({notificationsData: {}})); | |
| 129 var tasksAddSavedArgs = new SaveMockArguments(); | |
| 130 mockApisObj.expects(once()). | |
| 131 tasks_add( | |
| 132 tasksAddSavedArgs.match(ANYTHING), | |
| 133 tasksAddSavedArgs.match(ANYTHING)). | |
| 134 will(invokeCallback(tasksAddSavedArgs, 1, function() {})); | |
| 135 var updateCardsAttemptsIsRunningSavedArgs = new SaveMockArguments(); | |
| 136 mockApisObj.expects(once()). | |
| 137 updateCardsAttempts_isRunning( | |
| 138 updateCardsAttemptsIsRunningSavedArgs.match(ANYTHING)). | |
| 139 will( | |
| 140 invokeCallback( | |
| 141 updateCardsAttemptsIsRunningSavedArgs, 0, false)); | |
| 54 } | 142 } |
| 55 | 143 |
| 56 TEST_F( | 144 TEST_F( |
| 57 'GoogleNowBackgroundUnitTest', | 145 'GoogleNowBackgroundUnitTest', |
| 58 'Initialize_ToastStateEmpty1', | 146 'Initialize_ToastStateEmpty1', |
| 59 function() { | 147 function() { |
| 60 // Tests the case when toast state is empty and NOTIFICATION_CARDS_URL is | 148 // Tests the case when the user isn't signed in and NOTIFICATION_CARDS_URL |
| 61 // not set. In this case, the function should quietly exit after finding | 149 // is not set. Since NOTIFICATION_CARDS_URL is empty, |
| 62 // out that NOTIFICATION_CARDS_URL is empty. | 150 // nothing should start. |
| 63 | 151 |
| 64 // Setup and expectations. | 152 // Setup and expectations. |
| 65 var testToastState = {}; | |
| 66 NOTIFICATION_CARDS_URL = undefined; | 153 NOTIFICATION_CARDS_URL = undefined; |
| 154 var testIdentityToken = undefined; | |
| 155 var testGeolocationPref = false; | |
| 156 var testUserRespondedToToast = {}; | |
| 67 | 157 |
| 68 mockInitializeDependencies(this); | 158 mockInitializeDependencies(this); |
| 69 | 159 |
| 70 this.mockGlobals.expects(once()).recordEvent( | 160 this.mockGlobals.expects(once()).recordEvent( |
| 71 DiagnosticEvent.EXTENSION_START); | 161 DiagnosticEvent.EXTENSION_START); |
| 72 var storageGetSavedArgs = new SaveMockArguments(); | 162 |
| 73 this.mockApis.expects(once()). | 163 expectInitialization(this.mockApis); |
| 74 storage_get( | 164 |
| 75 storageGetSavedArgs.match(eq('toastState')), | 165 expectStateMachineCalls( |
| 76 storageGetSavedArgs.match(ANYTHING)). | 166 this.mockApis, |
| 77 will(invokeCallback(storageGetSavedArgs, 1, testToastState)); | 167 testIdentityToken, |
| 168 testGeolocationPref, | |
| 169 testUserRespondedToToast); | |
| 170 | |
| 171 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); | |
| 172 this.mockApis.expects(exactly(2)). | |
| 173 chrome_notifications_getAll( | |
| 174 chromeNotificationGetAllSavedArgs.match(ANYTHING)). | |
| 175 will( | |
| 176 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}), | |
| 177 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); | |
| 178 | |
| 179 // TODO(robliao,vadimt): Determine the granularity of testing to perform. | |
| 78 | 180 |
| 79 // Invoking the tested function. | 181 // Invoking the tested function. |
| 80 initialize(); | 182 initialize(); |
| 81 }); | 183 }); |
| 82 | 184 |
| 83 TEST_F( | 185 TEST_F( |
| 84 'GoogleNowBackgroundUnitTest', | 186 'GoogleNowBackgroundUnitTest', |
| 85 'Initialize_ToastStateEmpty2', | 187 'Initialize_ToastStateEmpty2', |
| 86 function() { | 188 function() { |
| 87 // Tests the case when toast state is empty and NOTIFICATION_CARDS_URL is | 189 // Tests the case when NOTIFICATION_CARDS_URL is but getAuthToken fails |
| 88 // set, but getAuthToken fails most likely because the user is not signed | 190 // most likely because the user is not signed in. In this case, the |
| 89 // in. In this case, the function should quietly exit after finding out | 191 // function should quietly exit after finding out that getAuthToken fails. |
| 90 // that getAuthToken fails. | |
| 91 | 192 |
| 92 // Setup and expectations. | 193 // Setup and expectations. |
| 93 var testToastState = {}; | |
| 94 NOTIFICATION_CARDS_URL = 'https://some.server.url.com'; | 194 NOTIFICATION_CARDS_URL = 'https://some.server.url.com'; |
| 95 var testIdentityToken = undefined; | 195 var testIdentityToken = undefined; |
| 196 var testGeolocationPref = false; | |
| 197 var testUserRespondedToToast = {}; | |
| 96 | 198 |
| 97 mockInitializeDependencies(this); | 199 mockInitializeDependencies(this); |
| 98 | 200 |
| 99 this.mockGlobals.expects(once()).recordEvent( | 201 this.mockGlobals.expects(once()).recordEvent( |
| 100 DiagnosticEvent.EXTENSION_START); | 202 DiagnosticEvent.EXTENSION_START); |
| 101 var storageGetSavedArgs = new SaveMockArguments(); | 203 |
| 102 this.mockApis.expects(once()). | 204 expectInitialization(this.mockApis); |
| 103 storage_get( | 205 |
| 104 storageGetSavedArgs.match(eq('toastState')), | 206 expectStateMachineCalls( |
| 105 storageGetSavedArgs.match(ANYTHING)). | 207 this.mockApis, |
| 106 will(invokeCallback(storageGetSavedArgs, 1, testToastState)); | 208 testIdentityToken, |
| 107 var chromeIdentityGetAuthTokenSavedArgs = new SaveMockArguments(); | 209 testGeolocationPref, |
| 108 this.mockApis.expects(once()). | 210 testUserRespondedToToast); |
| 109 chrome_identity_getAuthToken( | 211 |
| 110 chromeIdentityGetAuthTokenSavedArgs.match( | 212 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); |
| 111 eqJSON({interactive: false})), | 213 this.mockApis.expects(exactly(2)). |
| 112 chromeIdentityGetAuthTokenSavedArgs.match(ANYTHING)). | 214 chrome_notifications_getAll( |
| 113 will(invokeCallback( | 215 chromeNotificationGetAllSavedArgs.match(ANYTHING)). |
| 114 chromeIdentityGetAuthTokenSavedArgs, 1, testIdentityToken)); | 216 will( |
| 217 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}), | |
| 218 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); | |
| 115 | 219 |
| 116 // Invoking the tested function. | 220 // Invoking the tested function. |
| 117 initialize(); | 221 initialize(); |
| 118 }); | 222 }); |
| 119 | 223 |
| 120 TEST_F( | 224 TEST_F( |
| 121 'GoogleNowBackgroundUnitTest', | 225 'GoogleNowBackgroundUnitTest', |
| 122 'Initialize_ToastStateEmpty3', | 226 'Initialize_ToastStateEmpty3', |
| 123 function() { | 227 function() { |
| 124 // Tests the case when toast state is empty and NOTIFICATION_CARDS_URL is | 228 // Tests the case when NOTIFICATION_CARDS_URL is set, getAuthToken |
| 125 // set, and getAuthToken succeeds. In this case, the function should | 229 // succeeds, and the user has never responded to the toast. |
| 126 // invoke showWelcomeToast(). | 230 // In this case, the function should invoke showWelcomeToast(). |
| 127 | 231 |
| 128 // Setup and expectations. | 232 // Setup and expectations. |
| 129 var testToastState = {}; | |
| 130 NOTIFICATION_CARDS_URL = 'https://some.server.url.com'; | 233 NOTIFICATION_CARDS_URL = 'https://some.server.url.com'; |
| 131 var testIdentityToken = 'some identity token'; | 234 var testIdentityToken = 'some identity token'; |
| 235 var testGeolocationPref = false; | |
| 236 var testUserRespondedToToast = {}; | |
| 132 | 237 |
| 133 mockInitializeDependencies(this); | 238 mockInitializeDependencies(this); |
| 134 | 239 |
| 135 this.mockGlobals.expects(once()).recordEvent( | 240 this.mockGlobals.expects(once()).recordEvent( |
| 136 DiagnosticEvent.EXTENSION_START); | 241 DiagnosticEvent.EXTENSION_START); |
| 137 var storageGetSavedArgs = new SaveMockArguments(); | 242 |
| 138 this.mockApis.expects(once()). | 243 expectInitialization(this.mockApis); |
| 139 storage_get( | 244 |
| 140 storageGetSavedArgs.match(eq('toastState')), | 245 expectStateMachineCalls( |
| 141 storageGetSavedArgs.match(ANYTHING)). | 246 this.mockApis, |
| 142 will(invokeCallback(storageGetSavedArgs, 1, testToastState)); | 247 testIdentityToken, |
| 143 var chromeIdentityGetAuthTokenSavedArgs = new SaveMockArguments(); | 248 testGeolocationPref, |
| 144 this.mockApis.expects(once()). | 249 testUserRespondedToToast); |
| 145 chrome_identity_getAuthToken( | 250 |
| 146 chromeIdentityGetAuthTokenSavedArgs.match( | 251 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); |
| 147 eqJSON({interactive: false})), | 252 this.mockApis.expects(exactly(2)). |
| 148 chromeIdentityGetAuthTokenSavedArgs.match(ANYTHING)). | 253 chrome_notifications_getAll( |
| 149 will(invokeCallback( | 254 chromeNotificationGetAllSavedArgs.match(ANYTHING)). |
| 150 chromeIdentityGetAuthTokenSavedArgs, 1, testIdentityToken)); | 255 will( |
| 256 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}), | |
| 257 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); | |
| 258 | |
| 151 this.mockGlobals.expects(once()).showWelcomeToast(); | 259 this.mockGlobals.expects(once()).showWelcomeToast(); |
| 152 | 260 |
| 153 // Invoking the tested function. | 261 // Invoking the tested function. |
| 154 initialize(); | 262 initialize(); |
| 155 }); | 263 }); |
| 156 | 264 |
| 157 TEST_F('GoogleNowBackgroundUnitTest', 'Initialize_ToastStateYes', function() { | 265 TEST_F('GoogleNowBackgroundUnitTest', 'Initialize_RunGoogleNow', function() { |
| 158 // Tests the case when the user has answered "yes" to the toast in the past. | 266 // Tests if Google Now will invoke startPollingCards when all |
| 159 // In this case, the function should invoke startPollingCards(). | 267 // of the required state is fulfilled. |
| 160 | 268 |
| 161 // Setup and expectations. | 269 // Setup and expectations. |
| 162 var testToastState = {toastState: ToastOptionResponse.CHOSE_YES}; | 270 NOTIFICATION_CARDS_URL = 'https://some.server.url.com'; |
| 271 var testIdentityToken = 'some identity token'; | |
| 272 var testGeolocationPref = true; | |
| 273 var testUserRespondedToToast = {userRespondedToToast: true}; | |
| 163 | 274 |
| 164 mockInitializeDependencies(this); | 275 mockInitializeDependencies(this); |
| 165 | 276 |
| 166 this.mockGlobals.expects(once()).recordEvent(DiagnosticEvent.EXTENSION_START); | 277 this.mockGlobals.expects(once()).recordEvent( |
| 167 var storageGetSavedArgs = new SaveMockArguments(); | 278 DiagnosticEvent.EXTENSION_START); |
| 168 this.mockApis.expects(once()). | |
| 169 storage_get( | |
| 170 storageGetSavedArgs.match(eq('toastState')), | |
| 171 storageGetSavedArgs.match(ANYTHING)). | |
| 172 will(invokeCallback(storageGetSavedArgs, 1, testToastState)); | |
| 173 this.mockGlobals.expects(once()).startPollingCards(); | |
| 174 | 279 |
| 175 // Invoking the tested function. | 280 expectInitialization(this.mockApis); |
| 176 initialize(); | 281 |
| 282 expectStateMachineCalls( | |
| 283 this.mockApis, | |
| 284 testIdentityToken, | |
| 285 testGeolocationPref, | |
| 286 testUserRespondedToToast); | |
| 287 | |
| 288 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); | |
| 289 this.mockApis.expects(exactly(2)). | |
| 290 chrome_notifications_getAll( | |
| 291 chromeNotificationGetAllSavedArgs.match(ANYTHING)). | |
| 292 will( | |
| 293 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}), | |
| 294 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); | |
| 295 | |
| 296 this.mockGlobals.expects(once()).startPollingCards(); | |
| 297 | |
| 298 // Invoking the tested function. | |
| 299 initialize(); | |
| 177 }); | 300 }); |
| 178 | 301 |
| 179 TEST_F('GoogleNowBackgroundUnitTest', 'Initialize_ToastStateNo', function() { | 302 TEST_F('GoogleNowBackgroundUnitTest', 'Initialize_NoGeolocation', function() { |
| 180 // Tests the case when the user has answered "no" to the toast in the past. | 303 // Tests the case where everything is in place except for the |
| 181 // In this case, the function should do nothing. | 304 // Geolocation Preference after the user responded to the toast. |
| 182 | 305 |
| 183 // Setup and expectations. | 306 // Setup and expectations. |
| 184 var testToastState = {toastState: ToastOptionResponse.CHOSE_NO}; | 307 NOTIFICATION_CARDS_URL = 'https://some.server.url.com'; |
| 308 var testIdentityToken = 'some identity token'; | |
| 309 var testGeolocationPref = false; | |
| 310 var testUserRespondedToToast = {userRespondedToToast: true}; | |
| 185 | 311 |
| 186 mockInitializeDependencies(this); | 312 mockInitializeDependencies(this); |
| 187 | 313 |
| 188 this.mockGlobals.expects(once()).recordEvent(DiagnosticEvent.EXTENSION_START); | 314 this.mockGlobals.expects(once()).recordEvent( |
| 189 var storageGetSavedArgs = new SaveMockArguments(); | 315 DiagnosticEvent.EXTENSION_START); |
| 190 this.mockApis.expects(once()). | |
| 191 storage_get( | |
| 192 storageGetSavedArgs.match(eq('toastState')), | |
| 193 storageGetSavedArgs.match(ANYTHING)). | |
| 194 will(invokeCallback(storageGetSavedArgs, 1, testToastState)); | |
| 195 | 316 |
| 196 // Invoking the tested function. | 317 expectInitialization(this.mockApis); |
| 197 initialize(); | 318 |
| 319 expectStateMachineCalls( | |
| 320 this.mockApis, | |
| 321 testIdentityToken, | |
| 322 testGeolocationPref, | |
| 323 testUserRespondedToToast); | |
| 324 | |
| 325 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); | |
| 326 this.mockApis.expects(exactly(2)). | |
| 327 chrome_notifications_getAll( | |
| 328 chromeNotificationGetAllSavedArgs.match(ANYTHING)). | |
| 329 will( | |
| 330 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}), | |
| 331 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); | |
| 332 | |
| 333 // Invoking the tested function. | |
| 334 initialize(); | |
| 198 }); | 335 }); |
| 199 | 336 |
| 200 /** | 337 /** |
| 201 * Mocks global functions and APIs that onNotificationClicked() depends upon. | 338 * Mocks global functions and APIs that onNotificationClicked() depends upon. |
| 202 * @param {Test} fixture Test fixture. | 339 * @param {Test} fixture Test fixture. |
| 203 */ | 340 */ |
| 204 function mockOnNotificationClickedDependencies(fixture) { | 341 function mockOnNotificationClickedDependencies(fixture) { |
| 205 fixture.makeAndRegisterMockApis([ | 342 fixture.makeAndRegisterMockApis([ |
| 206 'storage.get', | 343 'storage.get', |
| 207 'chrome.tabs.create', | 344 'chrome.tabs.create', |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), | 506 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), |
| 370 chromeTabsCreateSavedArgs.match(ANYTHING)). | 507 chromeTabsCreateSavedArgs.match(ANYTHING)). |
| 371 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); | 508 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); |
| 372 this.mockApis.expects(once()).chrome_windows_create( | 509 this.mockApis.expects(once()).chrome_windows_create( |
| 373 eqJSON({url: testActionUrl})); | 510 eqJSON({url: testActionUrl})); |
| 374 | 511 |
| 375 // Invoking the tested function. | 512 // Invoking the tested function. |
| 376 onNotificationClicked( | 513 onNotificationClicked( |
| 377 testNotificationId, this.mockLocalFunctions.functions().selector); | 514 testNotificationId, this.mockLocalFunctions.functions().selector); |
| 378 }); | 515 }); |
| OLD | NEW |