Bug 1346286 - Remove CPOWs from browser_911547.js. r=Felipe draft
authorBlake Kaplan <mrbkap@gmail.com>
Thu, 09 Mar 2017 11:36:28 -0800
changeset 499550 8b70f9886950e0caaefee35e2e3927315887e85f
parent 499549 2f3311619efef35ad97c6ffbe6e1fd0857afa722
child 499551 705fbd00ac358ed170d4bd00f695adc05a340765
push id49450
push userbmo:mrbkap@mozilla.com
push dateWed, 15 Mar 2017 23:51:54 +0000
reviewersFelipe
bugs1346286
milestone55.0a1
Bug 1346286 - Remove CPOWs from browser_911547.js. r=Felipe MozReview-Commit-ID: 3Y5K84X2EIe
browser/components/sessionstore/test/browser_911547.js
--- a/browser/components/sessionstore/test/browser_911547.js
+++ b/browser/components/sessionstore/test/browser_911547.js
@@ -11,42 +11,53 @@ add_task(function* test() {
   let tab = gBrowser.selectedTab = gBrowser.addTab(testURL);
   gBrowser.selectedTab = tab;
 
   let browser = tab.linkedBrowser;
   yield promiseBrowserLoaded(browser);
 
   // this is a baseline to ensure CSP is active
   // attempt to inject and run a script via inline (pre-restore, allowed)
-  injectInlineScript(browser, 'document.getElementById("test_id").value = "fail";');
-  is(browser.contentDocument.getElementById("test_id").value, "ok",
-     "CSP should block the inline script that modifies test_id");
+  yield injectInlineScript(browser, `document.getElementById("test_id").value = "fail";`);
+
+  let loadedPromise = promiseBrowserLoaded(browser);
+  yield ContentTask.spawn(browser, null, function() {
+    is(content.document.getElementById("test_id").value, "ok",
+       "CSP should block the inline script that modifies test_id");
 
-  // attempt to click a link to a data: URI (will inherit the CSP of the
-  // origin document) and navigate to the data URI in the link.
-  browser.contentDocument.getElementById("test_data_link").click();
-  yield promiseBrowserLoaded(browser);
+    // attempt to click a link to a data: URI (will inherit the CSP of the
+    // origin document) and navigate to the data URI in the link.
+    content.document.getElementById("test_data_link").click();
+  });
 
-  is(browser.contentDocument.getElementById("test_id2").value, "ok",
-     "CSP should block the script loaded by the clicked data URI");
+  yield loadedPromise;
+
+  yield ContentTask.spawn(browser, null, function() {
+    is(content.document.getElementById("test_id2").value, "ok",
+       "CSP should block the script loaded by the clicked data URI");
+  });
 
   // close the tab
   yield promiseRemoveTab(tab);
 
   // open new tab and recover the state
   tab = ss.undoCloseTab(window, 0);
   yield promiseTabRestored(tab);
   browser = tab.linkedBrowser;
 
-  is(browser.contentDocument.getElementById("test_id2").value, "ok",
-     "CSP should block the script loaded by the clicked data URI after restore");
+  yield ContentTask.spawn(browser, null, function() {
+    is(content.document.getElementById("test_id2").value, "ok",
+       "CSP should block the script loaded by the clicked data URI after restore");
+  });
 
   // clean up
   gBrowser.removeTab(tab);
 });
 
 // injects an inline script element (with a text body)
 function injectInlineScript(browser, scriptText) {
-  let scriptElt = browser.contentDocument.createElement("script");
-  scriptElt.type = "text/javascript";
-  scriptElt.text = scriptText;
-  browser.contentDocument.body.appendChild(scriptElt);
+  return ContentTask.spawn(browser, scriptText, function(text) {
+    let scriptElt = content.document.createElement("script");
+    scriptElt.type = "text/javascript";
+    scriptElt.text = text;
+    content.document.body.appendChild(scriptElt);
+  });
 }