OLD | NEW |
---|---|
1 <script src="../../resources/testharness.js"></script> | 1 <script src="../../resources/testharness.js"></script> |
2 <script src="../../resources/get-host-info.js?pipe=sub"></script> | 2 <script src="../../resources/get-host-info.js?pipe=sub"></script> |
3 <script src="test-helpers.js"></script> | 3 <script src="test-helpers.js"></script> |
4 <script> | 4 <script> |
5 var host_info = get_host_info(); | 5 var host_info = get_host_info(); |
6 | 6 |
7 function get_boundary(headers) { | 7 function get_boundary(headers) { |
8 var reg = new RegExp('multipart\/form-data; boundary=(.*)'); | 8 var reg = new RegExp('multipart\/form-data; boundary=(.*)'); |
9 for (var i = 0; i < headers.length; ++i) { | 9 for (var i = 0; i < headers.length; ++i) { |
10 if (headers[i][0] != 'content-type') { | 10 if (headers[i][0] != 'content-type') { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 }; | 48 }; |
49 xhr.responseType = 'text'; | 49 xhr.responseType = 'text'; |
50 if (with_credentials) { | 50 if (with_credentials) { |
51 xhr.withCredentials = true; | 51 xhr.withCredentials = true; |
52 } | 52 } |
53 xhr.open(method, url_base + '/dummy?test', true); | 53 xhr.open(method, url_base + '/dummy?test', true); |
54 xhr.send(data); | 54 xhr.send(data); |
55 }); | 55 }); |
56 } | 56 } |
57 | 57 |
58 function get_sorted_header_name_list(headers) { | |
yhirano
2016/07/19 07:28:40
ditto as fetch-event.html
tyoshino (SeeGerritForStatus)
2016/07/19 08:50:31
Done.
| |
59 var header_names = []; | |
60 for (var i in headers) { | |
61 header_names.push(headers[i][0]); | |
62 } | |
63 header_names.sort(); | |
64 return header_names; | |
65 } | |
66 | |
67 function get_header_test() { | |
68 return xhr_send(host_info['HTTP_ORIGIN'], 'GET', '', false) | |
69 .then(function(response) { | |
70 assert_array_equals( | |
71 get_sorted_header_name_list(response.headers), | |
72 ["accept", "user-agent"], | |
73 'event.request has the expected headers for same-origin GET.'); | |
74 }); | |
75 } | |
76 | |
77 // TODO(tyoshino): Fix the stack not to include the Origin header as specified | |
78 // in the spec. | |
79 function post_header_test() { | |
80 return xhr_send(host_info['HTTP_ORIGIN'], 'POST', '', false) | |
81 .then(function(response) { | |
82 assert_array_equals( | |
83 get_sorted_header_name_list(response.headers), | |
84 ["accept", "content-type", "origin", "user-agent"], | |
85 'event.request has the expected headers for same-origin POST.'); | |
86 }); | |
87 } | |
88 | |
89 function cross_origin_get_header_test() { | |
90 return xhr_send(host_info['HTTP_REMOTE_ORIGIN'], 'GET', '', false) | |
91 .then(function(response) { | |
92 assert_array_equals( | |
93 get_sorted_header_name_list(response.headers), | |
94 ["accept", "user-agent"], | |
95 'event.request has the expected headers for cross-origin GET.'); | |
96 }); | |
97 } | |
98 | |
99 // TODO(tyoshino): Fix the stack not to include the Origin header as specified | |
100 // in the spec. | |
101 function cross_origin_post_header_test() { | |
102 return xhr_send(host_info['HTTP_REMOTE_ORIGIN'], 'POST', '', false) | |
103 .then(function(response) { | |
104 assert_array_equals( | |
105 get_sorted_header_name_list(response.headers), | |
106 ["accept", "content-type", "origin", "user-agent"], | |
107 'event.request has the expected headers for cross-origin POST.'); | |
108 }); | |
109 } | |
110 | |
58 function string_test() { | 111 function string_test() { |
59 return xhr_send(host_info['HTTP_ORIGIN'], 'POST', 'test string', false) | 112 return xhr_send(host_info['HTTP_ORIGIN'], 'POST', 'test string', false) |
60 .then(function(response) { | 113 .then(function(response) { |
61 assert_equals(response.method, 'POST'); | 114 assert_equals(response.method, 'POST'); |
62 assert_equals(response.body, 'test string'); | 115 assert_equals(response.body, 'test string'); |
63 }); | 116 }); |
64 } | 117 } |
65 | 118 |
66 function blob_test() { | 119 function blob_test() { |
67 return xhr_send(host_info['HTTP_ORIGIN'], 'POST', new Blob(['test blob']), | 120 return xhr_send(host_info['HTTP_ORIGIN'], 'POST', new Blob(['test blob']), |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 xhr.open('GET', 'data:text/html,Foobar', true); | 218 xhr.open('GET', 'data:text/html,Foobar', true); |
166 xhr.send(); | 219 xhr.send(); |
167 }) | 220 }) |
168 .then(function(data) { | 221 .then(function(data) { |
169 assert_equals(data, 'Foobar'); | 222 assert_equals(data, 'Foobar'); |
170 }); | 223 }); |
171 } | 224 } |
172 | 225 |
173 window.addEventListener('message', function(evt) { | 226 window.addEventListener('message', function(evt) { |
174 var port = evt.ports[0]; | 227 var port = evt.ports[0]; |
175 string_test() | 228 get_header_test() |
229 .then(post_header_test) | |
230 .then(cross_origin_get_header_test) | |
231 .then(cross_origin_post_header_test) | |
232 .then(string_test) | |
176 .then(blob_test) | 233 .then(blob_test) |
177 .then(custom_method_test) | 234 .then(custom_method_test) |
178 .then(options_method_test) | 235 .then(options_method_test) |
179 .then(form_data_test) | 236 .then(form_data_test) |
180 .then(mode_credentials_test) | 237 .then(mode_credentials_test) |
181 .then(data_url_test) | 238 .then(data_url_test) |
182 .then(function() { port.postMessage({results: 'finish'}); }) | 239 .then(function() { port.postMessage({results: 'finish'}); }) |
183 .catch(function(e) { port.postMessage({results: 'failure:' + e}); }); | 240 .catch(function(e) { port.postMessage({results: 'failure:' + e}); }); |
184 }); | 241 }); |
185 </script> | 242 </script> |
OLD | NEW |