Bug 1478743 part 3. Remove bogus clearing of the response when xhr.overrideMimeType throws. r=baku
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 30 Jul 2018 11:51:52 -0400
changeset 429260 7f4dd832985c43d9ff08ef857c15ddb0e222af11
parent 429259 2e2e905fdb24de5861b79d750bbab4c661e8942b
child 429261 627dfd5ef235b3ea22a1534eedb131a8a333d9b0
push id67094
push userccoroiu@mozilla.com
push dateMon, 30 Jul 2018 22:02:32 +0000
treeherderautoland@397b4d841690 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1478743
milestone63.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 1478743 part 3. Remove bogus clearing of the response when xhr.overrideMimeType throws. r=baku
dom/xhr/XMLHttpRequestMainThread.cpp
dom/xhr/tests/test_xhr_overridemimetype_throws_on_invalid_state.html
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/xhr/overridemimetype-done-state.any.js
testing/web-platform/tests/xhr/responsetype.any.js
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -3099,17 +3099,16 @@ XMLHttpRequestMainThread::ReadyState() c
 void
 XMLHttpRequestMainThread::OverrideMimeType(const nsAString& aMimeType,
                                            ErrorResult& aRv)
 {
   NOT_CALLABLE_IN_SYNC_SEND_RV
 
   if (mState == XMLHttpRequest_Binding::LOADING ||
       mState == XMLHttpRequest_Binding::DONE) {
-    ResetResponse();
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_XHR_MUST_NOT_BE_LOADING_OR_DONE);
     return;
   }
 
   mOverrideMimeType = aMimeType;
 }
 
 bool
--- a/dom/xhr/tests/test_xhr_overridemimetype_throws_on_invalid_state.html
+++ b/dom/xhr/tests/test_xhr_overridemimetype_throws_on_invalid_state.html
@@ -12,20 +12,20 @@ SimpleTest.waitForExplicitFinish();
 var url = "file_XHR_pass1.xml";
 
 function onWindowLoad() {
   runTest();
 }
 
 function runTest() {
   var testFunctions = [
-    function() { testOverMimeTypeThrowsDuringReadyState(3, "application/xml"); },
-    function() { testOverMimeTypeThrowsDuringReadyState(3, "application/xml;charset=Shift-JIS"); },
-    function() { testOverMimeTypeThrowsDuringReadyState(4, "application/xml"); },
-    function() { testOverMimeTypeThrowsDuringReadyState(4, "application/xml;charset=Shift-JIS"); },
+    function() { testOverMimeTypeThrowsDuringReadyState(3, "text/plain"); },
+    function() { testOverMimeTypeThrowsDuringReadyState(3, "text/plain;charset=Shift-JIS"); },
+    function() { testOverMimeTypeThrowsDuringReadyState(4, "text/plain"); },
+    function() { testOverMimeTypeThrowsDuringReadyState(4, "text/plain;charset=Shift-JIS"); },
   ];
 
   function nextTest() {
     if (testFunctions.length == 0) {
       SimpleTest.finish();
       return;
     }
     (testFunctions.shift())();
@@ -42,18 +42,19 @@ function runTest() {
           ok(false, "No exception thrown, but expected InvalidStateError" +
                     " for readyState=" + readyState + ", mimeType=" + mimeType);
         } catch(exc) {
           is(exc.name, "InvalidStateError", "Expected InvalidStateError, got " + exc.name +
                        " for readyState=" + readyState + ", mimeType=" + mimeType);
         }
       }
       if (xhr.readyState === 4) {
-        is(xhr.responseXML, null, "responseXML was not null" +
-                                  " for readyState=" + readyState + ", mimeType=" + mimeType);
+        isnot(xhr.responseXML, null, "responseXML was null" +
+                                     " for readyState=" + readyState +
+                                     ", mimeType=" + mimeType);
         nextTest();
       }
     }
     xhr.open("GET", url);
     xhr.send();
   }
 }
 </script>
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -633262,17 +633262,17 @@
    "9e28bf35af12bb962fdfd2213d7e20e031a29703",
    "testharness"
   ],
   "xhr/overridemimetype-blob.html": [
    "38a7f6e2871ac0def651e5b82bb8a43b061633bb",
    "testharness"
   ],
   "xhr/overridemimetype-done-state.any.js": [
-   "bbdf30a044795788f81e6e7addbdc3355fe93fa4",
+   "5924cec26f0bf551a7d37969a62941fc88c177f1",
    "testharness"
   ],
   "xhr/overridemimetype-edge-cases.window.js": [
    "a76e1c81a86823765be280747d2fa6994395cc25",
    "testharness"
   ],
   "xhr/overridemimetype-headers-received-state-force-shiftjis.htm": [
    "92a00af686310d8b44fb5e4c70cc6fbea28e0a88",
@@ -633750,17 +633750,17 @@
    "ab52417826b3953b71b5f6037ebd616d4b862ad4",
    "testharness"
   ],
   "xhr/responsetext-decoding.htm": [
    "d08dd5c1d0b21b639389dfc1deec65215b3334dc",
    "testharness"
   ],
   "xhr/responsetype.any.js": [
-   "8c5d86795c3a88e485990a31e95619b77ab0360c",
+   "eda46254f0b786635b91fdd7f2b63992f2f9ad5d",
    "testharness"
   ],
   "xhr/responseurl.html": [
    "b7ac10fed9c8a07afcd13f1d4906e10996ae56c6",
    "testharness"
   ],
   "xhr/responsexml-basic.htm": [
    "962765bd28850b740b0945d08f31fd94c8883191",
--- a/testing/web-platform/tests/xhr/overridemimetype-done-state.any.js
+++ b/testing/web-platform/tests/xhr/overridemimetype-done-state.any.js
@@ -2,16 +2,19 @@
 
 /**
  * Spec: <https://xhr.spec.whatwg.org/#the-overridemimetype()-method>; data-tested-assertations="/following::ol/li[1]"
  */
 var test = async_test();
 var client = new XMLHttpRequest();
 client.onreadystatechange = test.step_func( function() {
   if (client.readyState !== 4) return;
+  var text = client.responseText;
+  assert_not_equals(text, "");
   assert_throws("InvalidStateError", function() { client.overrideMimeType('application/xml;charset=Shift-JIS'); });
   if (GLOBAL.isWindow()) {
     assert_equals(client.responseXML, null);
   }
+  assert_equals(client.responseText, text);
   test.done();
 });
 client.open("GET", "resources/status.py?type="+encodeURIComponent('text/plain;charset=iso-8859-1')+'&content=%3Cmsg%3E%83%65%83%58%83%67%3C%2Fmsg%3E');
 client.send();
--- a/testing/web-platform/tests/xhr/responsetype.any.js
+++ b/testing/web-platform/tests/xhr/responsetype.any.js
@@ -80,24 +80,27 @@ types.forEach(function(type) {
     xhr.send();
   }, 'Set responseType to ' + format_value(type) + ' when readyState is LOADING.');
 
   async_test(function() {
     var xhr = new XMLHttpRequest();
     xhr.open('get', '/');
     xhr.onreadystatechange = this.step_func(function() {
       if (xhr.readyState === XMLHttpRequest.DONE) {
+        var text = xhr.responseText;
+        assert_not_equals(text, "");
         if (isIgnoredType(type)) {
           xhr.responseType = type;
         } else {
           assert_throws("InvalidStateError", function() {
             xhr.responseType = type;
           });
         }
         assert_equals(xhr.responseType, "");
+        assert_equals(xhr.responseText, text);
         this.done();
       }
     });
     xhr.send();
   }, 'Set responseType to ' + format_value(type) + ' when readyState is DONE.');
 
   // Note: the case of setting responseType first, and then calling synchronous
   // open(), is tested in open-method-responsetype-set-sync.htm.