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

Unified Diff: chrome/browser/resources/google_now/utility_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/utility_unittest.gtestjs
diff --git a/chrome/browser/resources/google_now/utility_unittest.gtestjs b/chrome/browser/resources/google_now/utility_unittest.gtestjs
index 8a10e7a68eb493cb1a39f0fd3d3e2100e2683fb4..6170f8a96fc4eb09dc80c6d973543083051a0c32 100644
--- a/chrome/browser/resources/google_now/utility_unittest.gtestjs
+++ b/chrome/browser/resources/google_now/utility_unittest.gtestjs
@@ -768,9 +768,20 @@ var testMaximumDelaySeconds = 2239;
// the moment.
var testRandomValue = 0.31415926;
-function createTestAttempStorageEntry(delaySeconds) {
- // Creates a test storage object that attempt manager uses to store current
- // delay.
+/**
+ * Creates a default storage current delay object.
+ */
+function createTestAttemptStorageEntryRequest() {
+ var storageObject = {};
+ storageObject[testAttemptStorageKey] = testMaximumDelaySeconds;
+ return storageObject;
+}
+
+/**
+ * Creates a test storage object that attempt manager uses to store current
+ * delay.
+ */
+function createTestAttemptStorageEntry(delaySeconds) {
var storageObject = {};
storageObject[testAttemptStorageKey] = delaySeconds;
return storageObject;
@@ -789,8 +800,8 @@ function setupAttemptManagerTest(fixture) {
'chrome.alarms.create',
'chrome.storage.local.remove',
'chrome.storage.local.set',
- 'instrumented.alarms.get',
- 'instrumented.storage.local.get'
+ 'fillFromChromeLocalStorage',
+ 'instrumented.alarms.get'
]);
var testAttempts = buildAttemptManager(
@@ -836,7 +847,7 @@ TEST_F('GoogleNowUtilityUnitTest', 'AttemptManagerStartStop', function() {
periodInMinutes: testMaximumDelaySeconds / 60
}));
this.mockApis.expects(once()).chrome_storage_local_set(
- eqJSON(createTestAttempStorageEntry(expectedRetryDelaySeconds)));
+ eqJSON(createTestAttemptStorageEntry(expectedRetryDelaySeconds)));
// Invocation.
test.attempts.start();
Mock4JS.verifyAllMocks();
@@ -902,21 +913,17 @@ TEST_F('GoogleNowUtilityUnitTest', 'AttemptManagerExponGrowth', function() {
// Expectations.
var expectedRetryDelaySeconds =
testStoredRetryDelay * 2 * (1 + testRandomValue * 0.2);
- var storageGetSavedArgs = new SaveMockArguments();
- this.mockApis.expects(once()).instrumented_storage_local_get(
- storageGetSavedArgs.match(eq(testAttemptStorageKey)),
- storageGetSavedArgs.match(ANYTHING)).
- will(invokeCallback(
- storageGetSavedArgs,
- 1,
- createTestAttempStorageEntry(testStoredRetryDelay)));
+ expectChromeLocalStorageGet(
+ this,
+ createTestAttemptStorageEntryRequest(),
+ createTestAttemptStorageEntry(testStoredRetryDelay));
this.mockApis.expects(once()).chrome_alarms_create(
testAttemptAlarmName,
eqJSON({
delayInMinutes: expectedRetryDelaySeconds / 60,
periodInMinutes: testMaximumDelaySeconds / 60}));
this.mockApis.expects(once()).chrome_storage_local_set(
- eqJSON(createTestAttempStorageEntry(expectedRetryDelaySeconds)));
+ eqJSON(createTestAttemptStorageEntry(expectedRetryDelaySeconds)));
this.mockLocalFunctions.expects(once()).planForNextCallback();
// Invocation.
test.attempts.planForNext(
@@ -934,15 +941,11 @@ TEST_F('GoogleNowUtilityUnitTest', 'AttemptManagerGrowthLimit', function() {
// is greater than 1/2 of the maximum delay.
// Expectations.
var expectedRetryDelaySeconds = testMaximumDelaySeconds;
- var storageGetSavedArgs = new SaveMockArguments();
- this.mockApis.expects(once()).
- instrumented_storage_local_get(
- storageGetSavedArgs.match(eq(testAttemptStorageKey)),
- storageGetSavedArgs.match(ANYTHING)).
- will(invokeCallback(
- storageGetSavedArgs,
- 1,
- createTestAttempStorageEntry(testStoredRetryDelay)));
+ expectChromeLocalStorageGet(
+ this,
+ createTestAttemptStorageEntryRequest(),
+ createTestAttemptStorageEntry(testStoredRetryDelay)
+ );
this.mockApis.expects(once()).chrome_alarms_create(
testAttemptAlarmName,
eqJSON({
@@ -950,7 +953,7 @@ TEST_F('GoogleNowUtilityUnitTest', 'AttemptManagerGrowthLimit', function() {
periodInMinutes: testMaximumDelaySeconds / 60
}));
this.mockApis.expects(once()).chrome_storage_local_set(
- eqJSON(createTestAttempStorageEntry(expectedRetryDelaySeconds)));
+ eqJSON(createTestAttemptStorageEntry(expectedRetryDelaySeconds)));
this.mockLocalFunctions.expects(once()).planForNextCallback();
// Invocation.
test.attempts.planForNext(

Powered by Google App Engine
This is Rietveld 408576698