test_file_put_get_object.html 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 blob = getRandomBlob(1000);
  17. const file = getRandomFile("random.bin", 100000);
  18. const objectData1 = { key: 1, object: { foo: blob, bar: blob } };
  19. const objectData2 = { key: 2, object: { foo: file, bar: file } };
  20. SpecialPowers.pushPrefEnv({ set: [["dom.indexedDB.dataThreshold", -1]] },
  21. continueToNextStep);
  22. yield undefined;
  23. let request = indexedDB.open(name, 1);
  24. request.onerror = errorHandler;
  25. request.onupgradeneeded = grabEventAndContinueHandler;
  26. request.onsuccess = grabEventAndContinueHandler;
  27. let event = yield undefined;
  28. is(event.type, "upgradeneeded", "Got correct event type");
  29. let db = event.target.result;
  30. db.onerror = errorHandler;
  31. let objectStore = db.createObjectStore(objectStoreName, { });
  32. objectStore.add(objectData1.object, objectData1.key);
  33. objectStore.add(objectData2.object, objectData2.key);
  34. event = yield undefined;
  35. is(event.type, "success", "Got correct event type");
  36. objectStore = db.transaction([objectStoreName])
  37. .objectStore(objectStoreName);
  38. request = objectStore.get(objectData1.key);
  39. request.onsuccess = grabEventAndContinueHandler;
  40. event = yield undefined;
  41. let result = event.target.result;
  42. verifyBlob(result.foo, blob, 1);
  43. yield undefined;
  44. verifyBlob(result.bar, blob, 1);
  45. yield undefined;
  46. objectStore = db.transaction([objectStoreName])
  47. .objectStore(objectStoreName);
  48. request = objectStore.get(objectData2.key);
  49. request.onsuccess = grabEventAndContinueHandler;
  50. event = yield undefined;
  51. result = event.target.result;
  52. verifyBlob(result.foo, file, 2);
  53. yield undefined;
  54. verifyBlob(result.bar, file, 2);
  55. yield undefined;
  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>