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