test_global_data.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 objectStore = { name: "Objects",
  10. options: { keyPath: "id", autoIncrement: true } };
  11. let request = indexedDB.open(name, 1);
  12. request.onerror = errorHandler;
  13. request.onupgradeneeded = grabEventAndContinueHandler;
  14. let event = yield undefined;
  15. let db1 = event.target.result;
  16. is(db1.objectStoreNames.length, 0, "No objectStores in db1");
  17. db1.createObjectStore(objectStore.name, objectStore.options);
  18. continueToNextStep();
  19. yield undefined;
  20. request = indexedDB.open(name, 1);
  21. request.onerror = errorHandler;
  22. request.onsuccess = grabEventAndContinueHandler;
  23. event = yield undefined;
  24. let db2 = event.target.result;
  25. ok(db1 !== db2, "Databases are not the same object");
  26. is(db1.objectStoreNames.length, 1, "1 objectStore in db1");
  27. is(db1.objectStoreNames.item(0), objectStore.name, "Correct name");
  28. is(db2.objectStoreNames.length, 1, "1 objectStore in db2");
  29. is(db2.objectStoreNames.item(0), objectStore.name, "Correct name");
  30. let objectStore1 = db1.transaction(objectStore.name)
  31. .objectStore(objectStore.name);
  32. is(objectStore1.name, objectStore.name, "Same name");
  33. is(objectStore1.keyPath, objectStore.options.keyPath, "Same keyPath");
  34. let objectStore2 = db2.transaction(objectStore.name)
  35. .objectStore(objectStore.name);
  36. ok(objectStore1 !== objectStore2, "Different objectStores");
  37. is(objectStore1.name, objectStore2.name, "Same name");
  38. is(objectStore1.keyPath, objectStore2.keyPath, "Same keyPath");
  39. finishTest();
  40. yield undefined;
  41. }