Bug 1397151 - Remove the support for moz-chunk-text type in XHR, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 22 Sep 2017 07:18:49 +0200
changeset 668894 9fb93fcf2b8eece6b7b23d12e29cbacc16e90b0c
parent 668893 cfb739b281f8640bcb4a4ec4515e8a6dd7c22040
child 668895 66ce2b29437497779221055ae087feffc181994b
child 669122 aad29639fd5bc9ac04c63fa8f2390a3731f1af0c
push id81146
push userbmo:topwu.tw@gmail.com
push dateFri, 22 Sep 2017 05:24:51 +0000
reviewerssmaug
bugs1397151
milestone58.0a1
Bug 1397151 - Remove the support for moz-chunk-text type in XHR, r=smaug
dom/base/domerr.msg
dom/webidl/XMLHttpRequest.webidl
dom/xhr/XMLHttpRequestMainThread.cpp
dom/xhr/tests/test_XHR.html
dom/xhr/tests/test_html_in_xhr.html
dom/xhr/tests/test_xhr_progressevents.html
dom/xhr/tests/xhr2_worker.js
testing/web-platform/meta/XMLHttpRequest/historical.html.ini
toolkit/components/telemetry/Histograms.json
--- a/dom/base/domerr.msg
+++ b/dom/base/domerr.msg
@@ -156,11 +156,11 @@ DOM4_MSG_DEF(SyntaxError, "The URI is ma
 DOM4_MSG_DEF(SyntaxError, "Invalid header name.", NS_ERROR_DOM_INVALID_HEADER_NAME)
 
 /* XMLHttpRequest errors. */
 DOM4_MSG_DEF(InvalidStateError, "XMLHttpRequest has an invalid context.", NS_ERROR_DOM_INVALID_STATE_XHR_HAS_INVALID_CONTEXT)
 DOM4_MSG_DEF(InvalidStateError, "XMLHttpRequest state must be OPENED.", NS_ERROR_DOM_INVALID_STATE_XHR_MUST_BE_OPENED)
 DOM4_MSG_DEF(InvalidStateError, "XMLHttpRequest must not be sending.", NS_ERROR_DOM_INVALID_STATE_XHR_MUST_NOT_BE_SENDING)
 DOM4_MSG_DEF(InvalidStateError, "XMLHttpRequest state must not be LOADING or DONE.", NS_ERROR_DOM_INVALID_STATE_XHR_MUST_NOT_BE_LOADING_OR_DONE)
 DOM4_MSG_DEF(InvalidStateError, "responseXML is only available if responseType is '' or 'document'.", NS_ERROR_DOM_INVALID_STATE_XHR_HAS_WRONG_RESPONSETYPE_FOR_RESPONSEXML)
-DOM4_MSG_DEF(InvalidStateError, "responseText is only available if responseType is '', 'document', or 'moz-chunked-text'.", NS_ERROR_DOM_INVALID_STATE_XHR_HAS_WRONG_RESPONSETYPE_FOR_RESPONSETEXT)
-DOM4_MSG_DEF(InvalidStateError, "synchronous XMLHttpRequests do not support 'moz-chunked-text' or 'moz-chunked-arraybuffer' responseType.", NS_ERROR_DOM_INVALID_STATE_XHR_CHUNKED_RESPONSETYPES_UNSUPPORTED_FOR_SYNC)
+DOM4_MSG_DEF(InvalidStateError, "responseText is only available if responseType is '' or 'document'.", NS_ERROR_DOM_INVALID_STATE_XHR_HAS_WRONG_RESPONSETYPE_FOR_RESPONSETEXT)
+DOM4_MSG_DEF(InvalidStateError, "synchronous XMLHttpRequests do not support 'moz-chunked-arraybuffer' responseType.", NS_ERROR_DOM_INVALID_STATE_XHR_CHUNKED_RESPONSETYPES_UNSUPPORTED_FOR_SYNC)
 DOM4_MSG_DEF(InvalidAccessError, "synchronous XMLHttpRequests do not support timeout and responseType.", NS_ERROR_DOM_INVALID_ACCESS_XHR_TIMEOUT_AND_RESPONSETYPE_UNSUPPORTED_FOR_SYNC)
--- a/dom/webidl/XMLHttpRequest.webidl
+++ b/dom/webidl/XMLHttpRequest.webidl
@@ -18,17 +18,16 @@ enum XMLHttpRequestResponseType {
   "",
   "arraybuffer",
   "blob",
   "document",
   "json",
   "text",
 
   // Mozilla-specific stuff
-  "moz-chunked-text",
   "moz-chunked-arraybuffer",
 };
 
 /**
  * Parameters for instantiating an XMLHttpRequest. They are passed as an
  * optional argument to the constructor:
  *
  *  new XMLHttpRequest({anon: true, system: true});
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -496,18 +496,17 @@ XMLHttpRequestMainThread::GetResponseXML
 nsresult
 XMLHttpRequestMainThread::DetectCharset()
 {
   mResponseCharset = nullptr;
   mDecoder = nullptr;
 
   if (mResponseType != XMLHttpRequestResponseType::_empty &&
       mResponseType != XMLHttpRequestResponseType::Text &&
-      mResponseType != XMLHttpRequestResponseType::Json &&
-      mResponseType != XMLHttpRequestResponseType::Moz_chunked_text) {
+      mResponseType != XMLHttpRequestResponseType::Json) {
     return NS_OK;
   }
 
   nsAutoCString charsetVal;
   const Encoding* encoding;
   bool ok = mChannel &&
             NS_SUCCEEDED(mChannel->GetContentCharset(charsetVal)) &&
             (encoding = Encoding::ForLabel(charsetVal));
@@ -602,28 +601,21 @@ XMLHttpRequestMainThread::GetResponseTex
 
 void
 XMLHttpRequestMainThread::GetResponseText(XMLHttpRequestStringSnapshot& aSnapshot,
                                           ErrorResult& aRv)
 {
   aSnapshot.Reset();
 
   if (mResponseType != XMLHttpRequestResponseType::_empty &&
-      mResponseType != XMLHttpRequestResponseType::Text &&
-      mResponseType != XMLHttpRequestResponseType::Moz_chunked_text) {
+      mResponseType != XMLHttpRequestResponseType::Text) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_XHR_HAS_WRONG_RESPONSETYPE_FOR_RESPONSETEXT);
     return;
   }
 
-  if (mResponseType == XMLHttpRequestResponseType::Moz_chunked_text &&
-      !mInLoadProgressEvent) {
-    aSnapshot.SetVoid();
-    return;
-  }
-
   if (mState != State::loading && mState != State::done) {
     return;
   }
 
   // Main Fetch step 18 requires to ignore body for head/connect methods.
   if (mRequestMethod.EqualsLiteral("HEAD") ||
       mRequestMethod.EqualsLiteral("CONNECT")) {
     return;
@@ -717,26 +709,23 @@ XMLHttpRequestMainThread::SetResponseTyp
   // sync request is not allowed setting responseType in window context
   if (HasOrHasHadOwner() && mState != State::unsent && mFlagSynchronous) {
     LogMessage("ResponseTypeSyncXHRWarning", GetOwner());
     aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_XHR_TIMEOUT_AND_RESPONSETYPE_UNSUPPORTED_FOR_SYNC);
     return;
   }
 
   if (mFlagSynchronous &&
-      (aResponseType == XMLHttpRequestResponseType::Moz_chunked_text ||
-       aResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer)) {
+      aResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_XHR_CHUNKED_RESPONSETYPES_UNSUPPORTED_FOR_SYNC);
     return;
   }
 
   // We want to get rid of this moz-only types. Bug 1335365.
-  if (aResponseType == XMLHttpRequestResponseType::Moz_chunked_text) {
-    Telemetry::Accumulate(Telemetry::MOZ_CHUNKED_TEXT_IN_XHR, 1);
-  } else if (aResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer) {
+  if (aResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer) {
     Telemetry::Accumulate(Telemetry::MOZ_CHUNKED_ARRAYBUFFER_IN_XHR, 1);
   }
 
   // Set the responseType attribute's value to the given value.
   mResponseType = aResponseType;
 }
 
 NS_IMETHODIMP
@@ -750,17 +739,16 @@ XMLHttpRequestMainThread::GetResponse(JS
 void
 XMLHttpRequestMainThread::GetResponse(JSContext* aCx,
                                       JS::MutableHandle<JS::Value> aResponse,
                                       ErrorResult& aRv)
 {
   switch (mResponseType) {
   case XMLHttpRequestResponseType::_empty:
   case XMLHttpRequestResponseType::Text:
-  case XMLHttpRequestResponseType::Moz_chunked_text:
   {
     DOMString str;
     GetResponseText(str, aRv);
     if (aRv.Failed()) {
       return;
     }
     if (!xpc::StringToJsval(aCx, str, aResponse)) {
       aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
@@ -1391,18 +1379,17 @@ XMLHttpRequestMainThread::DispatchProgre
   event->SetTrusted(true);
 
   DispatchOrStoreEvent(aTarget, event);
 
   if (aType == ProgressEventType::progress) {
     mInLoadProgressEvent = false;
 
     // clear chunked responses after every progress event
-    if (mResponseType == XMLHttpRequestResponseType::Moz_chunked_text ||
-        mResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer) {
+    if (mResponseType == XMLHttpRequestResponseType::Moz_chunked_arraybuffer) {
       mResponseBody.Truncate();
       TruncateResponseText();
       mResultArrayBuffer = nullptr;
       mArrayBufferBuilder.reset();
     }
   }
 
   // If we're sending a load, error, timeout or abort event, then
@@ -1698,18 +1685,17 @@ XMLHttpRequestMainThread::StreamReaderFu
   } else if (xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::_empty &&
              xmlHttpRequest->mResponseXML) {
     // Copy for our own use
     if (!xmlHttpRequest->mResponseBody.Append(fromRawSegment, count, fallible)) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
   } else if (xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::_empty ||
              xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Text ||
-             xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Json ||
-             xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Moz_chunked_text) {
+             xmlHttpRequest->mResponseType == XMLHttpRequestResponseType::Json) {
     NS_ASSERTION(!xmlHttpRequest->mResponseXML,
                  "We shouldn't be parsing a doc here");
     rv = xmlHttpRequest->AppendToResponseText(fromRawSegment, count);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
--- a/dom/xhr/tests/test_XHR.html
+++ b/dom/xhr/tests/test_XHR.html
@@ -124,30 +124,28 @@ function checkOpenThrows(xhr, method, ur
 // test if setting responseType before calling open() works
 xhr = new XMLHttpRequest();
 checkSetResponseType(xhr, "");
 checkSetResponseType(xhr, "text");
 checkSetResponseType(xhr, "document");
 checkSetResponseType(xhr, "arraybuffer");
 checkSetResponseType(xhr, "blob");
 checkSetResponseType(xhr, "json");
-checkSetResponseType(xhr, "moz-chunked-text");
 checkSetResponseType(xhr, "moz-chunked-arraybuffer");
 checkOpenThrows(xhr, "GET", "file_XHR_pass2.txt", false);
 
 // test response (sync, responseType is not changeable)
 xhr = new XMLHttpRequest();
 xhr.open("GET", 'file_XHR_pass2.txt', false); 
 checkSetResponseTypeThrows(xhr, "");
 checkSetResponseTypeThrows(xhr, "text");
 checkSetResponseTypeThrows(xhr, "document");
 checkSetResponseTypeThrows(xhr, "arraybuffer");
 checkSetResponseTypeThrows(xhr, "blob");
 checkSetResponseTypeThrows(xhr, "json");
-checkSetResponseTypeThrows(xhr, "moz-chunked-text");
 checkSetResponseTypeThrows(xhr, "moz-chunked-arraybuffer");
 xhr.send(null);
 checkSetResponseTypeThrows(xhr, "document");
 is(xhr.status, 200, "wrong status");
 is(xhr.response, "hello pass\n", "wrong response");
 
 // test response (responseType='document')
 xhr = new XMLHttpRequest();
--- a/dom/xhr/tests/test_html_in_xhr.html
+++ b/dom/xhr/tests/test_html_in_xhr.html
@@ -69,39 +69,24 @@ function continueAfterReport() {
 }
 
 function testNonParsingText() {
   xhr = new XMLHttpRequest();
   xhr.onreadystatechange = function() {
     if (this.readyState == 4) {
       is(this.responseText.indexOf("\u042E"), -1, "Honored meta in text mode.");
       is(this.responseText.indexOf("\uFFFD"), 29, "Honored meta in text mode 2.");
-      testChunkedText();
+      testSyncXHR();
     }
   }
   xhr.open("GET", "file_html_in_xhr2.html");
   xhr.responseType = "text";
   xhr.send();   
 }
 
-function testChunkedText() {
-  xhr = new XMLHttpRequest();
-  xhr.onprogress = function() {
-    is(this.responseText.indexOf("\u042E"), -1, "Honored meta in chunked text mode.");
-  }
-  xhr.onreadystatechange = function() {
-    if (this.readyState == 4) {
-      testSyncXHR();
-    }
-  }
-  xhr.open("GET", "file_html_in_xhr2.html");
-  xhr.responseType = "moz-chunked-text";
-  xhr.send();   
-}
-
 function testSyncXHR() {
   xhr = new XMLHttpRequest();
   xhr.open("GET", "file_html_in_xhr3.html", false);
   xhr.send();   
   is(xhr.responseText, "SUCCESS\n", "responseText should be ready by now");
   is(xhr.responseXML, null, "responseXML should be null in the sync case");
   SimpleTest.finish();
 }
--- a/dom/xhr/tests/test_xhr_progressevents.html
+++ b/dom/xhr/tests/test_xhr_progressevents.html
@@ -130,17 +130,16 @@ function* runTests() {
   xhr.onprogress = xhr.onload = xhr.onerror = xhr.onreadystatechange = xhr.onloadend = getEvent;
 
   var responseTypes = [{ type: "text", text: true },
                        { type: "arraybuffer", text: false, nodata: true },
                        { type: "blob", text: false, nodata: true, blob: true },
                        { type: "document", text: true, nodata: true },
                        { type: "json", text: true, nodata: true },
                        { type: "", text: true },
-                       { type: "moz-chunked-text", text: true, chunked: true },
                        { type: "moz-chunked-arraybuffer", text: false, chunked: true },
                       ];
   var responseType;
   var fileExpectedResult = "";
   for (var i = 0; i < 65536; i++) {
     fileExpectedResult += String.fromCharCode(i & 255);
   }
   while (responseType = responseTypes.shift()) {
--- a/dom/xhr/tests/xhr2_worker.js
+++ b/dom/xhr/tests/xhr2_worker.js
@@ -91,73 +91,10 @@ onmessage = function(event) {
   xhr.open("GET", url, false);
   xhr.responseType = "document";
   xhr.send();
 
   if (xhr.responseText != refText) {
     throw new Error("'document' type not working correctly");
   }
 
-  // Make sure setting responseType before open or after send fails.
-  var exception;
-
-  xhr = new XMLHttpRequest();
-  xhr.open("GET", url);
-  xhr.responseType = "text";
-  xhr.onload = function(event) {
-    if (event.target.response != refText) {
-      throw new Error("Bad response!");
-    }
-
-    xhr = new XMLHttpRequest();
-    xhr.open("GET", url);
-    xhr.responseType = "moz-chunked-text";
-
-    var lastIndex = 0;
-    xhr.onprogress = function(event) {
-      if (refText.substr(lastIndex, xhr.response.length) != xhr.response) {
-        throw new Error("Bad chunk!");
-      }
-
-      lastIndex += xhr.response.length;
-    };
-
-    xhr.onload = function(event) {
-      if (lastIndex != refText.length) {
-        throw new Error("Didn't see all the data!");
-      }
-
-      setTimeout(function() {
-        if (xhr.response !== null) {
-          throw new Error("Should have gotten null response outside of event!");
-        }
-        postMessage("done");
-      }, 0);
-    }
-
-    xhr.send(null);
-  };
-  xhr.send();
-
-  exception = null;
-
-  try {
-    xhr.responseType = "arraybuffer";
-  }
-  catch(e) {
-    exception = e;
-  }
-
-  if (!exception) {
-    throw new Error("Failed to throw when setting responseType after " +
-                    "calling send()");
-  }
-
-  if (exception.name != "InvalidStateError") {
-    throw new Error("Unexpected error when setting responseType after " +
-                    "calling send()");
-  }
-
-  if (exception.code != DOMException.INVALID_STATE_ERR) {
-    throw new Error("Unexpected error code when setting responseType after " +
-                    "calling send()");
-  }
+  postMessage("done");
 }
--- a/testing/web-platform/meta/XMLHttpRequest/historical.html.ini
+++ b/testing/web-platform/meta/XMLHttpRequest/historical.html.ini
@@ -1,8 +1,5 @@
 [historical.html]
   type: testharness
-  [Support for responseType = moz-chunked-text]
-    expected: FAIL
-
   [Support for responseType = moz-chunked-arraybuffer]
     expected: FAIL
 
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -12958,25 +12958,16 @@
     "expires_in_version": "60",
     "kind": "exponential",
     "keyed": true,
     "high": 10000,
     "n_buckets": 10,
     "bug_numbers": [1331804],
     "description": "The time a given main thread runnable took to run (in milliseconds). The key comes from the runnables nsINamed::name value."
   },
-  "MOZ_CHUNKED_TEXT_IN_XHR": {
-    "record_in_processes": ["main", "content"],
-    "alert_emails": ["amarchesini@mozilla.com"],
-    "expires_in_version": "58",
-    "kind": "boolean",
-    "bug_numbers": [1335365],
-    "releaseChannelCollection": "opt-out",
-    "description": "XMLHttpRequest.responseType set to moz-chunked-text"
-  },
   "MOZ_CHUNKED_ARRAYBUFFER_IN_XHR": {
     "record_in_processes": ["main", "content"],
     "alert_emails": ["amarchesini@mozilla.com"],
     "expires_in_version": "58",
     "kind": "boolean",
     "bug_numbers": [1335365],
     "releaseChannelCollection": "opt-out",
     "description": "XMLHttpRequest.responseType set to moz-chunked-arraybuffer"