| OLD | NEW |
| 1 importScripts('worker-testharness.js'); | 1 importScripts('worker-testharness.js'); |
| 2 importScripts('/resources/testharness-helpers.js'); | 2 importScripts('/resources/testharness-helpers.js'); |
| 3 | 3 |
| 4 // A set of Request/Response pairs to be used with prepopulated_cache_test(). | 4 // A set of Request/Response pairs to be used with prepopulated_cache_test(). |
| 5 var simple_entries = { | 5 var simple_entries = { |
| 6 a: { | 6 a: { |
| 7 request: new Request('http://example.com/a'), | 7 request: new Request('http://example.com/a'), |
| 8 response: new Response('') | 8 response: new Response('') |
| 9 }, | 9 }, |
| 10 | 10 |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 var request = new Request('http://example.com'); | 331 var request = new Request('http://example.com'); |
| 332 var response; | 332 var response; |
| 333 var request_url = new URL('simple.txt', location.href).href; | 333 var request_url = new URL('simple.txt', location.href).href; |
| 334 return fetch(request_url) | 334 return fetch(request_url) |
| 335 .then(function(fetch_result) { | 335 .then(function(fetch_result) { |
| 336 response = fetch_result; | 336 response = fetch_result; |
| 337 assert_equals( | 337 assert_equals( |
| 338 response.url, request_url, | 338 response.url, request_url, |
| 339 '[https://fetch.spec.whatwg.org/#dom-response-url] ' + | 339 '[https://fetch.spec.whatwg.org/#dom-response-url] ' + |
| 340 'Reponse.url should return the URL of the response.'); | 340 'Reponse.url should return the URL of the response.'); |
| 341 return cache.put(request, response); | 341 return cache.put(request, response.clone()); |
| 342 }) | 342 }) |
| 343 .then(function() { | 343 .then(function() { |
| 344 return cache.match(request.url); | 344 return cache.match(request.url); |
| 345 }) | 345 }) |
| 346 .then(function(result) { | 346 .then(function(result) { |
| 347 assert_object_equals( | 347 assert_object_equals( |
| 348 result, response, | 348 result, response, |
| 349 'Cache.match should return a Response object that has the same ' + | 349 'Cache.match should return a Response object that has the same ' + |
| 350 'properties as the stored response.'); | 350 'properties as the stored response.'); |
| 351 return cache.match(response.url); | 351 return cache.match(response.url); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 | 391 |
| 392 // Run |test_function| with a Cache object as its only parameter. Prior to the | 392 // Run |test_function| with a Cache object as its only parameter. Prior to the |
| 393 // call, the Cache is populated by cache entries from |entries|. The latter is | 393 // call, the Cache is populated by cache entries from |entries|. The latter is |
| 394 // expected to be an Object mapping arbitrary keys to objects of the form | 394 // expected to be an Object mapping arbitrary keys to objects of the form |
| 395 // {request: <Request object>, response: <Response object>}. | 395 // {request: <Request object>, response: <Response object>}. |
| 396 // | 396 // |
| 397 // |test_function| should return a Promise that can be used with promise_test. | 397 // |test_function| should return a Promise that can be used with promise_test. |
| 398 function prepopulated_cache_test(entries, test_function, description) { | 398 function prepopulated_cache_test(entries, test_function, description) { |
| 399 cache_test(function(cache) { | 399 cache_test(function(cache) { |
| 400 return Promise.all(Object.keys(entries).map(function(k) { | 400 return Promise.all(Object.keys(entries).map(function(k) { |
| 401 return cache.put(entries[k].request, entries[k].response); | 401 return cache.put(entries[k].request.clone(), |
| 402 entries[k].response.clone()); |
| 402 })) | 403 })) |
| 403 .catch(function(reason) { | 404 .catch(function(reason) { |
| 404 assert_unreached('Test setup failed: ' + reason.message); | 405 assert_unreached('Test setup failed: ' + reason.message); |
| 405 }) | 406 }) |
| 406 .then(function() { | 407 .then(function() { |
| 407 return test_function(cache); | 408 return test_function(cache); |
| 408 }); | 409 }); |
| 409 }, description); | 410 }, description); |
| 410 } | 411 } |
| OLD | NEW |