Bug 1478743 part 1. Add some test coverage for setting xhr.responseType on workers. r=baku
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 30 Jul 2018 11:51:47 -0400
changeset 429258 565222693850d45b60b64ddc04e7106ae15b027b
parent 429257 3895fde69249ee14f4f3d55aafe090bcfd0d6cb0
child 429259 2e2e905fdb24de5861b79d750bbab4c661e8942b
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 1. Add some test coverage for setting xhr.responseType on workers. r=baku Most of the change is just making the responseType wpt run on workers and annotating the resulting failures. The change to the initial value of mResponseType is a drive-by fix for an easy-to-fix issue the test caught. There is a corresponding mochitest fix to fix our incorrect test for the behavior.
dom/xhr/XMLHttpRequestWorker.cpp
dom/xhr/tests/xhr2_worker.js
testing/web-platform/meta/MANIFEST.json
testing/web-platform/meta/xhr/responsetype.any.js.ini
testing/web-platform/tests/xhr/responsetype.any.js
testing/web-platform/tests/xhr/responsetype.html
--- a/dom/xhr/XMLHttpRequestWorker.cpp
+++ b/dom/xhr/XMLHttpRequestWorker.cpp
@@ -1524,17 +1524,17 @@ SendRunnable::RunOnMainThread(ErrorResul
         MOZ_ASSERT(false, "This should never fail!");
       }
     }
   }
 }
 
 XMLHttpRequestWorker::XMLHttpRequestWorker(WorkerPrivate* aWorkerPrivate)
   : mWorkerPrivate(aWorkerPrivate)
-  , mResponseType(XMLHttpRequestResponseType::Text)
+  , mResponseType(XMLHttpRequestResponseType::_empty)
   , mTimeout(0)
   , mBackgroundRequest(false)
   , mWithCredentials(false)
   , mCanceled(false)
   , mMozAnon(false)
   , mMozSystem(false)
 {
   mWorkerPrivate->AssertIsOnWorkerThread();
--- a/dom/xhr/tests/xhr2_worker.js
+++ b/dom/xhr/tests/xhr2_worker.js
@@ -79,17 +79,17 @@ onmessage = function(event) {
   }
 
   testResponseTextException("arraybuffer");
   testResponseTextException("blob");
 
   // Make sure "document" works, but returns text.
   xhr = new XMLHttpRequest();
 
-  if (xhr.responseType != "text") {
+  if (xhr.responseType != "") {
     throw new Error("Default value for responseType is wrong!");
   }
 
   xhr.open("GET", url, false);
   xhr.responseType = "document";
   xhr.send();
 
   if (xhr.responseText != refText) {
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -389588,19 +389588,23 @@
     ]
    ],
    "xhr/responsetext-decoding.htm": [
     [
      "/xhr/responsetext-decoding.htm",
      {}
     ]
    ],
-   "xhr/responsetype.html": [
-    [
-     "/xhr/responsetype.html",
+   "xhr/responsetype.any.js": [
+    [
+     "/xhr/responsetype.any.html",
+     {}
+    ],
+    [
+     "/xhr/responsetype.any.worker.html",
      {}
     ]
    ],
    "xhr/responseurl.html": [
     [
      "/xhr/responseurl.html",
      {}
     ]
@@ -633741,18 +633745,18 @@
   "xhr/responsedocument-decoding.htm": [
    "ab52417826b3953b71b5f6037ebd616d4b862ad4",
    "testharness"
   ],
   "xhr/responsetext-decoding.htm": [
    "d08dd5c1d0b21b639389dfc1deec65215b3334dc",
    "testharness"
   ],
-  "xhr/responsetype.html": [
-   "090ae5981aed9e0ed5e5f8a2f5615d57df0c366b",
+  "xhr/responsetype.any.js": [
+   "8c5d86795c3a88e485990a31e95619b77ab0360c",
    "testharness"
   ],
   "xhr/responseurl.html": [
    "b7ac10fed9c8a07afcd13f1d4906e10996ae56c6",
    "testharness"
   ],
   "xhr/responsexml-basic.htm": [
    "962765bd28850b740b0945d08f31fd94c8883191",
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/xhr/responsetype.any.js.ini
@@ -0,0 +1,16 @@
+[responsetype.any.worker.html]
+  [Set responseType to "" when readyState is HEADERS_RECEIVED.]
+    expected: FAIL
+
+  [Set responseType to "json" when readyState is HEADERS_RECEIVED.]
+    expected: FAIL
+
+  [Set responseType to "arraybuffer" when readyState is HEADERS_RECEIVED.]
+    expected: FAIL
+
+  [Set responseType to "blob" when readyState is HEADERS_RECEIVED.]
+    expected: FAIL
+
+  [Set responseType to "text" when readyState is HEADERS_RECEIVED.]
+    expected: FAIL
+
rename from testing/web-platform/tests/xhr/responsetype.html
rename to testing/web-platform/tests/xhr/responsetype.any.js
--- a/testing/web-platform/tests/xhr/responsetype.html
+++ b/testing/web-platform/tests/xhr/responsetype.any.js
@@ -1,96 +1,132 @@
-<!DOCTYPE html>
-<meta charset="utf-8">
-<title>XMLHttpRequest.responseType</title>
-<link rel="author" title="Mathias Bynens" href="http://mathiasbynens.be/">
-<link rel="author" title="Ms2ger" href="mailto:Ms2ger@gmail.com">
-<link rel="help" href="https://xhr.spec.whatwg.org/#the-responsetype-attribute">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<div id="log"></div>
-<script>
+// META: title=XMLHttpRequest.responseType
+
+/**
+ * Author: Mathias Bynens <http://mathiasbynens.be/>
+ * Author: Ms2ger <mailto:Ms2ger@gmail.com>
+ *
+ * Spec: <https://xhr.spec.whatwg.org/#the-responsetype-attribute>
+ */
 test(function() {
   var xhr = new XMLHttpRequest();
   assert_equals(xhr.responseType, '');
 }, 'Initial value of responseType');
 
-var types = ['', 'json', 'document', 'arraybuffer', 'blob', 'text'];
+var types = ['', 'json', 'document', 'arraybuffer', 'blob', 'text', "nosuchtype"];
+
+function isIgnoredType(type) {
+  if (type == "nosuchtype") {
+    return true;
+  }
+
+  if (type != "document") {
+    return false;
+  }
+
+  // "document" is ignored only on workers.
+  return GLOBAL.isWorker();
+}
+
+function expectedType(type) {
+  if (!isIgnoredType(type)) {
+    return type;
+  }
+
+  return "";
+}
+
 types.forEach(function(type) {
   test(function() {
     var xhr = new XMLHttpRequest();
     xhr.responseType = type;
-    assert_equals(xhr.responseType, type);
+    assert_equals(xhr.responseType, expectedType(type));
   }, 'Set responseType to ' + format_value(type) + ' when readyState is UNSENT.');
 
   test(function() {
     var xhr = new XMLHttpRequest();
     xhr.open('get', '/');
     xhr.responseType = type;
-    assert_equals(xhr.responseType, type);
+    assert_equals(xhr.responseType, expectedType(type));
   }, 'Set responseType to ' + format_value(type) + ' when readyState is OPENED.');
 
   async_test(function() {
     var xhr = new XMLHttpRequest();
     xhr.open('get', '/');
     xhr.onreadystatechange = this.step_func(function() {
       if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
         xhr.responseType = type;
-        assert_equals(xhr.responseType, type);
+        assert_equals(xhr.responseType, expectedType(type));
         this.done();
       }
     });
     xhr.send();
   }, 'Set responseType to ' + format_value(type) + ' when readyState is HEADERS_RECEIVED.');
 
   async_test(function() {
     var xhr = new XMLHttpRequest();
     xhr.open('get', '/');
     xhr.onreadystatechange = this.step_func(function() {
       if (xhr.readyState === XMLHttpRequest.LOADING) {
-        assert_throws("InvalidStateError", function() {
+        if (isIgnoredType(type)) {
           xhr.responseType = type;
-        });
+        } else {
+          assert_throws("InvalidStateError", function() {
+            xhr.responseType = type;
+          });
+        }
         assert_equals(xhr.responseType, "");
         this.done();
       }
     });
     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) {
-        assert_throws("InvalidStateError", function() {
+        if (isIgnoredType(type)) {
           xhr.responseType = type;
-        });
+        } else {
+          assert_throws("InvalidStateError", function() {
+            xhr.responseType = type;
+          });
+        }
         assert_equals(xhr.responseType, "");
         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.
   test(function() {
     var xhr = new XMLHttpRequest();
     xhr.open('get', '/', false);
-    assert_throws("InvalidAccessError", function() {
+    if (GLOBAL.isWorker() || isIgnoredType(type)) {
+      // Setting responseType on workers is valid even for a sync XHR.
       xhr.responseType = type;
-    });
-    assert_equals(xhr.responseType, "");
+      assert_equals(xhr.responseType, expectedType(type));
+    } else {
+      assert_throws("InvalidAccessError", function() {
+        xhr.responseType = type;
+      });
+    }
   }, 'Set responseType to ' + format_value(type) + ' when readyState is OPENED and the sync flag is set.');
 
   test(function() {
     var xhr = new XMLHttpRequest();
     xhr.open('get', '/', false);
     xhr.send();
     assert_equals(xhr.readyState, XMLHttpRequest.DONE);
-    assert_throws("InvalidStateError", function() {
+    if (isIgnoredType(type)) {
       xhr.responseType = type;
-    });
+    } else {
+      assert_throws("InvalidStateError", function() {
+        xhr.responseType = type;
+      });
+    }
     assert_equals(xhr.responseType, "");
   }, 'Set responseType to ' + format_value(type) + ' when readyState is DONE and the sync flag is set.');
 });
-</script>