Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: LayoutTests/http/tests/inspector/cache-storage/cache-storage-test.js

Issue 1111563006: [CacheStorage] Entry deletion and cache refresh in Inspector. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Test and comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var initialize_CacheStorageTest = function() { 5 var initialize_CacheStorageTest = function() {
6 InspectorTest.preloadPanel("resources"); 6 InspectorTest.preloadPanel("resources");
7 7
8 InspectorTest.dumpCacheTree = function() 8 InspectorTest.dumpCacheTree = function()
9 { 9 {
10 WebInspector.panels.resources.cacheStorageListTreeElement.expand(); 10 WebInspector.panels.resources.cacheStorageListTreeElement.expand();
(...skipping 25 matching lines...) Expand all
36 view = cacheTreeElement._view; 36 view = cacheTreeElement._view;
37 37
38 function addDataResult() 38 function addDataResult()
39 { 39 {
40 if (view._entries.length == 0) { 40 if (view._entries.length == 0) {
41 InspectorTest.addResult(" (cache empty)"); 41 InspectorTest.addResult(" (cache empty)");
42 nextOrResolve(); 42 nextOrResolve();
43 return; 43 return;
44 } 44 }
45 for (var entry of view._entries) 45 for (var entry of view._entries)
46 InspectorTest.addResult(" '" + entry.request._val ue + "': '" + entry.response._value + "'"); 46 InspectorTest.addResult(" '" + entry.request + "' : '" + entry.response + "'");
47 nextOrResolve(); 47 nextOrResolve();
48 } 48 }
49 49
50 function nextOrResolve() 50 function nextOrResolve()
51 { 51 {
52 var next = i + 1; 52 var next = i + 1;
53 if (next < cachesTreeElement.childCount()) 53 if (next < cachesTreeElement.childCount())
54 queryView(next); 54 queryView(next);
55 else 55 else
56 resolve(); 56 resolve();
57 } 57 }
58 } 58 }
59 } 59 }
60 }); 60 });
61 WebInspector.panels.resources.cacheStorageListTreeElement._refreshCaches(); 61 WebInspector.panels.resources.cacheStorageListTreeElement._refreshCaches();
62 return promise; 62 return promise;
63 } 63 }
64 64
65 InspectorTest.deleteCacheFromInspector = function(cacheName) 65 // If optionalEntry is not specified, then the whole cache is deleted.
66 InspectorTest.deleteCacheFromInspector = function(cacheName, optionalEntry)
66 { 67 {
67 WebInspector.panels.resources.cacheStorageListTreeElement.expand(); 68 WebInspector.panels.resources.cacheStorageListTreeElement.expand();
68 InspectorTest.addResult("Deleting CacheStorage cache " + cacheName); 69 if (optionalEntry) {
70 InspectorTest.addResult("Deleting CacheStorage entry " + optionalEntry + " in cache " + cacheName);
71 } else {
72 InspectorTest.addResult("Deleting CacheStorage cache " + cacheName);
73 }
69 var cachesTreeElement = WebInspector.panels.resources.cacheStorageListTreeEl ement; 74 var cachesTreeElement = WebInspector.panels.resources.cacheStorageListTreeEl ement;
70 var promise = new Promise(function(resolve, reject) { 75 var promise = new Promise(function(resolve, reject) {
71 InspectorTest.addSnifferPromise(WebInspector.ServiceWorkerCacheModel.pro totype, "_updateCacheNames") 76 InspectorTest.addSnifferPromise(WebInspector.ServiceWorkerCacheModel.pro totype, "_updateCacheNames")
72 .then(function() { 77 .then(function() {
73 if (!cachesTreeElement.childCount()) 78 if (!cachesTreeElement.childCount()) {
74 return resolve(); 79 reject("Error: Could not find CacheStorage cache " + cacheNa me);
80 return;
81 }
75 for (var i = 0; i < cachesTreeElement.childCount(); i++) { 82 for (var i = 0; i < cachesTreeElement.childCount(); i++) {
76 var cacheTreeElement = cachesTreeElement.childAt(i); 83 var cacheTreeElement = cachesTreeElement.childAt(i);
77 var title = cacheTreeElement.titleText; 84 var title = cacheTreeElement.titleText;
78 var elementCacheName = title.substring(0, title.lastIndexOf( " - ")); 85 var elementCacheName = title.substring(0, title.lastIndexOf( " - "));
79 if (elementCacheName != cacheName) 86 if (elementCacheName != cacheName)
80 continue; 87 continue;
81 InspectorTest.addSniffer(WebInspector.ServiceWorkerCacheMode l.prototype, "_cacheRemoved", resolve) 88 if (!optionalEntry) {
82 cacheTreeElement._clearCache(); 89 // Here we're deleting the whole cache.
90 InspectorTest.addSniffer(WebInspector.ServiceWorkerCache Model.prototype, "_cacheRemoved", resolve)
91 cacheTreeElement._clearCache();
92 return;
93 }
94
95 // Here we're deleting only the entry. We verify that it is present in the table.
96 var view = cacheTreeElement._view;
97 InspectorTest.addSniffer(WebInspector.ServiceWorkerCacheView .prototype, "_updateDataCallback", deleteEntryOrReject, false);
98 if (!view)
99 cacheTreeElement.onselect(false);
100 else
101 view._updateData(true);
102 view = cacheTreeElement._view;
103
104 function deleteEntryOrReject()
105 {
106 for (var entry of view._entries) {
107 if (entry.request == optionalEntry) {
108 view._model.deleteCacheEntry(view._cache, entry. request, resolve);
109 return;
110 }
111 }
112 reject("Error: Could not find cache entry to delete: " + optionalEntry);
113 return;
114 }
83 return; 115 return;
84 } 116 }
85 InspectorTest.addResult("Error: Could not find cache to delete." ); 117 reject("Error: Could not find CacheStorage cache " + cacheName);
86 reject();
87 }).catch(reject); 118 }).catch(reject);
88 }); 119 });
89 WebInspector.panels.resources.cacheStorageListTreeElement._refreshCaches(); 120 WebInspector.panels.resources.cacheStorageListTreeElement._refreshCaches();
90 return promise; 121 return promise;
91 } 122 }
92 123
93 InspectorTest.waitForCacheRefresh = function(callback) 124 InspectorTest.waitForCacheRefresh = function(callback)
94 { 125 {
95 InspectorTest.addSniffer(WebInspector.ServiceWorkerCacheModel.prototype, "_u pdateCacheNames", callback, false); 126 InspectorTest.addSniffer(WebInspector.ServiceWorkerCacheModel.prototype, "_u pdateCacheNames", callback, false);
96 } 127 }
97 128
98 InspectorTest.createCache = function(cacheName) 129 InspectorTest.createCache = function(cacheName)
99 { 130 {
100 return InspectorTest.invokePageFunctionPromise("createCache", [cacheName]); 131 return InspectorTest.invokePageFunctionPromise("createCache", [cacheName]);
101 } 132 }
102 133
103 InspectorTest.addCacheEntry = function(cacheName, requestUrl, responseText) 134 InspectorTest.addCacheEntry = function(cacheName, requestUrl, responseText)
104 { 135 {
105 return InspectorTest.invokePageFunctionPromise("addCacheEntry", [cacheName, requestUrl, responseText]); 136 return InspectorTest.invokePageFunctionPromise("addCacheEntry", [cacheName, requestUrl, responseText]);
106 } 137 }
107 138
108 InspectorTest.deleteCache = function(cacheName) 139 InspectorTest.deleteCache = function(cacheName)
109 { 140 {
110 return InspectorTest.invokePageFunctionPromise("deleteCache", [cacheName]); 141 return InspectorTest.invokePageFunctionPromise("deleteCache", [cacheName]);
111 } 142 }
112 143
144 InspectorTest.deleteCacheEntry = function(cacheName, requestUrl)
145 {
146 return InspectorTest.invokePageFunctionPromise("deleteCacheEntry", [cacheNam e, requestUrl]);
147 }
148
113 InspectorTest.clearAllCaches = function() 149 InspectorTest.clearAllCaches = function()
114 { 150 {
115 return InspectorTest.invokePageFunctionPromise("clearAllCaches", []); 151 return InspectorTest.invokePageFunctionPromise("clearAllCaches", []);
116 } 152 }
117 } 153 }
118 154
119 function onCacheStorageError(reject, e) 155 function onCacheStorageError(reject, e)
120 { 156 {
121 console.error("CacheStorage error: " + e); 157 console.error("CacheStorage error: " + e);
122 reject(); 158 reject();
(...skipping 22 matching lines...) Expand all
145 { 181 {
146 caches.delete(cacheName) 182 caches.delete(cacheName)
147 .then(function(success) { 183 .then(function(success) {
148 if (success) 184 if (success)
149 resolve(); 185 resolve();
150 else 186 else
151 onCacheStorageError(reject, "Could not find cache " + cacheName) ; 187 onCacheStorageError(reject, "Could not find cache " + cacheName) ;
152 }).catch(onCacheStorageError.bind(this, reject)); 188 }).catch(onCacheStorageError.bind(this, reject));
153 } 189 }
154 190
191 function deleteCacheEntry(resolve, reject, cacheName, requestUrl)
192 {
193 caches.open(cacheName)
194 .then(function(cache) {
195 var request = new Request(requestUrl);
196 return cache.delete(request);
197 })
198 .then(resolve)
199 .catch(onCacheStorageError.bind(this, reject));
200 }
201
155 function clearAllCaches(resolve, reject) 202 function clearAllCaches(resolve, reject)
156 { 203 {
157 caches.keys() 204 caches.keys()
158 .then(function(keys) { 205 .then(function(keys) {
159 return Promise.all(keys.map(function(key) { 206 return Promise.all(keys.map(function(key) {
160 return caches.delete(key); 207 return caches.delete(key);
161 })); 208 }));
162 }) 209 })
163 .then(resolve) 210 .then(resolve)
164 .catch(onCacheStorageError.bind(this, reject)); 211 .catch(onCacheStorageError.bind(this, reject));
165 } 212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698