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

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

Issue 32583004: Some unit tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: robliao@ comments Created 7 years, 2 months 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 | « no previous file | no next file » | 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 21bd1882825c0200bbc2348e01ed7c45de9277e4..b6e929910d0b20bbbf0e427ed6f066102b6e32ab 100644
--- a/chrome/browser/resources/google_now/background_unittest.gtestjs
+++ b/chrome/browser/resources/google_now/background_unittest.gtestjs
@@ -318,6 +318,137 @@ TEST_F(
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'}
+ }));
+
+ // Invoking the tested function.
+ mergeAndShowNotificationCards(testGroups);
+ });
+
+// 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.
+ Date.now = function() { return 500; };
+
+ 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: [],
+ nextPollTime: Date.now()
+ },
+ 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));
+
+ this.mockApis.expects(once()).
+ chrome_storage_local_set(
+ eqJSON({notificationGroups: expectedUpdatedGroups}));
+
+ this.mockGlobals.expects(once()).
+ mergeAndShowNotificationCards(eqJSON(expectedUpdatedGroups));
+
+ 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 | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698