Chromium Code Reviews| Index: LayoutTests/inspector/storage-panel-dom-storage-undo-redo.html |
| diff --git a/LayoutTests/inspector/storage-panel-dom-storage-undo-redo.html b/LayoutTests/inspector/storage-panel-dom-storage-undo-redo.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e14ed3e93ec6541d2735f12ddf30bc00dbd51f6d |
| --- /dev/null |
| +++ b/LayoutTests/inspector/storage-panel-dom-storage-undo-redo.html |
| @@ -0,0 +1,230 @@ |
| +<html> |
| +<head> |
| +<script src="../http/tests/inspector/inspector-test.js"></script> |
| +<script> |
| + |
| +function initializeDOMStorage() |
| +{ |
| + localStorage.clear(); |
| + sessionStorage.clear(); |
| +} |
| + |
| +function getDOMStorageEntries(isLocalStorage) |
| +{ |
| + var storage = isLocalStorage ? localStorage : sessionStorage; |
| + var entries = []; |
| + for (var i = 0; i < storage.length; ++i) { |
| + var key = storage.key(i); |
| + var value = storage.getItem(key); |
| + entries.push(key + value); |
|
apavlov
2013/08/01 09:19:16
Are you sure you used this code to generate the ex
|
| + } |
| + entries.sort(); |
| + return "[" + entries.join() + "]"; |
|
apavlov
2013/08/01 09:19:16
This will just glue them together without "," in b
|
| +} |
| + |
| +function test() |
| +{ |
| + // Resources panel must be visible |
|
apavlov
2013/08/01 09:19:16
Comments are not required in tests (these are typi
|
| + WebInspector.showPanel("resources"); |
| + |
| + var LocalStorage; |
|
apavlov
2013/08/01 09:19:16
in order to follow the naming guidelines, these ca
|
| + var SessionStorage; |
| + var storages = WebInspector.domStorageModel.storages(); |
| + for (var i = 0; i < storages.length; ++i) { |
| + var storage = storages[i]; |
| + if (storage.isLocalStorage) |
| + LocalStorage = storage; |
| + else |
| + SessionStorage = storage; |
| + } |
| + |
| + function dumpDOMStorage(next) |
| + { |
| + function storageEntriesReceived(entries) |
|
apavlov
2013/08/01 09:19:16
We have moved to the practice of putting callbacks
|
| + { |
| + InspectorTest.addResult((this.isLocalStorage ? "LocalStorage" : "SessionStorage") + " contents:" + entries.description); |
| + next(); |
| + } |
| + if (this.isLocalStorage) |
| + InspectorTest.evaluateInPage("getDOMStorageEntries(true)", storageEntriesReceived.bind(this)); |
| + else |
| + InspectorTest.evaluateInPage("getDOMStorageEntries(false)", storageEntriesReceived.bind(this)); |
| + } |
| + |
| + function show(storage) |
| + { |
| + WebInspector.panels.resources._showDOMStorage(storage); |
| + } |
| + |
| + function undo(operations, next) |
| + { |
| + for (var i = 0; i < operations; ++i) |
| + this.undo(); |
| + InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next)); |
| + } |
| + |
| + function redo(operations, next) |
| + { |
| + for (var i = 0; i < operations; ++i) |
| + this.redo(); |
| + InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next)); |
| + } |
| + |
| + function addKeyValuePair(storage, key, value) |
| + { |
| + var dataGrid = WebInspector.panels.resources._domStorageViews.get(storage)._dataGrid; |
| + var creationNode = dataGrid.rootNode().children[dataGrid.rootNode().children.length - 1]; |
| + |
| + var elementKey = creationNode._element.children[0]; |
| + dataGrid._startEditing(elementKey); |
| + elementKey.textContent = key; |
| + elementKey.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
| + |
| + var elementValue = creationNode._element.children[1]; |
| + dataGrid._startEditing(elementValue); |
| + elementValue.textContent = "=" + value; |
| + elementValue.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
| + } |
| + |
| + function modifyValueForKey(storage, key, newValue) |
| + { |
| + var dataGrid = WebInspector.panels.resources._domStorageViews.get(storage)._dataGrid; |
| + var children = dataGrid.rootNode().children; |
| + |
| + var modificationNode; |
| + for (var i = 0; i < children.length; ++i) { |
| + if (children[i]._element.children[0].textContent === key) { |
| + modificationNode = children[i]; |
| + break; |
| + } |
| + } |
| + |
| + var elementValue = modificationNode._element.children[1]; |
| + dataGrid._startEditing(elementValue); |
| + elementValue.textContent = "=" + newValue; |
| + elementValue.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
| + } |
| + |
| + function changeKey(storage, oldKey, newKey) |
| + { |
| + var dataGrid = WebInspector.panels.resources._domStorageViews.get(storage)._dataGrid; |
| + var children = dataGrid.rootNode().children; |
| + |
| + var modificationNode; |
| + for (var i = 0; i < children.length; ++i) { |
| + if (children[i]._element.children[0].textContent === oldKey) { |
| + modificationNode = children[i]; |
| + break; |
| + } |
| + } |
| + var elementKey = modificationNode._element.children[0]; |
| + dataGrid._startEditing(elementKey); |
| + elementKey.textContent = newKey; |
| + elementKey.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
| + } |
| + |
| + InspectorTest.runTestSuite([ |
| + function initialize(next) |
| + { |
| + function initialized(result) |
| + { |
| + InspectorTest.addResult("Initialized localStorage and sessionStorage by clearing entries"); |
| + next(); |
| + } |
| + InspectorTest.evaluateInPage("initializeDOMStorage()", initialized ); |
| + }, |
| + |
| + function addLocalStorageEntries(next) |
| + { |
| + function domStorageViewShown() |
| + { |
| + addKeyValuePair(this, "a1", "b1"); |
| + addKeyValuePair(this, "a2", "b2"); |
| + InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next)); |
| + } |
| + show(LocalStorage); |
| + InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(LocalStorage)); |
| + }, |
| + |
| + function undoLocalStorageLastAddition(next) |
| + { |
| + show(LocalStorage); |
| + InspectorTest.runAfterPendingDispatches(undo.bind(LocalStorage, 2, next)); |
| + }, |
| + |
| + function addSessionStorageEntries(next) |
| + { |
| + function domStorageViewShown() |
| + { |
| + addKeyValuePair(this, "p1", "q1"); |
| + addKeyValuePair(this, "p2", "q2"); |
| + addKeyValuePair(this, "p3", "q3"); |
| + addKeyValuePair(this, "p4", "q4"); |
| + InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next)); |
| + } |
| + show(SessionStorage); |
| + InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(SessionStorage)); |
| + }, |
| + |
| + function redoLocalStorageLastAddition(next) |
| + { |
| + show(LocalStorage); |
| + InspectorTest.runAfterPendingDispatches(redo.bind(LocalStorage, 2, next)); |
| + }, |
| + |
| + function undoSessionStorageLastAddition(next) |
| + { |
| + show(SessionStorage); |
| + InspectorTest.runAfterPendingDispatches(undo.bind(SessionStorage, 2, next)); |
| + }, |
| + |
| + function modifyLocalStorageValues(next) |
| + { |
| + function domStorageViewShown() |
| + { |
| + modifyValueForKey(this, "a1", "x1"); |
| + modifyValueForKey(this, "a2", "x2"); |
| + InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next)); |
| + } |
| + show(LocalStorage); |
| + InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(LocalStorage)); |
| + }, |
| + |
| + function undoLocalStorageModifications(next) |
| + { |
| + show(LocalStorage); |
| + InspectorTest.runAfterPendingDispatches(undo.bind(LocalStorage, 2, next)); |
| + }, |
| + |
| + function redoLocalStorageModifications(next) |
| + { |
| + show(LocalStorage); |
| + InspectorTest.runAfterPendingDispatches(redo.bind(LocalStorage, 2, next)); |
| + }, |
| + |
| + function modifySessionStorageEntriesKey(next) |
| + { |
| + function domStorageViewShown() |
| + { |
| + changeKey(this, "p1", "m1"); |
| + changeKey(this, "p2", "m2"); |
| + changeKey(this, "p3", "m3"); |
| + InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next)); |
| + } |
| + show(SessionStorage); |
| + InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(SessionStorage)); |
| + }, |
| + |
| + function undoLocalStorageModifications(next) |
| + { |
| + show(LocalStorage); |
| + InspectorTest.runAfterPendingDispatches(undo.bind(LocalStorage, 2, next)); |
| + } |
| + ]); |
| +} |
| +</script> |
| +</head> |
| +<body onload="runTest()"> |
| +<p>This test demonstrates the undo/redo operations performed on the storage views</p> |
|
apavlov
2013/08/01 09:19:16
tests do not demonstrate, they check that somethin
|
| +</body> |
| +</html> |