test_cursor_cycle.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 Bob = { ss: "237-23-7732", name: "Bob" };
  9. let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
  10. request.onerror = errorHandler;
  11. request.onupgradeneeded = grabEventAndContinueHandler;
  12. let event = yield undefined;
  13. let db = event.target.result;
  14. event.target.onsuccess = continueToNextStep;
  15. let objectStore = db.createObjectStore("foo", { keyPath: "ss" });
  16. objectStore.createIndex("name", "name", { unique: true });
  17. objectStore.add(Bob);
  18. yield undefined;
  19. db.transaction("foo", "readwrite").objectStore("foo")
  20. .index("name").openCursor().onsuccess = function(event) {
  21. event.target.transaction.oncomplete = continueToNextStep;
  22. let cursor = event.target.result;
  23. if (cursor) {
  24. let objectStore = event.target.transaction.objectStore("foo");
  25. objectStore.delete(Bob.ss)
  26. .onsuccess = function(event) { cursor.continue(); };
  27. }
  28. };
  29. yield undefined;
  30. finishTest();
  31. objectStore = null; // Bug 943409 workaround.
  32. yield undefined;
  33. }