test_file_replace.html 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 name = window.location.pathname;
  14. const objectStoreName = "Blobs";
  15. const blobData = { key: 42, blobs: [] };
  16. for (let i = 0; i < 100; i++) {
  17. blobData.blobs[i] = getRandomBlob(i);
  18. }
  19. SpecialPowers.pushPrefEnv({ set: [["dom.indexedDB.dataThreshold", -1]] },
  20. continueToNextStep);
  21. yield undefined;
  22. let request = indexedDB.open(name, 1);
  23. request.onerror = errorHandler;
  24. request.onupgradeneeded = grabEventAndContinueHandler;
  25. request.onsuccess = grabEventAndContinueHandler;
  26. let event = yield undefined;
  27. is(event.type, "upgradeneeded", "Got correct event type");
  28. let db = event.target.result;
  29. db.onerror = errorHandler;
  30. let objectStore = db.createObjectStore(objectStoreName, { });
  31. for (let i = 0; i < blobData.blobs.length; i++) {
  32. objectStore.put(blobData.blobs[i], blobData.key);
  33. }
  34. event = yield undefined;
  35. is(event.type, "success", "Got correct event type");
  36. for (let id = 1; id <= 100; id++) {
  37. let refs = {};
  38. let dbRefs = {};
  39. let hasFileInfo = utils.getFileReferences(name, id, null, refs, dbRefs);
  40. ok(hasFileInfo, "Has file info");
  41. is(refs.value, 1, "Correct ref count");
  42. is(dbRefs.value, id / 100 >> 0, "Correct db ref count");
  43. }
  44. finishTest();
  45. yield undefined;
  46. }
  47. </script>
  48. <script type="text/javascript;version=1.7" src="file.js"></script>
  49. <script type="text/javascript;version=1.7" src="helpers.js"></script>
  50. </head>
  51. <body onload="runTest();"></body>
  52. </html>