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

Side by Side 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, 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-iframe.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src="../../resources/testharness.js"></script>
3 <script src="../../resources/testharnessreport.js"></script>
4 <script src="../../serviceworker/resources/test-helpers.js"></script>
5 <body>
6 <script>
7 var ORIGIN = get_host_info()['HTTP_ORIGIN'];
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';
10
11 function register() {
12 return new Promise(function(resolve, reject) {
13 with_iframe(IFRAME_BASE_URL + '?register')
14 .then(function(frame) {
15 var channel = new MessageChannel;
16 channel.port1.onmessage = function(msg) {
17 if (msg.data.msg == 'registered') {
18 unload_iframe(frame);
19 resolve();
20 } else {
21 reject(msg.data.msg);
22 }
23 };
24 frame.contentWindow.postMessage({}, [channel.port2], "*");
25 });
26 });
27 }
28
29 function unregister_and_done(t) {
30 return new Promise(function(resolve, reject) {
31 with_iframe(IFRAME_BASE_URL + '?unregister')
32 .then(function(frame) {
33 var channel = new MessageChannel;
34 channel.port1.onmessage = function(msg) {
35 if (msg.data.msg == 'unregistered') {
36 unload_iframe(frame);
37 t.done();
38 } else {
39 reject(msg.data.msg);
40 }
41 };
42 frame.contentWindow.postMessage({}, [channel.port2], "*");
43 });
44 });
45 }
46
47 function get_boundary(headers) {
48 var reg = new RegExp('multipart\/form-data; boundary=(.*)');
49 for (var i = 0; i < headers.length; ++i) {
50 if (headers[i][0] != 'content-type') {
51 continue;
52 }
53 var regResult = reg.exec(headers[i][1]);
54 if (!regResult) {
55 continue;
56 }
57 return regResult[1];
58 }
59 return '';
60 }
61
62 async_test(function(t) {
63 register()
64 .then(function() {
65 return new Promise(function(resolve) {
66 var frame_name = 'frame_name';
67 var frame = document.createElement('iframe');
68 frame.name = frame_name;
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));
126 }, 'Service Worker fetch request body with file.');
127 </script>
128 </body>
OLDNEW
« 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