Bug 1265970. When throwing an exception from XHR open() due to not being in an active document, make sure it's an InvalidStateError. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 20 Apr 2016 18:05:58 -0400
changeset 294130 408ac64b72edd03b0b9f480d06787d03f90f07a0
parent 294129 4b03e85de2207b0eb5af7dde859ed10f83f050cc
child 294131 051353392264ed655014e2ad0c5d34ec441d28f4
push id75440
push userbzbarsky@mozilla.com
push dateWed, 20 Apr 2016 22:06:25 +0000
treeherdermozilla-inbound@408ac64b72ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1265970
milestone48.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 1265970. When throwing an exception from XHR open() due to not being in an active document, make sure it's an InvalidStateError. r=smaug
dom/base/nsXMLHttpRequest.cpp
testing/web-platform/meta/MANIFEST.json
testing/web-platform/meta/XMLHttpRequest/open-url-multi-window-2.htm.ini
testing/web-platform/meta/XMLHttpRequest/open-url-multi-window-5.htm.ini
testing/web-platform/tests/XMLHttpRequest/open-url-multi-window-6.htm
testing/web-platform/tests/XMLHttpRequest/resources/init.htm
--- a/dom/base/nsXMLHttpRequest.cpp
+++ b/dom/base/nsXMLHttpRequest.cpp
@@ -1548,17 +1548,19 @@ nsXMLHttpRequest::Open(const nsACString&
     mState &= ~XML_HTTP_REQUEST_ASYNC;
   }
 
   nsCOMPtr<nsIDocument> doc = GetDocumentIfCurrent();
   if (!doc) {
     // This could be because we're no longer current or because we're in some
     // non-window context...
     nsresult rv = CheckInnerWindowCorrectness();
-    NS_ENSURE_SUCCESS(rv, rv);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return NS_ERROR_DOM_INVALID_STATE_ERR;
+    }
   }
 
   nsCOMPtr<nsIURI> baseURI;
   if (mBaseURI) {
     baseURI = mBaseURI;
   }
   else if (doc) {
     baseURI = doc->GetBaseURI();
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -35220,16 +35220,22 @@
                 "=="
               ]
             ],
             "url": "/compat/webkit-text-fill-color-property-006.html"
           }
         ]
       },
       "testharness": {
+        "XMLHttpRequest/open-url-multi-window-6.htm": [
+          {
+            "path": "XMLHttpRequest/open-url-multi-window-6.htm",
+            "url": "/XMLHttpRequest/open-url-multi-window-6.htm"
+          }
+        ],
         "html/semantics/embedded-content/the-embed-element/embed-ignored-in-media-element.html": [
           {
             "path": "html/semantics/embedded-content/the-embed-element/embed-ignored-in-media-element.html",
             "url": "/html/semantics/embedded-content/the-embed-element/embed-ignored-in-media-element.html"
           }
         ],
         "html/webappapis/scripting/processing-model-2/window-onerror-with-cross-frame-event-listeners-1.html": [
           {
deleted file mode 100644
--- a/testing/web-platform/meta/XMLHttpRequest/open-url-multi-window-2.htm.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[open-url-multi-window-2.htm]
-  type: testharness
-  [XMLHttpRequest: open() resolving URLs (multi-Window; 2; evil)]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/XMLHttpRequest/open-url-multi-window-5.htm.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[open-url-multi-window-5.htm]
-  type: testharness
-  [XMLHttpRequest: open() resolving URLs (multi-Window; 5)]
-    expected: FAIL
-
copy from testing/web-platform/tests/XMLHttpRequest/open-url-multi-window-5.htm
copy to testing/web-platform/tests/XMLHttpRequest/open-url-multi-window-6.htm
--- a/testing/web-platform/tests/XMLHttpRequest/open-url-multi-window-5.htm
+++ b/testing/web-platform/tests/XMLHttpRequest/open-url-multi-window-6.htm
@@ -1,30 +1,41 @@
 <!DOCTYPE html>
 <html>
   <head>
-    <title>XMLHttpRequest: open() resolving URLs (multi-Window; 5)</title>
+    <title>XMLHttpRequest: open() in document that is not fully active (but may be active) should throw</title>
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
-    <link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol[1]/li[2]/ol[1]/li[1]" />
+    <link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method">
   </head>
   <body>
     <div id="log"></div>
     <script>
       var test = async_test(),
           client,
-          count = 0
+          count = 0,
+          win = window.open("resources/init.htm");
+      test.add_cleanup(function() { win.close(); });
       function init() {
         test.step(function() {
           if(0 == count) {
-            client = new self[0].XMLHttpRequest()
-            count++
-            self[0].location.reload()
+            var doc = win.document;
+            var ifr = document.createElement("iframe");
+            ifr.onload = function() {
+              // Again, do things async so we're not doing loads from inside
+              // load events.
+              setTimeout(function() {
+                client = new ifr.contentWindow.XMLHttpRequest();
+                count++;
+                // Important to do a normal navigation, not a reload.
+                win.location.href = "resources/init.htm";
+              }, 100);
+            }
+            doc.body.appendChild(ifr);
           } else if(1 == count) {
             assert_throws("InvalidStateError", function() { client.open("GET", "...") })
             test.done()
           }
         })
       }
     </script>
-    <iframe src="resources/init.htm"></iframe>
   </body>
 </html>
--- a/testing/web-platform/tests/XMLHttpRequest/resources/init.htm
+++ b/testing/web-platform/tests/XMLHttpRequest/resources/init.htm
@@ -1,9 +1,20 @@
 <!doctype html>
 <html>
   <head>
     <title>support init file</title>
   </head>
   <body>
-    <script> parent.init() </script>
+    <script>
+      onload = function() {
+        // Run async, because navigations from inside onload can be a bit weird.
+        setTimeout(function() {
+          if (parent != window) {
+            parent.init()
+          } else {
+            opener.init();
+          }
+        }, 0);
+      }
+    </script>
   </body>
 </html>