OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <script src="../http/tests/inspector/inspector-test.js"></script> |
| 4 <script> |
| 5 |
| 6 function initializeDOMStorage() |
| 7 { |
| 8 localStorage.clear(); |
| 9 sessionStorage.clear(); |
| 10 } |
| 11 |
| 12 function test() |
| 13 { |
| 14 // Resources panel must be visible |
| 15 WebInspector.showPanel("resources"); |
| 16 |
| 17 var LocalStorage; |
| 18 var SessionStorage; |
| 19 var storages = WebInspector.domStorageModel.storages(); |
| 20 for (var i = 0; i < storages.length; ++i) { |
| 21 var storage = storages[i]; |
| 22 if (storage.isLocalStorage) |
| 23 LocalStorage = storage; |
| 24 else |
| 25 SessionStorage = storage; |
| 26 } |
| 27 |
| 28 function dumpDataGrid(next) |
| 29 { |
| 30 InspectorTest.addResult((this.isLocalStorage ? "localStorage: " : "sessi
onStorage: ") + "contents"); |
| 31 var dataGrid = WebInspector.panels.resources._domStorageViews.get(this).
_dataGrid; |
| 32 var nodes = dataGrid.rootNode().children; |
| 33 var rows = []; |
| 34 for (var i = 0; i < nodes.length; ++i) { |
| 35 var node = nodes[i]; |
| 36 if (node._data.key) |
| 37 rows.push(node._data.key + node._data.value); |
| 38 } |
| 39 rows.sort(); |
| 40 InspectorTest.addResult("[" + rows.join() + "]"); |
| 41 next(); |
| 42 } |
| 43 |
| 44 function show(storage) |
| 45 { |
| 46 WebInspector.panels.resources._showDOMStorage(storage); |
| 47 } |
| 48 |
| 49 function undo(operations, next) |
| 50 { |
| 51 for (var i = 0; i < operations; ++i) { |
| 52 InspectorTest.addResult("Undoing"); |
| 53 this.undo(); |
| 54 } |
| 55 InspectorTest.runAfterPendingDispatches(dumpDataGrid.bind(this, next)); |
| 56 } |
| 57 |
| 58 function redo(operations, next) |
| 59 { |
| 60 for (var i = 0; i < operations; ++i) |
| 61 this.redo(); |
| 62 InspectorTest.runAfterPendingDispatches(dumpDataGrid.bind(this, next)); |
| 63 } |
| 64 |
| 65 function addKeyValuePair(storage, key, value) |
| 66 { |
| 67 var dataGrid = WebInspector.panels.resources._domStorageViews.get(storag
e)._dataGrid; |
| 68 var creationNode = dataGrid.rootNode().children[dataGrid.rootNode().chil
dren.length - 1]; |
| 69 |
| 70 var elementKey = creationNode._element.children[0]; |
| 71 dataGrid._startEditing(elementKey); |
| 72 elementKey.textContent = key; |
| 73 elementKey.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
| 74 |
| 75 setTimeout(function() { |
| 76 var elementValue = creationNode._element.children[1]; |
| 77 dataGrid._startEditing(elementValue); |
| 78 elementValue.textContent = "=" + value; |
| 79 elementValue.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
| 80 }, 1000); |
| 81 } |
| 82 |
| 83 function modifyValueForKey(storage, key, newValue) |
| 84 { |
| 85 var dataGrid = WebInspector.panels.resources._domStorageViews.get(storag
e)._dataGrid; |
| 86 var children = dataGrid.rootNode().children; |
| 87 |
| 88 var modificationNode; |
| 89 for (var i = 0; i < children.length; ++i) { |
| 90 if (children[i]._element.children[0].textContent === key) { |
| 91 modificationNode = children[i]; |
| 92 break; |
| 93 } |
| 94 } |
| 95 |
| 96 var elementValue = modificationNode._element.children[1]; |
| 97 dataGrid._startEditing(elementValue); |
| 98 elementValue.textContent = "=" + newValue; |
| 99 elementValue.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
| 100 } |
| 101 |
| 102 function changeKey(storage, oldKey, newKey) |
| 103 { |
| 104 var dataGrid = WebInspector.panels.resources._domStorageViews.get(storag
e)._dataGrid; |
| 105 var children = dataGrid.rootNode().children; |
| 106 |
| 107 var modificationNode; |
| 108 for (var i = 0; i < children.length; ++i) { |
| 109 if (children[i]._element.children[0].textContent === oldKey) { |
| 110 modificationNode = children[i]; |
| 111 break; |
| 112 } |
| 113 } |
| 114 var elementKey = modificationNode._element.children[0]; |
| 115 dataGrid._startEditing(elementKey); |
| 116 elementKey.textContent = newKey; |
| 117 elementKey.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
| 118 } |
| 119 |
| 120 InspectorTest.runTestSuite([ |
| 121 function initialize(next) |
| 122 { |
| 123 function initialized(result) |
| 124 { |
| 125 InspectorTest.addResult("Initialized localStorage and sessionSto
rage by clearing entries"); |
| 126 next(); |
| 127 } |
| 128 InspectorTest.evaluateInPage("initializeDOMStorage()", initialized )
; |
| 129 }, |
| 130 |
| 131 function addLocalStorageEntries(next) |
| 132 { |
| 133 function domStorageViewShown() |
| 134 { |
| 135 addKeyValuePair(this, "a1", "b1"); |
| 136 addKeyValuePair(this, "a2", "b2"); |
| 137 InspectorTest.runAfterPendingDispatches(dumpDataGrid.bind(this,
next)); |
| 138 } |
| 139 show(LocalStorage); |
| 140 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(Loc
alStorage)); |
| 141 }, |
| 142 |
| 143 function undoLocalStorageLastAddition(next) |
| 144 { |
| 145 show(LocalStorage); |
| 146 InspectorTest.runAfterPendingDispatches(undo.bind(LocalStorage, 2, n
ext)); |
| 147 }, |
| 148 |
| 149 function addSessionStorageEntries(next) |
| 150 { |
| 151 function domStorageViewShown() |
| 152 { |
| 153 addKeyValuePair(this, "p1", "q1"); |
| 154 addKeyValuePair(this, "p2", "q2"); |
| 155 addKeyValuePair(this, "p3", "q3"); |
| 156 addKeyValuePair(this, "p4", "q4"); |
| 157 InspectorTest.runAfterPendingDispatches(dumpDataGrid.bind(this,
next)); |
| 158 } |
| 159 show(SessionStorage); |
| 160 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(Ses
sionStorage)); |
| 161 }, |
| 162 |
| 163 function redoLocalStorageLastAddition(next) |
| 164 { |
| 165 show(LocalStorage); |
| 166 InspectorTest.runAfterPendingDispatches(redo.bind(LocalStorage, 2, n
ext)); |
| 167 }, |
| 168 |
| 169 function undoSessionStorageLastAddition(next) |
| 170 { |
| 171 show(SessionStorage); |
| 172 InspectorTest.runAfterPendingDispatches(undo.bind(SessionStorage, 2,
next)); |
| 173 }, |
| 174 |
| 175 function modifyLocalStorageValues(next) |
| 176 { |
| 177 function domStorageViewShown() |
| 178 { |
| 179 modifyValueForKey(this, "a1", "x1"); |
| 180 modifyValueForKey(this, "a2", "x2"); |
| 181 InspectorTest.runAfterPendingDispatches(dumpDataGrid.bind(this,
next)); |
| 182 } |
| 183 show(LocalStorage); |
| 184 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(Loc
alStorage)); |
| 185 }, |
| 186 |
| 187 function undoLocalStorageModifications(next) |
| 188 { |
| 189 show(LocalStorage); |
| 190 InspectorTest.runAfterPendingDispatches(undo.bind(LocalStorage, 2, n
ext)); |
| 191 }, |
| 192 |
| 193 function redoLocalStorageModifications(next) |
| 194 { |
| 195 show(LocalStorage); |
| 196 InspectorTest.runAfterPendingDispatches(redo.bind(LocalStorage, 2, n
ext)); |
| 197 }, |
| 198 |
| 199 function modifySessionStorageEntriesKey(next) |
| 200 { |
| 201 function domStorageViewShown() |
| 202 { |
| 203 changeKey(this, "p1", "m1"); |
| 204 changeKey(this, "p2", "m2"); |
| 205 changeKey(this, "p3", "m3"); |
| 206 InspectorTest.runAfterPendingDispatches(dumpDataGrid.bind(this,
next)); |
| 207 } |
| 208 show(SessionStorage); |
| 209 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(Ses
sionStorage)); |
| 210 }, |
| 211 |
| 212 function undoLocalStorageModifications(next) |
| 213 { |
| 214 show(LocalStorage); |
| 215 InspectorTest.runAfterPendingDispatches(undo.bind(LocalStorage, 2, n
ext)); |
| 216 }, |
| 217 |
| 218 function undoSessionStorageKeyModifications(next) |
| 219 { |
| 220 show(SessionStorage); |
| 221 InspectorTest.runAfterPendingDispatches(undo.bind(SessionStorage, 3,
next)); |
| 222 }, |
| 223 ]); |
| 224 } |
| 225 </script> |
| 226 </head> |
| 227 <body onload="runTest()"> |
| 228 <p>This test demonstrates the undo/redo operations performed on the storage view
s</p> |
| 229 </body> |
| 230 </html> |
OLD | NEW |