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

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: 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 unified diff | Download patch
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 IFRAME_BASE_URL = 'http://127.0.0.1:8000/local/serviceworker/resources/fetch -request-body-file-iframe.html';
8 var SCOPE = 'http://127.0.0.1:8000/local/serviceworker/resources/fetch-request-b ody-file-test';
9
10 function register(t) {
11 return new Promise(function(resolve) {
12 with_iframe(IFRAME_BASE_URL + '?register')
13 .then(t.step_func(function(frame) {
nhiroki 2014/08/25 04:29:36 You don't have to wrap with "step_func" in a promi
horo 2014/08/25 11:20:23 Done.
14 var channel = new MessageChannel;
15 channel.port1.onmessage = function(msg) {
16 if (msg.data.msg == 'registered') {
17 resolve();
18 document.body.removeChild(frame);
19 }
20 };
21 frame.contentWindow.postMessage({}, [channel.port2], "*");
22 }));
23 });
24 }
25
26 function unregister_and_done(t) {
27 return new Promise(function(resolve) {
28 with_iframe(IFRAME_BASE_URL + '?unregister')
29 .then(t.step_func(function(frame) {
nhiroki 2014/08/25 04:29:37 ditto (step_func)
horo 2014/08/25 11:20:23 Done.
30 var channel = new MessageChannel;
31 channel.port1.onmessage = function(msg) {
32 if (msg.data.msg == 'unregistered') {
33 t.done();
34 document.body.removeChild(frame);
35 }
36 };
37 frame.contentWindow.postMessage({}, [channel.port2], "*");
38 }));
39 });
40 }
41
42 function get_boundary(headers) {
43 var reg = new RegExp('multipart\/form-data; boundary=(.*)');
44 for (var i = 0; i < headers.length; ++i) {
45 if (headers[i][0] != 'content-type') {
46 continue;
47 }
48 var regResult = reg.exec(headers[i][1]);
49 if (!regResult) {
50 continue;
51 }
52 return regResult[1];
53 }
54 return '';
55 }
56
57 async_test(function(t) {
58 register(t)
59 .then(t.step_func(function() {
nhiroki 2014/08/25 04:29:36 ditto (step_func)
horo 2014/08/25 11:20:23 Done.
60 return new Promise(function(resolve) {
61 var frame_name = 'frame_name';
62 var frame = document.createElement('iframe');
63 frame.name = frame_name;
64 document.body.appendChild(frame);
65 var form = document.createElement('form');
66 form.target = frame_name;
67 form.enctype = 'multipart/form-data';
68 form.action = SCOPE + '?form-post';
69 form.method = 'post';
70 var input1 = document.createElement('input');
71 input1.type = 'text';
72 input1.value = 'testValue1';
73 input1.name = 'testName1'
74 form.appendChild(input1);
75 var input2 = document.createElement('input');
76 input2.type = 'text';
77 input2.value = 'testValue2';
78 input2.name = 'testName2'
79 form.appendChild(input2);
80 var input3 = document.createElement('input');
81 input3.type = 'file';
82 input3.name = 'testFile'
83 form.appendChild(input3);
84 document.body.appendChild(form);
85 eventSender.beginDragWithFiles(
86 ["../resources/file-for-drag-to-send.txt"]);
87 eventSender.mouseMoveTo(input3.offsetLeft + input3.offsetWidth / 2,
88 input3.offsetTop + input3.offsetHeight / 2);
89 eventSender.mouseUp();
90 frame.onload = function() {
91 document.body.removeChild(form);
92 resolve(frame);
93 };
94 form.submit();
95 });
96 }))
97 .then(t.step_func(function(frame) {
nhiroki 2014/08/25 04:29:37 ditto (step_func)
horo 2014/08/25 11:20:23 Done.
98 var data = JSON.parse(frame.contentDocument.body.textContent);
99 document.body.removeChild(frame);
100 assert_equals(data.method, 'POST');
101 var boundary = get_boundary(data.headers);
102 var expected_body =
103 '--' + boundary + '\r\n' +
104 'Content-Disposition: form-data; name="testName1"\r\n' +
105 '\r\n' +
106 'testValue1\r\n' +
107 '--' + boundary + '\r\n' +
108 'Content-Disposition: form-data; name="testName2"\r\n' +
109 '\r\n' +
110 'testValue2\r\n' +
111 '--' + boundary + '\r\n' +
112 'Content-Disposition: form-data; name="testFile"; filename="file-for -drag-to-send.txt"\r\n' +
113 'Content-Type: text/plain\r\n' +
114 '\r\n' +
115 '1234567890\r\n' +
116 '--' + boundary + '--\r\n';
117 assert_equals(data.body, expected_body);
118 return unregister_and_done(t);
119 }))
120 .catch(unreached_rejection(t));
121 }, 'Service Worker fetch request body with file.');
122 </script>
123 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698