Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Unified Diff: LayoutTests/http/tests/local/serviceworker/fetch-request-body-file.html

Issue 491203002: [ServiceWorker] Add test for FetchEvent's body with a local file. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: remove test-helpers.js from iframe Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/http/tests/local/serviceworker/resources/fetch-request-body-file-iframe.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/http/tests/local/serviceworker/fetch-request-body-file.html
diff --git a/LayoutTests/http/tests/local/serviceworker/fetch-request-body-file.html b/LayoutTests/http/tests/local/serviceworker/fetch-request-body-file.html
new file mode 100644
index 0000000000000000000000000000000000000000..2b41492e30afb1127508b8668ede2cb893f9eb15
--- /dev/null
+++ b/LayoutTests/http/tests/local/serviceworker/fetch-request-body-file.html
@@ -0,0 +1,128 @@
+<!DOCTYPE html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../serviceworker/resources/test-helpers.js"></script>
+<body>
+<script>
+var ORIGIN = get_host_info()['HTTP_ORIGIN'];
+var IFRAME_BASE_URL = ORIGIN + '/local/serviceworker/resources/fetch-request-body-file-iframe.html';
+var SCOPE = ORIGIN + '/local/serviceworker/resources/fetch-request-body-file-test';
+
+function register() {
+ return new Promise(function(resolve, reject) {
+ with_iframe(IFRAME_BASE_URL + '?register')
+ .then(function(frame) {
+ var channel = new MessageChannel;
+ channel.port1.onmessage = function(msg) {
+ if (msg.data.msg == 'registered') {
+ unload_iframe(frame);
+ resolve();
+ } else {
+ reject(msg.data.msg);
+ }
+ };
+ frame.contentWindow.postMessage({}, [channel.port2], "*");
+ });
+ });
+}
+
+function unregister_and_done(t) {
+ return new Promise(function(resolve, reject) {
+ with_iframe(IFRAME_BASE_URL + '?unregister')
+ .then(function(frame) {
+ var channel = new MessageChannel;
+ channel.port1.onmessage = function(msg) {
+ if (msg.data.msg == 'unregistered') {
+ unload_iframe(frame);
+ t.done();
+ } else {
+ reject(msg.data.msg);
+ }
+ };
+ frame.contentWindow.postMessage({}, [channel.port2], "*");
+ });
+ });
+}
+
+function get_boundary(headers) {
+ var reg = new RegExp('multipart\/form-data; boundary=(.*)');
+ for (var i = 0; i < headers.length; ++i) {
+ if (headers[i][0] != 'content-type') {
+ continue;
+ }
+ var regResult = reg.exec(headers[i][1]);
+ if (!regResult) {
+ continue;
+ }
+ return regResult[1];
+ }
+ return '';
+}
+
+async_test(function(t) {
+ register()
+ .then(function() {
+ return new Promise(function(resolve) {
+ var frame_name = 'frame_name';
+ var frame = document.createElement('iframe');
+ frame.name = frame_name;
+ document.body.appendChild(frame);
+ var form = document.createElement('form');
+ form.target = frame_name;
+ form.enctype = 'multipart/form-data';
+ form.action = SCOPE + '?form-post';
+ form.method = 'post';
+ var input1 = document.createElement('input');
+ input1.type = 'text';
+ input1.value = 'testValue1';
+ input1.name = 'testName1'
+ form.appendChild(input1);
+ var input2 = document.createElement('input');
+ input2.type = 'text';
+ input2.value = 'testValue2';
+ input2.name = 'testName2'
+ form.appendChild(input2);
+ var input3 = document.createElement('input');
+ input3.type = 'file';
+ input3.name = 'testFile'
+ form.appendChild(input3);
+ document.body.appendChild(form);
+ eventSender.beginDragWithFiles(
+ ["../resources/file-for-drag-to-send.txt"]);
+ eventSender.mouseMoveTo(input3.offsetLeft + input3.offsetWidth / 2,
+ input3.offsetTop + input3.offsetHeight / 2);
+ eventSender.mouseUp();
+ frame.onload = function() {
+ document.body.removeChild(form);
+ resolve(frame);
+ };
+ form.submit();
+ });
+ })
+ .then(function(frame) {
+ var data = JSON.parse(frame.contentDocument.body.textContent);
+ unload_iframe(frame);
+ assert_equals(data.method, 'POST');
+ var boundary = get_boundary(data.headers);
+ var expected_body =
+ '--' + boundary + '\r\n' +
+ 'Content-Disposition: form-data; name="testName1"\r\n' +
+ '\r\n' +
+ 'testValue1\r\n' +
+ '--' + boundary + '\r\n' +
+ 'Content-Disposition: form-data; name="testName2"\r\n' +
+ '\r\n' +
+ 'testValue2\r\n' +
+ '--' + boundary + '\r\n' +
+ 'Content-Disposition: form-data; name="testFile"; filename="file-for-drag-to-send.txt"\r\n' +
+ 'Content-Type: text/plain\r\n' +
+ '\r\n' +
+ '1234567890\r\n' +
+ '--' + boundary + '--\r\n';
+ assert_equals(data.body, expected_body);
+ return unregister_and_done(t);
+ })
+ .catch(unreached_rejection(t));
+ }, 'Service Worker fetch request body with file.');
+</script>
+</body>
« no previous file with comments | « no previous file | LayoutTests/http/tests/local/serviceworker/resources/fetch-request-body-file-iframe.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698