Commit d68c0fc0 authored by David Bertoni's avatar David Bertoni Committed by Commit Bot

[Extensions] Re-enable a Storage API test.

The ExtensionSettingsApiTest.OnChangedNotificationsFromSyncCheck
was disabled for flakiness and became stale. This CL fixes the test
and cleans up the JavaScript code. The test passed 3000 iterations
on the bots.

Bug: 101110
Change-Id: Ia969ba620900382395d09ec28e8d8ea379c79d5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2211079
Commit-Queue: David Bertoni <dbertoni@chromium.org>
Reviewed-by: default avatarArchana Simha <archanasimha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771884}
parent 2b757da9
......@@ -339,9 +339,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
}
// Disabled, see crbug.com/101110
IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
DISABLED_OnChangedNotificationsFromSync) {
OnChangedNotificationsFromSync) {
// We need 2 ResultCatchers because we'll be running the same test in both
// regular and incognito mode.
ResultCatcher catcher, catcher_incognito;
......
......@@ -2,15 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var api = chrome.storage;
var assertEq = chrome.test.assertEq;
var inIncognitoContext = chrome.extension.inIncognitoContext;
['sync', 'local'].forEach(function(namespace) {
api[namespace].notifications = {};
api.onChanged.addListener(function(changes, event_namespace) {
chrome.storage[namespace].notifications = {};
chrome.storage.onChanged.addListener(function(changes, event_namespace) {
if (event_namespace == namespace) {
var notifications = api[namespace].notifications;
var notifications = chrome.storage[namespace].notifications;
Object.keys(changes).forEach(function(key) {
notifications[key] = changes[key];
});
......@@ -29,13 +25,13 @@ var testActions = {
},
assertEmpty: function(callback) {
this.get(null, function(settings) {
assertEq({}, settings);
chrome.test.assertEq({}, settings);
callback();
});
},
assertFoo: function(callback) {
this.get(null, function(settings) {
assertEq({foo: "bar"}, settings);
chrome.test.assertEq({foo: "bar"}, settings);
callback();
});
},
......@@ -49,7 +45,7 @@ var testActions = {
this.clear(callback);
},
assertNoNotifications: function(callback) {
assertEq({}, this.notifications);
chrome.test.assertEq({}, this.notifications);
callback();
},
clearNotifications: function(callback) {
......@@ -57,11 +53,11 @@ var testActions = {
callback();
},
assertAddFooNotification: function(callback) {
assertEq({ foo: { newValue: 'bar' } }, this.notifications);
chrome.test.assertEq({ foo: { newValue: 'bar' } }, this.notifications);
callback();
},
assertDeleteFooNotification: function(callback) {
assertEq({ foo: { oldValue: 'bar' } }, this.notifications);
chrome.test.assertEq({ foo: { oldValue: 'bar' } }, this.notifications);
callback();
}
};
......@@ -70,15 +66,20 @@ var testActions = {
// to stop (when the message has isFinalAction set to true).
function testEverything() {
function next() {
var waiting = inIncognitoContext ? "waiting_incognito" : "waiting";
var waiting =
chrome.extension.inIncognitoContext ? "waiting_incognito" : "waiting";
chrome.test.sendMessage(waiting, function(messageJson) {
var message = JSON.parse(messageJson);
// We will get empty messages, which are considered a noop.
var message = { action: 'noop', isFinalAction: false, namespace: 'sync' };
if (messageJson.length != 0) {
message = JSON.parse(messageJson);
}
var action = testActions[message.action];
if (!action) {
chrome.test.fail("Unknown action: " + message.action);
return;
}
action.bind(api[message.namespace])(
action.bind(chrome.storage[message.namespace])(
message.isFinalAction ? chrome.test.succeed : next);
});
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment