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