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); | |
|
apavlov
2013/08/01 09:19:16
Are you sure you used this code to generate the ex
| |
| 20 } | |
| 21 entries.sort(); | |
| 22 return "[" + entries.join() + "]"; | |
|
apavlov
2013/08/01 09:19:16
This will just glue them together without "," in b
| |
| 23 } | |
| 24 | |
| 25 function test() | |
| 26 { | |
| 27 // Resources panel must be visible | |
|
apavlov
2013/08/01 09:19:16
Comments are not required in tests (these are typi
| |
| 28 WebInspector.showPanel("resources"); | |
| 29 | |
| 30 var LocalStorage; | |
|
apavlov
2013/08/01 09:19:16
in order to follow the naming guidelines, these ca
| |
| 31 var SessionStorage; | |
| 32 var storages = WebInspector.domStorageModel.storages(); | |
| 33 for (var i = 0; i < storages.length; ++i) { | |
| 34 var storage = storages[i]; | |
| 35 if (storage.isLocalStorage) | |
| 36 LocalStorage = storage; | |
| 37 else | |
| 38 SessionStorage = storage; | |
| 39 } | |
| 40 | |
| 41 function dumpDOMStorage(next) | |
| 42 { | |
| 43 function storageEntriesReceived(entries) | |
|
apavlov
2013/08/01 09:19:16
We have moved to the practice of putting callbacks
| |
| 44 { | |
| 45 InspectorTest.addResult((this.isLocalStorage ? "LocalStorage" : "Ses sionStorage") + " contents:" + entries.description); | |
| 46 next(); | |
| 47 } | |
| 48 if (this.isLocalStorage) | |
| 49 InspectorTest.evaluateInPage("getDOMStorageEntries(true)", storageEn triesReceived.bind(this)); | |
| 50 else | |
| 51 InspectorTest.evaluateInPage("getDOMStorageEntries(false)", storageE ntriesReceived.bind(this)); | |
| 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[dataGrid.rootNode().chil dren.length - 1]; | |
| 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 function initialized(result) | |
| 130 { | |
| 131 InspectorTest.addResult("Initialized localStorage and sessionSto rage by clearing entries"); | |
| 132 next(); | |
| 133 } | |
| 134 InspectorTest.evaluateInPage("initializeDOMStorage()", initialized ) ; | |
| 135 }, | |
| 136 | |
| 137 function addLocalStorageEntries(next) | |
| 138 { | |
| 139 function domStorageViewShown() | |
| 140 { | |
| 141 addKeyValuePair(this, "a1", "b1"); | |
| 142 addKeyValuePair(this, "a2", "b2"); | |
| 143 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this , next)); | |
| 144 } | |
| 145 show(LocalStorage); | |
| 146 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(Loc alStorage)); | |
| 147 }, | |
| 148 | |
| 149 function undoLocalStorageLastAddition(next) | |
| 150 { | |
| 151 show(LocalStorage); | |
| 152 InspectorTest.runAfterPendingDispatches(undo.bind(LocalStorage, 2, n ext)); | |
| 153 }, | |
| 154 | |
| 155 function addSessionStorageEntries(next) | |
| 156 { | |
| 157 function domStorageViewShown() | |
| 158 { | |
| 159 addKeyValuePair(this, "p1", "q1"); | |
| 160 addKeyValuePair(this, "p2", "q2"); | |
| 161 addKeyValuePair(this, "p3", "q3"); | |
| 162 addKeyValuePair(this, "p4", "q4"); | |
| 163 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this , next)); | |
| 164 } | |
| 165 show(SessionStorage); | |
| 166 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(Ses sionStorage)); | |
| 167 }, | |
| 168 | |
| 169 function redoLocalStorageLastAddition(next) | |
| 170 { | |
| 171 show(LocalStorage); | |
| 172 InspectorTest.runAfterPendingDispatches(redo.bind(LocalStorage, 2, n ext)); | |
| 173 }, | |
| 174 | |
| 175 function undoSessionStorageLastAddition(next) | |
| 176 { | |
| 177 show(SessionStorage); | |
| 178 InspectorTest.runAfterPendingDispatches(undo.bind(SessionStorage, 2, next)); | |
| 179 }, | |
| 180 | |
| 181 function modifyLocalStorageValues(next) | |
| 182 { | |
| 183 function domStorageViewShown() | |
| 184 { | |
| 185 modifyValueForKey(this, "a1", "x1"); | |
| 186 modifyValueForKey(this, "a2", "x2"); | |
| 187 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this , next)); | |
| 188 } | |
| 189 show(LocalStorage); | |
| 190 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(Loc alStorage)); | |
| 191 }, | |
| 192 | |
| 193 function undoLocalStorageModifications(next) | |
| 194 { | |
| 195 show(LocalStorage); | |
| 196 InspectorTest.runAfterPendingDispatches(undo.bind(LocalStorage, 2, n ext)); | |
| 197 }, | |
| 198 | |
| 199 function redoLocalStorageModifications(next) | |
| 200 { | |
| 201 show(LocalStorage); | |
| 202 InspectorTest.runAfterPendingDispatches(redo.bind(LocalStorage, 2, n ext)); | |
| 203 }, | |
| 204 | |
| 205 function modifySessionStorageEntriesKey(next) | |
| 206 { | |
| 207 function domStorageViewShown() | |
| 208 { | |
| 209 changeKey(this, "p1", "m1"); | |
| 210 changeKey(this, "p2", "m2"); | |
| 211 changeKey(this, "p3", "m3"); | |
| 212 InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this , next)); | |
| 213 } | |
| 214 show(SessionStorage); | |
| 215 InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(Ses sionStorage)); | |
| 216 }, | |
| 217 | |
| 218 function undoLocalStorageModifications(next) | |
| 219 { | |
| 220 show(LocalStorage); | |
| 221 InspectorTest.runAfterPendingDispatches(undo.bind(LocalStorage, 2, n ext)); | |
| 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> | |
|
apavlov
2013/08/01 09:19:16
tests do not demonstrate, they check that somethin
| |
| 229 </body> | |
| 230 </html> | |
| OLD | NEW |