test_file_transaction_abort.html 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. event = yield undefined;
  28. is(event.type, "success", "Got correct event type");
  29. let trans = db.transaction([objectStoreName], READ_WRITE);
  30. objectStore = trans.objectStore(objectStoreName);
  31. request = objectStore.add(fileData.file, fileData.key);
  32. request.onsuccess = grabEventAndContinueHandler;
  33. event = yield undefined;
  34. is(event.target.result, fileData.key, "Got correct key");
  35. trans.onabort = grabEventAndContinueHandler;
  36. trans.abort();
  37. event = yield undefined;
  38. is(event.type, "abort", "Got correct event type");
  39. is(getFileDBRefCount(name, 1), 0, "Correct db ref count");
  40. fileData.file = null;
  41. }
  42. scheduleGC();
  43. yield undefined;
  44. ok(!hasFileInfo(name, 1), "Correct ref count");
  45. finishTest();
  46. yield undefined;
  47. }
  48. </script>
  49. <script type="text/javascript;version=1.7" src="file.js"></script>
  50. <script type="text/javascript;version=1.7" src="helpers.js"></script>
  51. </head>
  52. <body onload="runTest();"></body>
  53. </html>