OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 var initialize_CacheStorageTest = function() { | |
6 InspectorTest.preloadPanel("resources"); | |
7 | |
8 InspectorTest.dumpCacheTree = function() | |
9 { | |
10 WebInspector.panels.resources.cacheStorageListTreeElement.expand(); | |
11 InspectorTest.addResult("Dumping CacheStorage tree:"); | |
12 var cachesTreeElement = WebInspector.panels.resources.cacheStorageListTreeEl ement; | |
13 var promise = new Promise(function(resolve, reject) { | |
14 InspectorTest.addSnifferPromise(WebInspector.ServiceWorkerCacheModel.pro totype, "_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
| |
15 if (!cachesTreeElement.childCount()) { | |
16 InspectorTest.addResult(" (empty)"); | |
17 return resolve(); | |
18 } | |
19 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.
| |
20 var cacheTreeElement = cachesTreeElement.childAt(i); | |
21 InspectorTest.addResult(" cache: " + cacheTreeElement.titleTe xt); | |
22 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.
| |
23 var next = i + 1; | |
24 if (next < cachesTreeElement.childCount()) | |
25 queryView(next); | |
26 else | |
27 resolve(); | |
28 } | |
29 function addDataResult() { | |
30 if (view._entries.length == 0) { | |
31 InspectorTest.addResult(" (cache empty)"); | |
32 nextOrResolve(); | |
33 return; | |
34 } | |
35 for (var entry of view._entries) | |
36 InspectorTest.addResult(" '" + entry.request._val ue + "': '" + entry.response._value + "'"); | |
37 nextOrResolve(); | |
38 } | |
39 var view = cacheTreeElement._view; | |
40 InspectorTest.addSniffer(WebInspector.ServiceWorkerCacheView.pro totype, "_updateDataCallback", addDataResult, false); | |
41 if (!view) | |
42 cacheTreeElement.onselect(false); | |
43 else | |
44 view._updateData(true); | |
45 view = cacheTreeElement._view; | |
46 } | |
47 WebInspector.panels.resources.cacheStorageListTreeElement._refreshCa ches(); | |
48 queryView(0); | |
49 }).catch(reject); | |
50 }); | |
51 WebInspector.panels.resources.cacheStorageListTreeElement._refreshCaches(); | |
52 return promise; | |
53 } | |
54 | |
55 InspectorTest.deleteCacheFromInspector = function(cacheName) | |
56 { | |
57 WebInspector.panels.resources.cacheStorageListTreeElement.expand(); | |
58 InspectorTest.addResult("Deleting CacheStorage cache " + cacheName); | |
59 var cachesTreeElement = WebInspector.panels.resources.cacheStorageListTreeEl ement; | |
60 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
| |
61 InspectorTest.addSnifferPromise(WebInspector.ServiceWorkerCacheModel.pro totype, "_updateCacheNames").then(function() { | |
62 if (!cachesTreeElement.childCount()) | |
63 return resolve(); | |
64 for (var i = 0; i < cachesTreeElement.childCount(); i++) { | |
65 var cacheTreeElement = cachesTreeElement.childAt(i); | |
66 var title = cacheTreeElement.titleText; | |
67 var elementCacheName = title.substring(0, title.lastIndexOf(" - ")); | |
68 if (elementCacheName != cacheName) | |
69 continue; | |
70 InspectorTest.addSniffer(WebInspector.ServiceWorkerCacheModel.pr ototype, "_cacheRemoved", resolve) | |
71 cacheTreeElement._clearCache(); | |
72 return; | |
73 } | |
74 console.error("Could not find cache to delete."); | |
75 reject(); | |
76 }).catch(reject); | |
77 }); | |
78 WebInspector.panels.resources.cacheStorageListTreeElement._refreshCaches(); | |
79 return promise; | |
80 } | |
81 | |
82 InspectorTest.waitForCacheRefresh = function(callback) | |
83 { | |
84 InspectorTest.addSniffer(WebInspector.ServiceWorkerCacheModel.prototype, "_u pdateCacheNames", callback, false); | |
85 } | |
86 | |
87 InspectorTest.createCache = function(cacheName) | |
88 { | |
89 return InspectorTest.invokePageFunctionPromise("createCache", [cacheName]); | |
90 } | |
91 | |
92 InspectorTest.addCacheEntry = function(cacheName, requestUrl, responseText) | |
93 { | |
94 return InspectorTest.invokePageFunctionPromise("addCacheEntry", [cacheName, requestUrl, responseText]); | |
95 } | |
96 | |
97 InspectorTest.deleteCache = function(cacheName) | |
98 { | |
99 return InspectorTest.invokePageFunctionPromise("deleteCache", [cacheName]); | |
100 } | |
101 | |
102 InspectorTest.clearAllCaches = function() | |
103 { | |
104 return InspectorTest.invokePageFunctionPromise("clearAllCaches", []); | |
105 } | |
106 } | |
107 | |
108 function onCacheStorageError(reject, e) | |
109 { | |
110 console.error("CacheStorage error: " + e); | |
111 reject(); | |
112 } | |
113 | |
114 function createCache(resolve, reject, cacheName) | |
115 { | |
116 caches.open(cacheName).then(resolve).catch(onCacheStorageError.bind(this, re ject)); | |
117 } | |
118 | |
119 function addCacheEntry(resolve, reject, cacheName, requestUrl, responseText) | |
120 { | |
121 caches.open(cacheName).then(function(cache) { | |
122 var request = new Request(requestUrl); | |
123 var myBlob = new Blob(); | |
124 var init = { "status" : 200 , "statusText" : responseText }; | |
125 var response = new Response(myBlob, init); | |
126 return cache.put(request, response); | |
127 }).then(resolve) | |
pfeldman
2015/04/15 17:50:08
Here and below: weird indent.
dmurph
2015/04/15 21:29:32
Done.
| |
128 .catch(onCacheStorageError.bind(this, reject)); | |
129 } | |
130 | |
131 function deleteCache(resolve, reject, cacheName) | |
132 { | |
133 caches.delete(cacheName).then(function(success) { | |
134 if (success) { | |
135 resolve(); | |
136 } else { | |
137 onCacheStorageError(reject, "Could not find cache " + cacheName) ; | |
138 } | |
139 }).catch(onCacheStorageError.bind(this, reject)); | |
140 } | |
141 | |
142 function clearAllCaches(resolve, reject) | |
143 { | |
144 caches.keys().then(function(keys) { | |
145 return Promise.all(keys.map(function(key) { | |
146 return caches.delete(key); | |
147 })); | |
148 }).then(resolve) | |
149 .catch(onCacheStorageError.bind(this, reject)); | |
150 } | |
OLD | NEW |