Chromium Code Reviews| 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 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)) ; | |
|
apavlov
2013/08/02 08:16:59
I know we generally avoid relying on InspectorTest
| |
| 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[dataGrid.rootNode().chil dren.length - 1]; | |
|
apavlov
2013/08/02 08:16:59
dataGrid.rootNode().children.peekLast() (defined i
| |
| 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("initializeDOMStorage()", 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 addLocalStorageEntries(next) | |
| 151 { | |
| 152 show(theLocalStorage); | |
| 153 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(the LocalStorage)); | |
| 154 | |
| 155 function domStorageViewShown() | |
| 156 { | |
| 157 addKeyValuePair(this, "a1", "b1"); | |
| 158 addKeyValuePair(this, "a2", "b2"); | |
| 159 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this , next)); | |
| 160 } | |
| 161 }, | |
| 162 | |
| 163 function undoLocalStorageLastAddition(next) | |
| 164 { | |
| 165 show(theLocalStorage); | |
| 166 InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 2 , next)); | |
| 167 }, | |
| 168 | |
| 169 function undoSessionStorageWithEmptyStack(next) | |
| 170 { | |
| 171 show(theSessionStorage); | |
| 172 InspectorTest.runAfterPendingDispatches(undo.bind(theSessionStorage, 10, next)); | |
| 173 }, | |
| 174 | |
| 175 function redoSessionStorageWithEmptyStack(next) | |
| 176 { | |
| 177 show(theSessionStorage); | |
| 178 InspectorTest.runAfterPendingDispatches(redo.bind(theSessionStorage, 10, next)); | |
| 179 }, | |
| 180 | |
| 181 function undoLocalStorageBeyondBounds(next) | |
| 182 { | |
| 183 show(theLocalStorage); | |
| 184 InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 1 0, next)); | |
| 185 }, | |
| 186 | |
| 187 function addSessionStorageEntries(next) | |
| 188 { | |
| 189 show(theSessionStorage); | |
| 190 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(the SessionStorage)); | |
| 191 | |
| 192 function domStorageViewShown() | |
| 193 { | |
| 194 addKeyValuePair(this, "p1", "q1"); | |
| 195 addKeyValuePair(this, "p2", "q2"); | |
| 196 addKeyValuePair(this, "p3", "q3"); | |
| 197 addKeyValuePair(this, "p4", "q4"); | |
| 198 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this , next)); | |
| 199 } | |
| 200 }, | |
| 201 | |
| 202 function redoLocalStorageBeyondBounds(next) | |
| 203 { | |
| 204 show(theLocalStorage); | |
| 205 InspectorTest.runAfterPendingDispatches(redo.bind(theLocalStorage, 1 0, next)); | |
| 206 }, | |
| 207 | |
| 208 function undoSessionStorageLastAddition(next) | |
| 209 { | |
| 210 show(theSessionStorage); | |
| 211 InspectorTest.runAfterPendingDispatches(undo.bind(theSessionStorage, 2, next)); | |
| 212 }, | |
| 213 | |
| 214 function modifyLocalStorageValues(next) | |
| 215 { | |
| 216 show(theLocalStorage); | |
| 217 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(the LocalStorage)); | |
| 218 | |
| 219 function domStorageViewShown() | |
| 220 { | |
| 221 modifyValueForKey(this, "a1", "x1"); | |
| 222 modifyValueForKey(this, "a2", "x2"); | |
| 223 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this , next)); | |
| 224 } | |
| 225 }, | |
| 226 | |
| 227 function undoLocalStorageModifications(next) | |
| 228 { | |
| 229 show(theLocalStorage); | |
| 230 InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 2 , next)); | |
| 231 }, | |
| 232 | |
| 233 function redoSessionStorageLastAddition(next) | |
| 234 { | |
| 235 show(theSessionStorage); | |
| 236 InspectorTest.runAfterPendingDispatches(redo.bind(theSessionStorage, 2, next)); | |
| 237 }, | |
| 238 | |
| 239 function redoLocalStorageModifications(next) | |
| 240 { | |
| 241 show(theLocalStorage); | |
| 242 InspectorTest.runAfterPendingDispatches(redo.bind(theLocalStorage, 2 , next)); | |
| 243 }, | |
| 244 | |
| 245 function modifySessionStorageEntriesKey(next) | |
| 246 { | |
| 247 show(theSessionStorage); | |
| 248 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(the SessionStorage)); | |
| 249 | |
| 250 function domStorageViewShown() | |
| 251 { | |
| 252 changeKey(this, "p1", "m1"); | |
| 253 changeKey(this, "p2", "m2"); | |
| 254 changeKey(this, "p3", "m3"); | |
| 255 changeKey(this, "p4", "m4"); | |
| 256 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this , next)); | |
| 257 } | |
| 258 }, | |
| 259 | |
| 260 function undoLocalStorageModifications(next) | |
| 261 { | |
| 262 show(theLocalStorage); | |
| 263 InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 2 , next)); | |
| 264 } | |
| 265 ]); | |
| 266 } | |
| 267 </script> | |
| 268 </head> | |
| 269 <body onload="runTest()"> | |
| 270 <p>This test checks the undo/redo operations are performed correctly on the DOM storage views</p> | |
| 271 </body> | |
| 272 </html> | |
| OLD | NEW |