test_file_resurrection_delete.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <!--
  2. Any copyright is dedicated to the Public Domain.
  3. http://creativecommons.org/publicdomain/zero/1.0/
  4. -->
  5. <html>
  6. <head>
  7. <title>Indexed Database Property Test</title>
  8. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  10. <script type="text/javascript;version=1.7">
  11. function testSteps()
  12. {
  13. const READ_WRITE = "readwrite";
  14. const name = window.location.pathname;
  15. const objectStoreName = "Blobs";
  16. const fileData = { key: 1, file: getRandomFile("random.bin", 100000) };
  17. {
  18. let request = indexedDB.open(name, 1);
  19. request.onerror = errorHandler;
  20. request.onupgradeneeded = grabEventAndContinueHandler;
  21. request.onsuccess = grabEventAndContinueHandler;
  22. let event = yield undefined;
  23. is(event.type, "upgradeneeded", "Got correct event type");
  24. let db = event.target.result;
  25. db.onerror = errorHandler;
  26. let objectStore = db.createObjectStore(objectStoreName, { });
  27. objectStore.add(fileData.file, fileData.key);
  28. event = yield undefined;
  29. is(event.type, "success", "Got correct event type");
  30. let trans = db.transaction([objectStoreName], READ_WRITE);
  31. objectStore = trans.objectStore(objectStoreName);
  32. objectStore.delete(fileData.key);
  33. trans.oncomplete = grabEventAndContinueHandler;
  34. event = yield undefined;
  35. is(getFileDBRefCount(name, 1), 0, "Correct db ref count");
  36. trans = db.transaction([objectStoreName], READ_WRITE);
  37. objectStore = trans.objectStore(objectStoreName);
  38. request = objectStore.add(fileData.file, fileData.key);
  39. request.onsuccess = grabEventAndContinueHandler;
  40. event = yield undefined;
  41. trans.oncomplete = grabEventAndContinueHandler;
  42. event = yield undefined;
  43. is(getFileDBRefCount(name, 1), 1, "Correct db ref count");
  44. fileData.file = null;
  45. }
  46. scheduleGC();
  47. yield undefined;
  48. is(getFileRefCount(name, 1), 0, "Correct ref count");
  49. {
  50. let request = indexedDB.open(name, 1);
  51. request.onerror = errorHandler;
  52. request.onsuccess = grabEventAndContinueHandler;
  53. let event = yield undefined;
  54. is(event.type, "success", "Got correct event type");
  55. let db = event.target.result;
  56. db.onerror = errorHandler;
  57. let trans = db.transaction([objectStoreName], READ_WRITE);
  58. objectStore = trans.objectStore(objectStoreName);
  59. request = objectStore.get(fileData.key);
  60. request.onsuccess = grabEventAndContinueHandler;
  61. event = yield undefined;
  62. let result = event.target.result;
  63. ok(result, "Got result");
  64. objectStore.delete(fileData.key);
  65. trans.oncomplete = grabEventAndContinueHandler;
  66. event = yield undefined;
  67. is(getFileDBRefCount(name, 1), 0, "Correct db ref count");
  68. trans = db.transaction([objectStoreName], READ_WRITE);
  69. objectStore = trans.objectStore(objectStoreName);
  70. request = objectStore.add(result, fileData.key);
  71. request.onsuccess = grabEventAndContinueHandler;
  72. event = yield undefined;
  73. trans.oncomplete = grabEventAndContinueHandler;
  74. event = yield undefined;
  75. is(getFileDBRefCount(name, 1), 1, "Correct db ref count");
  76. event = null;
  77. result = null;
  78. }
  79. scheduleGC();
  80. yield undefined;
  81. is(getFileRefCount(name, 1), 0, "Correct ref count");
  82. finishTest();
  83. yield undefined;
  84. }
  85. </script>
  86. <script type="text/javascript;version=1.7" src="file.js"></script>
  87. <script type="text/javascript;version=1.7" src="helpers.js"></script>
  88. </head>
  89. <body onload="runTest();"></body>
  90. </html>