From 5dad9554f62bbfcaa6c105aa1b45dd8417cee564 Mon Sep 17 00:00:00 2001 From: Shane Caraveo Date: Wed, 2 Nov 2016 09:27:48 -0700 Subject: [PATCH] Bug 1314493 simplify xhr webrequest tests for uploads, fix xhr blob send, r=kmag MozReview-Commit-ID: 4sQGgwD6HMC --HG-- extra : rebase_source : 52e103db1287d122e6b434840affbae7335c74f9 --- .../test/mochitest/file_WebRequest_page1.html | 98 +-------- .../extensions/test/mochitest/mochitest.ini | 2 + .../test/mochitest/test_ext_webrequest.html | 33 --- .../mochitest/test_ext_webrequest_upload.html | 195 ++++++++++++++++++ toolkit/modules/addons/WebRequestUpload.jsm | 4 +- 5 files changed, 204 insertions(+), 128 deletions(-) create mode 100644 toolkit/components/extensions/test/mochitest/test_ext_webrequest_upload.html diff --git a/toolkit/components/extensions/test/mochitest/file_WebRequest_page1.html b/toolkit/components/extensions/test/mochitest/file_WebRequest_page1.html index c6b5ca05a6c3..6477565fbcc4 100644 --- a/toolkit/components/extensions/test/mochitest/file_WebRequest_page1.html +++ b/toolkit/components/extensions/test/mochitest/file_WebRequest_page1.html @@ -29,105 +29,15 @@ link -
- - - - -
-
- - - - -
-
- - -
+
diff --git a/toolkit/components/extensions/test/mochitest/mochitest.ini b/toolkit/components/extensions/test/mochitest/mochitest.ini index 2c2a0c6a1fc1..aff1c595677a 100644 --- a/toolkit/components/extensions/test/mochitest/mochitest.ini +++ b/toolkit/components/extensions/test/mochitest/mochitest.ini @@ -93,6 +93,8 @@ skip-if = (os == 'android') # Bug 1258975 on android. skip-if = (os == 'android') # Bug 1258975 on android. [test_ext_webrequest.html] skip-if = os == 'android' # webrequest api unsupported (bug 1258975). +[test_ext_webrequest_upload.html] +skip-if = os == 'android' # webrequest api unsupported (bug 1258975). [test_ext_webnavigation.html] skip-if = os == 'android' # port.sender.tab is undefined on Android (bug 1258975). [test_ext_webnavigation_filters.html] diff --git a/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html b/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html index a054efa364e7..7514b2519a2a 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html @@ -328,31 +328,6 @@ function backgroundScript() { return {}; } - function onUpload(details) { - let url = new URL(details.url); - let upload = url.searchParams.get("upload"); - if (!upload) { - return; - } - let requestBody = details.requestBody; - browser.test.log(`onUpload ${details.url} ${JSON.stringify(details.requestBody)}`); - browser.test.assertTrue(!!requestBody, `Intercepted upload ${details.url} #${details.requestId} ${upload} have a requestBody`); - if (!requestBody) { - return; - } - let byteLength = parseInt(upload, 10); - if (byteLength) { - browser.test.assertTrue(!!requestBody.raw, `Binary upload ${details.url} #${details.requestId} ${upload} have a raw attribute`); - browser.test.assertEq(byteLength, requestBody.raw && requestBody.raw.map(r => r.bytes && r.bytes.byteLength || 0).reduce((a, b) => a + b), `Binary upload size matches`); - return; - } - if ("raw" in requestBody) { - browser.test.assertEq(upload, JSON.stringify(requestBody.raw).replace(/(\bfile: ")[^"]+/, "$1"), `Upload ${details.url} #${details.requestId} matches raw data`); - } else { - browser.test.assertEq(upload, JSON.stringify(requestBody.formData), `Upload ${details.url} #${details.requestId} matches form data.`); - } - } - function onBeforeSendHeaders(details) { browser.test.log(`onBeforeSendHeaders ${details.url}`); checkRequestId(details); @@ -469,14 +444,6 @@ function backgroundScript() { } browser.webRequest.onBeforeRequest.addListener(onBeforeRequest, {urls: [""]}, ["blocking"]); - try { - browser.webRequest.onBeforeRequest.addListener(onUpload, {urls: ["http://*/*"]}, ["blocking", "requestBody"]); - } catch (e) { - // requestBody is disabled in release builds - if (!/\brequestBody\b/.test(e.message)) { - throw e; - } - } browser.webRequest.onBeforeSendHeaders.addListener(onBeforeSendHeaders, {urls: [""]}, ["blocking", "requestHeaders"]); browser.webRequest.onSendHeaders.addListener(onSendHeaders, {urls: [""]}, ["requestHeaders"]); browser.webRequest.onBeforeRedirect.addListener(onBeforeRedirect, {urls: [""]}); diff --git a/toolkit/components/extensions/test/mochitest/test_ext_webrequest_upload.html b/toolkit/components/extensions/test/mochitest/test_ext_webrequest_upload.html new file mode 100644 index 000000000000..05520b1d9bfc --- /dev/null +++ b/toolkit/components/extensions/test/mochitest/test_ext_webrequest_upload.html @@ -0,0 +1,195 @@ + + + + + + + + + + + + + +
+ + + + +
+ +
+ + + +
+ + +
+ + +
+ + + diff --git a/toolkit/modules/addons/WebRequestUpload.jsm b/toolkit/modules/addons/WebRequestUpload.jsm index d500bc24acb7..789ce683f51c 100644 --- a/toolkit/modules/addons/WebRequestUpload.jsm +++ b/toolkit/modules/addons/WebRequestUpload.jsm @@ -19,7 +19,9 @@ var WebRequestUpload; function rewind(stream) { try { - stream.seek(0, 0); + if (stream instanceof Ci.nsISeekableStream) { + stream.seek(0, 0); + } } catch (e) { // It might be already closed, e.g. because of a previous error. }