Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Unified Diff: LayoutTests/inspector/storage-panel-dom-storage-undo-redo.html

Issue 21163003: DevTools: Implement undo, redo operations for the DOMStorage views. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..d4202ad8788b2a0ac6e2c283e1c9438ceedee443
--- /dev/null
+++ b/LayoutTests/inspector/storage-panel-dom-storage-undo-redo.html
@@ -0,0 +1,272 @@
+<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);
+ }
+ entries.sort();
+ return "[" + entries.join() + "]";
+}
+
+function test()
+{
+ WebInspector.showPanel("resources");
+
+ var theLocalStorage;
+ var theSessionStorage;
+ var storages = WebInspector.domStorageModel.storages();
+ for (var i = 0; i < storages.length; ++i) {
+ var storage = storages[i];
+ if (storage.isLocalStorage)
+ theLocalStorage = storage;
+ else
+ theSessionStorage = storage;
+ }
+
+ function dumpDOMStorage(next)
+ {
+ if (this.isLocalStorage)
+ InspectorTest.evaluateInPage("getDOMStorageEntries(true)", storageEntriesReceived.bind(this));
+ else
+ InspectorTest.evaluateInPage("getDOMStorageEntries(false)", storageEntriesReceived.bind(this));
+
+ function storageEntriesReceived(entries)
+ {
+ InspectorTest.addResult((this.isLocalStorage ? "LocalStorage" : "SessionStorage") + " contents:" + entries.description);
+ next();
+ }
+ }
+
+ 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));
apavlov 2013/08/02 08:16:59 I know we generally avoid relying on InspectorTest
+ }
+
+ 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];
apavlov 2013/08/02 08:16:59 dataGrid.rootNode().children.peekLast() (defined i
+
+ 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)
+ {
+ InspectorTest.evaluateInPage("initializeDOMStorage()", initialized);
+
+ function initialized(result)
+ {
+ InspectorTest.addResult("Initialized localStorage and sessionStorage by clearing entries");
+ next();
+ }
+ },
+
+ function undoLocalStorageWithEmptyStack(next)
+ {
+ show(theLocalStorage);
+ InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 10, next));
+ },
+
+ function redoLocalStorageWithEmptyStack(next)
+ {
+ show(theLocalStorage);
+ InspectorTest.runAfterPendingDispatches(redo.bind(theLocalStorage, 10, next));
+ },
+
+ function addLocalStorageEntries(next)
+ {
+ show(theLocalStorage);
+ InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(theLocalStorage));
+
+ function domStorageViewShown()
+ {
+ addKeyValuePair(this, "a1", "b1");
+ addKeyValuePair(this, "a2", "b2");
+ InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next));
+ }
+ },
+
+ function undoLocalStorageLastAddition(next)
+ {
+ show(theLocalStorage);
+ InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 2, next));
+ },
+
+ function undoSessionStorageWithEmptyStack(next)
+ {
+ show(theSessionStorage);
+ InspectorTest.runAfterPendingDispatches(undo.bind(theSessionStorage, 10, next));
+ },
+
+ function redoSessionStorageWithEmptyStack(next)
+ {
+ show(theSessionStorage);
+ InspectorTest.runAfterPendingDispatches(redo.bind(theSessionStorage, 10, next));
+ },
+
+ function undoLocalStorageBeyondBounds(next)
+ {
+ show(theLocalStorage);
+ InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 10, next));
+ },
+
+ function addSessionStorageEntries(next)
+ {
+ show(theSessionStorage);
+ InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(theSessionStorage));
+
+ function domStorageViewShown()
+ {
+ addKeyValuePair(this, "p1", "q1");
+ addKeyValuePair(this, "p2", "q2");
+ addKeyValuePair(this, "p3", "q3");
+ addKeyValuePair(this, "p4", "q4");
+ InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next));
+ }
+ },
+
+ function redoLocalStorageBeyondBounds(next)
+ {
+ show(theLocalStorage);
+ InspectorTest.runAfterPendingDispatches(redo.bind(theLocalStorage, 10, next));
+ },
+
+ function undoSessionStorageLastAddition(next)
+ {
+ show(theSessionStorage);
+ InspectorTest.runAfterPendingDispatches(undo.bind(theSessionStorage, 2, next));
+ },
+
+ function modifyLocalStorageValues(next)
+ {
+ show(theLocalStorage);
+ InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(theLocalStorage));
+
+ function domStorageViewShown()
+ {
+ modifyValueForKey(this, "a1", "x1");
+ modifyValueForKey(this, "a2", "x2");
+ InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next));
+ }
+ },
+
+ function undoLocalStorageModifications(next)
+ {
+ show(theLocalStorage);
+ InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 2, next));
+ },
+
+ function redoSessionStorageLastAddition(next)
+ {
+ show(theSessionStorage);
+ InspectorTest.runAfterPendingDispatches(redo.bind(theSessionStorage, 2, next));
+ },
+
+ function redoLocalStorageModifications(next)
+ {
+ show(theLocalStorage);
+ InspectorTest.runAfterPendingDispatches(redo.bind(theLocalStorage, 2, next));
+ },
+
+ function modifySessionStorageEntriesKey(next)
+ {
+ show(theSessionStorage);
+ InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(theSessionStorage));
+
+ function domStorageViewShown()
+ {
+ changeKey(this, "p1", "m1");
+ changeKey(this, "p2", "m2");
+ changeKey(this, "p3", "m3");
+ changeKey(this, "p4", "m4");
+ InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next));
+ }
+ },
+
+ function undoLocalStorageModifications(next)
+ {
+ show(theLocalStorage);
+ InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 2, next));
+ }
+ ]);
+}
+</script>
+</head>
+<body onload="runTest()">
+<p>This test checks the undo/redo operations are performed correctly on the DOM storage views</p>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698