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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 var testGoogleNowEnabled = undefined; | 272 var testGoogleNowEnabled = undefined; |
273 | 273 |
274 mockInitializeDependencies(this); | 274 mockInitializeDependencies(this); |
275 | 275 |
276 this.mockGlobals.expects(once()).recordEvent( | 276 this.mockGlobals.expects(once()).recordEvent( |
277 GoogleNowEvent.EXTENSION_START); | 277 GoogleNowEvent.EXTENSION_START); |
278 | 278 |
279 this.mockGlobals.expects(once()).recordEvent( | 279 this.mockGlobals.expects(once()).recordEvent( |
280 GoogleNowEvent.STOPPED); | 280 GoogleNowEvent.STOPPED); |
281 | 281 |
| 282 this.mockGlobals.expects(once()).recordEvent( |
| 283 GoogleNowEvent.SIGNED_OUT); |
| 284 |
282 expectInitialization(this.mockApis); | 285 expectInitialization(this.mockApis); |
283 | 286 |
284 expectStateMachineCalls( | 287 expectStateMachineCalls( |
285 this, | 288 this, |
286 testIdentityToken, | 289 testIdentityToken, |
287 testExperimentVariationParams, | 290 testExperimentVariationParams, |
288 testNotificationPermissionLevel, | 291 testNotificationPermissionLevel, |
289 testGoogleNowEnabled); | 292 testGoogleNowEnabled); |
290 | 293 |
291 // Invoking the tested function. | 294 // Invoking the tested function. |
(...skipping 24 matching lines...) Expand all Loading... |
316 testNotificationPermissionLevel, | 319 testNotificationPermissionLevel, |
317 testGoogleNowEnabled); | 320 testGoogleNowEnabled); |
318 | 321 |
319 this.mockGlobals.expects(once()).startPollingCards(); | 322 this.mockGlobals.expects(once()).startPollingCards(); |
320 | 323 |
321 // Invoking the tested function. | 324 // Invoking the tested function. |
322 initialize(); | 325 initialize(); |
323 }); | 326 }); |
324 | 327 |
325 /** | 328 /** |
| 329 * No Cards Event Recording Tests |
| 330 */ |
| 331 TEST_F('GoogleNowBackgroundUnitTest', 'NoCardsSignedOut', function() { |
| 332 var signedIn = false; |
| 333 var notificationEnabled = false; |
| 334 var googleNowEnabled = false; |
| 335 this.makeAndRegisterMockGlobals([ |
| 336 'recordEvent', |
| 337 'setBackgroundEnable', |
| 338 'setShouldPollCards']); |
| 339 |
| 340 this.mockGlobals.stubs().setBackgroundEnable(ANYTHING); |
| 341 this.mockGlobals.stubs().setShouldPollCards(ANYTHING); |
| 342 |
| 343 this.mockGlobals.expects(once()).recordEvent( |
| 344 GoogleNowEvent.STOPPED); |
| 345 this.mockGlobals.expects(once()).recordEvent( |
| 346 GoogleNowEvent.SIGNED_OUT); |
| 347 this.mockGlobals.expects(never()).recordEvent( |
| 348 GoogleNowEvent.NOTIFICATION_DISABLED); |
| 349 this.mockGlobals.expects(never()).recordEvent( |
| 350 GoogleNowEvent.GOOGLE_NOW_DISABLED); |
| 351 updateRunningState(signedIn, true, notificationEnabled, googleNowEnabled); |
| 352 }); |
| 353 |
| 354 TEST_F( |
| 355 'GoogleNowBackgroundUnitTest', |
| 356 'NoCardsNotificationsDisabled', |
| 357 function() { |
| 358 var signedIn = true; |
| 359 var notificationEnabled = false; |
| 360 var googleNowEnabled = false; |
| 361 this.makeAndRegisterMockGlobals([ |
| 362 'recordEvent', |
| 363 'setBackgroundEnable', |
| 364 'setShouldPollCards']); |
| 365 |
| 366 this.mockGlobals.stubs().setBackgroundEnable(ANYTHING); |
| 367 this.mockGlobals.stubs().setShouldPollCards(ANYTHING); |
| 368 |
| 369 this.mockGlobals.expects(once()).recordEvent( |
| 370 GoogleNowEvent.STOPPED); |
| 371 this.mockGlobals.expects(never()).recordEvent( |
| 372 GoogleNowEvent.SIGNED_OUT); |
| 373 this.mockGlobals.expects(once()).recordEvent( |
| 374 GoogleNowEvent.NOTIFICATION_DISABLED); |
| 375 this.mockGlobals.expects(never()).recordEvent( |
| 376 GoogleNowEvent.GOOGLE_NOW_DISABLED); |
| 377 updateRunningState(signedIn, true, notificationEnabled, googleNowEnabled); |
| 378 }); |
| 379 |
| 380 TEST_F('GoogleNowBackgroundUnitTest', 'NoCardsGoogleNowDisabled', function() { |
| 381 var signedIn = true; |
| 382 var notificationEnabled = true; |
| 383 var googleNowEnabled = false; |
| 384 this.makeAndRegisterMockGlobals([ |
| 385 'recordEvent', |
| 386 'setBackgroundEnable', |
| 387 'setShouldPollCards']); |
| 388 |
| 389 this.mockGlobals.stubs().setBackgroundEnable(ANYTHING); |
| 390 this.mockGlobals.stubs().setShouldPollCards(ANYTHING); |
| 391 |
| 392 this.mockGlobals.expects(never()).recordEvent( |
| 393 GoogleNowEvent.STOPPED); |
| 394 this.mockGlobals.expects(never()).recordEvent( |
| 395 GoogleNowEvent.SIGNED_OUT); |
| 396 this.mockGlobals.expects(never()).recordEvent( |
| 397 GoogleNowEvent.NOTIFICATION_DISABLED); |
| 398 this.mockGlobals.expects(once()).recordEvent( |
| 399 GoogleNowEvent.GOOGLE_NOW_DISABLED); |
| 400 updateRunningState(signedIn, true, notificationEnabled, googleNowEnabled); |
| 401 }); |
| 402 |
| 403 TEST_F('GoogleNowBackgroundUnitTest', 'NoCardsEverythingEnabled', function() { |
| 404 var signedIn = true; |
| 405 var notificationEnabled = true; |
| 406 var googleNowEnabled = true; |
| 407 this.makeAndRegisterMockGlobals([ |
| 408 'recordEvent', |
| 409 'setBackgroundEnable', |
| 410 'setShouldPollCards']); |
| 411 |
| 412 this.mockGlobals.stubs().setBackgroundEnable(ANYTHING); |
| 413 this.mockGlobals.stubs().setShouldPollCards(ANYTHING); |
| 414 |
| 415 this.mockGlobals.expects(never()).recordEvent( |
| 416 GoogleNowEvent.STOPPED); |
| 417 this.mockGlobals.expects(never()).recordEvent( |
| 418 GoogleNowEvent.SIGNED_OUT); |
| 419 this.mockGlobals.expects(never()).recordEvent( |
| 420 GoogleNowEvent.NOTIFICATION_DISABLED); |
| 421 this.mockGlobals.expects(never()).recordEvent( |
| 422 GoogleNowEvent.GOOGLE_NOW_DISABLED); |
| 423 updateRunningState(signedIn, true, notificationEnabled, googleNowEnabled); |
| 424 }); |
| 425 |
| 426 /** |
326 * Mocks global functions and APIs that onNotificationClicked() depends upon. | 427 * Mocks global functions and APIs that onNotificationClicked() depends upon. |
327 * @param {Test} fixture Test fixture. | 428 * @param {Test} fixture Test fixture. |
328 */ | 429 */ |
329 function mockOnNotificationClickedDependencies(fixture) { | 430 function mockOnNotificationClickedDependencies(fixture) { |
330 fixture.makeAndRegisterMockApis([ | 431 fixture.makeAndRegisterMockApis([ |
331 'chrome.windows.create', | 432 'chrome.windows.create', |
332 'chrome.windows.update', | 433 'chrome.windows.update', |
333 'fillFromChromeLocalStorage', | 434 'fillFromChromeLocalStorage', |
334 'instrumented.tabs.create']); | 435 'instrumented.tabs.create']); |
335 } | 436 } |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 eqJSON({ | 975 eqJSON({ |
875 notificationGroups: expectedUpdatedGroups, | 976 notificationGroups: expectedUpdatedGroups, |
876 recentDismissals: {}})); | 977 recentDismissals: {}})); |
877 | 978 |
878 this.mockGlobals.expects(once()). | 979 this.mockGlobals.expects(once()). |
879 recordEvent(GoogleNowEvent.CARDS_PARSE_SUCCESS); | 980 recordEvent(GoogleNowEvent.CARDS_PARSE_SUCCESS); |
880 | 981 |
881 // Invoking the tested function. | 982 // Invoking the tested function. |
882 processServerResponse(serverResponse, fakeOnCardShownFunction); | 983 processServerResponse(serverResponse, fakeOnCardShownFunction); |
883 }); | 984 }); |
OLD | NEW |