tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_constraint_error_messages.js (1674B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      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";
     12 
     13  info("Opening database");
     14 
     15  let request = indexedDB.open(name);
     16  let event = await expectingUpgrade(request);
     17 
     18  let db = event.target.result;
     19 
     20  info("Creating objectStore");
     21 
     22  let objectStore = db.createObjectStore(objectStoreName);
     23 
     24  info("Creating a duplicated object store to get an error");
     25 
     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  }
     42 
     43  info("Creating an index");
     44 
     45  objectStore.createIndex(indexName, keyPath);
     46 
     47  info("Creating a duplicated indexes to verify the error message");
     48 
     49  try {
     50    objectStore.createIndex(indexName, keyPath);
     51 
     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  }
     61 
     62  await expectingSuccess(request);
     63  db.close();
     64 }