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 |
index 1412ef660172d75d074637b9a283367d941157bd..6b5bb824778ad7aaa5777e09c3d1cd558ede5981 100644 |
--- a/LayoutTests/inspector/storage-panel-dom-storage-undo-redo.html |
+++ b/LayoutTests/inspector/storage-panel-dom-storage-undo-redo.html |
@@ -39,17 +39,17 @@ function test() |
theSessionStorage = storage; |
} |
- function dumpDOMStorage(next) |
+ function dumpDOMStorage(storage, callback) |
{ |
- if (this.isLocalStorage) |
- InspectorTest.evaluateInPage("getDOMStorageEntries(true)", storageEntriesReceived.bind(this)); |
+ if (storage.isLocalStorage) |
+ InspectorTest.evaluateInPage("getDOMStorageEntries(true)", storageEntriesReceived); |
else |
- InspectorTest.evaluateInPage("getDOMStorageEntries(false)", storageEntriesReceived.bind(this)); |
+ InspectorTest.evaluateInPage("getDOMStorageEntries(false)", storageEntriesReceived); |
function storageEntriesReceived(entries) |
{ |
- InspectorTest.addResult((this.isLocalStorage ? "LocalStorage" : "SessionStorage") + " contents:" + entries.description); |
- next(); |
+ InspectorTest.addResult((storage.isLocalStorage ? "LocalStorage" : "SessionStorage") + " contents:" + entries.description); |
+ callback(); |
} |
} |
@@ -58,73 +58,177 @@ function test() |
WebInspector.panels.resources._showDOMStorage(storage); |
} |
- function undo(operations, next) |
+ function undo(storage, operations, next) |
{ |
- for (var i = 0; i < operations; ++i) |
- this.undo(); |
- InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next)); |
+ var i = 1; |
+ show(storage); |
+ InspectorTest.runAfterPendingDispatches(undoOnce); |
+ |
+ function undoOnce() |
+ { |
+ if (i <= operations) { |
+ setTimeout(perform, 0); |
pfeldman
2013/08/27 14:27:34
Please don't use setTimeout in tests. It most like
|
+ function perform() |
+ { |
+ storage.undo(); |
+ ++i; |
+ InspectorTest.runAfterPendingDispatches(undoOnce); |
+ } |
+ } else |
+ dumpDOMStorage(storage, next); |
+ } |
} |
- function redo(operations, next) |
+ function redo(storage, operations, next) |
{ |
- for (var i = 0; i < operations; ++i) |
- this.redo(); |
- InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next)); |
+ var i = 1; |
+ show(storage); |
+ InspectorTest.runAfterPendingDispatches(redoOnce); |
+ |
+ function redoOnce() |
+ { |
+ if (i <= operations) { |
+ setTimeout(perform, 0); |
+ function perform() |
+ { |
+ storage.redo(); |
+ ++i; |
+ InspectorTest.runAfterPendingDispatches(redoOnce); |
+ } |
+ } else |
+ dumpDOMStorage(storage, next); |
+ } |
} |
- function addKeyValuePair(storage, key, value) |
+ function addKeyValuePair(storage, key, value, callback) |
{ |
var dataGrid = WebInspector.panels.resources._domStorageViews.get(storage)._dataGrid; |
var creationNode = dataGrid.rootNode().children.peekLast(); |
- var elementKey = creationNode._element.children[0]; |
- dataGrid._startEditing(elementKey); |
- elementKey.textContent = key; |
- elementKey.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
+ InspectorTest.runAfterPendingDispatches(addKey.bind(null, dataGrid, creationNode)); |
+ function addKey(dataGrid, creationNode) |
+ { |
+ var elementKey = creationNode._element.children[0]; |
+ dataGrid._startEditing(elementKey); |
+ elementKey.textContent = key; |
+ elementKey.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
+ |
+ InspectorTest.runAfterPendingDispatches(addValue.bind(null, dataGrid, creationNode)); |
- var elementValue = creationNode._element.children[1]; |
- dataGrid._startEditing(elementValue); |
- elementValue.textContent = value; |
- elementValue.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
+ function addValue(dataGrid, creationNode) |
+ { |
+ var elementValue = creationNode._element.children[1]; |
+ dataGrid._startEditing(elementValue); |
+ elementValue.textContent = value; |
+ elementValue.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
+ InspectorTest.runAfterPendingDispatches(callback); |
+ } |
+ } |
} |
- function modifyValueForKey(storage, key, newValue) |
+ function modifyValueForKey(storage, key, newValue, callback) |
{ |
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; |
+ InspectorTest.runAfterPendingDispatches(modifyValue.bind(null, dataGrid, children)); |
+ function modifyValue(dataGrid, 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")); |
+ var elementValue = modificationNode._element.children[1]; |
+ dataGrid._startEditing(elementValue); |
+ elementValue.textContent = newValue; |
+ elementValue.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
+ InspectorTest.runAfterPendingDispatches(callback); |
+ } |
} |
- function changeKey(storage, oldKey, newKey) |
+ function changeKey(storage, oldKey, newKey, callback) |
{ |
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; |
+ InspectorTest.runAfterPendingDispatches(modifyKey.bind(null, dataGrid, children)); |
+ function modifyKey(dataGrid, 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")); |
+ setTimeout(perform, 0); |
+ function perform() |
+ { |
+ InspectorTest.runAfterPendingDispatches(callback); |
+ } |
+ } |
+ } |
+ |
+ function addStorageEntries(storage, entries, autoSuffix, keyPrefix, valuePrefix, next) |
+ { |
+ var i = 1; |
+ show(storage); |
+ InspectorTest.runAfterPendingDispatches(domStorageViewShown); |
+ |
+ function domStorageViewShown() |
+ { |
+ if (i <= entries) { |
+ if (autoSuffix) |
+ addKeyValuePair(storage, keyPrefix + i, valuePrefix + i, domStorageViewShown); |
+ else |
+ addKeyValuePair(storage, keyPrefix, valuePrefix, domStorageViewShown); |
+ ++i; |
+ } else |
+ dumpDOMStorage(storage, next); |
} |
- var elementKey = modificationNode._element.children[0]; |
- dataGrid._startEditing(elementKey); |
- elementKey.textContent = newKey; |
- elementKey.dispatchEvent(InspectorTest.createKeyEvent("Enter")); |
} |
+ function setStorageEntryValue(storage, key, newValue, dumpStorage, callback) |
+ { |
+ show(storage); |
+ InspectorTest.runAfterPendingDispatches(domStorageViewShown); |
+ |
+ function domStorageViewShown() |
+ { |
+ if (dumpStorage) |
+ modifyValueForKey(storage, key, newValue, dumpDOMStorage.bind(null, storage, callback)); |
+ else |
+ modifyValueForKey(storage, key, newValue, callback); |
+ } |
+ } |
+ |
+ function setStorageEntryKey(storage, oldKey, newKey, dumpStorage, callback) |
+ { |
+ show(storage); |
+ InspectorTest.runAfterPendingDispatches(domStorageViewShown); |
+ |
+ function domStorageViewShown() |
+ { |
+ setTimeout(perform, 0); |
+ function perform() |
+ { |
+ if (dumpStorage) |
+ changeKey(storage, oldKey, newKey, dumpDOMStorage.bind(null, storage, callback)); |
+ else |
+ changeKey(storage, oldKey, newKey, callback); |
+ } |
+ } |
+ } |
+ |
+ |
InspectorTest.runTestSuite([ |
function initialize(next) |
{ |
@@ -139,34 +243,26 @@ function test() |
function undoLocalStorageWithEmptyStack(next) |
{ |
- show(theLocalStorage); |
- InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 10, next)); |
+ undo(theLocalStorage, 10, next); |
}, |
function redoLocalStorageWithEmptyStack(next) |
{ |
- show(theLocalStorage); |
- InspectorTest.runAfterPendingDispatches(redo.bind(theLocalStorage, 10, next)); |
+ redo(theLocalStorage, 10, next); |
}, |
function localStorageUndoInterlacedWithAddition(next) |
{ |
- show(theLocalStorage); |
- InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(theLocalStorage)); |
- function domStorageViewShown() |
+ addStorageEntries(theLocalStorage, 2, true, "a", "b", performFirstUndo); |
+ function performFirstUndo() |
{ |
- addKeyValuePair(this, "a1", "b1"); |
- addKeyValuePair(this, "a2", "b2"); |
- InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 2, firstUndoDone.bind(null, next))); |
- |
- function firstUndoDone(callback) |
+ undo(theLocalStorage, 2, addOneMoreEntry); |
+ function addOneMoreEntry() |
{ |
- addKeyValuePair(theLocalStorage, "a3", "b3"); |
- InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(theLocalStorage, nextUndoDone.bind(null, callback))); |
- |
- function nextUndoDone(callback) |
+ addStorageEntries(theLocalStorage, 1, false, "a3", "b3", performNextUndo); |
+ function performNextUndo() |
{ |
- InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 2, callback)); |
+ undo(theLocalStorage, 2, next); |
} |
} |
} |
@@ -174,147 +270,138 @@ function test() |
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)); |
- } |
+ addStorageEntries(theLocalStorage, 2, true, "a", "b", next); |
}, |
function undoLocalStorageLastAddition(next) |
{ |
- show(theLocalStorage); |
- InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 2, next)); |
+ undo(theLocalStorage, 2, next); |
}, |
function undoSessionStorageWithEmptyStack(next) |
{ |
- show(theSessionStorage); |
- InspectorTest.runAfterPendingDispatches(undo.bind(theSessionStorage, 10, next)); |
+ undo(theSessionStorage, 10, next); |
}, |
function redoSessionStorageWithEmptyStack(next) |
{ |
- show(theSessionStorage); |
- InspectorTest.runAfterPendingDispatches(redo.bind(theSessionStorage, 10, next)); |
+ redo(theSessionStorage, 10, next); |
}, |
function undoLocalStorageBeyondBounds(next) |
{ |
InspectorTest.addResult("The entry a1=b1 is removed and any attempt to undo beyond it shouldn't cause any failure!") |
- show(theLocalStorage); |
- InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 10, next)); |
+ undo(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)); |
- } |
+ addStorageEntries(theSessionStorage, 4, true, "p", "q", next); |
}, |
function redoLocalStorageBeyondBounds(next) |
{ |
InspectorTest.addResult("The entry a1=b1 and a2=b2 is added back and any attempt to redo beyond it shouldn't cause any failure!") |
- show(theLocalStorage); |
- InspectorTest.runAfterPendingDispatches(redo.bind(theLocalStorage, 10, next)); |
+ redo(theLocalStorage, 10, next); |
}, |
function undoSessionStorageLastAddition(next) |
{ |
- show(theSessionStorage); |
- InspectorTest.runAfterPendingDispatches(undo.bind(theSessionStorage, 2, next)); |
+ undo(theSessionStorage, 2, next); |
}, |
function modifyLocalStorageValues(next) |
{ |
- show(theLocalStorage); |
- InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(theLocalStorage)); |
- |
- function domStorageViewShown() |
+ setStorageEntryValue(theLocalStorage, "a1", "x1", false, modifyAnotherValue); |
+ function modifyAnotherValue() |
{ |
- modifyValueForKey(this, "a1", "x1"); |
- modifyValueForKey(this, "a2", "x2"); |
- InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next)); |
+ setStorageEntryValue(theLocalStorage, "a2", "x2", true, next); |
} |
}, |
function undoLocalStorageModifications(next) |
{ |
- show(theLocalStorage); |
- InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 2, next)); |
+ undo(theLocalStorage, 2, next); |
}, |
function redoSessionStorageLastAddition(next) |
{ |
- show(theSessionStorage); |
- InspectorTest.runAfterPendingDispatches(redo.bind(theSessionStorage, 2, next)); |
+ redo(theSessionStorage, 2, next); |
}, |
function redoLocalStorageModifications(next) |
{ |
show(theLocalStorage); |
- InspectorTest.runAfterPendingDispatches(redo.bind(theLocalStorage, 2, next)); |
+ redo(theLocalStorage, 2, next); |
}, |
function modifySessionStorageEntriesKey(next) |
{ |
- show(theSessionStorage); |
- InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(theSessionStorage)); |
- |
- function domStorageViewShown() |
+ setStorageEntryKey(theSessionStorage, "p1", "m1", false, firstDone); |
+ function firstDone() |
{ |
- changeKey(this, "p1", "m1"); |
- changeKey(this, "p2", "m2"); |
- changeKey(this, "p3", "m3"); |
- changeKey(this, "p4", "m4"); |
- InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, next)); |
+ setStorageEntryKey(theSessionStorage, "p2", "m2", false, secondDone); |
+ function secondDone() |
+ { |
+ setStorageEntryKey(theSessionStorage, "p3", "m3", false, thirdDone); |
+ function thirdDone() |
+ { |
+ setStorageEntryKey(theSessionStorage, "p4", "m4", true, next); |
+ } |
+ } |
} |
}, |
function undoLocalStorageModifications(next) |
{ |
- show(theLocalStorage); |
- InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, 2, next)); |
+ undo(theLocalStorage, 2, next); |
}, |
function undoSessionStorageKeyModifications(next) |
{ |
- show(theSessionStorage); |
- InspectorTest.runAfterPendingDispatches(undo.bind(theSessionStorage, 8, next)); |
+ undo(theSessionStorage, 8, next); |
}, |
function validateMaxUndoRedoStackDepth(next) |
{ |
- show(theLocalStorage); |
- InspectorTest.runAfterPendingDispatches(domStorageViewShown.bind(theLocalStorage)); |
+ var stackDepth = WebInspector.DOMStorageHistory.MAX_UNDO_STACK_DEPTH; |
+ InspectorTest.addResult("Undo/redo stack depth limit is " + stackDepth); |
+ InspectorTest.addResult("Performing " + (2 * stackDepth) + " actions"); |
+ addStorageEntries(theLocalStorage, stackDepth, true, "x", "y", undoMoreThanDepth); |
- function domStorageViewShown() |
+ function undoMoreThanDepth() |
{ |
- var stackDepth = WebInspector.DOMStorageHistory.MAX_UNDO_STACK_DEPTH; |
- InspectorTest.addResult("Undo/redo stack depth limit is " + stackDepth); |
- InspectorTest.addResult("Performing " + (2 * stackDepth) + " actions"); |
- for (var i = 1; i <= stackDepth; ++i) |
- addKeyValuePair(this, "x" + i, "y" + i); |
- |
- InspectorTest.runAfterPendingDispatches(dumpDOMStorage.bind(this, undoMoreThanDepth)); |
+ InspectorTest.addResult("Performing undo operation three times the depth i.e. " + (3 * stackDepth) + " times but only last " + stackDepth + " operations are undone"); |
+ undo(theLocalStorage, (3 * stackDepth), next); |
+ } |
+ }, |
- function undoMoreThanDepth() |
+ function resetDOMStorageHistoryUponPageModification(next) |
+ { |
+ InspectorTest.addResult("Adding u1=v1 and u2=v2 in the localStorage"); |
+ addStorageEntries(theLocalStorage, 2, true, "u", "v", tryUndoOnce); |
+ function tryUndoOnce() |
+ { |
+ InspectorTest.addResult(""); |
+ InspectorTest.addResult("Performing undo for removing u2=v2") |
+ undo(theLocalStorage, 2, pageModifiesTheStorage); |
+ function pageModifiesTheStorage() |
{ |
- InspectorTest.addResult("Performing undo operation three times the depth i.e. " + (3 * stackDepth) + " times but only last " + stackDepth + " operations are undone"); |
- InspectorTest.runAfterPendingDispatches(undo.bind(theLocalStorage, (3 * stackDepth), next)); |
+ InspectorTest.addResult(""); |
+ InspectorTest.addResult("Page has modified the storage by adding u3=v3"); |
+ InspectorTest.evaluateInPage("localStorage['u3'] = 'v3'", modificationDone); |
+ function modificationDone() |
+ { |
+ InspectorTest.addResult(""); |
+ InspectorTest.addResult("Undo wont work anymore as page modification has cleared the history.") |
+ undo(theLocalStorage, 10, tryRedo); |
+ function tryRedo() |
+ { |
+ InspectorTest.addResult(""); |
+ InspectorTest.addResult("Redo wont work anymore as page modification has cleared the history.") |
+ redo(theLocalStorage, 10, next); |
+ } |
+ } |
} |
} |
}, |