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

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

Issue 514113003: [ServiceWorker] Create a new Blob when body.asBody() is called if the size of body is not set. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | LayoutTests/http/tests/local/serviceworker/resources/fetch-request-body-file-worker.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../../resources/testharness.js"></script> 2 <script src="../../resources/testharness.js"></script>
3 <script src="../../resources/testharnessreport.js"></script> 3 <script src="../../resources/testharnessreport.js"></script>
4 <script src="../../serviceworker/resources/test-helpers.js"></script> 4 <script src="../../serviceworker/resources/test-helpers.js"></script>
5 <body> 5 <body>
6 <script> 6 <script>
7 var ORIGIN = get_host_info()['HTTP_ORIGIN']; 7 var ORIGIN = get_host_info()['HTTP_ORIGIN'];
8 var IFRAME_BASE_URL = ORIGIN + '/local/serviceworker/resources/fetch-request-bod y-file-iframe.html'; 8 var IFRAME_BASE_URL = ORIGIN + '/local/serviceworker/resources/fetch-request-bod y-file-iframe.html';
9 var SCOPE = ORIGIN + '/local/serviceworker/resources/fetch-request-body-file-tes t'; 9 var SCOPE = ORIGIN + '/local/serviceworker/resources/fetch-request-body-file-tes t';
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 var regResult = reg.exec(headers[i][1]); 53 var regResult = reg.exec(headers[i][1]);
54 if (!regResult) { 54 if (!regResult) {
55 continue; 55 continue;
56 } 56 }
57 return regResult[1]; 57 return regResult[1];
58 } 58 }
59 return ''; 59 return '';
60 } 60 }
61 61
62 function send_post_frame_promise(action) {
63 return new Promise(function(resolve) {
64 var frame_name = 'frame_name';
65 var frame = document.createElement('iframe');
66 frame.name = frame_name;
67 document.body.appendChild(frame);
68 var form = document.createElement('form');
69 form.target = frame_name;
70 form.enctype = 'multipart/form-data';
71 form.action = SCOPE + '?' + action;
72 form.method = 'post';
73 var input1 = document.createElement('input');
74 input1.type = 'text';
75 input1.value = 'testValue1';
76 input1.name = 'testName1'
77 form.appendChild(input1);
78 var input2 = document.createElement('input');
79 input2.type = 'text';
80 input2.value = 'testValue2';
81 input2.name = 'testName2'
82 form.appendChild(input2);
83 var input3 = document.createElement('input');
84 input3.type = 'file';
85 input3.name = 'testFile'
86 form.appendChild(input3);
87 document.body.appendChild(form);
88 eventSender.beginDragWithFiles(
89 ["../resources/file-for-drag-to-send.txt"]);
90 eventSender.mouseMoveTo(input3.offsetLeft + input3.offsetWidth / 2,
91 input3.offsetTop + input3.offsetHeight / 2);
92 eventSender.mouseUp();
93 frame.onload = function() {
94 document.body.removeChild(form);
95 resolve(frame);
96 };
97 form.submit();
98 });
99 }
100
101 function create_expected_body(boundary) {
102 return '--' + boundary + '\r\n' +
103 'Content-Disposition: form-data; name="testName1"\r\n' +
104 '\r\n' +
105 'testValue1\r\n' +
106 '--' + boundary + '\r\n' +
107 'Content-Disposition: form-data; name="testName2"\r\n' +
108 '\r\n' +
109 'testValue2\r\n' +
110 '--' + boundary + '\r\n' +
111 'Content-Disposition: form-data; name="testFile"; filename="file-for-dr ag-to-send.txt"\r\n' +
112 'Content-Type: text/plain\r\n' +
113 '\r\n' +
114 '1234567890\r\n' +
115 '--' + boundary + '--\r\n';
116 }
117
118 function as_text_test_frame_check(frame) {
119 var data = JSON.parse(frame.contentDocument.body.textContent);
120 unload_iframe(frame);
121 assert_equals(data.method, 'POST');
122 var boundary = get_boundary(data.headers);
123 var expected_body = create_expected_body(boundary);
124 assert_equals(data.body, expected_body);
125 }
126
127 function as_blob_test_frame_check(frame) {
128 var data = JSON.parse(frame.contentDocument.body.textContent);
129 unload_iframe(frame);
130 assert_equals(data.method, 'POST');
131 var boundary = get_boundary(data.headers);
132 var expected_body = create_expected_body(boundary);
133 assert_equals(data.body_size, expected_body.length);
134 }
135
62 async_test(function(t) { 136 async_test(function(t) {
63 register() 137 register()
64 .then(function() { 138 .then(function() { return send_post_frame_promise('asText'); })
65 return new Promise(function(resolve) { 139 .then(as_text_test_frame_check)
66 var frame_name = 'frame_name'; 140 .then(function() { return send_post_frame_promise('asBlob'); })
67 var frame = document.createElement('iframe'); 141 .then(as_blob_test_frame_check)
68 frame.name = frame_name; 142 .then(function() { return unregister_and_done(t); })
69 document.body.appendChild(frame);
70 var form = document.createElement('form');
71 form.target = frame_name;
72 form.enctype = 'multipart/form-data';
73 form.action = SCOPE + '?form-post';
74 form.method = 'post';
75 var input1 = document.createElement('input');
76 input1.type = 'text';
77 input1.value = 'testValue1';
78 input1.name = 'testName1'
79 form.appendChild(input1);
80 var input2 = document.createElement('input');
81 input2.type = 'text';
82 input2.value = 'testValue2';
83 input2.name = 'testName2'
84 form.appendChild(input2);
85 var input3 = document.createElement('input');
86 input3.type = 'file';
87 input3.name = 'testFile'
88 form.appendChild(input3);
89 document.body.appendChild(form);
90 eventSender.beginDragWithFiles(
91 ["../resources/file-for-drag-to-send.txt"]);
92 eventSender.mouseMoveTo(input3.offsetLeft + input3.offsetWidth / 2,
93 input3.offsetTop + input3.offsetHeight / 2);
94 eventSender.mouseUp();
95 frame.onload = function() {
96 document.body.removeChild(form);
97 resolve(frame);
98 };
99 form.submit();
100 });
101 })
102 .then(function(frame) {
103 var data = JSON.parse(frame.contentDocument.body.textContent);
104 unload_iframe(frame);
105 assert_equals(data.method, 'POST');
106 var boundary = get_boundary(data.headers);
107 var expected_body =
108 '--' + boundary + '\r\n' +
109 'Content-Disposition: form-data; name="testName1"\r\n' +
110 '\r\n' +
111 'testValue1\r\n' +
112 '--' + boundary + '\r\n' +
113 'Content-Disposition: form-data; name="testName2"\r\n' +
114 '\r\n' +
115 'testValue2\r\n' +
116 '--' + boundary + '\r\n' +
117 'Content-Disposition: form-data; name="testFile"; filename="file-for -drag-to-send.txt"\r\n' +
118 'Content-Type: text/plain\r\n' +
119 '\r\n' +
120 '1234567890\r\n' +
121 '--' + boundary + '--\r\n';
122 assert_equals(data.body, expected_body);
123 return unregister_and_done(t);
124 })
125 .catch(unreached_rejection(t)); 143 .catch(unreached_rejection(t));
126 }, 'Service Worker fetch request body with file.'); 144 }, 'Service Worker fetch request body with file.');
127 </script> 145 </script>
128 </body> 146 </body>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/http/tests/local/serviceworker/resources/fetch-request-body-file-worker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698