| 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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 var testNotificationData = { | 473 var testNotificationData = { |
| 474 notificationsData: {'TEST_ID': {actionUrls: testActionUrls}} | 474 notificationsData: {'TEST_ID': {actionUrls: testActionUrls}} |
| 475 }; | 475 }; |
| 476 | 476 |
| 477 mockOnNotificationClickedDependencies(this); | 477 mockOnNotificationClickedDependencies(this); |
| 478 this.makeMockLocalFunctions(['selector']); | 478 this.makeMockLocalFunctions(['selector']); |
| 479 | 479 |
| 480 expectChromeLocalStorageGet( | 480 expectChromeLocalStorageGet( |
| 481 this, testNotificationDataRequest, testNotificationData); | 481 this, testNotificationDataRequest, testNotificationData); |
| 482 | 482 |
| 483 this.mockLocalFunctions.expects(once()).selector(undefined).will( | 483 this.mockLocalFunctions.expects(once()) |
| 484 returnValue(undefined)); | 484 .selector(eqJSON( |
| 485 testNotificationData.notificationsData[testNotificationId])) |
| 486 .will(returnValue(undefined)); |
| 485 | 487 |
| 486 // Invoking the tested function. | 488 // Invoking the tested function. |
| 487 onNotificationClicked( | 489 onNotificationClicked( |
| 488 testNotificationId, this.mockLocalFunctions.functions().selector); | 490 testNotificationId, this.mockLocalFunctions.functions().selector); |
| 489 }); | 491 }); |
| 490 | 492 |
| 491 TEST_F( | 493 TEST_F( |
| 492 'GoogleNowBackgroundUnitTest', | 494 'GoogleNowBackgroundUnitTest', |
| 493 'OnNotificationClicked_TabCreateSuccess', | 495 'OnNotificationClicked_TabCreateSuccess', |
| 494 function() { | 496 function() { |
| 495 // Tests the selected URL is OK and crome.tabs.create suceeds. | 497 // Tests the selected URL is OK and crome.tabs.create suceeds. |
| 496 | 498 |
| 497 // Setup and expectations. | 499 // Setup and expectations. |
| 498 var testActionUrls = {testField: 'TEST VALUE'}; | 500 var testActionUrls = {testField: 'TEST VALUE'}; |
| 499 var testNotificationId = 'TEST_ID'; | 501 var testNotificationId = 'TEST_ID'; |
| 500 var testNotificationDataRequest = {notificationsData: {}}; | 502 var testNotificationDataRequest = {notificationsData: {}}; |
| 501 var testNotificationData = { | 503 var testNotificationData = { |
| 502 notificationsData: {'TEST_ID': {actionUrls: testActionUrls}} | 504 notificationsData: {'TEST_ID': {actionUrls: testActionUrls}} |
| 503 }; | 505 }; |
| 504 var testActionUrl = 'http://testurl.com'; | 506 var testActionUrl = 'http://testurl.com'; |
| 505 var testCreatedTab = {windowId: 239}; | 507 var testCreatedTab = {windowId: 239}; |
| 506 | 508 |
| 507 mockOnNotificationClickedDependencies(this); | 509 mockOnNotificationClickedDependencies(this); |
| 508 this.makeMockLocalFunctions(['selector']); | 510 this.makeMockLocalFunctions(['selector']); |
| 509 | 511 |
| 510 expectChromeLocalStorageGet( | 512 expectChromeLocalStorageGet( |
| 511 this, testNotificationDataRequest, testNotificationData); | 513 this, testNotificationDataRequest, testNotificationData); |
| 512 this.mockLocalFunctions.expects(once()).selector(testActionUrls).will( | 514 this.mockLocalFunctions.expects(once()) |
| 513 returnValue(testActionUrl)); | 515 .selector(eqJSON( |
| 516 testNotificationData.notificationsData[testNotificationId])) |
| 517 .will(returnValue(testActionUrl)); |
| 514 var chromeTabsCreateSavedArgs = new SaveMockArguments(); | 518 var chromeTabsCreateSavedArgs = new SaveMockArguments(); |
| 515 this.mockApis.expects(once()). | 519 this.mockApis.expects(once()). |
| 516 instrumented_tabs_create( | 520 instrumented_tabs_create( |
| 517 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), | 521 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), |
| 518 chromeTabsCreateSavedArgs.match(ANYTHING)). | 522 chromeTabsCreateSavedArgs.match(ANYTHING)). |
| 519 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); | 523 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); |
| 520 this.mockApis.expects(once()).chrome_windows_update( | 524 this.mockApis.expects(once()).chrome_windows_update( |
| 521 testCreatedTab.windowId, | 525 testCreatedTab.windowId, |
| 522 eqJSON({focused: true})); | 526 eqJSON({focused: true})); |
| 523 | 527 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 542 notificationsData: {'TEST_ID': {actionUrls: testActionUrls}} | 546 notificationsData: {'TEST_ID': {actionUrls: testActionUrls}} |
| 543 }; | 547 }; |
| 544 var testActionUrl = 'http://testurl.com'; | 548 var testActionUrl = 'http://testurl.com'; |
| 545 var testCreatedTab = undefined; // chrome.tabs.create fails | 549 var testCreatedTab = undefined; // chrome.tabs.create fails |
| 546 | 550 |
| 547 mockOnNotificationClickedDependencies(this); | 551 mockOnNotificationClickedDependencies(this); |
| 548 this.makeMockLocalFunctions(['selector']); | 552 this.makeMockLocalFunctions(['selector']); |
| 549 | 553 |
| 550 expectChromeLocalStorageGet( | 554 expectChromeLocalStorageGet( |
| 551 this, testNotificationDataRequest, testNotificationData); | 555 this, testNotificationDataRequest, testNotificationData); |
| 552 this.mockLocalFunctions.expects(once()).selector(testActionUrls).will( | 556 this.mockLocalFunctions.expects(once()) |
| 553 returnValue(testActionUrl)); | 557 .selector(eqJSON( |
| 558 testNotificationData.notificationsData[testNotificationId])) |
| 559 .will(returnValue(testActionUrl)); |
| 554 var chromeTabsCreateSavedArgs = new SaveMockArguments(); | 560 var chromeTabsCreateSavedArgs = new SaveMockArguments(); |
| 555 this.mockApis.expects(once()). | 561 this.mockApis.expects(once()). |
| 556 instrumented_tabs_create( | 562 instrumented_tabs_create( |
| 557 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), | 563 chromeTabsCreateSavedArgs.match(eqJSON({url: testActionUrl})), |
| 558 chromeTabsCreateSavedArgs.match(ANYTHING)). | 564 chromeTabsCreateSavedArgs.match(ANYTHING)). |
| 559 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); | 565 will(invokeCallback(chromeTabsCreateSavedArgs, 1, testCreatedTab)); |
| 560 this.mockApis.expects(once()).chrome_windows_create( | 566 this.mockApis.expects(once()).chrome_windows_create( |
| 561 eqJSON({url: testActionUrl, focused: true})); | 567 eqJSON({url: testActionUrl, focused: true})); |
| 562 | 568 |
| 563 // Invoking the tested function. | 569 // Invoking the tested function. |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 eqJSON({ | 981 eqJSON({ |
| 976 notificationGroups: expectedUpdatedGroups, | 982 notificationGroups: expectedUpdatedGroups, |
| 977 recentDismissals: {}})); | 983 recentDismissals: {}})); |
| 978 | 984 |
| 979 this.mockGlobals.expects(once()). | 985 this.mockGlobals.expects(once()). |
| 980 recordEvent(GoogleNowEvent.CARDS_PARSE_SUCCESS); | 986 recordEvent(GoogleNowEvent.CARDS_PARSE_SUCCESS); |
| 981 | 987 |
| 982 // Invoking the tested function. | 988 // Invoking the tested function. |
| 983 processServerResponse(serverResponse, fakeOnCardShownFunction); | 989 processServerResponse(serverResponse, fakeOnCardShownFunction); |
| 984 }); | 990 }); |
| OLD | NEW |