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.length) |
| 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 this.undo(); |
| 53 InspectorTest.runAfterPendingDispatches(dumpDataGrid.bind(this, next)); |
| 54 } |
| 55 |
| 56 function redo(operations, next) |
| 57 { |
| 58 for (var i = 0; i < operations; ++i) |
| 59 this.redo(); |
| 60 InspectorTest.runAfterPendingDispatches(dumpDataGrid.bind(this, next)); |
| 61 } |
| 62 |
| 63 function addKeyValuePair(storage, key, value) |
| 64 { |
| 65 var dataGrid = WebInspector.panels.resources._domStorageViews.get(storag
e)._dataGrid; |
| 66 var creationNode = dataGrid.rootNode().children[dataGrid.rootNode().chil
dren.length - 1]; |
| 67 |
| 68 var elementKey = creationNode._element.children[0]; |
| 69 dataGrid._startEditing(elementKey); |
| 70 elementKey.textContent = key; |
| 71 elementKey.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
| 72 |
| 73 var elementValue = creationNode._element.children[1]; |
| 74 dataGrid._startEditing(elementValue); |
| 75 elementValue.textContent = "=" + value; |
| 76 elementValue.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
| 77 } |
| 78 |
| 79 function modifyValueForKey(storage, key, newValue) |
| 80 { |
| 81 var dataGrid = WebInspector.panels.resources._domStorageViews.get(storag
e)._dataGrid; |
| 82 var children = dataGrid.rootNode().children; |
| 83 |
| 84 var modificationNode; |
| 85 for (var i = 0; i < children.length; ++i) { |
| 86 if (children[i]._element.children[0].textContent === key) { |
| 87 modificationNode = children[i]; |
| 88 break; |
| 89 } |
| 90 } |
| 91 |
| 92 var elementValue = modificationNode._element.children[1]; |
| 93 dataGrid._startEditing(elementValue); |
| 94 elementValue.textContent = "=" + newValue; |
| 95 elementValue.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
| 96 } |
| 97 |
| 98 function changeKey(storage, oldKey, newKey) |
| 99 { |
| 100 var dataGrid = WebInspector.panels.resources._domStorageViews.get(storag
e)._dataGrid; |
| 101 var children = dataGrid.rootNode().children; |
| 102 |
| 103 var modificationNode; |
| 104 for (var i = 0; i < children.length; ++i) { |
| 105 if (children[i]._element.children[0].textContent === oldKey) { |
| 106 modificationNode = children[i]; |
| 107 break; |
| 108 } |
| 109 } |
| 110 var elementKey = modificationNode._element.children[0]; |
| 111 dataGrid._startEditing(elementKey); |
| 112 elementKey.textContent = newKey; |
| 113 elementKey.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
| 114 } |
| 115 |
| 116 InspectorTest.runTestSuite([ |
| 117 function initialize(next) |
| 118 { |
| 119 function initialized(result) |
| 120 { |
| 121 InspectorTest.addResult("Initialized localStorage and sessionSto
rage by clearing entries"); |
| 122 next(); |
| 123 } |
| 124 InspectorTest.evaluateInPage("initializeDOMStorage()", initialized )
; |
| 125 }, |
| 126 |
| 127 function addLocalStorageEntries(next) |
| 128 { |
| 129 function domStorageViewShown() |
| 130 { |
| 131 addKeyValuePair(this, "a1", "b1"); |
| 132 addKeyValuePair(this, "a2", "b2"); |
| 133 InspectorTest.runAfterPendingDispatches(dumpDataGrid.bind(this,
next)); |
| 134 } |
| 135 show(LocalStorage); |
| 136 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(Loc
alStorage)); |
| 137 }, |
| 138 |
| 139 function undoLocalStorageLastAddition(next) |
| 140 { |
| 141 show(LocalStorage); |
| 142 InspectorTest.runAfterPendingDispatches(undo.bind(LocalStorage, 2, n
ext)); |
| 143 }, |
| 144 |
| 145 function addSessionStorageEntries(next) |
| 146 { |
| 147 function domStorageViewShown() |
| 148 { |
| 149 addKeyValuePair(this, "p1", "q1"); |
| 150 addKeyValuePair(this, "p2", "q2"); |
| 151 addKeyValuePair(this, "p3", "q3"); |
| 152 addKeyValuePair(this, "p4", "q4"); |
| 153 InspectorTest.runAfterPendingDispatches(dumpDataGrid.bind(this,
next)); |
| 154 } |
| 155 show(SessionStorage); |
| 156 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(Ses
sionStorage)); |
| 157 }, |
| 158 |
| 159 function redoLocalStorageLastAddition(next) |
| 160 { |
| 161 show(LocalStorage); |
| 162 InspectorTest.runAfterPendingDispatches(redo.bind(LocalStorage, 2, n
ext)); |
| 163 }, |
| 164 |
| 165 function undoSessionStorageLastAddition(next) |
| 166 { |
| 167 show(SessionStorage); |
| 168 InspectorTest.runAfterPendingDispatches(undo.bind(SessionStorage, 2,
next)); |
| 169 }, |
| 170 |
| 171 function modifyLocalStorageValues(next) |
| 172 { |
| 173 function domStorageViewShown() |
| 174 { |
| 175 modifyValueForKey(this, "a1", "x1"); |
| 176 modifyValueForKey(this, "a2", "x2"); |
| 177 InspectorTest.runAfterPendingDispatches(dumpDataGrid.bind(this,
next)); |
| 178 } |
| 179 show(LocalStorage); |
| 180 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(Loc
alStorage)); |
| 181 }, |
| 182 |
| 183 function undoLocalStorageModifications(next) |
| 184 { |
| 185 show(LocalStorage); |
| 186 InspectorTest.runAfterPendingDispatches(undo.bind(LocalStorage, 2, n
ext)); |
| 187 }, |
| 188 |
| 189 function redoLocalStorageModifications(next) |
| 190 { |
| 191 show(LocalStorage); |
| 192 InspectorTest.runAfterPendingDispatches(redo.bind(LocalStorage, 2, n
ext)); |
| 193 }, |
| 194 |
| 195 function modifySessionStorageEntriesKey(next) |
| 196 { |
| 197 function domStorageViewShown() |
| 198 { |
| 199 changeKey(this, "p1", "m1"); |
| 200 changeKey(this, "p2", "m2"); |
| 201 changeKey(this, "p3", "m3"); |
| 202 InspectorTest.runAfterPendingDispatches(dumpDataGrid.bind(this,
next)); |
| 203 } |
| 204 show(SessionStorage); |
| 205 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(Ses
sionStorage)); |
| 206 }, |
| 207 |
| 208 function undoLocalStorageModifications(next) |
| 209 { |
| 210 show(LocalStorage); |
| 211 InspectorTest.runAfterPendingDispatches(undo.bind(LocalStorage, 2, n
ext)); |
| 212 }, |
| 213 |
| 214 function undoSessionStorageKeyModifications(next) |
| 215 { |
| 216 show(SessionStorage); |
| 217 InspectorTest.runAfterPendingDispatches(undo.bind(SessionStorage, 3,
next)); |
| 218 }, |
| 219 ]); |
| 220 } |
| 221 </script> |
| 222 </head> |
| 223 |
| 224 <body onload="runTest()"> |
| 225 <p>This test demonstrates the undo/redo operations performed on the storage view
s</p> |
| 226 </body> |
| 227 </html> |
OLD | NEW |