OLD | NEW |
1 importScripts('worker-test-harness.js'); | 1 importScripts('worker-test-harness.js'); |
2 importScripts('test-helpers.js'); | 2 importScripts('test-helpers.js'); |
3 | 3 |
4 var URL = 'https://www.example.com/test.html'; | 4 var URL = 'https://www.example.com/test.html'; |
5 | 5 |
6 test(function() { | 6 test(function() { |
7 var headers = new Headers; | 7 var headers = new Headers; |
8 headers.set('User-Agent', 'Mozilla/5.0'); | 8 headers.set('User-Agent', 'Mozilla/5.0'); |
9 headers.set('Accept', 'text/html'); | 9 headers.set('Accept', 'text/html'); |
10 headers.set('X-ServiceWorker-Test', 'request test field'); | 10 headers.set('X-ServiceWorker-Test', 'request test field'); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return; | 90 return; |
91 } | 91 } |
92 request1 = new Request(URL, init1); | 92 request1 = new Request(URL, init1); |
93 assert_equals(request1.method, method1 ? method1 : 'GET', 'Request.m
ethod should match'); | 93 assert_equals(request1.method, method1 ? method1 : 'GET', 'Request.m
ethod should match'); |
94 assert_equals(request1.mode, mode1 ? mode1 : 'cors', 'Request.mode s
hould match'); | 94 assert_equals(request1.mode, mode1 ? mode1 : 'cors', 'Request.mode s
hould match'); |
95 request1 = new Request(request1); | 95 request1 = new Request(request1); |
96 assert_equals(request1.method, method1 ? method1 : 'GET', 'Request.m
ethod should match'); | 96 assert_equals(request1.method, method1 ? method1 : 'GET', 'Request.m
ethod should match'); |
97 assert_equals(request1.mode, mode1 ? mode1 : 'cors', 'Request.mode s
hould match'); | 97 assert_equals(request1.mode, mode1 ? mode1 : 'cors', 'Request.mode s
hould match'); |
98 METHODS.forEach(function(method2) { | 98 METHODS.forEach(function(method2) { |
99 MODES.forEach(function(mode2) { | 99 MODES.forEach(function(mode2) { |
| 100 // We need to construct a new request1 because as soon as it |
| 101 // is used in a constructor it will be flagged as 'used', |
| 102 // and we can no longer construct objects with it. |
| 103 request1 = new Request(URL, init1); |
100 var init2 = {}; | 104 var init2 = {}; |
101 if (method2 != undefined) { init2['method'] = method2; } | 105 if (method2 != undefined) { init2['method'] = method2; } |
102 if (mode2 != undefined) { init2['mode'] = mode2; } | 106 if (mode2 != undefined) { init2['mode'] = mode2; } |
103 if (!isSimpleMethod(effectiveMethod(method1, method2)) && ef
fectiveMode(mode1, mode2) == 'no-cors') { | 107 if (!isSimpleMethod(effectiveMethod(method1, method2)) && ef
fectiveMode(mode1, mode2) == 'no-cors') { |
104 assert_throws( | 108 assert_throws( |
105 {name:'TypeError'}, | 109 {name:'TypeError'}, |
106 function() { request2 = new Request(request1, init2)
; }, | 110 function() { request2 = new Request(request1, init2)
; }, |
107 'new no-cors Request with non simple method should t
hrow'); | 111 'new no-cors Request with non simple method should t
hrow'); |
108 return; | 112 return; |
109 } | 113 } |
(...skipping 15 matching lines...) Expand all Loading... |
125 var request2 = {}; | 129 var request2 = {}; |
126 var CREDENTIALS = ['omit', 'same-origin', 'include', '', undefined]; | 130 var CREDENTIALS = ['omit', 'same-origin', 'include', '', undefined]; |
127 CREDENTIALS.forEach(function(credentials1) { | 131 CREDENTIALS.forEach(function(credentials1) { |
128 var init1 = {}; | 132 var init1 = {}; |
129 if (credentials1 != undefined) { init1['credentials'] = credentials1; } | 133 if (credentials1 != undefined) { init1['credentials'] = credentials1; } |
130 request1 = new Request(URL, init1); | 134 request1 = new Request(URL, init1); |
131 assert_equals(request1.credentials, credentials1 ? credentials1 : 'omit'
, 'Request.credentials should match'); | 135 assert_equals(request1.credentials, credentials1 ? credentials1 : 'omit'
, 'Request.credentials should match'); |
132 request1 = new Request(request1); | 136 request1 = new Request(request1); |
133 assert_equals(request1.credentials, credentials1 ? credentials1 : 'omit'
, 'Request.credentials should match'); | 137 assert_equals(request1.credentials, credentials1 ? credentials1 : 'omit'
, 'Request.credentials should match'); |
134 CREDENTIALS.forEach(function(credentials2) { | 138 CREDENTIALS.forEach(function(credentials2) { |
| 139 request1 = new Request(URL, init1); |
135 var init2 = {}; | 140 var init2 = {}; |
136 if (credentials2 != undefined) { init2['credentials'] = credentials2
; } | 141 if (credentials2 != undefined) { init2['credentials'] = credentials2
; } |
137 request2 = new Request(request1, init2); | 142 request2 = new Request(request1, init2); |
138 assert_equals(request2.credentials, | 143 assert_equals(request2.credentials, |
139 credentials2 ? credentials2 : request1.credentials, | 144 credentials2 ? credentials2 : request1.credentials, |
140 'Request.credentials should be overridden'); | 145 'Request.credentials should be overridden'); |
141 }); | 146 }); |
142 }); | 147 }); |
143 }, 'Request credentials test in ServiceWorkerGlobalScope'); | 148 }, 'Request credentials test in ServiceWorkerGlobalScope'); |
144 | 149 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 282 |
278 ['PATCH', 'MKCOL', 'CUSTOM', 'X-FILES'].forEach(function(method) { | 283 ['PATCH', 'MKCOL', 'CUSTOM', 'X-FILES'].forEach(function(method) { |
279 assert_equals(new Request(url, {method: method}).method, method, | 284 assert_equals(new Request(url, {method: method}).method, method, |
280 'method should not be changed when normalized: ' + method); | 285 'method should not be changed when normalized: ' + method); |
281 method = method.toLowerCase(); | 286 method = method.toLowerCase(); |
282 assert_equals(new Request(url, {method: method}).method, method, | 287 assert_equals(new Request(url, {method: method}).method, method, |
283 'method should not be changed when normalized: ' + method); | 288 'method should not be changed when normalized: ' + method); |
284 }); | 289 }); |
285 }, 'Request method names are normalized'); | 290 }, 'Request method names are normalized'); |
286 | 291 |
| 292 |
| 293 test(function() { |
| 294 var req = new Request(URL); |
| 295 assert_false(req.bodyUsed, |
| 296 "Request should not be flagged as used if it has not been consumed."); |
| 297 var req2 = new Request(req); |
| 298 assert_true(req.bodyUsed, |
| 299 "Request should be flagged as used if it is used as a construction " + |
| 300 "argument of another Request."); |
| 301 assert_false(req2.bodyUsed, |
| 302 "Request should not be flagged as used if it has not been consumed."); |
| 303 assert_throws(new TypeError(), function() { new Request(req); }, |
| 304 "Request cannot be constructed with a request that has been flagged as use
d."); |
| 305 }, 'Request construction behavior regarding "used" body flag and exceptions.')
; |
| 306 |
287 async_test(function(t) { | 307 async_test(function(t) { |
288 var getContentType = function(headers) { | 308 var getContentType = function(headers) { |
289 var content_type = ''; | 309 var content_type = ''; |
290 headers.forEach(function(value, key) { | 310 headers.forEach(function(value, key) { |
291 if (key == 'content-type') { | 311 if (key == 'content-type') { |
292 content_type = value; | 312 content_type = value; |
293 } | 313 } |
294 }); | 314 }); |
295 return content_type; | 315 return content_type; |
296 }; | 316 }; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 result, expected_body, | 398 result, expected_body, |
379 'Creating a Request with FormData body should success.'); | 399 'Creating a Request with FormData body should success.'); |
380 }) | 400 }) |
381 .then(function() { | 401 .then(function() { |
382 t.done(); | 402 t.done(); |
383 }) | 403 }) |
384 .catch(unreached_rejection(t)); | 404 .catch(unreached_rejection(t)); |
385 assert_true(request.bodyUsed, | 405 assert_true(request.bodyUsed, |
386 'bodyUsed must be true after calling text()'); | 406 'bodyUsed must be true after calling text()'); |
387 }, 'Request body test in ServiceWorkerGlobalScope'); | 407 }, 'Request body test in ServiceWorkerGlobalScope'); |
OLD | NEW |