OLD | NEW |
1 if (self.importScripts) { | 1 if (self.importScripts) { |
2 importScripts('/resources/testharness.js'); | 2 importScripts('/resources/testharness.js'); |
3 importScripts('../resources/test-helpers.js'); | 3 importScripts('../resources/test-helpers.js'); |
4 } | 4 } |
5 | 5 |
6 (function() { | 6 (function() { |
7 var next_index = 1; | 7 var next_index = 1; |
8 | 8 |
9 // Returns a transaction (request, response, and url) for a unique URL. | 9 // Returns a transaction (request, response, and url) for a unique URL. |
10 function create_unique_transaction(test) { | 10 function create_unique_transaction(test) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 }); | 53 }); |
54 }, 'CacheStorageMatch from one of many caches'); | 54 }, 'CacheStorageMatch from one of many caches'); |
55 | 55 |
56 promise_test(function(test) { | 56 promise_test(function(test) { |
57 var transaction = create_unique_transaction(); | 57 var transaction = create_unique_transaction(); |
58 | 58 |
59 var test_cache_list = ['x', 'y', 'z']; | 59 var test_cache_list = ['x', 'y', 'z']; |
60 return Promise.all(test_cache_list.map(function(key) { | 60 return Promise.all(test_cache_list.map(function(key) { |
61 return self.caches.open(key); | 61 return self.caches.open(key); |
62 })) | 62 })) |
63 .then(function() { return caches.open('x'); }) | 63 .then(function() { return self.caches.open('x'); }) |
64 .then(function(cache) { | 64 .then(function(cache) { |
65 return cache.put(transaction.request.clone(), | 65 return cache.put(transaction.request.clone(), |
66 transaction.response.clone()); | 66 transaction.response.clone()); |
67 }) | 67 }) |
68 .then(function() { | 68 .then(function() { |
69 return self.caches.match(transaction.request, {cacheName: 'x'}); | 69 return self.caches.match(transaction.request, {cacheName: 'x'}); |
70 }) | 70 }) |
71 .then(function(response) { | 71 .then(function(response) { |
72 assert_response_equals(response, transaction.response, | 72 assert_response_equals(response, transaction.response, |
73 'The response should not have changed.'); | 73 'The response should not have changed.'); |
(...skipping 12 matching lines...) Expand all Loading... |
86 return cache.put(transaction.url, transaction.response.clone()) | 86 return cache.put(transaction.url, transaction.response.clone()) |
87 .then(function() { | 87 .then(function() { |
88 return self.caches.match(transaction.request); | 88 return self.caches.match(transaction.request); |
89 }) | 89 }) |
90 .then(function(response) { | 90 .then(function(response) { |
91 assert_response_equals(response, transaction.response, | 91 assert_response_equals(response, transaction.response, |
92 'The response should not have changed.'); | 92 'The response should not have changed.'); |
93 }); | 93 }); |
94 }, 'CacheStorageMatch a string request'); | 94 }, 'CacheStorageMatch a string request'); |
95 | 95 |
| 96 cache_test(function(cache) { |
| 97 var transaction = create_unique_transaction(); |
| 98 return cache.put(transaction.request.clone(), transaction.response.clone()) |
| 99 .then(function() { |
| 100 return self.caches.match(new Request(transaction.request.url, |
| 101 {method: 'HEAD'})); |
| 102 }) |
| 103 .then(function(response) { |
| 104 assert_equals(response, undefined, |
| 105 'A HEAD request should not be matched'); |
| 106 }); |
| 107 }, 'CacheStorageMatch a HEAD request'); |
| 108 |
96 promise_test(function(test) { | 109 promise_test(function(test) { |
97 var transaction = create_unique_transaction(); | 110 var transaction = create_unique_transaction(); |
98 return self.caches.match(transaction.request) | 111 return self.caches.match(transaction.request) |
99 .then(function(response) { | 112 .then(function(response) { |
100 assert_equals(response, undefined, | 113 assert_equals(response, undefined, |
101 'The response should not be found.'); | 114 'The response should not be found.'); |
102 }) | 115 }); |
103 }, 'CacheStorageMatch with no cached entry'); | 116 }, 'CacheStorageMatch with no cached entry'); |
104 | 117 |
105 promise_test(function(test) { | 118 promise_test(function(test) { |
106 var transaction = create_unique_transaction(); | 119 var transaction = create_unique_transaction(); |
107 return self.caches.has('foo') | 120 return self.caches.has('foo') |
108 .then(function(has_foo) { | 121 .then(function(has_foo) { |
109 assert_false(has_foo, "The cache should not exist."); | 122 assert_false(has_foo, "The cache should not exist."); |
110 return self.caches.match(transaction.request, {cacheName: 'foo'}); | 123 return self.caches.match(transaction.request, {cacheName: 'foo'}); |
111 }) | 124 }) |
112 .then(function(response) { | 125 .then(function(response) { |
113 assert_equals(response, undefined, | 126 assert_equals(response, undefined, |
114 'The match with bad cache name should resolve to ' + | 127 'The match with bad cache name should resolve to ' + |
115 'undefined.'); | 128 'undefined.'); |
116 return self.caches.has('foo'); | 129 return self.caches.has('foo'); |
117 }) | 130 }) |
118 .then(function(has_foo) { | 131 .then(function(has_foo) { |
119 assert_false(has_foo, "The cache should still not exist."); | 132 assert_false(has_foo, "The cache should still not exist."); |
120 }) | 133 }); |
121 }, 'CacheStorageMatch with no caches available but name provided'); | 134 }, 'CacheStorageMatch with no caches available but name provided'); |
122 | 135 |
123 done(); | 136 done(); |
OLD | NEW |