| 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 { | 6 { |
| 7 name: 'a', | 7 name: 'a', |
| 8 request: new Request('http://example.com/a'), | 8 request: new Request('http://example.com/a'), |
| 9 response: new Response('') | 9 response: new Response('') |
| 10 }, | 10 }, |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 var request = new Request('http://example.com'); | 503 var request = new Request('http://example.com'); |
| 504 var response; | 504 var response; |
| 505 var request_url = new URL('simple.txt', location.href).href; | 505 var request_url = new URL('simple.txt', location.href).href; |
| 506 return fetch(request_url) | 506 return fetch(request_url) |
| 507 .then(function(fetch_result) { | 507 .then(function(fetch_result) { |
| 508 response = fetch_result; | 508 response = fetch_result; |
| 509 assert_equals( | 509 assert_equals( |
| 510 response.url, request_url, | 510 response.url, request_url, |
| 511 '[https://fetch.spec.whatwg.org/#dom-response-url] ' + | 511 '[https://fetch.spec.whatwg.org/#dom-response-url] ' + |
| 512 'Reponse.url should return the URL of the response.'); | 512 'Reponse.url should return the URL of the response.'); |
| 513 return cache.put(request, response); | 513 return cache.put(request, response.clone()); |
| 514 }) | 514 }) |
| 515 .then(function() { | 515 .then(function() { |
| 516 return cache.match(request.url); | 516 return cache.match(request.url); |
| 517 }) | 517 }) |
| 518 .then(function(result) { | 518 .then(function(result) { |
| 519 assert_object_equals( | 519 assert_object_equals( |
| 520 result, response, | 520 result, response, |
| 521 'Cache.match should return a Response object that has the same ' + | 521 'Cache.match should return a Response object that has the same ' + |
| 522 'properties as the stored response.'); | 522 'properties as the stored response.'); |
| 523 return cache.match(response.url); | 523 return cache.match(response.url); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 // {request: <Request object>, response: <Response object>}. There's no | 567 // {request: <Request object>, response: <Response object>}. There's no |
| 568 // guarantee on the order in which entries will be added to the cache. | 568 // guarantee on the order in which entries will be added to the cache. |
| 569 // | 569 // |
| 570 // |test_function| should return a Promise that can be used with promise_test. | 570 // |test_function| should return a Promise that can be used with promise_test. |
| 571 function prepopulated_cache_test(entries, test_function, description) { | 571 function prepopulated_cache_test(entries, test_function, description) { |
| 572 cache_test(function(cache) { | 572 cache_test(function(cache) { |
| 573 var p = Promise.resolve(); | 573 var p = Promise.resolve(); |
| 574 var hash = {}; | 574 var hash = {}; |
| 575 entries.forEach(function(entry) { | 575 entries.forEach(function(entry) { |
| 576 p = p.then(function() { | 576 p = p.then(function() { |
| 577 return cache.put(entry.request, entry.response) | 577 return cache.put(entry.request.clone(), |
| 578 entry.response.clone()) |
| 578 .catch(function(e) { | 579 .catch(function(e) { |
| 579 assert_unreached('Test setup failed for entry ' + | 580 assert_unreached('Test setup failed for entry ' + |
| 580 entry.name + ': ' + e); | 581 entry.name + ': ' + e); |
| 581 }); | 582 }); |
| 582 }); | 583 }); |
| 583 hash[entry.name] = entry; | 584 hash[entry.name] = entry; |
| 584 }); | 585 }); |
| 585 p = p.then(function() { | 586 p = p.then(function() { |
| 586 assert_equals(Object.keys(hash).length, entries.length); | 587 assert_equals(Object.keys(hash).length, entries.length); |
| 587 }); | 588 }); |
| 588 | 589 |
| 589 return p.then(function() { | 590 return p.then(function() { |
| 590 return test_function(cache, hash); | 591 return test_function(cache, hash); |
| 591 }); | 592 }); |
| 592 }, description); | 593 }, description); |
| 593 } | 594 } |
| OLD | NEW |