test_file_array.html 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 b1 = getRandomBlob(10000);
  16. const b2 = [ getRandomBlob(5000), getRandomBlob(3000), getRandomBlob(12000),
  17. getRandomBlob(17000), getRandomBlob(16000), getRandomBlob(16000),
  18. getRandomBlob(8000)
  19. ];
  20. const b3 = [ getRandomBlob(5000), getRandomBlob(3000), getRandomBlob(9000)];
  21. const objectStoreData = [
  22. { key: 1, blobs: [ b1, b1, b1, b1, b1, b1, b1, b1, b1, b1 ],
  23. expectedFileIds: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] },
  24. { key: 2, blobs: [ b2[0], b2[1], b2[2], b2[3], b2[4], b2[5], b2[6] ],
  25. expectedFileIds: [2, 3, 4, 5, 6, 7, 8] },
  26. { key: 3, blobs: [ b3[0], b3[0], b3[1], b3[2], b3[2], b3[0], b3[0] ],
  27. expectedFileIds: [9, 9, 10, 11, 11, 9, 9] }
  28. ];
  29. SpecialPowers.pushPrefEnv({ set: [["dom.indexedDB.dataThreshold", -1]] },
  30. continueToNextStep);
  31. yield undefined;
  32. let request = indexedDB.open(name, 1);
  33. request.onerror = errorHandler;
  34. request.onupgradeneeded = grabEventAndContinueHandler;
  35. request.onsuccess = grabEventAndContinueHandler;
  36. let event = yield undefined;
  37. is(event.type, "upgradeneeded", "Got correct event type");
  38. let db = event.target.result;
  39. db.onerror = errorHandler;
  40. let objectStore = db.createObjectStore(objectStoreName, { });
  41. for (let data of objectStoreData) {
  42. objectStore.add(data.blobs, data.key);
  43. }
  44. event = yield undefined;
  45. is(event.type, "success", "Got correct event type");
  46. for (let data of objectStoreData) {
  47. objectStore = db.transaction([objectStoreName])
  48. .objectStore(objectStoreName);
  49. request = objectStore.get(data.key);
  50. request.onsuccess = grabEventAndContinueHandler;
  51. event = yield undefined;
  52. verifyBlobArray(event.target.result, data.blobs, data.expectedFileIds);
  53. yield undefined;
  54. }
  55. is(bufferCache.length, 11, "Correct length");
  56. finishTest();
  57. yield undefined;
  58. }
  59. </script>
  60. <script type="text/javascript;version=1.7" src="file.js"></script>
  61. <script type="text/javascript;version=1.7" src="helpers.js"></script>
  62. </head>
  63. <body onload="runTest();"></body>
  64. </html>