Bug 1529038 [wpt PR 15361] - KV storage: add schema checks when initializing, a=testonly
authorDomenic Denicola <domenic@chromium.org>
Tue, 05 Mar 2019 12:17:40 +0000
changeset 464570 872d7defb5d40de2d006e27516d237ad1f0594cb
parent 464569 26d55c6031ffe95018cbc5dd37dea0579b589d2c
child 464571 8b570896ed6855a3dd1aaa00f3038971a8e3e58d
push id35717
push useraciure@mozilla.com
push dateSun, 17 Mar 2019 09:45:26 +0000
treeherdermozilla-central@e0861be8d6c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1529038, 15361, 931263, 1466865, 632696
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1529038 [wpt PR 15361] - KV storage: add schema checks when initializing, a=testonly Automatic update from web-platform-tests KV storage: add schema checks when initializing Follows https://github.com/WICG/kv-storage/pull/52. Bug: 931263 Change-Id: I4a943dd2d7dde28c98b88eff397cde769bb64e19 Reviewed-on: https://chromium-review.googlesource.com/c/1466865 Commit-Queue: Domenic Denicola <domenic@chromium.org> Reviewed-by: Victor Costan <pwnall@chromium.org> Cr-Commit-Position: refs/heads/master@{#632696} -- wpt-commits: 1fc9a5125f12c95954b4dc2e6ce599bde447f63e wpt-pr: 15361
testing/web-platform/tests/kv-storage/cause-errors-via-idb.https.html
testing/web-platform/tests/kv-storage/helpers/kvs-tests.js
--- a/testing/web-platform/tests/kv-storage/cause-errors-via-idb.https.html
+++ b/testing/web-platform/tests/kv-storage/cause-errors-via-idb.https.html
@@ -2,17 +2,17 @@
 <meta charset="utf-8">
 <title>KV Storage: causing errors by directly manipulating the IDB</title>
 
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="/IndexedDB/support-promises.js"></script>
 
 <script type="module">
-import { testWithArea } from "./helpers/kvs-tests.js";
+import { testWithArea, testWithAreaNoCleanup } from "./helpers/kvs-tests.js";
 
 const mustFail = {
   "set()": area => area.set(1, "value 1"),
   "get()": area => area.get(1),
   "delete()": area => area.delete(1),
   "keys()": area => {
     const iter = area.keys();
     return iter.next();
@@ -24,30 +24,92 @@ const mustFail = {
   "entries()": area => {
     const iter = area.entries();
     return iter.next();
   }
 };
 
 for (const [method, testFn] of Object.entries(mustFail)) {
   testWithArea(async (area, t) => {
-    const { database, store, version } = area.backingStore;
+    const { database, version } = area.backingStore;
     const db = await migrateNamedDatabase(t, database, version + 1, () => {});
 
     const result = testFn(area);
 
     await promise_rejects(t, "VersionError", result);
   }, `${method}: upgrading the database must cause a "VersionError" DOMException`);
 
-  testWithArea(async (area, t) => {
-    const { database, store } = area.backingStore;
+  testWithAreaNoCleanup(async (area, t) => {
+    const { database } = area.backingStore;
 
     // Set up a new database with that name, but with no object stores!
     // NB: this depends on the fact that createNameDatabase sets the initial version to 1, which is
     // the same as the database version used/expected by KV Storage.
     const db = await createNamedDatabase(t, database, () => {});
 
     const result = testFn(area);
 
-    await promise_rejects(t, "NotFoundError", result);
-  }, `${method}: creating a same-named database with no object store must cause a "NotFoundError" DOMException`);
+    await promise_rejects(t, "InvalidStateError", result);
+  }, `${method}: creating a same-named database with no object store must cause an "InvalidStateError" DOMException`);
+
+  testWithAreaNoCleanup(async (area, t) => {
+    const { database } = area.backingStore;
+
+    const db = await createNamedDatabase(t, database, db => {
+      db.createObjectStore("wrongName");
+    });
+
+    const result = testFn(area);
+
+    await promise_rejects(t, "InvalidStateError", result);
+  }, `${method}: creating a same-named database with a single object store with the wrong name must cause an "InvalidStateError" DOMException`);
+
+  testWithAreaNoCleanup(async (area, t) => {
+    const { database, store } = area.backingStore;
+
+    const db = await createNamedDatabase(t, database, db => {
+      db.createObjectStore(store);
+      db.createObjectStore("wrongName");
+    });
+
+    const result = testFn(area);
+
+    await promise_rejects(t, "InvalidStateError", result);
+  }, `${method}: creating a same-named database with more than one object store must cause an "InvalidStateError" DOMException`);
+
+  testWithAreaNoCleanup(async (area, t) => {
+    const { database, store } = area.backingStore;
+
+    const db = await createNamedDatabase(t, database, db => {
+      db.createObjectStore(store, { autoIncrement: true });
+    });
+
+    const result = testFn(area);
+
+    await promise_rejects(t, "InvalidStateError", result);
+  }, `${method}: creating a same-named database the right object store but a bad schema (autoIncrement = true) must cause an "InvalidStateError" DOMException`);
+
+  testWithAreaNoCleanup(async (area, t) => {
+    const { database, store } = area.backingStore;
+
+    const db = await createNamedDatabase(t, database, db => {
+      db.createObjectStore(store, { keyPath: "somekey" });
+    });
+
+    const result = testFn(area);
+
+    await promise_rejects(t, "InvalidStateError", result);
+  }, `${method}: creating a same-named database the right object store but a bad schema (keyPath != null) must cause an "InvalidStateError" DOMException`);
+
+  testWithAreaNoCleanup(async (area, t) => {
+    const { database, store } = area.backingStore;
+
+    const db = await createNamedDatabase(t, database, db => {
+      const s = db.createObjectStore(store);
+      s.createIndex("index", "indexKey");
+    });
+
+    const result = testFn(area);
+
+    await promise_rejects(t, "InvalidStateError", result);
+  }, `${method}: creating a same-named database the right object store but a bad schema (has indices) must cause an "InvalidStateError" DOMException`);
 }
 </script>
--- a/testing/web-platform/tests/kv-storage/helpers/kvs-tests.js
+++ b/testing/web-platform/tests/kv-storage/helpers/kvs-tests.js
@@ -1,11 +1,22 @@
 import { StorageArea, storage as defaultArea } from "std:kv-storage";
 import { assertAsyncIteratorEquals, assertAsyncIteratorCustomEquals } from "./equality-asserters.js";
 
+// Used when we're manually creating the database, and so the IDB helpers also want to clean it up.
+// If we used testWithArea, then the IDB helpers would time out in their cleanup steps when they
+// fail to delete the already-deleted database.
+export function testWithAreaNoCleanup(testFn, description) {
+  promise_test(t => {
+    const area = new StorageArea(description);
+
+    return testFn(area, t);
+  }, description);
+}
+
 export function testWithArea(testFn, description) {
   promise_test(t => {
     const area = new StorageArea(description);
     t.add_cleanup(t => area.clear());
 
     return testFn(area, t);
   }, description);
 }