Chromium Code Reviews| Index: LayoutTests/http/tests/inspector/cache-storage/cache-storage-test.js |
| diff --git a/LayoutTests/http/tests/inspector/cache-storage/cache-storage-test.js b/LayoutTests/http/tests/inspector/cache-storage/cache-storage-test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..884564c89a9517ad4f414353e60866b303dd9d04 |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/inspector/cache-storage/cache-storage-test.js |
| @@ -0,0 +1,150 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +var initialize_CacheStorageTest = function() { |
| +InspectorTest.preloadPanel("resources"); |
| + |
| +InspectorTest.dumpCacheTree = function() |
| +{ |
| + WebInspector.panels.resources.cacheStorageListTreeElement.expand(); |
| + InspectorTest.addResult("Dumping CacheStorage tree:"); |
| + var cachesTreeElement = WebInspector.panels.resources.cacheStorageListTreeElement; |
| + var promise = new Promise(function(resolve, reject) { |
| + InspectorTest.addSnifferPromise(WebInspector.ServiceWorkerCacheModel.prototype, "_updateCacheNames").then(function() { |
|
pfeldman
2015/04/15 17:50:08
Devtools uses named functions everywhere. I know i
dmurph
2015/04/15 21:29:32
It looks like it's already used this way here:
ht
|
| + if (!cachesTreeElement.childCount()) { |
| + InspectorTest.addResult(" (empty)"); |
| + return resolve(); |
| + } |
| + function queryView(i) { |
|
pfeldman
2015/04/15 17:50:08
Here and below, blank lines around named functions
dmurph
2015/04/15 21:29:32
Done.
|
| + var cacheTreeElement = cachesTreeElement.childAt(i); |
| + InspectorTest.addResult(" cache: " + cacheTreeElement.titleText); |
| + function nextOrResolve() { |
|
pfeldman
2015/04/15 17:50:08
Here and below, { on the next line please.
dmurph
2015/04/15 21:29:32
Done.
|
| + var next = i + 1; |
| + if (next < cachesTreeElement.childCount()) |
| + queryView(next); |
| + else |
| + resolve(); |
| + } |
| + function addDataResult() { |
| + if (view._entries.length == 0) { |
| + InspectorTest.addResult(" (cache empty)"); |
| + nextOrResolve(); |
| + return; |
| + } |
| + for (var entry of view._entries) |
| + InspectorTest.addResult(" '" + entry.request._value + "': '" + entry.response._value + "'"); |
| + nextOrResolve(); |
| + } |
| + var view = cacheTreeElement._view; |
| + InspectorTest.addSniffer(WebInspector.ServiceWorkerCacheView.prototype, "_updateDataCallback", addDataResult, false); |
| + if (!view) |
| + cacheTreeElement.onselect(false); |
| + else |
| + view._updateData(true); |
| + view = cacheTreeElement._view; |
| + } |
| + WebInspector.panels.resources.cacheStorageListTreeElement._refreshCaches(); |
| + queryView(0); |
| + }).catch(reject); |
| + }); |
| + WebInspector.panels.resources.cacheStorageListTreeElement._refreshCaches(); |
| + return promise; |
| +} |
| + |
| +InspectorTest.deleteCacheFromInspector = function(cacheName) |
| +{ |
| + WebInspector.panels.resources.cacheStorageListTreeElement.expand(); |
| + InspectorTest.addResult("Deleting CacheStorage cache " + cacheName); |
| + var cachesTreeElement = WebInspector.panels.resources.cacheStorageListTreeElement; |
| + var promise = new Promise(function(resolve, reject) { |
|
pfeldman
2015/04/15 17:50:08
Same on named functions and blank lines. This is h
dmurph
2015/04/15 21:29:32
Done. I reordered the functions so it's hopefully
|
| + InspectorTest.addSnifferPromise(WebInspector.ServiceWorkerCacheModel.prototype, "_updateCacheNames").then(function() { |
| + if (!cachesTreeElement.childCount()) |
| + return resolve(); |
| + for (var i = 0; i < cachesTreeElement.childCount(); i++) { |
| + var cacheTreeElement = cachesTreeElement.childAt(i); |
| + var title = cacheTreeElement.titleText; |
| + var elementCacheName = title.substring(0, title.lastIndexOf(" - ")); |
| + if (elementCacheName != cacheName) |
| + continue; |
| + InspectorTest.addSniffer(WebInspector.ServiceWorkerCacheModel.prototype, "_cacheRemoved", resolve) |
| + cacheTreeElement._clearCache(); |
| + return; |
| + } |
| + console.error("Could not find cache to delete."); |
| + reject(); |
| + }).catch(reject); |
| + }); |
| + WebInspector.panels.resources.cacheStorageListTreeElement._refreshCaches(); |
| + return promise; |
| +} |
| + |
| +InspectorTest.waitForCacheRefresh = function(callback) |
| +{ |
| + InspectorTest.addSniffer(WebInspector.ServiceWorkerCacheModel.prototype, "_updateCacheNames", callback, false); |
| +} |
| + |
| +InspectorTest.createCache = function(cacheName) |
| +{ |
| + return InspectorTest.invokePageFunctionPromise("createCache", [cacheName]); |
| +} |
| + |
| +InspectorTest.addCacheEntry = function(cacheName, requestUrl, responseText) |
| +{ |
| + return InspectorTest.invokePageFunctionPromise("addCacheEntry", [cacheName, requestUrl, responseText]); |
| +} |
| + |
| +InspectorTest.deleteCache = function(cacheName) |
| +{ |
| + return InspectorTest.invokePageFunctionPromise("deleteCache", [cacheName]); |
| +} |
| + |
| +InspectorTest.clearAllCaches = function() |
| +{ |
| + return InspectorTest.invokePageFunctionPromise("clearAllCaches", []); |
| +} |
| +} |
| + |
| +function onCacheStorageError(reject, e) |
| +{ |
| + console.error("CacheStorage error: " + e); |
| + reject(); |
| +} |
| + |
| +function createCache(resolve, reject, cacheName) |
| +{ |
| + caches.open(cacheName).then(resolve).catch(onCacheStorageError.bind(this, reject)); |
| +} |
| + |
| +function addCacheEntry(resolve, reject, cacheName, requestUrl, responseText) |
| +{ |
| + caches.open(cacheName).then(function(cache) { |
| + var request = new Request(requestUrl); |
| + var myBlob = new Blob(); |
| + var init = { "status" : 200 , "statusText" : responseText }; |
| + var response = new Response(myBlob, init); |
| + return cache.put(request, response); |
| + }).then(resolve) |
|
pfeldman
2015/04/15 17:50:08
Here and below: weird indent.
dmurph
2015/04/15 21:29:32
Done.
|
| + .catch(onCacheStorageError.bind(this, reject)); |
| +} |
| + |
| +function deleteCache(resolve, reject, cacheName) |
| +{ |
| + caches.delete(cacheName).then(function(success) { |
| + if (success) { |
| + resolve(); |
| + } else { |
| + onCacheStorageError(reject, "Could not find cache " + cacheName); |
| + } |
| + }).catch(onCacheStorageError.bind(this, reject)); |
| +} |
| + |
| +function clearAllCaches(resolve, reject) |
| +{ |
| + caches.keys().then(function(keys) { |
| + return Promise.all(keys.map(function(key) { |
| + return caches.delete(key); |
| + })); |
| + }).then(resolve) |
| + .catch(onCacheStorageError.bind(this, reject)); |
| +} |