d90fb4f0ffabef23c97023c6ad09cf0c19e25bb9
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / storage-panel-dom-storage-update.html
1 <html>
2 <head>
3 <script src="../http/tests/inspector/inspector-test.js"></script>
4 <script>
5
6 function addItem(key, value)
7 {
8     localStorage.setItem(key, value);
9 }
10
11 function removeItem(key)
12 {
13     localStorage.removeItem(key);
14 }
15
16 function updateItem(key, newValue)
17 {
18     localStorage.setItem(key, newValue);
19 }
20
21 function clear()
22 {
23     localStorage.clear();
24 }
25
26 function test()
27 {
28     var view = null;
29
30     // Resources panel must be visible
31     WebInspector.inspectorView.showPanel("resources");
32
33     function dumpDataGrid(rootNode)
34     {
35         var nodes = rootNode.children;
36         var rows = [];
37         for (var i = 0; i < nodes.length; ++i) {
38             var node = nodes[i];
39             if (typeof node._data.key === "string")
40                 rows.push(node._data.key + " = " + node._data.value);
41         }
42         rows.sort();
43         InspectorTest.addResult("Table rows: [" + rows.join(", ") + "]");
44     }
45
46     InspectorTest.runTestSuite([
47         function initialize(next)
48         {
49             InspectorTest.evaluateInPage("clear();", next);
50         },
51
52         function updateLocalStorageView(next)
53         {
54             function viewUpdated(items)
55             {
56                 InspectorTest.addResult("Resource Panel with localStorage view updated.");
57                 next();
58             }
59
60             var storage = null;
61             var storages = WebInspector.domStorageModel.storages();
62             for (var i = 0; i < storages.length; ++i) {
63                 if (storages[i].isLocalStorage) {
64                     storage = storages[i];
65                     break;
66                 }
67             }
68
69             InspectorTest.assertTrue(!!storage, "Local storage not found.");
70
71             WebInspector.panels.resources._showDOMStorage(storage);
72             view = WebInspector.panels.resources._domStorageViews.get(storage);
73             InspectorTest.addSniffer(view, "_dataGridForDOMStorageItems", viewUpdated);
74         },
75
76         function addItemTest(next)
77         {
78             var indicesToAdd = [1, 2, 3, 4, 5, 6];
79
80             function itemAdded()
81             {
82                 dumpDataGrid(view._dataGrid.rootNode());
83                 addItem();
84             }
85
86             function addItem()
87             {
88                 var index = indicesToAdd.shift();
89                 if (!index) {
90                     next();
91                     return;
92                 }
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);
98             }
99
100             addItem();
101         },
102
103         function removeItemTest(next)
104         {
105             var indicesToRemove = [1, 3, 5];
106
107             function itemRemoved()
108             {
109                 dumpDataGrid(view._dataGrid.rootNode());
110                 removeItem();
111             }
112
113             function removeItem()
114             {
115                 var index = indicesToRemove.shift();
116                 if (!index) {
117                     next();
118                     return;
119                 }
120                 InspectorTest.addResult("");
121                 InspectorTest.addSniffer(WebInspector.domStorageModel, "_domStorageItemRemoved", itemRemoved);
122                 var command = "removeItem('key" + index + "');";
123                 InspectorTest.addResult(command);
124                 InspectorTest.evaluateInPage(command);
125             }
126
127             removeItem();
128         },
129
130         function updateItemTest(next)
131         {
132             InspectorTest.addResult("");
133             InspectorTest.addSniffer(WebInspector.domStorageModel, "_domStorageItemUpdated", itemUpdated);
134             var command = "updateItem('key2', 'VALUE2');";
135             InspectorTest.addResult(command);
136             InspectorTest.evaluateInPage(command);
137
138             function itemUpdated()
139             {
140                 dumpDataGrid(view._dataGrid.rootNode());
141                 next();
142             }
143         },
144
145         function clearTest(next)
146         {
147             function itemsCleared()
148             {
149                 dumpDataGrid(view._dataGrid.rootNode());
150                 next();
151             }
152
153             InspectorTest.addResult("");
154             InspectorTest.addSniffer(WebInspector.domStorageModel, "_domStorageItemsCleared", itemsCleared);
155             var command = "clear()";
156             InspectorTest.addResult(command);
157             InspectorTest.evaluateInPage(command);
158         }
159     ]);
160 }
161 </script>
162 </head>
163
164 <body onload="runTest()">
165 <p>Test that storage panel is present and that it contains correct data whenever localStorage is updated.</p>
166 </body>
167 </html>