forked from WebKit/WebKit-http
/
storage-panel-dom-storage-update.html
150 lines (130 loc) · 4.31 KB
/
storage-panel-dom-storage-update.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<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[0].length)
rows.push(node._data[0] + node._data[1]);
}
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 = storage._domStorageView._dataGrid.rootNode();
InspectorTest.addResult("Resource Panel with localStorage view updated");
next();
}
var storages = WebInspector.panels.resources._domStorage;
for (var i = 0; i < storages.length; ++i) {
storage = storages[i];
if (storage.isLocalStorage) {
WebInspector.inspectorView.currentPanel().showDOMStorage(storage);
InspectorTest.runAfterPendingDispatches(localStorageViewUpdated);
break;
}
}
},
function addItemTest(next)
{
function viewUpdatedAfterAddition()
{
InspectorTest.runAfterPendingDispatches(function() {
rootNode = storage._domStorageView._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 = storage._domStorageView._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 = storage._domStorageView._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>