3 <script src=
"../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"../http/tests/inspector/resources-test.js"></script>
7 function addItem(key
, value
)
9 localStorage
.setItem(key
, value
);
12 function removeItem(key
)
14 localStorage
.removeItem(key
);
17 function updateItem(key
, newValue
)
19 localStorage
.setItem(key
, newValue
);
31 function dumpDataGrid(rootNode
)
33 var nodes
= rootNode
.children
;
35 for (var i
= 0; i
< nodes
.length
; ++i
) {
37 if (typeof node
._data
.key
=== "string")
38 rows
.push(node
._data
.key
+ " = " + node
._data
.value
);
41 InspectorTest
.addResult("Table rows: [" + rows
.join(", ") + "]");
44 InspectorTest
.runTestSuite([
45 function initialize(next
)
47 InspectorTest
.evaluateInPage("clear();", next
);
50 function updateLocalStorageView(next
)
52 function viewUpdated(items
)
54 InspectorTest
.addResult("Resource Panel with localStorage view updated.");
59 var storages
= InspectorTest
.domStorageModel().storages();
60 for (var i
= 0; i
< storages
.length
; ++i
) {
61 if (storages
[i
].isLocalStorage
) {
62 storage
= storages
[i
];
67 InspectorTest
.assertTrue(!!storage
, "Local storage not found.");
69 WebInspector
.panels
.resources
._showDOMStorage(storage
);
70 view
= WebInspector
.panels
.resources
._domStorageViews
.get(storage
);
71 InspectorTest
.addSniffer(view
, "_dataGridForDOMStorageItems", viewUpdated
);
74 function addItemTest(next
)
76 var indicesToAdd
= [1, 2, 3, 4, 5, 6];
80 dumpDataGrid(view
._dataGrid
.rootNode());
86 var index
= indicesToAdd
.shift();
91 InspectorTest
.addResult("");
92 InspectorTest
.addSniffer(InspectorTest
.domStorageModel(), "_domStorageItemAdded", itemAdded
);
93 var command
= "addItem('key" + index
+ "', 'value" + index
+ "');";
94 InspectorTest
.addResult(command
);
95 InspectorTest
.evaluateInPage(command
);
101 function removeItemTest(next
)
103 var indicesToRemove
= [1, 3, 5];
105 function itemRemoved()
107 dumpDataGrid(view
._dataGrid
.rootNode());
111 function removeItem()
113 var index
= indicesToRemove
.shift();
118 InspectorTest
.addResult("");
119 InspectorTest
.addSniffer(InspectorTest
.domStorageModel(), "_domStorageItemRemoved", itemRemoved
);
120 var command
= "removeItem('key" + index
+ "');";
121 InspectorTest
.addResult(command
);
122 InspectorTest
.evaluateInPage(command
);
128 function updateItemTest(next
)
130 InspectorTest
.addResult("");
131 InspectorTest
.addSniffer(InspectorTest
.domStorageModel(), "_domStorageItemUpdated", itemUpdated
);
132 var command
= "updateItem('key2', 'VALUE2');";
133 InspectorTest
.addResult(command
);
134 InspectorTest
.evaluateInPage(command
);
136 function itemUpdated()
138 dumpDataGrid(view
._dataGrid
.rootNode());
143 function clearTest(next
)
145 function itemsCleared()
147 dumpDataGrid(view
._dataGrid
.rootNode());
151 InspectorTest
.addResult("");
152 InspectorTest
.addSniffer(InspectorTest
.domStorageModel(), "_domStorageItemsCleared", itemsCleared
);
153 var command
= "clear()";
154 InspectorTest
.addResult(command
);
155 InspectorTest
.evaluateInPage(command
);
162 <body onload=
"runTest()">
163 <p>Test that storage panel is present and that it contains correct data whenever localStorage is updated.
</p>