| 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
|
| index 2b41492e30afb1127508b8668ede2cb893f9eb15..533b6b5972bdb318e12559574db0514b301647bc 100644
|
| --- a/LayoutTests/http/tests/local/serviceworker/fetch-request-body-file.html
|
| +++ b/LayoutTests/http/tests/local/serviceworker/fetch-request-body-file.html
|
| @@ -59,69 +59,87 @@ function get_boundary(headers) {
|
| return '';
|
| }
|
|
|
| +function send_post_frame_promise(action) {
|
| + 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 + '?' + action;
|
| + 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();
|
| + });
|
| +}
|
| +
|
| +function create_expected_body(boundary) {
|
| + return '--' + 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';
|
| +}
|
| +
|
| +function as_text_test_frame_check(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 = create_expected_body(boundary);
|
| + assert_equals(data.body, expected_body);
|
| +}
|
| +
|
| +function as_blob_test_frame_check(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 = create_expected_body(boundary);
|
| + assert_equals(data.body_size, expected_body.length);
|
| +}
|
| +
|
| 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);
|
| - })
|
| + .then(function() { return send_post_frame_promise('asText'); })
|
| + .then(as_text_test_frame_check)
|
| + .then(function() { return send_post_frame_promise('asBlob'); })
|
| + .then(as_blob_test_frame_check)
|
| + .then(function() { return unregister_and_done(t); })
|
| .catch(unreached_rejection(t));
|
| }, 'Service Worker fetch request body with file.');
|
| </script>
|
|
|