blob: 19aa722ccc89ba705ef578da46d977274412bebb [file] [log] [blame]
<html>
<head>
<script src="../http/tests/inspector/inspector-test.js"></script>
<script>
function addItem(key,value)
{
localStorage.setItem(key,value);
}
function removeItem(key)
{
localStorage.removeItem(key);
}
function clear()
{
localStorage.clear();
}
function test()
{
var storage = null;
var rootNode = null;
var count = 1;
// Resources panel must be visible
WebInspector.showPanel("resources");
function dumpDataGrid()
{
var nodes = rootNode.children;
var rows = [];
for (var i = 0; i < nodes.length; ++i) {
var node = nodes[i];
if (node._data.key.length)
rows.push(node._data.key + node._data.value);
}
rows.sort();
InspectorTest.addResult("KeyValue pairs: [" + rows.join() + "]");
}
InspectorTest.runTestSuite([
function initialize(next)
{
function initialized(result)
{
InspectorTest.addResult("Initialized localStorage by clearing entries");
next();
}
InspectorTest.evaluateInPage("clear()", initialized );
},
function updateLocalStorageView(next)
{
function localStorageViewUpdated()
{
rootNode = WebInspector.panels.resources._domStorageViews.get(storage)._dataGrid.rootNode();
InspectorTest.addResult("Resource Panel with localStorage view updated");
next();
}
var storages = WebInspector.domStorageModel.storages();
for (var i = 0; i < storages.length; ++i) {
storage = storages[i];
if (storage.isLocalStorage) {
WebInspector.panels.resources._showDOMStorage(storage);
InspectorTest.runAfterPendingDispatches(localStorageViewUpdated);
break;
}
}
},
function addItemTest(next)
{
function viewUpdatedAfterAddition()
{
InspectorTest.runAfterPendingDispatches(function()
{
rootNode = WebInspector.panels.resources._domStorageViews.get(storage)._dataGrid.rootNode();
dumpDataGrid();
if (count < 6)
addItemTest(next);
else
next();
});
}
function itemAdded(result)
{
viewUpdatedAfterAddition();
}
InspectorTest.addResult("addItem('a"+count+"','=value"+count+"')");
InspectorTest.evaluateInPage("addItem('a"+count+"','=value"+count+"')", itemAdded );
count++;
},
function removeItemTest(next)
{
function viewUpdatedAfterRemoval()
{
InspectorTest.runAfterPendingDispatches(function() {
rootNode = WebInspector.panels.resources._domStorageViews.get(storage)._dataGrid.rootNode();
dumpDataGrid();
if (count > 4)
removeItemTest(next);
else
next();
});
}
function itemRemoved(result)
{
setTimeout(viewUpdatedAfterRemoval, 0 );
}
--count;
InspectorTest.addResult("removeItem('a"+count+"')");
InspectorTest.evaluateInPage("removeItem('a"+count+"')", itemRemoved );
},
function clearTest(next)
{
function viewUpdatedAfterClear()
{
InspectorTest.runAfterPendingDispatches(function() {
rootNode = WebInspector.panels.resources._domStorageViews.get(storage)._dataGrid.rootNode();
dumpDataGrid();
next();
});
}
function cleared(result)
{
setTimeout(viewUpdatedAfterClear, 0 );
}
InspectorTest.addResult("clear()");
InspectorTest.evaluateInPage("clear()", cleared );
}
]);
}
</script>
</head>
<body onload="runTest()">
<p>Test that storage panel is present and that it contains correct data whenever localStorage is updated.</p>
</body>
</html>