OLD | NEW |
---|---|
1 if (self.importScripts) { | 1 if (self.importScripts) { |
2 importScripts('../resources/fetch-test-helpers.js'); | 2 importScripts('../resources/fetch-test-helpers.js'); |
3 } | 3 } |
4 | 4 |
5 promise_test(function() { | 5 promise_test(function() { |
6 var response = new Response; | 6 var response = new Response; |
7 return response.text() | 7 return response.text() |
8 .then(function(text) { | 8 .then(function(text) { |
9 assert_equals(text, '', | 9 assert_equals(text, '', |
10 'response.text() must return an empty string' + | 10 'response.text() must return an empty string' + |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 return response.arrayBuffer() | 71 return response.arrayBuffer() |
72 .then(function(buffer) { | 72 .then(function(buffer) { |
73 var resultIntView = new Int32Array(buffer); | 73 var resultIntView = new Int32Array(buffer); |
74 assert_array_equals( | 74 assert_array_equals( |
75 resultIntView, [1, 2, 3], | 75 resultIntView, [1, 2, 3], |
76 'Response body ArrayBuffer should match ArrayBufferView ' + | 76 'Response body ArrayBuffer should match ArrayBufferView ' + |
77 'slice it was constructed with.'); | 77 'slice it was constructed with.'); |
78 }); | 78 }); |
79 }, 'Behavior of Response with ArrayBufferView content with a slice.'); | 79 }, 'Behavior of Response with ArrayBufferView content with a slice.'); |
80 | 80 |
81 promise_test(function() { | 81 promise_test(function(t) { |
82 var formData = new FormData(); | 82 var formData = new FormData(); |
83 formData.append('sample string', '1234567890'); | 83 formData.append('sample string', '1234567890'); |
84 formData.append('sample blob', new Blob(['blob content'])); | 84 formData.append('sample blob', new Blob(['blob content'])); |
85 formData.append('sample file', | 85 formData.append('sample file', |
86 new File(['file content'], 'file.dat')); | 86 new File(['file content'], 'file.dat')); |
87 var response = new Response(formData); | 87 var response = new Response(formData); |
88 return response.text() | 88 return response.text() |
89 .then(function(result) { | 89 .then(function(result) { |
90 var reg = new RegExp('multipart\/form-data; boundary=(.*)'); | 90 var reg = new RegExp('multipart\/form-data; boundary=(.*)'); |
91 var regResult = reg.exec(getContentType(response.headers)); | 91 var regResult = reg.exec(getContentType(response.headers)); |
(...skipping 12 matching lines...) Expand all Loading... | |
104 '--' + boundary + '\r\n' + | 104 '--' + boundary + '\r\n' + |
105 'Content-Disposition: form-data; name="sample file"; ' + | 105 'Content-Disposition: form-data; name="sample file"; ' + |
106 'filename="file.dat"\r\n' + | 106 'filename="file.dat"\r\n' + |
107 'Content-Type: application/octet-stream\r\n' + | 107 'Content-Type: application/octet-stream\r\n' + |
108 '\r\n' + | 108 '\r\n' + |
109 'file content\r\n' + | 109 'file content\r\n' + |
110 '--' + boundary + '--\r\n'; | 110 '--' + boundary + '--\r\n'; |
111 assert_equals( | 111 assert_equals( |
112 result, expected_body, | 112 result, expected_body, |
113 'Creating a Response with FormData body must succeed.'); | 113 'Creating a Response with FormData body must succeed.'); |
114 }); | 114 response = new Response( |
115 expected_body, {headers: [['Content-Type', regResult[0]]]}); | |
116 return response.formData(); | |
117 }) | |
118 .then(function(result) { | |
119 assert_equals(result.get('sample string'), | |
120 formData.get('sample string')); | |
121 assert_equals(result.get('sample blob').size, | |
122 formData.get('sample blob').size); | |
horo
2016/08/30 05:12:55
Please check the content of the blob and .name and
e_hakkinen
2016/08/30 07:59:08
Done.
| |
123 assert_equals(result.get('sample file').size, | |
124 formData.get('sample file').size); | |
125 }) | |
horo
2016/08/30 05:12:55
ditto
e_hakkinen
2016/08/30 07:59:08
Done.
| |
126 .catch(unreached_rejection(t)); | |
horo
2016/08/30 05:12:55
You don't need this catch.
promise_test() checks i
e_hakkinen
2016/08/30 07:59:08
Done.
| |
115 }, 'Behavior of Response with FormData content'); | 127 }, 'Behavior of Response with FormData content'); |
116 | 128 |
117 promise_test(function() { | 129 promise_test(function() { |
118 const urlSearchParams = new URLSearchParams(); | 130 const urlSearchParams = new URLSearchParams(); |
119 urlSearchParams.append('sample string', '1234567890'); | 131 urlSearchParams.append('sample string', '1234567890'); |
120 urlSearchParams.append('sample string 2', '1234567890 & 2'); | 132 urlSearchParams.append('sample string 2', '1234567890 & 2'); |
121 var response = new Response(urlSearchParams); | 133 var response = new Response(urlSearchParams); |
122 assert_equals( | 134 assert_equals( |
123 response.headers.get('Content-Type'), | 135 response.headers.get('Content-Type'), |
124 'application/x-www-form-urlencoded;charset=UTF-8', | 136 'application/x-www-form-urlencoded;charset=UTF-8', |
125 'A Response constructed with a URLSearchParams should have a Content-Type. '); | 137 'A Response constructed with a URLSearchParams should have a Content-Type. '); |
126 return response.text() | 138 return response.text() |
127 .then(function(result) { | 139 .then(function(result) { |
140 const expected_body = | |
141 'sample+string=1234567890&sample+string+2=1234567890+%26+2'; | |
128 assert_equals( | 142 assert_equals( |
129 result, 'sample+string=1234567890&sample+string+2=1234567890+%26+2', | 143 result, expected_body, |
130 'Creating a Response with URLSearchParams body must succeed.'); | 144 'Creating a Response with URLSearchParams body must succeed.'); |
145 response = new Response( | |
146 expected_body, {headers: [ | |
147 ['Content-Type', | |
148 'application/x-www-form-urlencoded; charset=UTF-8']]}); | |
149 return response.formData(); | |
150 }) | |
151 .then(function(result) { | |
152 assert_equals(result.get('sample string'), | |
153 urlSearchParams.get('sample string')); | |
154 assert_equals(result.get('sample string 2'), | |
155 urlSearchParams.get('sample string 2')); | |
131 }); | 156 }); |
132 }, 'Behavior of Response with URLSearchParams content'); | 157 }, 'Behavior of Response with URLSearchParams content'); |
133 | 158 |
134 promise_test(function() { | 159 promise_test(function() { |
135 var headers = new Headers; | 160 var headers = new Headers; |
136 headers.set('Content-Language', 'ja'); | 161 headers.set('Content-Language', 'ja'); |
137 var response = new Response( | 162 var response = new Response( |
138 'test string', {method: 'GET', headers: headers}); | 163 'test string', {method: 'GET', headers: headers}); |
139 assert_false(response.bodyUsed); | 164 assert_false(response.bodyUsed); |
140 var response2 = response.clone(); | 165 var response2 = response.clone(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 'A Response constructed with no body should have no Content-Type.'); | 210 'A Response constructed with no body should have no Content-Type.'); |
186 return response.text() | 211 return response.text() |
187 .then(function(text) { | 212 .then(function(text) { |
188 assert_equals(text, '', | 213 assert_equals(text, '', |
189 'Response with no body accessed as text should ' + | 214 'Response with no body accessed as text should ' + |
190 'resolve to the empty string.'); | 215 'resolve to the empty string.'); |
191 }); | 216 }); |
192 }, 'Behavior of Response with no body.'); | 217 }, 'Behavior of Response with no body.'); |
193 | 218 |
194 done(); | 219 done(); |
OLD | NEW |