test_overlapping_transactions.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 objectStores = [ "foo", "bar" ];
  10. let request = indexedDB.open(name, 1);
  11. request.onerror = errorHandler;
  12. request.onupgradeneeded = grabEventAndContinueHandler;
  13. let event = yield undefined;
  14. let db = event.target.result;
  15. is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
  16. event.target.onsuccess = grabEventAndContinueHandler;
  17. for (let i in objectStores) {
  18. db.createObjectStore(objectStores[i], { autoIncrement: true });
  19. }
  20. event = yield undefined;
  21. is(db.objectStoreNames.length, objectStores.length,
  22. "Correct objectStoreNames list");
  23. for (let i = 0; i < 50; i++) {
  24. let stepNumber = 0;
  25. request = db.transaction(["foo"], "readwrite")
  26. .objectStore("foo")
  27. .add({});
  28. request.onerror = errorHandler;
  29. request.onsuccess = function(event) {
  30. is(stepNumber, 1, "This callback came first");
  31. stepNumber++;
  32. event.target.transaction.oncomplete = grabEventAndContinueHandler;
  33. }
  34. request = db.transaction(["foo"], "readwrite")
  35. .objectStore("foo")
  36. .add({});
  37. request.onerror = errorHandler;
  38. request.onsuccess = function(event) {
  39. is(stepNumber, 2, "This callback came second");
  40. stepNumber++;
  41. event.target.transaction.oncomplete = grabEventAndContinueHandler;
  42. }
  43. request = db.transaction(["foo", "bar"], "readwrite")
  44. .objectStore("bar")
  45. .add({});
  46. request.onerror = errorHandler;
  47. request.onsuccess = function(event) {
  48. is(stepNumber, 3, "This callback came third");
  49. stepNumber++;
  50. event.target.transaction.oncomplete = grabEventAndContinueHandler;
  51. }
  52. request = db.transaction(["foo", "bar"], "readwrite")
  53. .objectStore("bar")
  54. .add({});
  55. request.onerror = errorHandler;
  56. request.onsuccess = function(event) {
  57. is(stepNumber, 4, "This callback came fourth");
  58. stepNumber++;
  59. event.target.transaction.oncomplete = grabEventAndContinueHandler;
  60. }
  61. request = db.transaction(["bar"], "readwrite")
  62. .objectStore("bar")
  63. .add({});
  64. request.onerror = errorHandler;
  65. request.onsuccess = function(event) {
  66. is(stepNumber, 5, "This callback came fifth");
  67. stepNumber++;
  68. event.target.transaction.oncomplete = grabEventAndContinueHandler;
  69. }
  70. stepNumber++;
  71. yield undefined; yield undefined; yield undefined; yield undefined; yield undefined;
  72. is(stepNumber, 6, "All callbacks received");
  73. }
  74. finishTest();
  75. yield undefined;
  76. }