Bug 1231695 - Don't use contentWindow on remote browsers. r=mccr8
authorBlake Kaplan <mrbkap@gmail.com>
Thu, 10 Dec 2015 16:50:58 -0500
changeset 310287 d9f0f6221e06ccea601772206c8f602e1255651c
parent 310286 f5d0b9f5e3f6b61648c205238da4dbcad4e53b4d
child 310288 6fb0e753c32b66c279093dfe04cc5e16fc729c03
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1231695
milestone45.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 1231695 - Don't use contentWindow on remote browsers. r=mccr8
dom/base/test/browser_bug593387.js
--- a/dom/base/test/browser_bug593387.js
+++ b/dom/base/test/browser_bug593387.js
@@ -1,65 +1,70 @@
 /*
  * Test for bug 593387
  * Loads a chrome document in a content docshell and then inserts a
  * X-Frame-Options: DENY iframe into the document and verifies that the document
  * loads. The policy we are enforcing is outlined here:
  * https://bugzilla.mozilla.org/show_bug.cgi?id=593387#c17
 */
-var newBrowser;
 
-function test() {
-  waitForExplicitFinish();
+add_task(function* test() {
+  yield BrowserTestUtils.withNewTab({ gBrowser,
+                                      url: "chrome://global/content/mozilla.xhtml" },
+                                     function* (newBrowser) {
+    // NB: We load the chrome:// page in the parent process.
+    yield testXFOFrameInChrome(newBrowser);
 
-  var newTab = gBrowser.addTab();
-  gBrowser.selectedTab = newTab;
-  newBrowser = gBrowser.getBrowserForTab(newTab);
-  //alert(newBrowser.contentWindow);
+    // Run next test (try the same with a content top-level context)
+    yield BrowserTestUtils.loadURI(newBrowser, "http://example.com/");
+    yield BrowserTestUtils.browserLoaded(newBrowser);
 
-  newBrowser.addEventListener("load", testXFOFrameInChrome, true);
-  newBrowser.contentWindow.location = "chrome://global/content/mozilla.xhtml";
-}
+    yield ContentTask.spawn(newBrowser, null, testXFOFrameInContent);
+  });
+});
 
-function testXFOFrameInChrome() {
-  newBrowser.removeEventListener("load", testXFOFrameInChrome, true);
-
+function testXFOFrameInChrome(newBrowser) {
   // Insert an iframe that specifies "X-Frame-Options: DENY" and verify
   // that it loads, since the top context is chrome
+  var deferred = {};
+  deferred.promise = new Promise((resolve) => {
+    deferred.resolve = resolve;
+  });
+
   var frame = newBrowser.contentDocument.createElement("iframe");
   frame.src = "http://mochi.test:8888/tests/dom/base/test/file_x-frame-options_page.sjs?testid=deny&xfo=deny";
-  frame.addEventListener("load", function() {
-    frame.removeEventListener("load", arguments.callee, true);
+  frame.addEventListener("load", function loaded() {
+    frame.removeEventListener("load", loaded, true);
 
     // Test that the frame loaded
     var test = this.contentDocument.getElementById("test");
     is(test.tagName, "H1", "wrong element type");
     is(test.textContent, "deny", "wrong textContent");
-    
-    // Run next test (try the same with a content top-level context)
-    newBrowser.addEventListener("load", testXFOFrameInContent, true);
-    newBrowser.contentWindow.location = "http://example.com/";  
+    deferred.resolve();
   }, true);
 
   newBrowser.contentDocument.body.appendChild(frame);
+  return deferred.promise;
 }
 
-function testXFOFrameInContent() {
-  newBrowser.removeEventListener("load", testXFOFrameInContent, true);
-
+function testXFOFrameInContent(newBrowser) {
   // Insert an iframe that specifies "X-Frame-Options: DENY" and verify that it
   // is blocked from loading since the top browsing context is another site
-  var frame = newBrowser.contentDocument.createElement("iframe");
+  var deferred = {};
+  deferred.promise = new Promise((resolve) => {
+    deferred.resolve = resolve;
+  });
+
+  var frame = content.document.createElement("iframe");
   frame.src = "http://mochi.test:8888/tests/dom/base/test/file_x-frame-options_page.sjs?testid=deny&xfo=deny";
-  frame.addEventListener("load", function() {
-    frame.removeEventListener("load", arguments.callee, true);
+  frame.addEventListener("load", function loaded() {
+    frame.removeEventListener("load", loaded, true);
 
     // Test that the frame DID NOT load
     var test = this.contentDocument.getElementById("test");
-    is(test, undefined, "should be about:blank");
+    is(test, null, "should be about:blank");
 
-    // Finalize the test
-    gBrowser.removeCurrentTab();
-    finish();
+    deferred.resolve();
   }, true);
 
-  newBrowser.contentDocument.body.appendChild(frame);
+  content.document.body.appendChild(frame);
+  return deferred.promise;
 }