Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Unified Diff: chrome/browser/resources/google_now/background_unittest.gtestjs

Issue 107033002: Combining cards instead of merging (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rgistafson's verbal comment Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/google_now/background.js ('k') | chrome/browser/resources/google_now/cards.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/google_now/background_unittest.gtestjs
diff --git a/chrome/browser/resources/google_now/background_unittest.gtestjs b/chrome/browser/resources/google_now/background_unittest.gtestjs
index a837bfe4bf67c7ac720d5da2e6c18b34aefff1c4..0099576f4a1e4c67b983095e34186f27dff82e50 100644
--- a/chrome/browser/resources/google_now/background_unittest.gtestjs
+++ b/chrome/browser/resources/google_now/background_unittest.gtestjs
@@ -51,406 +51,6 @@ TEST_F('GoogleNowBackgroundUnitTest', 'AreTasksConflicting', function() {
testTaskPair(STATE_CHANGED_TASK_NAME, STATE_CHANGED_TASK_NAME, false);
});
-var testNotificationId = 'TEST GROUP-SOME TEST ID';
-var testChromeNotificationId = 'TEST CARD ID';
-var testNotification1 =
- {testNotificationField: 'TEST NOTIFICATION VALUE1', priority: -1};
-var testNotification2 =
- {testNotificationField: 'TEST NOTIFICATION VALUE2', priority: 0};
-var testActionUrls1 = {testField: 'TEST VALUE1'};
-var testActionUrls2 = {testField: 'TEST VALUE2'};
-var testDismissal1 = {testDismissalField: 'TEST DISMISSAL VALUE 1'};
-var testDismissal2 = {testDismissalField: 'TEST DISMISSAL VALUE 2'};
-var testVersion = 7;
-var testTimestamp1 = 300000;
-var testTimestamp2 = 600000;
-var testGroupRank1 = 19;
-var testGroupRank2 = 23;
-var testTriggerUnmerged = {showTimeSec: 100, hideTimeSec: 200};
-var testTriggerMerged = {showTime: 300007, hideTime: 300011};
-var testVersion1 = 29;
-var testVersion2 = 31;
-
-TEST_F(
- 'GoogleNowBackgroundUnitTest',
- 'MergeCardsEmptyNoTrigger',
- function() {
- // Tests merging a card with an empty trigger into an 'undefined' merged
- // card. This should start a new card.
-
- // Invoking the tested function.
- var resultingMergedCard = mergeCards(undefined, {
- notificationId: testNotificationId,
- chromeNotificationId: testChromeNotificationId,
- version: testVersion1,
- chromeNotificationOptions: testNotification1,
- actionUrls: testActionUrls1,
- dismissal: testDismissal1
- }, testTimestamp1, testGroupRank1);
-
- // Check the return value.
- assertEquals(
- JSON.stringify({
- dismissals: [
- {
- notificationId: testNotificationId,
- parameters: testDismissal1
- }
- ],
- groupRank: testGroupRank1,
- trigger: {},
- timestamp: testTimestamp1,
- notification: testNotification1,
- actionUrls: testActionUrls1,
- version: testVersion1
- }),
- JSON.stringify(resultingMergedCard));
- });
-
-TEST_F(
- 'GoogleNowBackgroundUnitTest',
- 'MergeCards1',
- function() {
- // Tests merging a unmerged card into a merged card.
- // Unmerged card priority is greater than merged card one. Unmerged card
- // rank is less than merged card one, and it's older.
-
- // Setup.
- var mergedCard = {
- trigger: testTriggerMerged,
- version: testVersion1,
- timestamp: testTimestamp2,
- notification: testNotification1,
- actionUrls: testActionUrls1,
- groupRank: testGroupRank2,
- dismissals:
- [{notificationId: testNotificationId, parameters: testDismissal1}]
- };
-
- var unmergedNotification = {
- notificationId: testNotificationId,
- chromeNotificationId: testChromeNotificationId,
- version: testVersion2,
- chromeNotificationOptions: testNotification2,
- actionUrls: testActionUrls2,
- dismissal: testDismissal2,
- trigger: testTriggerUnmerged
- };
-
- // Invoking the tested function.
- var resultingMergedCard = mergeCards(
- mergedCard, unmergedNotification, testTimestamp1, testGroupRank1);
-
- // Check the return value.
- assertEquals(
- JSON.stringify({
- trigger: testTriggerMerged,
- version: testVersion1,
- timestamp: testTimestamp2,
- notification: {
- testNotificationField: 'TEST NOTIFICATION VALUE1',
- priority: 0
- },
- actionUrls: testActionUrls1,
- groupRank: testGroupRank2,
- dismissals: [
- {notificationId: testNotificationId, parameters: testDismissal1},
- {notificationId: testNotificationId, parameters: testDismissal2}
- ]
- }),
- JSON.stringify(resultingMergedCard));
- });
-
-TEST_F(
- 'GoogleNowBackgroundUnitTest',
- 'MergeCards2',
- function() {
- // Tests merging a unmerged card into a merged card.
- // Unmerged card priority is less than merged card one. Unmerged card rank
- // is greater than merged card one, and it's older.
-
- // Setup.
- var mergedCard = {
- trigger: testTriggerMerged,
- version: testVersion1,
- timestamp: testTimestamp2,
- notification: testNotification2,
- actionUrls: testActionUrls1,
- groupRank: testGroupRank1,
- dismissals:
- [{notificationId: testNotificationId, parameters: testDismissal1}]
- };
-
- var unmergedNotification = {
- notificationId: testNotificationId,
- chromeNotificationId: testChromeNotificationId,
- version: testVersion2,
- chromeNotificationOptions: testNotification1,
- actionUrls: testActionUrls2,
- dismissal: testDismissal2,
- trigger: testTriggerUnmerged
- };
-
- // Invoking the tested function.
- var resultingMergedCard = mergeCards(
- mergedCard, unmergedNotification, testTimestamp1, testGroupRank2);
-
- // Check the return value.
- assertEquals(
- JSON.stringify({
- trigger: {showTime: 400000, hideTime: 500000},
- version: testVersion1,
- timestamp: testTimestamp2,
- notification: {
- testNotificationField: 'TEST NOTIFICATION VALUE2',
- priority: 0
- },
- actionUrls: testActionUrls1,
- groupRank: testGroupRank2,
- dismissals: [
- {notificationId: testNotificationId, parameters: testDismissal1},
- {notificationId: testNotificationId, parameters: testDismissal2}
- ]
- }),
- JSON.stringify(resultingMergedCard));
- });
-
-TEST_F(
- 'GoogleNowBackgroundUnitTest',
- 'MergeCards3',
- function() {
- // Tests merging a unmerged card into a merged card.
- // Unmerged card priority is less than merged card one. Unmerged card rank
- // is less than merged card one, and it's newer.
-
- // Setup.
- var mergedCard = {
- trigger: testTriggerMerged,
- version: testVersion1,
- timestamp: testTimestamp1,
- notification: testNotification2,
- actionUrls: testActionUrls1,
- groupRank: testGroupRank2,
- dismissals:
- [{notificationId: testNotificationId, parameters: testDismissal1}]
- };
-
- var unmergedNotification = {
- notificationId: testNotificationId,
- chromeNotificationId: testChromeNotificationId,
- version: testVersion2,
- chromeNotificationOptions: testNotification1,
- actionUrls: testActionUrls2,
- dismissal: testDismissal2,
- trigger: testTriggerUnmerged
- };
-
- // Invoking the tested function.
- var resultingMergedCard = mergeCards(
- mergedCard, unmergedNotification, testTimestamp2, testGroupRank1);
-
- // Check the return value.
- assertEquals(
- JSON.stringify({
- trigger: testTriggerMerged,
- version: testVersion2,
- timestamp: testTimestamp2,
- notification: {
- testNotificationField: 'TEST NOTIFICATION VALUE1',
- priority: 0
- },
- actionUrls: testActionUrls2,
- groupRank: testGroupRank2,
- dismissals: [
- {notificationId: testNotificationId, parameters: testDismissal1},
- {notificationId: testNotificationId, parameters: testDismissal2}
- ]
- }),
- JSON.stringify(resultingMergedCard));
- });
-
-TEST_F(
- 'GoogleNowBackgroundUnitTest',
- 'MergeGroup',
- function() {
- // Tests mergeGroup method.
-
- // Setup.
- this.makeAndRegisterMockGlobals(['mergeCards']);
-
- this.mockGlobals.expects(once()).
- mergeCards(
- undefined,
- eqJSON({chromeNotificationId: 'ID 1', testField: 'TEST_FIELD1'}),
- 300000,
- 17).
- will(returnValue({testField: 'RESULT 1'}));
- this.mockGlobals.expects(once()).
- mergeCards(
- eqJSON({testField: 'TEST_FIELD22'}),
- eqJSON({chromeNotificationId: 'ID 2', testField: 'TEST_FIELD2'}),
- 300000,
- 17).
- will(returnValue({testField: 'RESULT 2'}));
-
- var group = {
- cards: [
- {chromeNotificationId: 'ID 1', testField: 'TEST_FIELD1'},
- {chromeNotificationId: 'ID 2', testField: 'TEST_FIELD2'}
- ],
- cardsTimestamp: 300000,
- nextPollTime: 600000,
- rank: 17
- };
-
- var mergedCards = {
- 'ID 2': { testField: 'TEST_FIELD22' },
- 'ID 3': { testField: 'TEST_FIELD3' }
- };
-
- // Invoking the tested function.
- mergeGroup(mergedCards, group);
-
- // Check the output parameter.
- assertEquals(
- JSON.stringify({
- 'ID 2': { testField: 'RESULT 2' },
- 'ID 3': { testField: 'TEST_FIELD3'},
- 'ID 1': { testField: 'RESULT 1' }}),
- JSON.stringify(mergedCards));
- });
-
-TEST_F(
- 'GoogleNowBackgroundUnitTest',
- 'MergeAndShowNotificationCards',
- function() {
- // Tests mergeAndShowNotificationCards function.
- // The test passes 2 groups to mergeAndShowNotificationCards, checks that
- // it calls mergeGroup() for each of these groups and calls
- // showNotificationCards() with the results of these mergeGroup() calls.
-
- // Setup and expectations.
- var testGroups = {
- 'TEST GROUP 1': {testField: 'TEST VALUE 1'},
- 'TEST GROUP 2': {testField: 'TEST VALUE 2'}
- };
-
- this.makeAndRegisterMockGlobals(['mergeGroup', 'showNotificationCards']);
-
- var mergeGroupSavedArgs = new SaveMockArguments();
- this.mockGlobals.expects(once()).
- mergeGroup(
- mergeGroupSavedArgs.match(eqJSON({})),
- mergeGroupSavedArgs.match(eqJSON({testField: 'TEST VALUE 1'}))).
- will(callFunction(function() {
- mergeGroupSavedArgs.arguments[0].card1 = {
- testValue: 'TEST CARD VALUE 1'
- };
- }));
- this.mockGlobals.expects(once()).
- mergeGroup(
- mergeGroupSavedArgs.match(
- eqJSON({card1: {testValue: 'TEST CARD VALUE 1'}})),
- mergeGroupSavedArgs.match(
- eqJSON({testField: 'TEST VALUE 2'}))).
- will(callFunction(function() {
- mergeGroupSavedArgs.arguments[0].card2 = {
- testValue: 'TEST CARD VALUE 2'
- };
- }));
- this.mockGlobals.expects(once()).
- showNotificationCards(
- eqJSON({
- card1: {testValue: 'TEST CARD VALUE 1'},
- card2: {testValue: 'TEST CARD VALUE 2'}
- }),
- ANYTHING);
-
- // Invoking the tested function.
- mergeAndShowNotificationCards(testGroups, function() {});
- });
-
-// TODO(vadimt): Add more tests for parseAndShowNotificationCards().
-TEST_F(
- 'GoogleNowBackgroundUnitTest',
- 'ParseAndShowNotificationCardsAdd1Remove1',
- function() {
- // Tests parseAndShowNotificationCards function for the case when the
- // extension has 2 groups, and the server sends update with 2 groups, one
- // of which is new, and another one matches a stored group. The client
- // has to delete the group that didn't receive an update, keep the
- // existing group that received an update, and add a new stored group for
- // the new group from the server.
-
- // Setup and expectations.
- var serverResponse = {
- groups: {
- GROUP1: {},
- GROUP2: {}
- }
- };
-
- var storedGroups = {
- GROUP2: {
- cards: ['c2'],
- cardsTimestamp: 239,
- nextPollTime: 10000,
- rank: 1
- },
- GROUP3: {
- cards: ['c3'],
- cardsTimestamp: 240,
- nextPollTime: 10001,
- rank: 2
- }
- };
-
- var expectedUpdatedGroups = {
- GROUP1: {
- cards: []
- },
- GROUP2: {
- cards: ['c2'],
- cardsTimestamp: 239,
- nextPollTime: 10000,
- rank: 1
- }
- };
-
- this.makeAndRegisterMockGlobals(
- ['scheduleNextPoll', 'mergeAndShowNotificationCards', 'recordEvent']);
-
- this.makeAndRegisterMockApis([
- 'chrome.storage.local.set',
- 'instrumented.storage.local.get'
- ]);
-
- var storageGetSavedArgs = new SaveMockArguments();
- this.mockApis.expects(once()).
- instrumented_storage_local_get(
- storageGetSavedArgs.match(eq('notificationGroups')),
- storageGetSavedArgs.match(ANYTHING)).
- will(invokeCallback(
- storageGetSavedArgs, 1, {notificationGroups: storedGroups}));
-
- this.mockGlobals.expects(once()).
- scheduleNextPoll(eqJSON(expectedUpdatedGroups), true);
-
- this.mockApis.expects(once()).
- chrome_storage_local_set(
- eqJSON({notificationGroups: expectedUpdatedGroups}));
-
- this.mockGlobals.expects(once()).
- mergeAndShowNotificationCards(
- eqJSON(expectedUpdatedGroups), ANYTHING);
-
- this.mockGlobals.expects(once()).
- recordEvent(GoogleNowEvent.CARDS_PARSE_SUCCESS);
-
- // Invoking the tested function.
- parseAndShowNotificationCards(JSON.stringify(serverResponse));
- });
-
/**
* Mocks global functions and APIs that initialize() depends upon.
* @param {Test} fixture Test fixture.
« no previous file with comments | « chrome/browser/resources/google_now/background.js ('k') | chrome/browser/resources/google_now/cards.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698