Bug 1517448 - Set PrincipalInfo for Request and Response objects - tests, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 03 Jan 2019 19:24:38 +0100
changeset 509556 4ab6053311fcc01d98b227d4da53411c94bbd700
parent 509555 2a5bc7dcd7a83334d18728e9402d083fc6caef78
child 509557 7944bf2a3077cc35248099c2eceb24e4087aaf65
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1517448
milestone66.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 1517448 - Set PrincipalInfo for Request and Response objects - tests, r=smaug
dom/tests/mochitest/fetch/common_temporaryFileBlob.js
dom/tests/mochitest/fetch/test_temporaryFileBlob.html
dom/tests/mochitest/fetch/worker_temporaryFileBlob.js
--- a/dom/tests/mochitest/fetch/common_temporaryFileBlob.js
+++ b/dom/tests/mochitest/fetch/common_temporaryFileBlob.js
@@ -19,31 +19,17 @@ function test_fetch_basic() {
     fr.onload = function() {
       is(fr.result, data, "Data content matches");
       next();
     }
   });
 }
 
 function test_fetch_worker() {
-  info("fetch in workers");
-  var w = new Worker('worker_temporaryFileBlob.js');
-  w.onmessage = function(e) {
-    if (e.data.type == 'info') {
-      info(e.data.msg);
-    } else if (e.data.type == 'check') {
-      ok(e.data.what, e.data.msg);
-    } else if (e.data.type == 'finish') {
-      next();
-    } else {
-      ok(false, 'Something wrong happened');
-    }
-  }
-
-  w.postMessage('fetch');
+  generic_worker_test("fetch in workers", "fetch");
 }
 
 function test_xhr_basic() {
   info("Simple XHR test");
 
   let xhr = new XMLHttpRequest();
   xhr.responseType = "blob";
   xhr.open("POST", "/tests/dom/xhr/tests/temporaryFileBlob.sjs");
@@ -65,24 +51,77 @@ function test_xhr_basic() {
         is(fr.result, data, "Data content matches");
         next();
       }
     }
   }
 }
 
 function test_xhr_worker() {
-  info("XHR in workers");
+  generic_worker_test("XHR in workers", "xhr");
+}
+
+function test_response_basic() {
+  info("Response");
+
+  let r = new Response(data);
+  r.blob().then(blob => {
+    ok(blob instanceof Blob, "We have a blob!");
+    is(blob.size, data.length, "Data length matches");
+    if ("SpecialPowers" in self) {
+      is(SpecialPowers.wrap(blob).blobImplType, "StreamBlobImpl", "We have a blob stored into a stream file");
+    }
+
+    var fr = new FileReader();
+    fr.readAsText(blob);
+    fr.onload = function() {
+      is(fr.result, data, "Data content matches");
+      next();
+    }
+  });
+}
+
+function test_response_worker() {
+  generic_worker_test("Response in workers", "response");
+}
+
+function test_request_basic() {
+  info("Request");
+
+  let r = new Request("https://example.com", { body: data, method: 'POST' });
+  r.blob().then(blob => {
+    ok(blob instanceof Blob, "We have a blob!");
+    is(blob.size, data.length, "Data length matches");
+    if ("SpecialPowers" in self) {
+      is(SpecialPowers.wrap(blob).blobImplType, "StreamBlobImpl", "We have a blob stored into a stream file");
+    }
+
+    var fr = new FileReader();
+    fr.readAsText(blob);
+    fr.onload = function() {
+      is(fr.result, data, "Data content matches");
+      next();
+    }
+  });
+}
+
+function test_request_worker() {
+  generic_worker_test("Request in workers", "request");
+}
+
+function generic_worker_test(title, what) {
+  info(title);
+
   var w = new Worker('worker_temporaryFileBlob.js');
   w.onmessage = function(e) {
     if (e.data.type == 'info') {
       info(e.data.msg);
     } else if (e.data.type == 'check') {
       ok(e.data.what, e.data.msg);
     } else if (e.data.type == 'finish') {
       next();
     } else {
       ok(false, 'Something wrong happened');
     }
   }
 
-  w.postMessage('xhr');
+  w.postMessage(what);
 }
--- a/dom/tests/mochitest/fetch/test_temporaryFileBlob.html
+++ b/dom/tests/mochitest/fetch/test_temporaryFileBlob.html
@@ -11,16 +11,20 @@
   <script type="application/javascript">
 
 var tests = [
   // from common_temporaryFileBlob.js:
   test_fetch_basic,
   test_fetch_worker,
   test_xhr_basic,
   test_xhr_worker,
+  test_response_basic,
+  test_response_worker,
+  test_request_basic,
+  test_request_worker,
 ];
 
 function next() {
   if (!tests.length) {
     SimpleTest.finish();
     return;
   }
 
--- a/dom/tests/mochitest/fetch/worker_temporaryFileBlob.js
+++ b/dom/tests/mochitest/fetch/worker_temporaryFileBlob.js
@@ -12,14 +12,20 @@ function is(a, b, msg) {
   ok(a === b, msg);
 }
 
 function next() {
   postMessage({type: 'finish'});
 }
 
 onmessage = function(e) {
-  if (e == 'xhr') {
+  if (e.data == 'xhr') {
     test_xhr_basic();
+  } else if (e.data == 'fetch') {
+    test_fetch_basic();
+  } else if (e.data == 'response') {
+    test_response_basic();
+  } else if (e.data == 'request') {
+    test_request_basic();
   } else {
-    test_fetch_basic();
+    ok(false, "Unknown message");
   }
 }