OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <title>Service Worker: Memory Cache</title> | 3 <title>Service Worker: Memory Cache</title> |
4 <script src="../../resources/testharness.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
5 <script src="../../resources/testharnessreport.js"></script> | 5 <script src="../../resources/testharnessreport.js"></script> |
6 <script src="../resources/test-helpers.js"></script> | 6 <script src="../resources/test-helpers.js"></script> |
7 <script> | 7 <script> |
8 var callback; | 8 var callback; |
9 | 9 |
10 function getJSONP(url) { | 10 function getJSONP(url) { |
(...skipping 15 matching lines...) Expand all Loading... |
26 var promises = []; | 26 var promises = []; |
27 | 27 |
28 service_worker_unregister_and_register(t, worker, scope) | 28 service_worker_unregister_and_register(t, worker, scope) |
29 .then(function(r) { | 29 .then(function(r) { |
30 registration = r; | 30 registration = r; |
31 return wait_for_activated(t, registration); | 31 return wait_for_activated(t, registration); |
32 }) | 32 }) |
33 .then(function() { return with_iframe(scope); }) | 33 .then(function() { return with_iframe(scope); }) |
34 .then(function(f) { | 34 .then(function(f) { |
35 frame = f; | 35 frame = f; |
| 36 |
36 // Request a json file from controlled page. | 37 // Request a json file from controlled page. |
| 38 assert_false( |
| 39 frame.contentWindow.internals.isLoadingFromMemoryCache(json_url), |
| 40 'Cache for controlled page should be empty'); |
37 promises.push(frame.contentWindow.getJSONP(json_url)); | 41 promises.push(frame.contentWindow.getJSONP(json_url)); |
| 42 |
38 // Request a json file from non-controlled page. | 43 // Request a json file from non-controlled page. |
| 44 assert_false( |
| 45 internals.isLoadingFromMemoryCache(json_url), |
| 46 'Cache for non-controlled page should be empty'); |
39 promises.push(getJSONP(json_url)); | 47 promises.push(getJSONP(json_url)); |
| 48 |
40 return Promise.all(promises); | 49 return Promise.all(promises); |
41 }) | 50 }) |
42 .then(function(results) { | 51 .then(function(results) { |
43 assert_equals( | 52 assert_equals( |
44 results[0].src, | 53 results[0].src, |
45 'service worker', | 54 'service worker', |
46 'Response for controlled page should be served by Service Worker'); | 55 'Response for controlled page should be served by Service Worker'); |
47 assert_equals( | 56 assert_equals( |
48 results[1].src, | 57 results[1].src, |
49 'network', | 58 'network', |
50 'Response for non-controlled page should be served by network'); | 59 'Response for non-controlled page should be served by network'); |
| 60 assert_true( |
| 61 frame.contentWindow.internals.isLoadingFromMemoryCache(json_url), |
| 62 'Response for controlled page should be cached'); |
| 63 assert_true( |
| 64 internals.isLoadingFromMemoryCache(json_url), |
| 65 'Response for non-controlled page should be cached'); |
51 unload_iframe(frame); | 66 unload_iframe(frame); |
52 return registration.unregister(); | 67 return registration.unregister(); |
53 }) | 68 }) |
54 .then(function() { | 69 .then(function() { |
55 t.done(); | 70 t.done(); |
56 }) | 71 }) |
57 .catch(unreached_rejection(t)); | 72 .catch(unreached_rejection(t)); |
58 }, 'Non-controlled page should not use a cache filled by Service Worker'); | 73 }, 'Non-controlled page should not use a cache filled by Service Worker'); |
59 </script> | 74 </script> |
OLD | NEW |