test_file_put_get_values.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 blobData = { key: 1, blob: getRandomBlob(10000) };
  17. const fileData = { key: 2, file: getRandomFile("random.bin", 100000) };
  18. SpecialPowers.pushPrefEnv({ set: [["dom.indexedDB.dataThreshold", -1]] },
  19. continueToNextStep);
  20. yield undefined;
  21. let request = indexedDB.open(name, 1);
  22. request.onerror = errorHandler;
  23. request.onupgradeneeded = grabEventAndContinueHandler;
  24. request.onsuccess = grabEventAndContinueHandler;
  25. let event = yield undefined;
  26. is(event.type, "upgradeneeded", "Got correct event type");
  27. let db = event.target.result;
  28. db.onerror = errorHandler;
  29. db.createObjectStore(objectStoreName, { });
  30. event = yield undefined;
  31. is(event.type, "success", "Got correct event type");
  32. let objectStore = db.transaction([objectStoreName], READ_WRITE)
  33. .objectStore(objectStoreName);
  34. request = objectStore.add(blobData.blob, blobData.key);
  35. request.onsuccess = grabEventAndContinueHandler;
  36. event = yield undefined;
  37. is(event.target.result, blobData.key, "Got correct key");
  38. request = objectStore.get(blobData.key);
  39. request.onsuccess = grabEventAndContinueHandler;
  40. event = yield undefined;
  41. verifyBlob(event.target.result, blobData.blob, 1);
  42. yield undefined;
  43. request = db.transaction([objectStoreName])
  44. .objectStore(objectStoreName).get(blobData.key);
  45. request.onsuccess = grabEventAndContinueHandler;
  46. event = yield undefined;
  47. verifyBlob(event.target.result, blobData.blob, 1);
  48. yield undefined;
  49. objectStore = db.transaction([objectStoreName], READ_WRITE)
  50. .objectStore(objectStoreName);
  51. request = objectStore.add(fileData.file, fileData.key);
  52. request.onsuccess = grabEventAndContinueHandler;
  53. event = yield undefined;
  54. is(event.target.result, fileData.key, "Got correct key");
  55. request = objectStore.get(fileData.key);
  56. request.onsuccess = grabEventAndContinueHandler;
  57. event = yield undefined;
  58. verifyBlob(event.target.result, fileData.file, 2);
  59. yield undefined;
  60. request = db.transaction([objectStoreName])
  61. .objectStore(objectStoreName).get(fileData.key);
  62. request.onsuccess = grabEventAndContinueHandler;
  63. event = yield undefined;
  64. verifyBlob(event.target.result, fileData.file, 2);
  65. yield undefined;
  66. is(bufferCache.length, 2, "Correct length");
  67. finishTest();
  68. yield undefined;
  69. }
  70. </script>
  71. <script type="text/javascript;version=1.7" src="file.js"></script>
  72. <script type="text/javascript;version=1.7" src="helpers.js"></script>
  73. </head>
  74. <body onload="runTest();"></body>
  75. </html>