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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 initialize(); | 373 initialize(); |
374 }); | 374 }); |
375 | 375 |
376 /** | 376 /** |
377 * Mocks global functions and APIs that onNotificationClicked() depends upon. | 377 * Mocks global functions and APIs that onNotificationClicked() depends upon. |
378 * @param {Test} fixture Test fixture. | 378 * @param {Test} fixture Test fixture. |
379 */ | 379 */ |
380 function mockOnNotificationClickedDependencies(fixture) { | 380 function mockOnNotificationClickedDependencies(fixture) { |
381 fixture.makeAndRegisterMockApis([ | 381 fixture.makeAndRegisterMockApis([ |
382 'chrome.windows.create', | 382 'chrome.windows.create', |
| 383 'chrome.windows.update', |
383 'instrumented.storage.local.get', | 384 'instrumented.storage.local.get', |
384 'instrumented.tabs.create']); | 385 'instrumented.tabs.create']); |
385 } | 386 } |
386 | 387 |
387 TEST_F( | 388 TEST_F( |
388 'GoogleNowBackgroundUnitTest', | 389 'GoogleNowBackgroundUnitTest', |
389 'OnNotificationClicked_NoData', | 390 'OnNotificationClicked_NoData', |
390 function() { | 391 function() { |
391 // Tests the case when there is no data associated with notification id. | 392 // Tests the case when there is no data associated with notification id. |
392 // In this case, the function should do nothing. | 393 // In this case, the function should do nothing. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 function() { | 480 function() { |
480 // Tests the selected URL is OK and crome.tabs.create suceeds. | 481 // Tests the selected URL is OK and crome.tabs.create suceeds. |
481 | 482 |
482 // Setup and expectations. | 483 // Setup and expectations. |
483 var testActionUrls = {testField: 'TEST VALUE'}; | 484 var testActionUrls = {testField: 'TEST VALUE'}; |
484 var testNotificationId = 'TEST_ID'; | 485 var testNotificationId = 'TEST_ID'; |
485 var testNotificationData = { | 486 var testNotificationData = { |
486 notificationsData: {'TEST_ID': {actionUrls: testActionUrls}} | 487 notificationsData: {'TEST_ID': {actionUrls: testActionUrls}} |
487 }; | 488 }; |
488 var testActionUrl = 'http://testurl.com'; | 489 var testActionUrl = 'http://testurl.com'; |
489 var testCreatedTab = {}; | 490 var testCreatedTab = {windowId: 239}; |
490 | 491 |
491 mockOnNotificationClickedDependencies(this); | 492 mockOnNotificationClickedDependencies(this); |
492 this.makeMockLocalFunctions(['selector']); | 493 this.makeMockLocalFunctions(['selector']); |
493 | 494 |
494 var storageGetSavedArgs = new SaveMockArguments(); | 495 var storageGetSavedArgs = new SaveMockArguments(); |
495 this.mockApis.expects(once()). | 496 this.mockApis.expects(once()). |
496 instrumented_storage_local_get( | 497 instrumented_storage_local_get( |
497 storageGetSavedArgs.match(eq('notificationsData')), | 498 storageGetSavedArgs.match(eq('notificationsData')), |
498 storageGetSavedArgs.match(ANYTHING)). | 499 storageGetSavedArgs.match(ANYTHING)). |
499 will(invokeCallback(storageGetSavedArgs, 1, testNotificationData)); | 500 will(invokeCallback(storageGetSavedArgs, 1, testNotificationData)); |
500 this.mockLocalFunctions.expects(once()).selector(testActionUrls).will( | 501 this.mockLocalFunctions.expects(once()).selector(testActionUrls).will( |
501 returnValue(testActionUrl)); | 502 returnValue(testActionUrl)); |
502 var chromeTabsCreateSavedArgs = new SaveMockArguments(); | 503 var chromeTabsCreateSavedArgs = new SaveMockArguments(); |
503 this.mockApis.expects(once()). | 504 this.mockApis.expects(once()). |
504 instrumented_tabs_create( | 505 instrumented_tabs_create( |
505 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), | 506 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), |
506 chromeTabsCreateSavedArgs.match(ANYTHING)). | 507 chromeTabsCreateSavedArgs.match(ANYTHING)). |
507 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); | 508 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); |
| 509 this.mockApis.expects(once()).chrome_windows_update( |
| 510 testCreatedTab.windowId, |
| 511 eqJSON({focused: true})); |
508 | 512 |
509 // Invoking the tested function. | 513 // Invoking the tested function. |
510 onNotificationClicked( | 514 onNotificationClicked( |
511 testNotificationId, this.mockLocalFunctions.functions().selector); | 515 testNotificationId, this.mockLocalFunctions.functions().selector); |
512 }); | 516 }); |
513 | 517 |
514 TEST_F( | 518 TEST_F( |
515 'GoogleNowBackgroundUnitTest', | 519 'GoogleNowBackgroundUnitTest', |
516 'OnNotificationClicked_TabCreateFail', | 520 'OnNotificationClicked_TabCreateFail', |
517 function() { | 521 function() { |
(...skipping 21 matching lines...) Expand all Loading... |
539 will(invokeCallback(storageGetSavedArgs, 1, testNotificationData)); | 543 will(invokeCallback(storageGetSavedArgs, 1, testNotificationData)); |
540 this.mockLocalFunctions.expects(once()).selector(testActionUrls).will( | 544 this.mockLocalFunctions.expects(once()).selector(testActionUrls).will( |
541 returnValue(testActionUrl)); | 545 returnValue(testActionUrl)); |
542 var chromeTabsCreateSavedArgs = new SaveMockArguments(); | 546 var chromeTabsCreateSavedArgs = new SaveMockArguments(); |
543 this.mockApis.expects(once()). | 547 this.mockApis.expects(once()). |
544 instrumented_tabs_create( | 548 instrumented_tabs_create( |
545 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), | 549 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), |
546 chromeTabsCreateSavedArgs.match(ANYTHING)). | 550 chromeTabsCreateSavedArgs.match(ANYTHING)). |
547 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); | 551 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); |
548 this.mockApis.expects(once()).chrome_windows_create( | 552 this.mockApis.expects(once()).chrome_windows_create( |
549 eqJSON({url: testActionUrl})); | 553 eqJSON({url: testActionUrl, focused: true})); |
550 | 554 |
551 // Invoking the tested function. | 555 // Invoking the tested function. |
552 onNotificationClicked( | 556 onNotificationClicked( |
553 testNotificationId, this.mockLocalFunctions.functions().selector); | 557 testNotificationId, this.mockLocalFunctions.functions().selector); |
554 }); | 558 }); |
OLD | NEW |