Bug 1446310 - Remove CPOWs from browser_storage_updates.js r=jryans
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Fri, 16 Mar 2018 09:55:56 +0000
changeset 408608 3e8de42ee46ffc9603c3d02884b913200a207338
parent 408607 84badebad54b181df9667c15a07641dbf6780d11
child 408609 1f9f56aeb495482135d58d6edf8bf4a29841cb50
push id100996
push userbtara@mozilla.com
push dateSat, 17 Mar 2018 10:37:43 +0000
treeherdermozilla-inbound@97160a734959 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1446310
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1446310 - Remove CPOWs from browser_storage_updates.js r=jryans MozReview-Commit-ID: DVeLEYIfl9A
devtools/server/tests/browser/browser.ini
devtools/server/tests/browser/browser_storage_updates.js
--- a/devtools/server/tests/browser/browser.ini
+++ b/devtools/server/tests/browser/browser.ini
@@ -92,16 +92,15 @@ skip-if = e10s # Bug 1183605 - devtools/
 [browser_perf-recording-actor-02.js]
 skip-if = e10s # Bug 1183605 - devtools/server/tests/browser/ tests are still disabled in E10S
 [browser_perf-samples-01.js]
 [browser_perf-samples-02.js]
 [browser_storage_cookies-duplicate-names.js]
 [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]
 [browser_timeline_actors.js]
 [browser_timeline_iframes.js]
 [browser_register_actor.js]
 [browser_webextension_inspected_window.js]
--- a/devtools/server/tests/browser/browser_storage_updates.js
+++ b/devtools/server/tests/browser/browser_storage_updates.js
@@ -4,25 +4,25 @@
 
 "use strict";
 
 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: {
         cookies: {
           "http://test1.example.org": [
             getCookieId("c1", "test1.example.org",
                         "/browser/devtools/server/tests/browser/"),
             getCookieId("c2", "test1.example.org",
@@ -33,22 +33,22 @@ const TESTS = [
           "http://test1.example.org": ["l1"]
         }
       }
     }
   },
 
   // 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: {
         cookies: {
           "http://test1.example.org": [
             getCookieId("c1", "test1.example.org",
                         "/browser/devtools/server/tests/browser/"),
           ]
@@ -59,25 +59,25 @@ const TESTS = [
           "http://test1.example.org": ["l2"]
         }
       }
     }
   },
 
   // 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: {
         cookies: {
           "http://test1.example.org": [
             getCookieId("c2", "test1.example.org",
                         "/browser/devtools/server/tests/browser/"),
           ]
@@ -91,34 +91,34 @@ const TESTS = [
           "http://test1.example.org": ["l3"]
         }
       }
     }
   },
 
   // 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: {
         cookies: {
           "http://test1.example.org": [
             getCookieId("c3", "test1.example.org",
                         "/browser/devtools/server/tests/browser/"),
           ]
@@ -143,48 +143,68 @@ const TESTS = [
           "http://test1.example.org": ["l2"]
         }
       }
     }
   },
 
   // 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: {
         sessionStorage: {
           "http://test1.example.org": ["s1"]
         }
       }
     }
   },
 
   // index 5
   {
-    action: function(win) {
-      info("win.clearCookies()");
-      win.clearCookies();
+    action: async function() {
+      info("clearCookies()");
+      await clearCookies();
     },
     expected: {
       deleted: {
         cookies: {
           "http://test1.example.org": [
             getCookieId("c3", "test1.example.org",
                         "/browser/devtools/server/tests/browser/"),
           ]
         }
       }
     }
   }
 ];
 
+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");
     return;
   }
   ok(Object.keys(data).length, "At least one storage type should be present");
 
   for (let storageType in toBeEmptied) {
@@ -235,52 +255,51 @@ function onStoresUpdate(expected, {added
       (!expected.changed || !Object.keys(expected.changed).length) &&
       (!expected.deleted || !Object.keys(expected.deleted).length)) {
     info("Everything expected has been received for index " + index);
   } else {
     info("Still some updates pending for index " + 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();
+
+  let data = await front.once("stores-cleared");
+
+  storesCleared(data);
 
-      if (data.localStorage) {
-        localStorage = true;
-      }
-      if (data.sessionStorage) {
-        sessionStorage = true;
-      }
-      if (localStorage && sessionStorage) {
-        front.off("stores-cleared", onStoresCleared);
-        resolve();
-      }
-    });
+  if (data.localStorage) {
+    localStorage = true;
+  }
+
+  data = await front.once("stores-cleared");
 
-    win.clearLocalAndSessionStores();
-  });
+  if (data.sessionStorage) {
+    sessionStorage = true;
+  }
+
+  ok(localStorage, "localStorage was cleared");
+  ok(sessionStorage, "sessionStorage was cleared");
 }
 
 function storesCleared(data) {
   if (data.sessionStorage || data.localStorage) {
     let hosts = data.sessionStorage || data.localStorage;
     info("Stores cleared required for session storage");
     is(hosts.length, 1, "number of hosts is 1");
     is(hosts[0], "http://test1.example.org",
@@ -291,30 +310,55 @@ function storesCleared(data) {
 }
 
 async function finishTests(client) {
   await client.close();
   DebuggerServer.destroy();
   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);
+  });
+}
+
+async function removeCookie(name) {
+  await ContentTask.spawn(gBrowser.selectedBrowser, name, iName => {
+    content.wrappedJSObject.window.removeCookie(iName);
+  });
+}
 
-  initDebuggerServer();
+async function localStorageSetItem(name, value) {
+  await ContentTask.spawn(gBrowser.selectedBrowser, [name, value], ([iName, iValue]) => {
+    content.window.localStorage.setItem(iName, iValue);
+  });
+}
+
+async function localStorageRemoveItem(name) {
+  await ContentTask.spawn(gBrowser.selectedBrowser, name, iName => {
+    content.window.localStorage.removeItem(iName);
+  });
+}
 
-  let client = new DebuggerClient(DebuggerServer.connectPipe());
-  let form = await connectDebuggerClient(client);
-  let front = StorageFront(client, form);
-  let win = doc.defaultView.wrappedJSObject;
+async function sessionStorageSetItem(name, value) {
+  await ContentTask.spawn(gBrowser.selectedBrowser, [name, value], ([iName, iValue]) => {
+    content.window.sessionStorage.setItem(iName, iValue);
+  });
+}
 
-  await front.listStores();
+async function sessionStorageRemoveItem(name) {
+  await ContentTask.spawn(gBrowser.selectedBrowser, name, iName => {
+    content.window.sessionStorage.removeItem(iName);
+  });
+}
 
-  for (let i = 0; i < TESTS.length; i++) {
-    let test = TESTS[i];
-    await runTest(test, front, win, i);
-  }
+async function clearCookies() {
+  await ContentTask.spawn(gBrowser.selectedBrowser, {}, () => {
+    content.wrappedJSObject.window.clearCookies();
+  });
+}
 
-  await testClearLocalAndSessionStores(front, win);
-  await finishTests(client);
-});
+async function clearLocalAndSessionStores() {
+  await ContentTask.spawn(gBrowser.selectedBrowser, {}, () => {
+    content.wrappedJSObject.window.clearLocalAndSessionStores();
+  });
+}