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

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

Issue 166033010: Convert Google Now's use of chrome.local.storage.get to use Promises (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to r252941 Created 6 years, 10 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
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 5061584dfbea98880d57a924e8b51dc2acbe25a9..aaf760de96711837d96e3956ab832f5739a7883d 100644
--- a/chrome/browser/resources/google_now/background_unittest.gtestjs
+++ b/chrome/browser/resources/google_now/background_unittest.gtestjs
@@ -65,11 +65,11 @@ function mockInitializeDependencies(fixture) {
'authenticationManager.isSignedIn',
'chrome.location.clearWatch',
'chrome.storage.local.remove',
+ 'fillFromChromeLocalStorage',
'instrumented.metricsPrivate.getVariationParams',
'instrumented.notifications.getAll',
'instrumented.notifications.getPermissionLevel',
'instrumented.preferencesPrivate.googleGeolocationAccessEnabled.get',
- 'instrumented.storage.local.get',
'instrumented.webstorePrivate.getBrowserLogin',
'tasks.add',
'updateCardsAttempts.isRunning',
@@ -131,13 +131,10 @@ function expectStateMachineCalls(
0,
testNotificationPermissionLevel))
- var storageGetSavedArgs = new SaveMockArguments();
- fixture.mockApis.expects(once()).
- instrumented_storage_local_get(
- storageGetSavedArgs.match(eq('googleNowEnabled')),
- storageGetSavedArgs.match(ANYTHING)).
- will(invokeCallback(
- storageGetSavedArgs, 1, {googleNowEnabled: testGoogleNowEnabled}));
+ expectChromeLocalStorageGet(
+ fixture,
+ {googleNowEnabled: false},
+ {googleNowEnabled: testGoogleNowEnabled});
fixture.mockGlobals.expects(once()).
setBackgroundEnable(ANYTHING);
@@ -331,7 +328,7 @@ function mockOnNotificationClickedDependencies(fixture) {
fixture.makeAndRegisterMockApis([
'chrome.windows.create',
'chrome.windows.update',
- 'instrumented.storage.local.get',
+ 'fillFromChromeLocalStorage',
'instrumented.tabs.create']);
}
@@ -344,17 +341,14 @@ TEST_F(
// Setup and expectations.
var testNotificationId = 'TEST_ID';
- var testNotificationData = {};
+ var testNotificationDataRequest = {notificationsData: {}};
+ var testNotificationData = {notificationsData: {}};
mockOnNotificationClickedDependencies(this);
this.makeMockLocalFunctions(['selector']);
- var storageGetSavedArgs = new SaveMockArguments();
- this.mockApis.expects(once()).
- instrumented_storage_local_get(
- storageGetSavedArgs.match(eq('notificationsData')),
- storageGetSavedArgs.match(ANYTHING)).
- will(invokeCallback(storageGetSavedArgs, 1, testNotificationData));
+ expectChromeLocalStorageGet(
+ this, testNotificationDataRequest, testNotificationData);
// Invoking the tested function.
onNotificationClicked(
@@ -372,6 +366,7 @@ TEST_F(
// Setup and expectations.
var testActionUrls = undefined;
var testNotificationId = 'TEST_ID';
+ var testNotificationDataRequest = {notificationsData: {}};
var testNotificationData = {
notificationsData: {'TEST_ID': {actionUrls: testActionUrls}}
};
@@ -379,12 +374,9 @@ TEST_F(
mockOnNotificationClickedDependencies(this);
this.makeMockLocalFunctions(['selector']);
- var storageGetSavedArgs = new SaveMockArguments();
- this.mockApis.expects(once()).
- instrumented_storage_local_get(
- storageGetSavedArgs.match(eq('notificationsData')),
- storageGetSavedArgs.match(ANYTHING)).
- will(invokeCallback(storageGetSavedArgs, 1, testNotificationData));
+ expectChromeLocalStorageGet(
+ this, testNotificationDataRequest, testNotificationData);
+
this.mockLocalFunctions.expects(once()).selector(undefined).will(
returnValue(undefined));
@@ -402,6 +394,7 @@ TEST_F(
// Setup and expectations.
var testActionUrls = {testField: 'TEST VALUE'};
var testNotificationId = 'TEST_ID';
+ var testNotificationDataRequest = {notificationsData: {}};
var testNotificationData = {
notificationsData: {'TEST_ID': {actionUrls: testActionUrls}}
};
@@ -411,12 +404,8 @@ TEST_F(
mockOnNotificationClickedDependencies(this);
this.makeMockLocalFunctions(['selector']);
- var storageGetSavedArgs = new SaveMockArguments();
- this.mockApis.expects(once()).
- instrumented_storage_local_get(
- storageGetSavedArgs.match(eq('notificationsData')),
- storageGetSavedArgs.match(ANYTHING)).
- will(invokeCallback(storageGetSavedArgs, 1, testNotificationData));
+ expectChromeLocalStorageGet(
+ this, testNotificationDataRequest, testNotificationData);
this.mockLocalFunctions.expects(once()).selector(testActionUrls).will(
returnValue(testActionUrl));
var chromeTabsCreateSavedArgs = new SaveMockArguments();
@@ -445,6 +434,7 @@ TEST_F(
// Setup and expectations.
var testActionUrls = {testField: 'TEST VALUE'};
var testNotificationId = 'TEST_ID';
+ var testNotificationDataRequest = {notificationsData: {}};
var testNotificationData = {
notificationsData: {'TEST_ID': {actionUrls: testActionUrls}}
};
@@ -454,12 +444,8 @@ TEST_F(
mockOnNotificationClickedDependencies(this);
this.makeMockLocalFunctions(['selector']);
- var storageGetSavedArgs = new SaveMockArguments();
- this.mockApis.expects(once()).
- instrumented_storage_local_get(
- storageGetSavedArgs.match(eq('notificationsData')),
- storageGetSavedArgs.match(ANYTHING)).
- will(invokeCallback(storageGetSavedArgs, 1, testNotificationData));
+ expectChromeLocalStorageGet(
+ this, testNotificationDataRequest, testNotificationData);
this.mockLocalFunctions.expects(once()).selector(testActionUrls).will(
returnValue(testActionUrl));
var chromeTabsCreateSavedArgs = new SaveMockArguments();
@@ -757,29 +743,26 @@ TEST_F(
var fakeOnCardShownFunction = 'FAKE ON CARD SHOWN FUNCTION';
this.makeAndRegisterMockGlobals([
- 'scheduleNextPoll',
'combineAndShowNotificationCards',
- 'recordEvent'
+ 'recordEvent',
+ 'scheduleNextPoll'
]);
this.makeAndRegisterMockApis([
'chrome.storage.local.set',
- 'instrumented.storage.local.get'
+ 'fillFromChromeLocalStorage'
]);
- var storageGetSavedArgs = new SaveMockArguments();
- this.mockApis.expects(once()).
- instrumented_storage_local_get(
- storageGetSavedArgs.match(
- eq(['notificationGroups', 'recentDismissals'])),
- storageGetSavedArgs.match(ANYTHING)).
- will(invokeCallback(
- storageGetSavedArgs,
- 1,
- {
- notificationGroups: storedGroups,
- recentDismissals: recentDismissals
- }));
+ expectChromeLocalStorageGet(
+ this,
+ {
+ notificationGroups: {},
+ recentDismissals: {}
+ },
+ {
+ notificationGroups: storedGroups,
+ recentDismissals: recentDismissals
+ });
this.mockGlobals.expects(once()).
scheduleNextPoll(eqJSON(expectedUpdatedGroups), true);
@@ -842,15 +825,15 @@ TEST_F(
var fakeOnCardShownFunction = 'FAKE ON CARD SHOWN FUNCTION';
this.makeAndRegisterMockGlobals([
- 'scheduleNextPoll',
'combineAndShowNotificationCards',
+ 'onStateChange',
'recordEvent',
- 'onStateChange'
+ 'scheduleNextPoll'
]);
this.makeAndRegisterMockApis([
'chrome.storage.local.set',
- 'instrumented.storage.local.get'
+ 'fillFromChromeLocalStorage'
]);
this.mockApis.expects(once()).
@@ -859,14 +842,16 @@ TEST_F(
this.mockGlobals.expects(once()).onStateChange();
- var storageGetSavedArgs = new SaveMockArguments();
- this.mockApis.expects(once()).
- instrumented_storage_local_get(
- storageGetSavedArgs.match(
- eq(['notificationGroups', 'recentDismissals'])),
- storageGetSavedArgs.match(ANYTHING)).
- will(invokeCallback(
- storageGetSavedArgs, 1, {notificationGroups: storedGroups}));
+ expectChromeLocalStorageGet(
+ this,
+ {
+ notificationGroups: {},
+ recentDismissals: {}
+ },
+ {
+ notificationGroups: storedGroups,
+ recentDismissals: {}
+ });
this.mockGlobals.expects(once()).
scheduleNextPoll(eqJSON(expectedUpdatedGroups), false);

Powered by Google App Engine
This is Rietveld 408576698