Web Inspector: Test IndexedDB.requestDatabase
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Aug 2016 20:59:04 +0000 (20:59 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Aug 2016 20:59:04 +0000 (20:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161122

Reviewed by Brian Burg.

* inspector/indexeddb/requestDatabase-expected.txt: Added.
* inspector/indexeddb/requestDatabase.html: Added.
New tests.

* inspector/indexeddb/deleteDatabaseNamesWithSpace.html:
* inspector/indexeddb/requestDatabaseNames.html:
Share code.

* inspector/indexeddb/resources/utilities.js: Added.
(deleteDatabaseNames):
(createEmptyDatabase):
(createDatabaseWithStores):
Helpers that can be used by each test.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@205040 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector/indexeddb/deleteDatabaseNamesWithSpace.html
LayoutTests/inspector/indexeddb/requestDatabase-expected.txt [new file with mode: 0644]
LayoutTests/inspector/indexeddb/requestDatabase.html [new file with mode: 0644]
LayoutTests/inspector/indexeddb/requestDatabaseNames.html
LayoutTests/inspector/indexeddb/resources/utilities.js [new file with mode: 0644]

index cbe9369..d357233 100644 (file)
@@ -1,5 +1,26 @@
 2016-08-25  Joseph Pecoraro  <pecoraro@apple.com>
 
+        Web Inspector: Test IndexedDB.requestDatabase
+        https://bugs.webkit.org/show_bug.cgi?id=161122
+
+        Reviewed by Brian Burg.
+
+        * inspector/indexeddb/requestDatabase-expected.txt: Added.
+        * inspector/indexeddb/requestDatabase.html: Added.
+        New tests.
+
+        * inspector/indexeddb/deleteDatabaseNamesWithSpace.html:
+        * inspector/indexeddb/requestDatabaseNames.html:
+        Share code.
+
+        * inspector/indexeddb/resources/utilities.js: Added.
+        (deleteDatabaseNames):
+        (createEmptyDatabase):
+        (createDatabaseWithStores):
+        Helpers that can be used by each test.
+
+2016-08-25  Joseph Pecoraro  <pecoraro@apple.com>
+
         Web Inspector: Modernize inspector/indexeddb tests
         https://bugs.webkit.org/show_bug.cgi?id=161113
 
index 62cc4f5..f5515eb 100644 (file)
@@ -2,20 +2,8 @@
 <html>
 <head>
 <script src="../../http/tests/inspector/resources/inspector-test.js"></script>
+<script src="resources/utilities.js"></script>
 <script>
-function createDatabase(name) {
-    let request = window.indexedDB.open(name, 1);
-    request.addEventListener('success', function(event) {
-        console.log(`Created Database '${name}'`);
-        event.target.result.close();
-    });
-}
-
-function deleteDatabaseNames(names) {
-    for (let name of names)
-        window.indexedDB.deleteDatabase(name);
-}
-
 function test()
 {
     let suite = InspectorTest.createAsyncSuite("IndexedDB.requestDatabaseNames.spaces");
@@ -48,7 +36,7 @@ function test()
         name: "CreateDatabaseWithSpacesInName",
         description: "Create a database with spaces in the name.",
         test: (resolve, reject) => {
-            InspectorTest.evaluateInPage("createDatabase('Database With Space')");
+            InspectorTest.evaluateInPage("createEmptyDatabase('Database With Space')");
             IndexedDBAgent.requestDatabaseNames(WebInspector.frameResourceManager.mainFrame.securityOrigin, (error, names) => {
                 InspectorTest.expectNoError(error);
                 InspectorTest.expectThat(names.length === 1, "A single IndexedDB database should exist.");
diff --git a/LayoutTests/inspector/indexeddb/requestDatabase-expected.txt b/LayoutTests/inspector/indexeddb/requestDatabase-expected.txt
new file mode 100644 (file)
index 0000000..70e0eeb
--- /dev/null
@@ -0,0 +1,32 @@
+CONSOLE MESSAGE: line 9: Created Database 'EmptyDatabase'
+CONSOLE MESSAGE: line 18: Created Database 'CompleteDatabase'
+
+== Running test suite: IndexedDB.requestDatabase
+-- Running test case: ClearDatabases
+-- Running test case: CreateAndRequestEmptyDatabase
+PASS: Database name should be 'EmptyDatabase'.
+PASS: Database version should be 123.
+PASS: Database should not have any object stores.
+
+-- Running test case: CreateAndRequestDatabaseWithStores
+PASS: Database name should be 'EmptyDatabase'.
+PASS: Database version should be 456.
+PASS: Database should have 3 object stores.
+PASS: Object store should have name 'Empty'.
+PASS: Object store keypath is null.
+PASS: Object store should not autoIncrement.
+PASS: Object store should have no indexes.
+PASS: Object store should have name 'Reviewers'.
+PASS: Object store keypath is null.
+PASS: Object store should autoIncrement.
+PASS: Object store should have 2 indexes.
+INDEX: {"name":"Name Index","keyPath":{"type":"string","string":"name"},"unique":false,"multiEntry":false}
+INDEX: {"name":"Email Index","keyPath":{"type":"string","string":"email"},"unique":true,"multiEntry":false}
+PASS: Object store should have name 'Stats'.
+PASS: Object store keypath is string type.
+PASS: Object store keypath is 'name''.
+PASS: Object store should not autoIncrement.
+PASS: Object store should have 2 indexes.
+INDEX: {"name":"Directory Name Index","keyPath":{"type":"string","string":"name"},"unique":true,"multiEntry":false}
+INDEX: {"name":"File Count Index","keyPath":{"type":"string","string":"count"},"unique":false,"multiEntry":false}
+
diff --git a/LayoutTests/inspector/indexeddb/requestDatabase.html b/LayoutTests/inspector/indexeddb/requestDatabase.html
new file mode 100644 (file)
index 0000000..81b8abf
--- /dev/null
@@ -0,0 +1,92 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
+<script src="resources/utilities.js"></script>
+<script>
+function test()
+{
+    let suite = InspectorTest.createAsyncSuite("IndexedDB.requestDatabase");
+
+    suite.addTestCase({
+        name: "ClearDatabases",
+        description: "Remove any existing IndexedDB databases.",
+        test: (resolve, reject) => {
+            // FIXME: Remove any existing IndexedDB databases that might exist to workaround:
+            // <https://webkit.org/b/148006> Each test should run with its own clean data store
+            IndexedDBAgent.requestDatabaseNames(WebInspector.frameResourceManager.mainFrame.securityOrigin, (error, names) => {
+                InspectorTest.evaluateInPage("deleteDatabaseNames(" + JSON.stringify(names) + ")", resolve);
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: "CreateAndRequestEmptyDatabase",
+        test: (resolve, reject) => {
+            InspectorTest.evaluateInPage("createEmptyDatabase('EmptyDatabase', 123)");
+            IndexedDBAgent.requestDatabase(WebInspector.frameResourceManager.mainFrame.securityOrigin, "EmptyDatabase", (error, databaseWithObjectStores) => {
+                InspectorTest.expectNoError(error);
+                InspectorTest.expectThat(databaseWithObjectStores.name === "EmptyDatabase", "Database name should be 'EmptyDatabase'.");
+                InspectorTest.expectThat(databaseWithObjectStores.version === 123, "Database version should be 123.");
+                InspectorTest.expectThat(databaseWithObjectStores.objectStores.length === 0, "Database should not have any object stores.");
+                resolve();
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: "CreateAndRequestDatabaseWithStores",
+        test: (resolve, reject) => {
+            InspectorTest.evaluateInPage("createDatabaseWithStores('CompleteDatabase', 456)");
+            IndexedDBAgent.requestDatabase(WebInspector.frameResourceManager.mainFrame.securityOrigin, "CompleteDatabase", (error, databaseWithObjectStores) => {
+                InspectorTest.expectNoError(error);
+                let objectStores = databaseWithObjectStores.objectStores;
+                InspectorTest.expectThat(databaseWithObjectStores.name === "CompleteDatabase", "Database name should be 'EmptyDatabase'.");
+                InspectorTest.expectThat(databaseWithObjectStores.version === 456, "Database version should be 456.");
+                InspectorTest.expectThat(databaseWithObjectStores.objectStores.length === 3, "Database should have 3 object stores.");
+
+                InspectorTest.expectThat(objectStores[0].name === "Empty", "Object store should have name 'Empty'.");
+                InspectorTest.expectThat(objectStores[0].keyPath.type === "null", "Object store keypath is null.");
+                InspectorTest.expectThat(!objectStores[0].autoIncrement, "Object store should not autoIncrement.");
+                InspectorTest.expectThat(!objectStores[0].indexes.length, "Object store should have no indexes.");
+
+                InspectorTest.expectThat(objectStores[1].name === "Reviewers", "Object store should have name 'Reviewers'.");
+                InspectorTest.expectThat(objectStores[1].keyPath.type === "null", "Object store keypath is null.");
+                InspectorTest.expectThat(objectStores[1].autoIncrement, "Object store should autoIncrement.");
+                InspectorTest.expectThat(objectStores[1].indexes.length === 2, "Object store should have 2 indexes.");
+                InspectorTest.log("INDEX: " + JSON.stringify(objectStores[1].indexes[0]));
+                InspectorTest.log("INDEX: " + JSON.stringify(objectStores[1].indexes[1]));
+
+                InspectorTest.expectThat(objectStores[2].name === "Stats", "Object store should have name 'Stats'.");
+                InspectorTest.expectThat(objectStores[2].keyPath.type === "string", "Object store keypath is string type.");
+                InspectorTest.expectThat(objectStores[2].keyPath.string === "name", "Object store keypath is 'name''.");
+                InspectorTest.expectThat(!objectStores[2].autoIncrement, "Object store should not autoIncrement.");
+                InspectorTest.expectThat(objectStores[2].indexes.length === 2, "Object store should have 2 indexes.");
+                InspectorTest.log("INDEX: " + JSON.stringify(objectStores[2].indexes[0]));
+                InspectorTest.log("INDEX: " + JSON.stringify(objectStores[2].indexes[1]));
+
+                resolve();
+            });
+        }
+    });
+
+    // FIXME: <https://webkit.org/b/161121> Web Inspector: IndexedDB.requestDatabase() should not create a database if one did not exist
+    // suite.addTestCase({
+    //     name: "NoSuchDatabase",
+    //     description: "Request a database that does not exist.",
+    //     test: (resolve, reject) => {
+    //         IndexedDBAgent.requestDatabase(WebInspector.frameResourceManager.mainFrame.securityOrigin, "NameDoesNotExist", (error, databaseWithObjectStores) => {
+    //             InspectorTest.expectThat(error, "Should be an error trying to request a database that does not exist.");
+    //             InspectorTest.log(JSON.stringify(databaseWithObjectStores));
+    //             resolve();
+    //         });
+    //     }
+    // });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body onload="runTest()">
+</body>
+</html>
index 75a9556..010f217 100644 (file)
@@ -2,20 +2,8 @@
 <html>
 <head>
 <script src="../../http/tests/inspector/resources/inspector-test.js"></script>
+<script src="resources/utilities.js"></script>
 <script>
-function createDatabase(name) {
-    let request = window.indexedDB.open(name, 1);
-    request.addEventListener('success', function(event) {
-        console.log(`Created Database '${name}'`);
-        event.target.result.close();
-    });
-}
-
-function deleteDatabaseNames(names) {
-    for (let name of names)
-        window.indexedDB.deleteDatabase(name);
-}
-
 function test()
 {
     let suite = InspectorTest.createAsyncSuite("IndexedDB.requestDatabaseNames");
@@ -48,7 +36,7 @@ function test()
         name: "CreateDatabase1",
         description: "Create a first database.",
         test: (resolve, reject) => {
-            InspectorTest.evaluateInPage("createDatabase('Database1')");
+            InspectorTest.evaluateInPage("createEmptyDatabase('Database1')");
             IndexedDBAgent.requestDatabaseNames(WebInspector.frameResourceManager.mainFrame.securityOrigin, (error, names) => {
                 InspectorTest.expectNoError(error);
                 InspectorTest.expectThat(names.length === 1, "A single IndexedDB database should exist.");
@@ -62,7 +50,7 @@ function test()
         name: "CreateDatabase2",
         description: "Create a second database.",
         test: (resolve, reject) => {
-            InspectorTest.evaluateInPage("createDatabase('Database2')");
+            InspectorTest.evaluateInPage("createEmptyDatabase('Database2')");
             IndexedDBAgent.requestDatabaseNames(WebInspector.frameResourceManager.mainFrame.securityOrigin, (error, names) => {
                 InspectorTest.expectNoError(error);
                 InspectorTest.expectThat(names.length === 2, "Two IndexedDB databases should exist.");
@@ -76,7 +64,7 @@ function test()
         name: "CreateDatabase3",
         description: "Create a third database with a unicode name.",
         test: (resolve, reject) => {
-            InspectorTest.evaluateInPage("createDatabase('\u124d')");
+            InspectorTest.evaluateInPage("createEmptyDatabase('\u124d')");
             IndexedDBAgent.requestDatabaseNames(WebInspector.frameResourceManager.mainFrame.securityOrigin, (error, names) => {
                 InspectorTest.expectNoError(error);
                 InspectorTest.expectThat(names.length === 3, "Three IndexedDB databases should exist.");
@@ -90,7 +78,7 @@ function test()
         name: "CreateDatabase4",
         description: "Create a fourth database with a unicode name.",
         test: (resolve, reject) => {
-            InspectorTest.evaluateInPage("createDatabase('\ud800\udf46')");
+            InspectorTest.evaluateInPage("createEmptyDatabase('\ud800\udf46')");
             IndexedDBAgent.requestDatabaseNames(WebInspector.frameResourceManager.mainFrame.securityOrigin, (error, names) => {
                 InspectorTest.expectNoError(error);
                 InspectorTest.expectThat(names.length === 4, "Four IndexedDB databases should exist.");
diff --git a/LayoutTests/inspector/indexeddb/resources/utilities.js b/LayoutTests/inspector/indexeddb/resources/utilities.js
new file mode 100644 (file)
index 0000000..a33f383
--- /dev/null
@@ -0,0 +1,52 @@
+function deleteDatabaseNames(names) {
+    for (let name of names)
+        window.indexedDB.deleteDatabase(name);
+}
+
+function createEmptyDatabase(name, version=1) {
+    let request = window.indexedDB.open(name, version);
+    request.addEventListener('success', function(event) {
+        console.log(`Created Database '${name}'`);
+        let db = event.target.result;
+        db.close();
+    });
+}
+
+function createDatabaseWithStores(name, version) {
+    let request = window.indexedDB.open(name, version);
+    request.addEventListener("success", function(event) {
+        console.log(`Created Database '${name}'`);
+    });
+
+    request.addEventListener("upgradeneeded", function(event) {
+        let db = event.target.result;
+
+        // Reviewers => {name, email}
+        let reviewerObjectStore = db.createObjectStore("Reviewers", {autoIncrement: true});
+        reviewerObjectStore.createIndex("Name Index", "name", {unique: false});
+        reviewerObjectStore.createIndex("Email Index", "email", {unique: true});
+
+        // Stats => {name, count}
+        let statsObjectStore = db.createObjectStore("Stats", {keyPath: "name"});
+        statsObjectStore.createIndex("Directory Name Index", "name", {unique: true});
+        statsObjectStore.createIndex("File Count Index", "count", {unique: false});
+
+        // Empty => any value
+        let lastObjectStore = db.createObjectStore("Empty");
+
+        // Populate once stores are created.
+        lastObjectStore.transaction.oncomplete = (event) => {
+            let reviewerObjectStore = db.transaction("Reviewers", "readwrite").objectStore("Reviewers");
+            reviewerObjectStore.add({name: "Thirsty Hampster", email: "hampster@webkit.org"});
+            reviewerObjectStore.add({name: "Jamming Peacock", email: "peacock@webkit.org"});
+            reviewerObjectStore.add({name: "Bustling Badger", email: "badger@webkit.org"});
+            reviewerObjectStore.add({name: "Monstrous Beaver", email: "beaver@webkit.org"});
+
+            let statsObjectStore = db.transaction("Stats", "readwrite").objectStore("Stats");
+            statsObjectStore.add({name: "Images", count: 250, extensions: ["png", "svg"]});
+            statsObjectStore.add({name: "Models", count: 109, extensions: ["js"]});
+            statsObjectStore.add({name: "Views", count: 436, extensions: ["css", "js"]});
+            statsObjectStore.add({name: "Controllers", count: 41, extensions: ["css", "js"]});
+        };
+    });
+};