3 <script src="../http/tests/inspector/inspector-test.js"></script>
6 function addItem(key, value)
8 localStorage.setItem(key, value);
11 function removeItem(key)
13 localStorage.removeItem(key);
16 function updateItem(key, newValue)
18 localStorage.setItem(key, newValue);
30 // Resources panel must be visible
31 WebInspector.inspectorView.showPanel("resources");
33 function dumpDataGrid(rootNode)
35 var nodes = rootNode.children;
37 for (var i = 0; i < nodes.length; ++i) {
39 if (typeof node._data.key === "string")
40 rows.push(node._data.key + " = " + node._data.value);
43 InspectorTest.addResult("Table rows: [" + rows.join(", ") + "]");
46 InspectorTest.runTestSuite([
47 function initialize(next)
49 InspectorTest.evaluateInPage("clear();", next);
52 function updateLocalStorageView(next)
54 function viewUpdated(items)
56 InspectorTest.addResult("Resource Panel with localStorage view updated.");
61 var storages = WebInspector.domStorageModel.storages();
62 for (var i = 0; i < storages.length; ++i) {
63 if (storages[i].isLocalStorage) {
64 storage = storages[i];
69 InspectorTest.assertTrue(!!storage, "Local storage not found.");
71 WebInspector.panels.resources._showDOMStorage(storage);
72 view = WebInspector.panels.resources._domStorageViews.get(storage);
73 InspectorTest.addSniffer(view, "_dataGridForDOMStorageItems", viewUpdated);
76 function addItemTest(next)
78 var indicesToAdd = [1, 2, 3, 4, 5, 6];
82 dumpDataGrid(view._dataGrid.rootNode());
88 var index = indicesToAdd.shift();
93 InspectorTest.addResult("");
94 InspectorTest.addSniffer(WebInspector.domStorageModel, "_domStorageItemAdded", itemAdded);
95 var command = "addItem('key" + index + "', 'value" + index + "');";
96 InspectorTest.addResult(command);
97 InspectorTest.evaluateInPage(command);
103 function removeItemTest(next)
105 var indicesToRemove = [1, 3, 5];
107 function itemRemoved()
109 dumpDataGrid(view._dataGrid.rootNode());
113 function removeItem()
115 var index = indicesToRemove.shift();
120 InspectorTest.addResult("");
121 InspectorTest.addSniffer(WebInspector.domStorageModel, "_domStorageItemRemoved", itemRemoved);
122 var command = "removeItem('key" + index + "');";
123 InspectorTest.addResult(command);
124 InspectorTest.evaluateInPage(command);
130 function updateItemTest(next)
132 InspectorTest.addResult("");
133 InspectorTest.addSniffer(WebInspector.domStorageModel, "_domStorageItemUpdated", itemUpdated);
134 var command = "updateItem('key2', 'VALUE2');";
135 InspectorTest.addResult(command);
136 InspectorTest.evaluateInPage(command);
138 function itemUpdated()
140 dumpDataGrid(view._dataGrid.rootNode());
145 function clearTest(next)
147 function itemsCleared()
149 dumpDataGrid(view._dataGrid.rootNode());
153 InspectorTest.addResult("");
154 InspectorTest.addSniffer(WebInspector.domStorageModel, "_domStorageItemsCleared", itemsCleared);
155 var command = "clear()";
156 InspectorTest.addResult(command);
157 InspectorTest.evaluateInPage(command);
164 <body onload="runTest()">
165 <p>Test that storage panel is present and that it contains correct data whenever localStorage is updated.</p>