test_deleteDatabase_interactions.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. let request = indexedDB.open(name, 10);
  10. request.onerror = errorHandler;
  11. request.onsuccess = unexpectedSuccessHandler;
  12. request.onupgradeneeded = grabEventAndContinueHandler;
  13. ok(request instanceof IDBOpenDBRequest, "Expect an IDBOpenDBRequest");
  14. let event = yield undefined;
  15. is(event.type, "upgradeneeded", "Expect an upgradeneeded event");
  16. ok(event instanceof IDBVersionChangeEvent, "Expect a versionchange event");
  17. let db = event.target.result;
  18. db.createObjectStore("stuff");
  19. request.onsuccess = grabEventAndContinueHandler;
  20. event = yield undefined;
  21. is(event.type, "success", "Expect a success event");
  22. is(event.target, request, "Event has right target");
  23. ok(event.target.result instanceof IDBDatabase, "Result should be a database");
  24. is(db.objectStoreNames.length, 1, "Expect an objectStore here");
  25. db.close();
  26. request = indexedDB.deleteDatabase(name);
  27. request.onerror = errorHandler;
  28. request.onsuccess = grabEventAndContinueHandler;
  29. ok(request instanceof IDBOpenDBRequest, "Expect an IDBOpenDBRequest");
  30. let openRequest = indexedDB.open(name, 1);
  31. openRequest.onerror = errorHandler;
  32. openRequest.onsuccess = unexpectedSuccessHandler;
  33. event = yield undefined;
  34. is(event.type, "success", "expect a success event");
  35. is(event.target, request, "event has right target");
  36. is(event.target.result, undefined, "event should have no result");
  37. openRequest.onsuccess = grabEventAndContinueHandler;
  38. event = yield undefined;
  39. is(event.target.result.version, 1, "DB has proper version");
  40. is(event.target.result.objectStoreNames.length, 0, "DB should have no object stores");
  41. finishTest();
  42. yield undefined;
  43. }