Bug 1816170 - Disable perftest-on-autoland cron. r=aglavic
[gecko.git] / dom / indexedDB / test / unit / test_constraint_error_messages.js
blobb77431e71a79f63de0281ca4e185ae10b541429e
1 /**
2  * Any copyright is dedicated to the Public Domain.
3  * http://creativecommons.org/publicdomain/zero/1.0/
4  */
6 /* exported testSteps */
7 async function testSteps() {
8   const name = this.window ? window.location.pathname : "Splendid Test";
9   const objectStoreName = "foo";
10   const indexName = "bar",
11     keyPath = "bar";
13   info("Opening database");
15   let request = indexedDB.open(name);
16   let event = await expectingUpgrade(request);
18   let db = event.target.result;
20   info("Creating objectStore");
22   let objectStore = db.createObjectStore(objectStoreName);
24   info("Creating a duplicated object store to get an error");
26   try {
27     db.createObjectStore(objectStoreName);
28     ok(
29       false,
30       "ConstraintError should be thrown if object store already exists"
31     );
32   } catch (e) {
33     ok(true, "ConstraintError should be thrown if object store already exists");
34     is(
35       e.message,
36       "IDBDatabase.createObjectStore: Object store named '" +
37         objectStoreName +
38         "' already exists at index '0'",
39       "Threw with correct error message"
40     );
41   }
43   info("Creating an index");
45   objectStore.createIndex(indexName, keyPath);
47   info("Creating a duplicated indexes to verify the error message");
49   try {
50     objectStore.createIndex(indexName, keyPath);
52     ok(false, "ConstraintError should be thrown if index already exists");
53   } catch (e) {
54     ok(true, "ConstraintError should be thrown if index already exists");
55     is(
56       e.message,
57       `IDBObjectStore.createIndex: Index named '${indexName}' already exists at index '0'`,
58       "Threw with correct error message"
59     );
60   }
62   await expectingSuccess(request);
63   db.close();