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

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

Powered by Google App Engine
This is Rietveld 408576698