test_file_os_delete.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. getCurrentUsage(grabFileUsageAndContinueHandler);
  17. let startUsage = yield undefined;
  18. const fileData1 = {
  19. key: 1,
  20. obj: { id: 1, file: getRandomFile("random.bin", 100000) }
  21. };
  22. const fileData2 = {
  23. key: 2,
  24. obj: { id: 1, file: getRandomFile("random.bin", 100000) }
  25. };
  26. SpecialPowers.pushPrefEnv({ set: [["dom.indexedDB.dataThreshold", -1]] },
  27. continueToNextStep);
  28. yield undefined;
  29. {
  30. let request = indexedDB.open(name, 1);
  31. request.onerror = errorHandler;
  32. request.onupgradeneeded = grabEventAndContinueHandler;
  33. request.onsuccess = grabEventAndContinueHandler;
  34. let event = yield undefined;
  35. is(event.type, "upgradeneeded", "Got correct event type");
  36. let db = event.target.result;
  37. db.onerror = errorHandler;
  38. let objectStore = db.createObjectStore(objectStoreName, { });
  39. objectStore.createIndex("index", "id", { unique: true });
  40. objectStore.add(fileData1.obj, fileData1.key);
  41. request = objectStore.add(fileData2.obj, fileData2.key);
  42. request.addEventListener("error", new ExpectError("ConstraintError", true));
  43. request.onsuccess = unexpectedSuccessHandler;
  44. yield undefined;
  45. event = yield undefined;
  46. is(event.type, "success", "Got correct event type");
  47. getCurrentUsage(grabFileUsageAndContinueHandler);
  48. let usage = yield undefined;
  49. is(usage, startUsage + fileData1.obj.file.size + fileData2.obj.file.size,
  50. "Correct file usage");
  51. let trans = db.transaction([objectStoreName], READ_WRITE);
  52. trans.objectStore(objectStoreName).delete(fileData1.key);
  53. trans.oncomplete = grabEventAndContinueHandler;
  54. event = yield undefined;
  55. is(event.type, "complete", "Got correct event type");
  56. getCurrentUsage(grabFileUsageAndContinueHandler);
  57. usage = yield undefined;
  58. is(usage, startUsage + fileData1.obj.file.size + fileData2.obj.file.size,
  59. "OS files exists");
  60. fileData1.obj.file = null;
  61. fileData2.obj.file = null;
  62. }
  63. scheduleGC();
  64. yield undefined;
  65. // Flush pending file deletions before checking usage.
  66. flushPendingFileDeletions();
  67. getCurrentUsage(grabFileUsageAndContinueHandler);
  68. let endUsage = yield undefined;
  69. is(endUsage, startUsage, "OS files deleted");
  70. finishTest();
  71. yield undefined;
  72. }
  73. </script>
  74. <script type="text/javascript;version=1.7" src="file.js"></script>
  75. <script type="text/javascript;version=1.7" src="helpers.js"></script>
  76. </head>
  77. <body onload="runTest();"></body>
  78. </html>