Bug 1446310 - Remove CPOWs from browser_storage_updates.js r=jryans

MozReview-Commit-ID: DVeLEYIfl9A

--HG--
extra : rebase_source : 05d13aae50e886181f1d9385bba5febd3c6c67d9
This commit is contained in:
Michael Ratcliffe 2018-03-16 09:55:56 +00:00
parent 540eac7b3b
commit 81149f7410
2 changed files with 129 additions and 86 deletions

View File

@ -97,7 +97,6 @@ skip-if = e10s # Bug 1183605 - devtools/server/tests/browser/ tests are still di
[browser_storage_dynamic_windows.js]
[browser_storage_listings.js]
[browser_storage_updates.js]
uses-unsafe-cpows = true
[browser_stylesheets_getTextEmpty.js]
[browser_stylesheets_nested-iframes.js]
[browser_timeline.js]

View File

@ -9,15 +9,15 @@ const {StorageFront} = require("devtools/shared/fronts/storage");
const TESTS = [
// index 0
{
action: function(win) {
info('win.addCookie("c1", "foobar1")');
win.addCookie("c1", "foobar1");
action: async function(win) {
info('addCookie("c1", "foobar1")');
await addCookie("c1", "foobar1");
info('win.addCookie("c2", "foobar2")');
win.addCookie("c2", "foobar2");
info('addCookie("c2", "foobar2")');
await addCookie("c2", "foobar2");
info('win.localStorage.setItem("l1", "foobar1")');
win.localStorage.setItem("l1", "foobar1");
info('localStorageSetItem("l1", "foobar1")');
await localStorageSetItem("l1", "foobar1");
},
expected: {
added: {
@ -38,12 +38,12 @@ const TESTS = [
// index 1
{
action: function(win) {
info('win.addCookie("c1", "new_foobar1")');
win.addCookie("c1", "new_foobar1");
action: async function() {
info('addCookie("c1", "new_foobar1")');
await addCookie("c1", "new_foobar1");
info('win.localStorage.setItem("l2", "foobar2")');
win.localStorage.setItem("l2", "foobar2");
info('localStorageSetItem("l2", "foobar2")');
await localStorageSetItem("l2", "foobar2");
},
expected: {
changed: {
@ -64,15 +64,15 @@ const TESTS = [
// index 2
{
action: function(win) {
info('win.removeCookie("c2")');
win.removeCookie("c2");
action: async function() {
info('removeCookie("c2")');
await removeCookie("c2");
info('win.localStorage.removeItem("l1")');
win.localStorage.removeItem("l1");
info('localStorageRemoveItem("l1")');
await localStorageRemoveItem("l1");
info('win.localStorage.setItem("l3", "foobar3")');
win.localStorage.setItem("l3", "foobar3");
info('localStorageSetItem("l3", "foobar3")');
await localStorageSetItem("l3", "foobar3");
},
expected: {
deleted: {
@ -96,24 +96,24 @@ const TESTS = [
// index 3
{
action: function(win) {
info('win.removeCookie("c1")');
win.removeCookie("c1");
action: async function() {
info('removeCookie("c1")');
await removeCookie("c1");
info('win.addCookie("c3", "foobar3")');
win.addCookie("c3", "foobar3");
info('addCookie("c3", "foobar3")');
await addCookie("c3", "foobar3");
info('win.localStorage.removeItem("l2")');
win.localStorage.removeItem("l2");
info('localStorageRemoveItem("l2")');
await localStorageRemoveItem("l2");
info('win.sessionStorage.setItem("s1", "foobar1")');
win.sessionStorage.setItem("s1", "foobar1");
info('sessionStorageSetItem("s1", "foobar1")');
await sessionStorageSetItem("s1", "foobar1");
info('win.sessionStorage.setItem("s2", "foobar2")');
win.sessionStorage.setItem("s2", "foobar2");
info('sessionStorageSetItem("s2", "foobar2")');
await sessionStorageSetItem("s2", "foobar2");
info('win.localStorage.setItem("l3", "new_foobar3")');
win.localStorage.setItem("l3", "new_foobar3");
info('localStorageSetItem("l3", "new_foobar3")');
await localStorageSetItem("l3", "new_foobar3");
},
expected: {
added: {
@ -148,9 +148,9 @@ const TESTS = [
// index 4
{
action: function(win) {
info('win.sessionStorage.removeItem("s1")');
win.sessionStorage.removeItem("s1");
action: async function() {
info('sessionStorageRemoveItem("s1")');
await sessionStorageRemoveItem("s1");
},
expected: {
deleted: {
@ -163,9 +163,9 @@ const TESTS = [
// index 5
{
action: function(win) {
info("win.clearCookies()");
win.clearCookies();
action: async function() {
info("clearCookies()");
await clearCookies();
},
expected: {
deleted: {
@ -180,6 +180,26 @@ const TESTS = [
}
];
add_task(async function() {
await addTab(MAIN_DOMAIN + "storage-updates.html");
initDebuggerServer();
let client = new DebuggerClient(DebuggerServer.connectPipe());
let form = await connectDebuggerClient(client);
let front = StorageFront(client, form);
await front.listStores();
for (let i = 0; i < TESTS.length; i++) {
let test = TESTS[i];
await runTest(test, front, i);
}
await testClearLocalAndSessionStores(front);
await finishTests(client);
});
function markOutMatched(toBeEmptied, data) {
if (!Object.keys(toBeEmptied).length) {
info("Object empty");
@ -240,42 +260,41 @@ function onStoresUpdate(expected, {added, changed, deleted}, index) {
}
}
function runTest({action, expected}, front, win, index) {
return new Promise(resolve => {
front.once("stores-update", function(addedChangedDeleted) {
onStoresUpdate(expected, addedChangedDeleted, index);
resolve();
});
async function runTest({action, expected}, front, index) {
let update = front.once("stores-update");
info("Running test at index " + index);
action(win);
});
info("Running test at index " + index);
await action();
let addedChangedDeleted = await update;
onStoresUpdate(expected, addedChangedDeleted, index);
}
function testClearLocalAndSessionStores(front, win) {
return new Promise(resolve => {
// We need to wait until we have received stores-cleared for both local and
// session storage.
let localStorage = false;
let sessionStorage = false;
async function testClearLocalAndSessionStores(front) {
// We need to wait until we have received stores-cleared for both local and
// session storage.
let localStorage = false;
let sessionStorage = false;
front.on("stores-cleared", function onStoresCleared(data) {
storesCleared(data);
await clearLocalAndSessionStores();
if (data.localStorage) {
localStorage = true;
}
if (data.sessionStorage) {
sessionStorage = true;
}
if (localStorage && sessionStorage) {
front.off("stores-cleared", onStoresCleared);
resolve();
}
});
let data = await front.once("stores-cleared");
win.clearLocalAndSessionStores();
});
storesCleared(data);
if (data.localStorage) {
localStorage = true;
}
data = await front.once("stores-cleared");
if (data.sessionStorage) {
sessionStorage = true;
}
ok(localStorage, "localStorage was cleared");
ok(sessionStorage, "sessionStorage was cleared");
}
function storesCleared(data) {
@ -296,25 +315,50 @@ async function finishTests(client) {
finish();
}
add_task(async function() {
let browser = await addTab(MAIN_DOMAIN + "storage-updates.html");
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocumentAsCPOW;
async function addCookie(name, value) {
await ContentTask.spawn(gBrowser.selectedBrowser, [name, value], ([iName, iValue]) => {
content.wrappedJSObject.window.addCookie(iName, iValue);
});
}
initDebuggerServer();
async function removeCookie(name) {
await ContentTask.spawn(gBrowser.selectedBrowser, name, iName => {
content.wrappedJSObject.window.removeCookie(iName);
});
}
let client = new DebuggerClient(DebuggerServer.connectPipe());
let form = await connectDebuggerClient(client);
let front = StorageFront(client, form);
let win = doc.defaultView.wrappedJSObject;
async function localStorageSetItem(name, value) {
await ContentTask.spawn(gBrowser.selectedBrowser, [name, value], ([iName, iValue]) => {
content.window.localStorage.setItem(iName, iValue);
});
}
await front.listStores();
async function localStorageRemoveItem(name) {
await ContentTask.spawn(gBrowser.selectedBrowser, name, iName => {
content.window.localStorage.removeItem(iName);
});
}
for (let i = 0; i < TESTS.length; i++) {
let test = TESTS[i];
await runTest(test, front, win, i);
}
async function sessionStorageSetItem(name, value) {
await ContentTask.spawn(gBrowser.selectedBrowser, [name, value], ([iName, iValue]) => {
content.window.sessionStorage.setItem(iName, iValue);
});
}
await testClearLocalAndSessionStores(front, win);
await finishTests(client);
});
async function sessionStorageRemoveItem(name) {
await ContentTask.spawn(gBrowser.selectedBrowser, name, iName => {
content.window.sessionStorage.removeItem(iName);
});
}
async function clearCookies() {
await ContentTask.spawn(gBrowser.selectedBrowser, {}, () => {
content.wrappedJSObject.window.clearCookies();
});
}
async function clearLocalAndSessionStores() {
await ContentTask.spawn(gBrowser.selectedBrowser, {}, () => {
content.wrappedJSObject.window.clearLocalAndSessionStores();
});
}