From 8ffc4a204758fc6240e97d5dc35a3a51a24949b8 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Tue, 12 Jan 2016 12:15:12 -0800 Subject: [PATCH] Bug 1238134 P2 Test chrome-only Response.cloneUnfiltered(). r=ehsan --- dom/tests/mochitest/fetch/test_response.js | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/dom/tests/mochitest/fetch/test_response.js b/dom/tests/mochitest/fetch/test_response.js index 6adde5882756..e396184ee392 100644 --- a/dom/tests/mochitest/fetch/test_response.js +++ b/dom/tests/mochitest/fetch/test_response.js @@ -67,6 +67,30 @@ function testClone() { }); } +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"); @@ -234,5 +258,10 @@ function runTest() { .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!'); + }); }