test_remove_index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/
  4. */
  5. var testGenerator = testSteps();
  6. function testSteps()
  7. {
  8. const name = this.window ? window.location.pathname : "Splendid Test";
  9. const indexName = "My Test Index";
  10. let request = indexedDB.open(name, 1);
  11. request.onerror = errorHandler;
  12. request.onupgradeneeded = grabEventAndContinueHandler;
  13. let event = yield undefined;
  14. let db = event.target.result;
  15. is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
  16. let objectStore = db.createObjectStore("test store", { keyPath: "foo" });
  17. is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
  18. is(db.objectStoreNames.item(0), objectStore.name, "Correct name");
  19. is(objectStore.indexNames.length, 0, "Correct indexNames list");
  20. let index = objectStore.createIndex(indexName, "foo");
  21. is(objectStore.indexNames.length, 1, "Correct indexNames list");
  22. is(objectStore.indexNames.item(0), indexName, "Correct name");
  23. is(objectStore.index(indexName), index, "Correct instance");
  24. objectStore.deleteIndex(indexName);
  25. is(objectStore.indexNames.length, 0, "Correct indexNames list");
  26. try {
  27. objectStore.index(indexName);
  28. ok(false, "should have thrown");
  29. }
  30. catch(ex) {
  31. ok(ex instanceof DOMException, "Got a DOMException");
  32. is(ex.name, "NotFoundError", "expect a NotFoundError");
  33. is(ex.code, DOMException.NOT_FOUND_ERR, "expect a NOT_FOUND_ERR");
  34. }
  35. let index2 = objectStore.createIndex(indexName, "foo");
  36. isnot(index, index2, "New instance should be created");
  37. is(objectStore.indexNames.length, 1, "Correct recreacted indexNames list");
  38. is(objectStore.indexNames.item(0), indexName, "Correct recreacted name");
  39. is(objectStore.index(indexName), index2, "Correct instance");
  40. event.target.transaction.oncomplete = grabEventAndContinueHandler;
  41. event = yield undefined;
  42. finishTest();
  43. yield undefined;
  44. }