Web Inspector: Reduce flakiness of inspector/indexeddb/requestDatabaseNames
[WebKit-https.git] / LayoutTests / inspector / indexeddb / requestDatabaseNames.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../http/tests/inspector/resources/inspector-test.js"></script>
5 <script>
6 function createDatabase(name)
7 {
8     let request = window.indexedDB.open(name, 1);
9     request.addEventListener('success', function() {
10         console.log(`Created Database '${name}'`);
11     });
12 }
13
14 function deleteDatabaseNames(names)
15 {
16     for (let name of names)
17         window.indexedDB.deleteDatabase(name);
18 }
19
20 function test()
21 {
22     var steps = [
23         {
24             action: function() {
25                 // FIXME: Remove any existing IndexedDB databases that might exist to workaround:
26                 // <https://webkit.org/b/148006> Each test should run with its own clean data store
27                 IndexedDBAgent.requestDatabaseNames(WebInspector.frameResourceManager.mainFrame.securityOrigin, function(error, names) {
28                     InspectorTest.evaluateInPage("deleteDatabaseNames(" + JSON.stringify(names) + ")");
29                     next();
30                 });
31             }
32         },
33         {
34             action: function() {
35                 IndexedDBAgent.requestDatabaseNames(WebInspector.frameResourceManager.mainFrame.securityOrigin, function(error, names) {
36                     InspectorTest.expectNoError(error);
37                     InspectorTest.expectThat(names.length === 0, "No IndexedDB databases should exist initially");
38                     InspectorTest.evaluateInPage("createDatabase('Database1')");
39                 });
40             }
41         },
42         {
43             action: function() {
44                 IndexedDBAgent.requestDatabaseNames(WebInspector.frameResourceManager.mainFrame.securityOrigin, function(error, names) {
45                     InspectorTest.expectNoError(error);
46                     InspectorTest.expectThat(names.length === 1, "A single IndexedDB database should exist");
47                     InspectorTest.log(JSON.stringify(names));
48                     InspectorTest.evaluateInPage("createDatabase('Database2')");
49                 });
50             }
51         },
52         {
53             action: function() {
54                 IndexedDBAgent.requestDatabaseNames(WebInspector.frameResourceManager.mainFrame.securityOrigin, function(error, names) {
55                     InspectorTest.expectNoError(error);
56                     InspectorTest.expectThat(names.length === 2, "Two IndexedDB databases should exist");
57                     InspectorTest.log(JSON.stringify(names));
58                     next();
59                 });
60             }
61         }
62     ];
63
64     function next() {
65         let step = steps.shift();
66         if (!step) {
67             InspectorTest.completeTest();
68             return;
69         }
70         step.action();
71     }
72
73     WebInspector.logManager.addEventListener(WebInspector.LogManager.Event.MessageAdded, function(event) {
74         InspectorTest.log(event.data.message.messageText);
75         next();
76     });
77
78     InspectorTest.log("");
79     next();
80 }
81 </script>
82 </head>
83 <body onload="runTest()">
84 </body>
85 </html>