test_autoIncrement_indexes.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
  9. request.onerror = errorHandler;
  10. request.onupgradeneeded = grabEventAndContinueHandler;
  11. let event = yield undefined;
  12. let db = request.result;
  13. db.onerror = errorHandler;
  14. let objectStore = db.createObjectStore("foo", { keyPath: "id",
  15. autoIncrement: true });
  16. objectStore.createIndex("first","first");
  17. objectStore.createIndex("second","second");
  18. objectStore.createIndex("third","third");
  19. let data = { first: "foo", second: "foo", third: "foo" };
  20. objectStore.add(data).onsuccess = grabEventAndContinueHandler;
  21. event = yield undefined;
  22. is(event.target.result, 1, "Added entry");
  23. request.onsuccess = grabEventAndContinueHandler;
  24. event = yield undefined;
  25. objectStore = db.transaction("foo").objectStore("foo");
  26. let first = objectStore.index("first");
  27. let second = objectStore.index("second");
  28. let third = objectStore.index("third");
  29. first.get("foo").onsuccess = grabEventAndContinueHandler;
  30. event = yield undefined;
  31. is (event.target.result.id, 1, "Entry in first");
  32. second.get("foo").onsuccess = grabEventAndContinueHandler;
  33. event = yield undefined;
  34. is (event.target.result.id, 1, "Entry in second");
  35. third.get("foo").onsuccess = grabEventAndContinueHandler;
  36. event = yield undefined;
  37. is (event.target.result.id, 1, "Entry in third");
  38. finishTest();
  39. yield undefined;
  40. }