Bug 1384658 - Correctly account for openers that are the same as the parent window; r=qdot
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 31 Jul 2017 22:29:57 -0400
changeset 372165 566c5e68903a11fb7ddfb297368f98f7ce4dc102
parent 372164 d6e8c5e46a872611ddbe8703980212d5daf2984f
child 372166 5588a5f33bbca0700cdf552518f5deb2853e6401
push id32266
push userarchaeopteryx@coole-files.de
push dateTue, 01 Aug 2017 09:24:14 +0000
treeherdermozilla-central@51ffb9283f0c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1384658
milestone56.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 1384658 - Correctly account for openers that are the same as the parent window; r=qdot
dom/base/WebSocket.cpp
dom/base/test/file_bug1384658.html
dom/base/test/mochitest.ini
dom/base/test/test_bug1384658.html
dom/base/test/window_bug1384658.html
--- a/dom/base/WebSocket.cpp
+++ b/dom/base/WebSocket.cpp
@@ -1691,17 +1691,20 @@ WebSocketImpl::Init(JSContext* aCx,
             break;
           }
 
           currentInnerWindow = parentWindow->GetCurrentInnerWindow();
           if (NS_WARN_IF(!currentInnerWindow)) {
             return NS_ERROR_DOM_SECURITY_ERR;
           }
 
-          MOZ_ASSERT(currentInnerWindow != innerWindow);
+          if (currentInnerWindow == innerWindow) {
+            // The opener may be the same outer window as the parent.
+            break;
+          }
         }
 
         innerWindow = currentInnerWindow;
 
         nsCOMPtr<nsIDocument> document = innerWindow->GetExtantDoc();
         if (NS_WARN_IF(!document)) {
           return NS_ERROR_DOM_SECURITY_ERR;
         }
new file mode 100644
--- /dev/null
+++ b/dom/base/test/file_bug1384658.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<script>
+  onload = function() {
+    function done(success) {
+      var bc = new BroadcastChannel("test_channel");
+      bc.postMessage({success:success});
+      bc.close();
+    }
+    try {
+      new WebSocket("ws://mochi.test:8888/tests/dom/base/test/file_websocket_basic");
+      done(true); // no hang!
+    } catch (e) {
+      done(false);
+    }
+  }
+</script>
+</html>
+
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -60,16 +60,17 @@ support-files =
   eventsource_redirect.resource
   eventsource_redirect.resource^headers^
   eventsource_redirect_to.resource
   eventsource_redirect_to.resource^headers^
   file_base_xbl.xml
   file_bug1091883_frame.html
   file_bug1091883_subframe.html
   file_bug1091883_target.html
+  file_bug1384658.html
   file_bug28293.sjs
   file_bug326337.xml
   file_bug326337_inner.html
   file_bug326337_outer.html
   file_bug372086.xml
   file_bug416317.xhtml
   file_bug426646-1.html
   file_bug426646-2.html
@@ -246,16 +247,17 @@ support-files =
   iframe7_bug431701.xml
   iframe1_bug426646.html
   iframe2_bug426646.html
   file1_setting_opener.html
   file2_setting_opener.html
   file3_setting_opener.html
   file4_setting_opener.html
   PASS.html
+  window_bug1384658.html
 
 [test_anchor_area_referrer.html]
 [test_anchor_area_referrer_changing.html]
 [test_anchor_area_referrer_invalid.html]
 [test_anchor_area_referrer_rel.html]
 [test_anonymousContent_api.html]
 [test_anonymousContent_append_after_reflow.html]
 [test_anonymousContent_canvas.html]
@@ -616,16 +618,18 @@ skip-if = toolkit == 'android'
 [test_bug1274806.html]
 [test_bug1281963.html]
 [test_bug1295852.html]
 [test_bug1307730.html]
 [test_bug1308069.html]
 [test_bug1314032.html]
 [test_bug1318303.html]
 [test_bug1375050.html]
+[test_bug1384658.html]
+skip-if = toolkit == 'android'
 [test_caretPositionFromPoint.html]
 [test_change_policy.html]
 [test_clearTimeoutIntervalNoArg.html]
 [test_constructor-assignment.html]
 [test_constructor.html]
 [test_copyimage.html]
 subsuite = clipboard
 skip-if = toolkit == 'android' #bug 904183
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_bug1384658.html
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1384658
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1384658</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  /** Test for Bug 1384658 **/
+
+  SimpleTest.waitForExplicitFinish();
+  var win = window.open("http://example.com/tests/dom/base/test/window_bug1384658.html",
+                        "_blank", "width=100,height=100");
+  var bc = new BroadcastChannel("test_channel");
+  bc.onmessage = ev => {
+    ok(ev.data.success, "We didn't hang");
+    bc.close();
+    win.close();
+    SimpleTest.finish();
+  };
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1384658">Mozilla Bug 1384658</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/base/test/window_bug1384658.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+  onload = function() {
+    if (window.location.search == "") {
+      window.open("window_bug1384658.html?opened", "_top", "");
+    } else {
+      var iframeURL = "http://mochi.test:8888/tests/dom/base/test/file_bug1384658.html";
+      var iframe = document.createElement("iframe");
+      iframe.src = iframeURL;
+      document.body.appendChild(iframe);
+    }
+  };
+</script>
+</head>
+<body>
+</body>
+</html>