| 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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 } | 400 } |
| 401 | 401 |
| 402 /** | 402 /** |
| 403 * Sets up the test to expect the initialization calls that | 403 * Sets up the test to expect the initialization calls that |
| 404 * initialize() invokes. | 404 * initialize() invokes. |
| 405 * Note that this CAN NOT be used if any of the methods below are called | 405 * Note that this CAN NOT be used if any of the methods below are called |
| 406 * outside of this context with the same argument matchers. | 406 * outside of this context with the same argument matchers. |
| 407 * expects() calls cannot be chained with the same argument matchers. | 407 * expects() calls cannot be chained with the same argument matchers. |
| 408 */ | 408 */ |
| 409 function expectInitialization(mockApisObj) { | 409 function expectInitialization(mockApisObj) { |
| 410 mockApisObj.expects(once()). | |
| 411 chrome_location_clearWatch(ANYTHING); | |
| 412 mockApisObj.expects(once()). | |
| 413 updateCardsAttempts_stop(); | |
| 414 mockApisObj.expects(once()). | |
| 415 chrome_storage_local_remove( | |
| 416 eqJSON(['notificationsData', 'notificationGroups'])); | |
| 417 var tasksAddSavedArgs = new SaveMockArguments(); | 410 var tasksAddSavedArgs = new SaveMockArguments(); |
| 418 mockApisObj.expects(once()). | 411 mockApisObj.expects(once()). |
| 419 tasks_add( | 412 tasks_add( |
| 420 tasksAddSavedArgs.match(ANYTHING), | 413 tasksAddSavedArgs.match(ANYTHING), |
| 421 tasksAddSavedArgs.match(ANYTHING)). | 414 tasksAddSavedArgs.match(ANYTHING)). |
| 422 will(invokeCallback(tasksAddSavedArgs, 1, function() {})); | 415 will(invokeCallback(tasksAddSavedArgs, 1, function() {})); |
| 423 var updateCardsAttemptsIsRunningSavedArgs = new SaveMockArguments(); | 416 var updateCardsAttemptsIsRunningSavedArgs = new SaveMockArguments(); |
| 424 mockApisObj.expects(once()). | 417 mockApisObj.expects(once()). |
| 425 updateCardsAttempts_isRunning( | 418 updateCardsAttempts_isRunning( |
| 426 updateCardsAttemptsIsRunningSavedArgs.match(ANYTHING)). | 419 updateCardsAttemptsIsRunningSavedArgs.match(ANYTHING)). |
| (...skipping 28 matching lines...) Expand all Loading... |
| 455 expectInitialization(this.mockApis); | 448 expectInitialization(this.mockApis); |
| 456 | 449 |
| 457 expectStateMachineCalls( | 450 expectStateMachineCalls( |
| 458 this, | 451 this, |
| 459 testIdentityToken, | 452 testIdentityToken, |
| 460 testGeolocationPref, | 453 testGeolocationPref, |
| 461 testUserRespondedToToast, | 454 testUserRespondedToToast, |
| 462 testExperimentVariationParams); | 455 testExperimentVariationParams); |
| 463 | 456 |
| 464 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); | 457 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); |
| 465 this.mockApis.expects(exactly(2)). | 458 this.mockApis.expects(exactly(1)). |
| 466 instrumented_notifications_getAll( | 459 instrumented_notifications_getAll( |
| 467 chromeNotificationGetAllSavedArgs.match(ANYTHING)). | 460 chromeNotificationGetAllSavedArgs.match(ANYTHING)). |
| 468 will( | 461 will(invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); |
| 469 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}), | |
| 470 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); | |
| 471 | 462 |
| 472 // TODO(robliao,vadimt): Determine the granularity of testing to perform. | 463 // TODO(robliao,vadimt): Determine the granularity of testing to perform. |
| 473 | 464 |
| 474 // Invoking the tested function. | 465 // Invoking the tested function. |
| 475 initialize(); | 466 initialize(); |
| 476 }); | 467 }); |
| 477 | 468 |
| 478 TEST_F( | 469 TEST_F( |
| 479 'GoogleNowBackgroundUnitTest', | 470 'GoogleNowBackgroundUnitTest', |
| 480 'Initialize_ToastStateEmpty2', | 471 'Initialize_ToastStateEmpty2', |
| (...skipping 20 matching lines...) Expand all Loading... |
| 501 expectInitialization(this.mockApis); | 492 expectInitialization(this.mockApis); |
| 502 | 493 |
| 503 expectStateMachineCalls( | 494 expectStateMachineCalls( |
| 504 this, | 495 this, |
| 505 testIdentityToken, | 496 testIdentityToken, |
| 506 testGeolocationPref, | 497 testGeolocationPref, |
| 507 testUserRespondedToToast, | 498 testUserRespondedToToast, |
| 508 testExperimentVariationParams); | 499 testExperimentVariationParams); |
| 509 | 500 |
| 510 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); | 501 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); |
| 511 this.mockApis.expects(exactly(2)). | 502 this.mockApis.expects(exactly(1)). |
| 512 instrumented_notifications_getAll( | 503 instrumented_notifications_getAll( |
| 513 chromeNotificationGetAllSavedArgs.match(ANYTHING)). | 504 chromeNotificationGetAllSavedArgs.match(ANYTHING)). |
| 514 will( | 505 will(invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); |
| 515 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}), | |
| 516 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); | |
| 517 | 506 |
| 518 // Invoking the tested function. | 507 // Invoking the tested function. |
| 519 initialize(); | 508 initialize(); |
| 520 }); | 509 }); |
| 521 | 510 |
| 522 TEST_F( | 511 TEST_F( |
| 523 'GoogleNowBackgroundUnitTest', | 512 'GoogleNowBackgroundUnitTest', |
| 524 'DISABLED_Initialize_ToastStateEmpty3', | 513 'DISABLED_Initialize_ToastStateEmpty3', |
| 525 function() { | 514 function() { |
| 526 // Tests the case when NOTIFICATION_CARDS_URL is set, getAuthToken | 515 // Tests the case when NOTIFICATION_CARDS_URL is set, getAuthToken |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 expectInitialization(this.mockApis); | 570 expectInitialization(this.mockApis); |
| 582 | 571 |
| 583 expectStateMachineCalls( | 572 expectStateMachineCalls( |
| 584 this, | 573 this, |
| 585 testIdentityToken, | 574 testIdentityToken, |
| 586 testGeolocationPref, | 575 testGeolocationPref, |
| 587 testUserRespondedToToast, | 576 testUserRespondedToToast, |
| 588 testExperimentVariationParams); | 577 testExperimentVariationParams); |
| 589 | 578 |
| 590 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); | 579 var chromeNotificationGetAllSavedArgs = new SaveMockArguments(); |
| 591 this.mockApis.expects(exactly(2)). | 580 this.mockApis.expects(exactly(1)). |
| 592 instrumented_notifications_getAll( | 581 instrumented_notifications_getAll( |
| 593 chromeNotificationGetAllSavedArgs.match(ANYTHING)). | 582 chromeNotificationGetAllSavedArgs.match(ANYTHING)). |
| 594 will( | 583 will(invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); |
| 595 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {}), | |
| 596 invokeCallback(chromeNotificationGetAllSavedArgs, 0, {})); | |
| 597 | 584 |
| 598 this.mockGlobals.expects(once()).startPollingCards(); | 585 this.mockGlobals.expects(once()).startPollingCards(); |
| 599 | 586 |
| 600 // Invoking the tested function. | 587 // Invoking the tested function. |
| 601 initialize(); | 588 initialize(); |
| 602 }); | 589 }); |
| 603 | 590 |
| 604 TEST_F( | 591 TEST_F( |
| 605 'GoogleNowBackgroundUnitTest', | 592 'GoogleNowBackgroundUnitTest', |
| 606 'DISABLED_Initialize_NoGeolocation', | 593 'DISABLED_Initialize_NoGeolocation', |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), | 776 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), |
| 790 chromeTabsCreateSavedArgs.match(ANYTHING)). | 777 chromeTabsCreateSavedArgs.match(ANYTHING)). |
| 791 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); | 778 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); |
| 792 this.mockApis.expects(once()).chrome_windows_create( | 779 this.mockApis.expects(once()).chrome_windows_create( |
| 793 eqJSON({url: testActionUrl, focused: true})); | 780 eqJSON({url: testActionUrl, focused: true})); |
| 794 | 781 |
| 795 // Invoking the tested function. | 782 // Invoking the tested function. |
| 796 onNotificationClicked( | 783 onNotificationClicked( |
| 797 testNotificationId, this.mockLocalFunctions.functions().selector); | 784 testNotificationId, this.mockLocalFunctions.functions().selector); |
| 798 }); | 785 }); |
| OLD | NEW |