dom/indexedDB/test/unit/test_remove_index.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/indexedDB/test/unit/test_remove_index.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,55 @@
     1.4 +/**
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.7 + */
     1.8 +
     1.9 +var testGenerator = testSteps();
    1.10 +
    1.11 +function testSteps()
    1.12 +{
    1.13 +  const name = this.window ? window.location.pathname : "Splendid Test";
    1.14 +  const indexName = "My Test Index";
    1.15 +
    1.16 +  let request = indexedDB.open(name, 1);
    1.17 +  request.onerror = errorHandler;
    1.18 +  request.onupgradeneeded = grabEventAndContinueHandler;
    1.19 +  let event = yield undefined;
    1.20 +
    1.21 +  let db = event.target.result;
    1.22 +  is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
    1.23 +
    1.24 +  let objectStore = db.createObjectStore("test store", { keyPath: "foo" });
    1.25 +  is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
    1.26 +  is(db.objectStoreNames.item(0), objectStore.name, "Correct name");
    1.27 +
    1.28 +  is(objectStore.indexNames.length, 0, "Correct indexNames list");
    1.29 +
    1.30 +  let index = objectStore.createIndex(indexName, "foo");
    1.31 +
    1.32 +  is(objectStore.indexNames.length, 1, "Correct indexNames list");
    1.33 +  is(objectStore.indexNames.item(0), indexName, "Correct name");
    1.34 +  is(objectStore.index(indexName), index, "Correct instance");
    1.35 +
    1.36 +  objectStore.deleteIndex(indexName);
    1.37 +
    1.38 +  is(objectStore.indexNames.length, 0, "Correct indexNames list");
    1.39 +  try {
    1.40 +    objectStore.index(indexName);
    1.41 +    ok(false, "should have thrown");
    1.42 +  }
    1.43 +  catch(ex) {
    1.44 +    ok(ex instanceof DOMException, "Got a DOMException");
    1.45 +    is(ex.name, "NotFoundError", "expect a NotFoundError");
    1.46 +    is(ex.code, DOMException.NOT_FOUND_ERR, "expect a NOT_FOUND_ERR");
    1.47 +  }
    1.48 +
    1.49 +  let index2 = objectStore.createIndex(indexName, "foo");
    1.50 +  isnot(index, index2, "New instance should be created");
    1.51 +
    1.52 +  is(objectStore.indexNames.length, 1, "Correct recreacted indexNames list");
    1.53 +  is(objectStore.indexNames.item(0), indexName, "Correct recreacted name");
    1.54 +  is(objectStore.index(indexName), index2, "Correct instance");
    1.55 +
    1.56 +  finishTest();
    1.57 +  yield undefined;
    1.58 +}

mercurial