Bug 1238134 P2 Test chrome-only Response.cloneUnfiltered(). r=ehsan
authorBen Kelly <ben@wanderview.com>
Tue, 12 Jan 2016 12:15:12 -0800
changeset 314777 b12cc3b2697b8c004f2c2c22fca8b15473e74dcf
parent 314776 d0b39a33e04200fade4553f4cb5d72187b282bee
child 314778 fa3363702d5180b8fc3f182bf8f9cf0382661379
push id5703
push userraliiev@mozilla.com
push dateMon, 07 Mar 2016 14:18:41 +0000
treeherdermozilla-beta@31e373ad5b5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1238134
milestone46.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 1238134 P2 Test chrome-only Response.cloneUnfiltered(). r=ehsan
dom/tests/mochitest/fetch/test_response.js
--- a/dom/tests/mochitest/fetch/test_response.js
+++ b/dom/tests/mochitest/fetch/test_response.js
@@ -62,16 +62,40 @@ function testClone() {
       clone2.clone()
       ok(false, "Cannot clone Response whose body is already consumed");
     } catch (e) {
       is(e.name, "TypeError", "clone() of consumed body should throw TypeError");
     }
   });
 }
 
+function testCloneUnfiltered() {
+  var url = 'http://example.com/tests/dom/security/test/cors/file_CrossSiteXHR_server.sjs?status=200';
+  return fetch(url, { mode: 'no-cors' }).then(function(response) {
+    // By default the chrome-only function should not be available.
+    is(response.type, 'opaque', 'response should be opaque');
+    is(response.cloneUnfiltered, undefined,
+       'response.cloneUnfiltered should be undefined');
+
+    // When the test is run in a worker context we can't actually try to use
+    // the chrome-only function.  SpecialPowers is not defined.
+    if (typeof SpecialPowers !== 'object') {
+      return;
+    }
+
+    // With a chrome code, however, should be able to get an unfiltered response.
+    var chromeResponse = SpecialPowers.wrap(response);
+    is(typeof chromeResponse.cloneUnfiltered, 'function',
+       'chromeResponse.cloneFiltered should be a function');
+    var unfiltered = chromeResponse.cloneUnfiltered();
+    is(unfiltered.type, 'default', 'unfiltered response should be default');
+    is(unfiltered.status, 200, 'unfiltered response should have 200 status');
+  });
+}
+
 function testError() {
   var res = Response.error();
   is(res.status, 0, "Error response status should be 0");
   try {
     res.headers.set("someheader", "not allowed");
     ok(false, "Error response should have immutable headers");
   } catch(e) {
     ok(true, "Error response should have immutable headers");
@@ -229,10 +253,15 @@ function runTest() {
   testOk();
   testNullBodyStatus();
 
   return Promise.resolve()
     .then(testBodyCreation)
     .then(testBodyUsed)
     .then(testBodyExtraction)
     .then(testClone)
+    .then(testCloneUnfiltered)
     // Put more promise based tests here.
+    .catch(function(e) {
+      dump('### ### ' + e + '\n');
+      ok(false, 'got unexpected error!');
+    });
 }