OLD | NEW |
---|---|
(Empty) | |
1 <html> | |
2 <head> | |
3 <script src="../http/tests/inspector/inspector-test.js"></script> | |
4 <script> | |
5 | |
6 function clearDOMStorage() | |
7 { | |
8 localStorage.clear(); | |
9 sessionStorage.clear(); | |
10 } | |
11 | |
12 function getDOMStorageEntries(isLocalStorage) | |
13 { | |
14 var storage = isLocalStorage ? localStorage : sessionStorage; | |
15 var entries = []; | |
16 for (var i = 0; i < storage.length; ++i) { | |
17 var key = storage.key(i); | |
18 var value = storage.getItem(key); | |
19 entries.push(key + "=" + value); | |
20 } | |
21 entries.sort(); | |
22 return "[" + entries.join() + "]"; | |
23 } | |
24 | |
25 function test() | |
26 { | |
27 WebInspector.showPanel("resources"); | |
28 | |
29 var theLocalStorage; | |
30 var theSessionStorage; | |
31 var storages = WebInspector.domStorageModel.storages(); | |
32 for (var i = 0; i < storages.length; ++i) { | |
33 var storage = storages[i]; | |
34 if (storage.isLocalStorage) | |
35 theLocalStorage = storage; | |
36 else | |
37 theSessionStorage = storage; | |
38 } | |
39 | |
40 function dumpDOMStorage(next) | |
41 { | |
42 if (this.isLocalStorage) | |
43 InspectorTest.evaluateInPage("getDOMStorageEntries(true)", storageEn triesReceived.bind(this)); | |
44 else | |
45 InspectorTest.evaluateInPage("getDOMStorageEntries(false)", storageE ntriesReceived.bind(this)); | |
46 | |
47 function storageEntriesReceived(entries) | |
48 { | |
49 InspectorTest.addResult((this.isLocalStorage ? "LocalStorage" : "Ses sionStorage") + " contents:" + entries.description); | |
50 next(); | |
51 } | |
52 } | |
53 | |
54 function show(storage) | |
55 { | |
56 WebInspector.panels.resources._showDOMStorage(storage); | |
57 } | |
58 | |
59 function undo(operations, next) | |
60 { | |
61 for (var i = 0; i < operations; ++i) | |
62 this.undo(); | |
63 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next)) ; | |
64 } | |
65 | |
66 function redo(operations, next) | |
67 { | |
68 for (var i = 0; i < operations; ++i) | |
69 this.redo(); | |
70 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next)) ; | |
71 } | |
72 | |
73 function addKeyValuePair(storage, key, value) | |
74 { | |
75 var dataGrid = WebInspector.panels.resources._domStorageViews.get(storag e)._dataGrid; | |
76 var creationNode = dataGrid.rootNode().children.peekLast(); | |
77 | |
78 var elementKey = creationNode._element.children[0]; | |
79 dataGrid._startEditing(elementKey); | |
80 elementKey.textContent = key; | |
81 elementKey.dispatchEvent(InspectorTest.createKeyEvent("Enter")); | |
82 | |
83 var elementValue = creationNode._element.children[1]; | |
84 dataGrid._startEditing(elementValue); | |
85 elementValue.textContent = value; | |
86 elementValue.dispatchEvent(InspectorTest.createKeyEvent("Enter")); | |
87 } | |
88 | |
89 function modifyValueForKey(storage, key, newValue) | |
90 { | |
91 var dataGrid = WebInspector.panels.resources._domStorageViews.get(storag e)._dataGrid; | |
92 var children = dataGrid.rootNode().children; | |
93 | |
94 var modificationNode; | |
95 for (var i = 0; i < children.length; ++i) { | |
96 if (children[i]._element.children[0].textContent === key) { | |
97 modificationNode = children[i]; | |
98 break; | |
99 } | |
100 } | |
101 | |
102 var elementValue = modificationNode._element.children[1]; | |
103 dataGrid._startEditing(elementValue); | |
104 elementValue.textContent = newValue; | |
105 elementValue.dispatchEvent(InspectorTest.createKeyEvent("Enter")); | |
106 } | |
107 | |
108 function changeKey(storage, oldKey, newKey) | |
109 { | |
110 var dataGrid = WebInspector.panels.resources._domStorageViews.get(storag e)._dataGrid; | |
111 var children = dataGrid.rootNode().children; | |
112 | |
113 var modificationNode; | |
114 for (var i = 0; i < children.length; ++i) { | |
115 if (children[i]._element.children[0].textContent === oldKey) { | |
116 modificationNode = children[i]; | |
117 break; | |
118 } | |
119 } | |
120 var elementKey = modificationNode._element.children[0]; | |
121 dataGrid._startEditing(elementKey); | |
122 elementKey.textContent = newKey; | |
123 elementKey.dispatchEvent(InspectorTest.createKeyEvent("Enter")); | |
124 } | |
125 | |
126 InspectorTest.runTestSuite([ | |
127 function initialize(next) | |
128 { | |
129 InspectorTest.evaluateInPage("clearDOMStorage()", initialized); | |
130 | |
131 function initialized(result) | |
132 { | |
133 InspectorTest.addResult("Initialized localStorage and sessionSto rage by clearing entries."); | |
134 next(); | |
135 } | |
136 }, | |
137 | |
138 function undoLocalStorageWithEmptyStack(next) | |
139 { | |
140 show(theLocalStorage); | |
141 InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 1 0, next)); | |
142 }, | |
143 | |
144 function redoLocalStorageWithEmptyStack(next) | |
145 { | |
146 show(theLocalStorage); | |
147 InspectorTest.runAfterPendingDispatches(redo.bind(theLocalStorage, 1 0, next)); | |
148 }, | |
149 | |
150 function localStorageUndoInterlacedWithAddition(next) | |
151 { | |
152 show(theLocalStorage); | |
153 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(the LocalStorage)); | |
154 function domStorageViewShown() | |
155 { | |
156 addKeyValuePair(this, "a1", "b1"); | |
157 addKeyValuePair(this, "a2", "b2"); | |
158 InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorag e, 2, firstUndoDone.bind(next))); | |
apavlov
2013/08/05 09:07:15
Semantically, ...bind(next) is not the right way o
vivekg_samsung
2013/08/05 09:39:49
Done.
| |
159 | |
160 function firstUndoDone() | |
161 { | |
162 addKeyValuePair(theLocalStorage, "a3", "b3"); | |
163 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind( theLocalStorage, nextUndoDone.bind(this))); | |
164 | |
165 function nextUndoDone() | |
166 { | |
167 InspectorTest.runAfterPendingDispatches(undo.bind(theLoc alStorage, 2, this)); | |
168 } | |
169 } | |
170 } | |
171 }, | |
172 | |
173 function addLocalStorageEntries(next) | |
174 { | |
175 show(theLocalStorage); | |
176 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(the LocalStorage)); | |
177 | |
178 function domStorageViewShown() | |
179 { | |
180 addKeyValuePair(this, "a1", "b1"); | |
181 addKeyValuePair(this, "a2", "b2"); | |
182 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this , next)); | |
183 } | |
184 }, | |
185 | |
186 function undoLocalStorageLastAddition(next) | |
187 { | |
188 show(theLocalStorage); | |
189 InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 2 , next)); | |
190 }, | |
191 | |
192 function undoSessionStorageWithEmptyStack(next) | |
193 { | |
194 show(theSessionStorage); | |
195 InspectorTest.runAfterPendingDispatches(undo.bind(theSessionStorage, 10, next)); | |
196 }, | |
197 | |
198 function redoSessionStorageWithEmptyStack(next) | |
199 { | |
200 show(theSessionStorage); | |
201 InspectorTest.runAfterPendingDispatches(redo.bind(theSessionStorage, 10, next)); | |
202 }, | |
203 | |
204 function undoLocalStorageBeyondBounds(next) | |
205 { | |
206 InspectorTest.addResult("The entry a1=b1 is removed and any attempt to undo beyond it shouldn't cause any failure!") | |
207 show(theLocalStorage); | |
208 InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 1 0, next)); | |
209 }, | |
210 | |
211 function addSessionStorageEntries(next) | |
212 { | |
213 show(theSessionStorage); | |
214 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(the SessionStorage)); | |
215 | |
216 function domStorageViewShown() | |
217 { | |
218 addKeyValuePair(this, "p1", "q1"); | |
219 addKeyValuePair(this, "p2", "q2"); | |
220 addKeyValuePair(this, "p3", "q3"); | |
221 addKeyValuePair(this, "p4", "q4"); | |
222 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this , next)); | |
223 } | |
224 }, | |
225 | |
226 function redoLocalStorageBeyondBounds(next) | |
227 { | |
228 InspectorTest.addResult("The entry a1=b1 and a2=b2 is added back and any attempt to redo beyond it shouldn't cause any failure!") | |
229 show(theLocalStorage); | |
230 InspectorTest.runAfterPendingDispatches(redo.bind(theLocalStorage, 1 0, next)); | |
231 }, | |
232 | |
233 function undoSessionStorageLastAddition(next) | |
234 { | |
235 show(theSessionStorage); | |
236 InspectorTest.runAfterPendingDispatches(undo.bind(theSessionStorage, 2, next)); | |
237 }, | |
238 | |
239 function modifyLocalStorageValues(next) | |
240 { | |
241 show(theLocalStorage); | |
242 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(the LocalStorage)); | |
243 | |
244 function domStorageViewShown() | |
245 { | |
246 modifyValueForKey(this, "a1", "x1"); | |
247 modifyValueForKey(this, "a2", "x2"); | |
248 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this , next)); | |
249 } | |
250 }, | |
251 | |
252 function undoLocalStorageModifications(next) | |
253 { | |
254 show(theLocalStorage); | |
255 InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 2 , next)); | |
256 }, | |
257 | |
258 function redoSessionStorageLastAddition(next) | |
259 { | |
260 show(theSessionStorage); | |
261 InspectorTest.runAfterPendingDispatches(redo.bind(theSessionStorage, 2, next)); | |
262 }, | |
263 | |
264 function redoLocalStorageModifications(next) | |
265 { | |
266 show(theLocalStorage); | |
267 InspectorTest.runAfterPendingDispatches(redo.bind(theLocalStorage, 2 , next)); | |
268 }, | |
269 | |
270 function modifySessionStorageEntriesKey(next) | |
271 { | |
272 show(theSessionStorage); | |
273 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(the SessionStorage)); | |
274 | |
275 function domStorageViewShown() | |
276 { | |
277 changeKey(this, "p1", "m1"); | |
278 changeKey(this, "p2", "m2"); | |
279 changeKey(this, "p3", "m3"); | |
280 changeKey(this, "p4", "m4"); | |
281 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this , next)); | |
282 } | |
283 }, | |
284 | |
285 function undoLocalStorageModifications(next) | |
286 { | |
287 show(theLocalStorage); | |
288 InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 2 , next)); | |
289 }, | |
290 | |
291 function undoSessionStorageKeyModifications(next) | |
292 { | |
293 show(theSessionStorage); | |
294 InspectorTest.runAfterPendingDispatches(undo.bind(theSessionStorage, 8, next)); | |
295 }, | |
296 | |
297 function validateMaxUndoRedoStackDepth(next) | |
298 { | |
299 show(theLocalStorage); | |
300 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(the LocalStorage)); | |
301 | |
302 function domStorageViewShown() | |
303 { | |
304 var stackDepth = WebInspector.DOMStorageHistory.MAX_UNDO_REDO_DE PTH; | |
305 InspectorTest.addResult("Undo/redo stack depth limit is " + stac kDepth); | |
306 InspectorTest.addResult("Performing " + (2 * stackDepth) + " act ions"); | |
307 for (var i = 1; i <= stackDepth; ++i) | |
308 addKeyValuePair(this, "a" + i, "b" + i); | |
309 | |
310 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this , undoMoreThanDepth.bind(this))); | |
311 | |
312 function undoMoreThanDepth() | |
313 { | |
314 InspectorTest.addResult("Performing undo operation three tim es the depth i.e. " + (3 * stackDepth) + " times but only last " + stackDepth + " operations are undone"); | |
315 InspectorTest.runAfterPendingDispatches(undo.bind(theLocalSt orage, (3 * stackDepth), next)); | |
316 } | |
317 } | |
318 }, | |
319 | |
320 function clearDOMStorageAndFinish(next) | |
321 { | |
322 InspectorTest.evaluateInPage("clearDOMStorage()", finishTest); | |
323 | |
324 function finishTest(result) | |
325 { | |
326 InspectorTest.addResult("Finished DOMStorage undo/redo tests and cleared localStorage and sessionStorage entries."); | |
327 next(); | |
328 } | |
329 } | |
330 ]); | |
331 } | |
332 </script> | |
333 </head> | |
334 <body onload="runTest()"> | |
335 <p>This test checks the undo/redo operations are performed correctly on the DOM storage views</p> | |
336 </body> | |
337 </html> | |
OLD | NEW |