Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / cachestorage / script-tests / cache-storage-match.js
blobc42d1147c40136bc34469ff8b960c66d9c1bbb7d
1 if (self.importScripts) {
2 importScripts('/resources/testharness.js');
3 importScripts('/resources/testharness-helpers.js');
4 importScripts('../resources/test-helpers.js');
7 (function() {
8 var next_index = 1;
10 // Returns a transaction (request, response, and url) for a unique URL.
11 function create_unique_transaction(test) {
12 var uniquifier = String(next_index++);
13 var url = 'http://example.com/' + uniquifier;
15 return {
16 request: new Request(url),
17 response: new Response('hello'),
18 url: url
22 self.create_unique_transaction = create_unique_transaction;
23 })();
25 cache_test(function(cache) {
26 var transaction = create_unique_transaction();
28 return cache.put(transaction.request.clone(), transaction.response.clone())
29 .then(function() {
30 return self.caches.match(transaction.request);
32 .then(function(response) {
33 assert_response_equals(response, transaction.response,
34 'The response should not have changed.');
35 });
36 }, 'CacheStorageMatch with no cache name provided');
38 cache_test(function(cache) {
39 var transaction = create_unique_transaction();
41 var test_cache_list = ['a', 'b', 'c'];
42 return cache.put(transaction.request.clone(), transaction.response.clone())
43 .then(function() {
44 return Promise.all(test_cache_list.map(function(key) {
45 return self.caches.open(key);
46 }));
48 .then(function() {
49 return self.caches.match(transaction.request);
51 .then(function(response) {
52 assert_response_equals(response, transaction.response,
53 'The response should not have changed.');
54 });
55 }, 'CacheStorageMatch from one of many caches');
57 promise_test(function(test) {
58 var transaction = create_unique_transaction();
60 var test_cache_list = ['x', 'y', 'z'];
61 return Promise.all(test_cache_list.map(function(key) {
62 return self.caches.open(key);
63 }))
64 .then(function() { return caches.open('x'); })
65 .then(function(cache) {
66 return cache.put(transaction.request.clone(),
67 transaction.response.clone());
69 .then(function() {
70 return self.caches.match(transaction.request, {cacheName: 'x'});
72 .then(function(response) {
73 assert_response_equals(response, transaction.response,
74 'The response should not have changed.');
76 .then(function() {
77 return self.caches.match(transaction.request, {cacheName: 'y'});
79 .then(function(response) {
80 assert_equals(response, undefined,
81 'Cache y should not have a response for the request.');
82 });
83 }, 'CacheStorageMatch from one of many caches by name');
85 cache_test(function(cache) {
86 var transaction = create_unique_transaction();
87 return cache.put(transaction.url, transaction.response.clone())
88 .then(function() {
89 return self.caches.match(transaction.request);
91 .then(function(response) {
92 assert_response_equals(response, transaction.response,
93 'The response should not have changed.');
94 });
95 }, 'CacheStorageMatch a string request');
97 promise_test(function(test) {
98 var transaction = create_unique_transaction();
99 return self.caches.match(transaction.request)
100 .then(function(response) {
101 assert_equals(response, undefined,
102 'The response should not be found.');
104 }, 'CacheStorageMatch with no cached entry');
106 promise_test(function(test) {
107 var transaction = create_unique_transaction();
108 return self.caches.has('foo')
109 .then(function(has_foo) {
110 assert_false(has_foo, "The cache should not exist.");
111 return self.caches.match(transaction.request, {cacheName: 'foo'});
113 .then(function(response) {
114 assert_equals(response, undefined,
115 'The response should not be found.');
116 return self.caches.has('foo');
118 .then(function(has_foo) {
119 assert_false(has_foo, "The cache should still not exist.");
121 }, 'CacheStorageMatch with no caches available but name provided');
123 done();