test_file_sharing.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 objectStoreInfo = [
  16. { name: "Blobs", options: { } },
  17. { name: "Other Blobs", options: { } }
  18. ];
  19. const fileData = { key: 1, file: getRandomFile("random.bin", 100000) };
  20. let request = indexedDB.open(name, 1);
  21. request.onerror = errorHandler;
  22. request.onupgradeneeded = grabEventAndContinueHandler;
  23. request.onsuccess = grabEventAndContinueHandler;
  24. let event = yield undefined;
  25. is(event.type, "upgradeneeded", "Got correct event type");
  26. let db = event.target.result;
  27. db.onerror = errorHandler;
  28. for (let info of objectStoreInfo) {
  29. let objectStore = db.createObjectStore(info.name, info.options);
  30. objectStore.add(fileData.file, fileData.key);
  31. }
  32. event = yield undefined;
  33. is(event.type, "success", "Got correct event type");
  34. let refResult;
  35. for (let info of objectStoreInfo) {
  36. let objectStore = db.transaction([info.name])
  37. .objectStore(info.name);
  38. request = objectStore.get(fileData.key);
  39. request.onsuccess = grabEventAndContinueHandler;
  40. event = yield undefined;
  41. let result = event.target.result;
  42. verifyBlob(result, fileData.file, 1);
  43. yield undefined;
  44. if (!refResult) {
  45. refResult = result;
  46. continue;
  47. }
  48. is(getFilePath(result), getFilePath(refResult), "The same os file");
  49. }
  50. for (let i = 1; i < objectStoreInfo.length; i++) {
  51. let info = objectStoreInfo[i];
  52. let objectStore = db.transaction([info.name], READ_WRITE)
  53. .objectStore(info.name);
  54. request = objectStore.add(refResult, 2);
  55. request.onsuccess = grabEventAndContinueHandler;
  56. event = yield undefined;
  57. is(event.target.result, 2, "Got correct key");
  58. request = objectStore.get(2);
  59. request.onsuccess = grabEventAndContinueHandler;
  60. event = yield undefined;
  61. let result = event.target.result;
  62. verifyBlob(result, refResult, 1);
  63. yield undefined;
  64. is(getFilePath(result), getFilePath(refResult), "The same os file");
  65. }
  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>