test_deleteDatabase_onblocked_duringVersionChange.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 dbVersion = 10;
  10. let openRequest = indexedDB.open(name, dbVersion);
  11. openRequest.onerror = errorHandler;
  12. openRequest.onblocked = errorHandler;
  13. openRequest.onsuccess = unexpectedSuccessHandler;
  14. openRequest.onupgradeneeded = grabEventAndContinueHandler;
  15. let event = yield undefined;
  16. is(event.type, "upgradeneeded", "Expect an upgradeneeded event");
  17. ok(event instanceof IDBVersionChangeEvent, "Expect a versionchange event");
  18. let db = event.target.result;
  19. db.onversionchange = errorHandler;
  20. db.createObjectStore("stuff");
  21. let deletingRequest = indexedDB.deleteDatabase(name);
  22. deletingRequest.onerror = errorHandler;
  23. deletingRequest.onsuccess = errorHandler;
  24. deletingRequest.onblocked = errorHandler;
  25. openRequest.onsuccess = grabEventAndContinueHandler;
  26. event = yield undefined;
  27. is(event.type, "success", "Expect a success event");
  28. is(event.target, openRequest, "Event has right target");
  29. ok(event.target.result instanceof IDBDatabase, "Result should be a database");
  30. is(db.objectStoreNames.length, 1, "Expect an objectStore here");
  31. db.onversionchange = grabEventAndContinueHandler;
  32. event = yield undefined;
  33. is(event.type, "versionchange", "Expect an versionchange event");
  34. is(event.target, db, "Event has right target");
  35. ok(event instanceof IDBVersionChangeEvent, "Expect a versionchange event");
  36. is(event.oldVersion, dbVersion, "Correct old version");
  37. is(event.newVersion, null, "Correct new version");
  38. deletingRequest.onblocked = grabEventAndContinueHandler;
  39. event = yield undefined;
  40. is(event.type, "blocked", "Expect an blocked event");
  41. is(event.target, deletingRequest, "Event has right target");
  42. ok(event instanceof IDBVersionChangeEvent, "Expect a versionchange event");
  43. is(event.oldVersion, dbVersion, "Correct old version");
  44. is(event.newVersion, null, "Correct new version");
  45. deletingRequest.onsuccess = grabEventAndContinueHandler;
  46. db.close();
  47. event = yield undefined;
  48. is(event.type, "success", "expect a success event");
  49. is(event.target, deletingRequest, "event has right target");
  50. is(event.target.result, undefined, "event should have no result");
  51. openRequest = indexedDB.open(name, 1);
  52. openRequest.onerror = errorHandler;
  53. openRequest.onsuccess = grabEventAndContinueHandler;
  54. event = yield undefined;
  55. db = event.target.result;
  56. is(db.version, 1, "DB has proper version");
  57. is(db.objectStoreNames.length, 0, "DB should have no object stores");
  58. db.close();
  59. finishTest();
  60. yield undefined;
  61. }