test_filehandle_stream_tracking.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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>File Handle 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. var testBuffer = getRandomBuffer(100000);
  15. let request = indexedDB.open(name, 1);
  16. request.onerror = errorHandler;
  17. request.onsuccess = grabEventAndContinueHandler;
  18. let event = yield undefined;
  19. let db = event.target.result;
  20. db.onerror = errorHandler;
  21. request = db.createMutableFile("test.txt");
  22. request.onerror = errorHandler;
  23. request.onsuccess = grabEventAndContinueHandler;
  24. event = yield undefined;
  25. let mutableFile = event.target.result;
  26. mutableFile.onerror = errorHandler;
  27. let fileHandle = mutableFile.open("readwrite");
  28. request = fileHandle.write(testBuffer);
  29. request.onsuccess = grabEventAndContinueHandler;
  30. event = yield undefined;
  31. request = mutableFile.getFile();
  32. request.onsuccess = grabEventAndContinueHandler;
  33. event = yield undefined;
  34. let file = event.target.result;
  35. let resultBuffer1;
  36. let resultBuffer2;
  37. let reader1 = new FileReader();
  38. reader1.readAsArrayBuffer(file);
  39. reader1.onerror = errorHandler;
  40. reader1.onload = function(event)
  41. {
  42. resultBuffer1 = event.target.result;
  43. let reader = new FileReader();
  44. try {
  45. reader.readAsArrayBuffer(file);
  46. ok(false, "Should have thrown!");
  47. }
  48. catch (e) {
  49. ok(e instanceof DOMException, "Got exception.");
  50. is(e.name, "FileHandleInactiveError", "Good error.");
  51. is(e.code, 0, "Good error code.");
  52. }
  53. if (resultBuffer2) {
  54. testGenerator.next();
  55. }
  56. }
  57. let reader2 = new FileReader();
  58. reader2.readAsArrayBuffer(file);
  59. reader2.onerror = errorHandler;
  60. reader2.onload = function(event)
  61. {
  62. resultBuffer2 = event.target.result;
  63. let reader = new FileReader();
  64. try {
  65. reader.readAsArrayBuffer(file);
  66. ok(false, "Should have thrown!");
  67. }
  68. catch (e) {
  69. ok(e instanceof DOMException, "Got exception.");
  70. is(e.name, "FileHandleInactiveError", "Good error.");
  71. is(e.code, 0, "Good error code.");
  72. }
  73. if (resultBuffer1) {
  74. testGenerator.next();
  75. }
  76. }
  77. yield undefined;
  78. ok(compareBuffers(resultBuffer1, testBuffer), "Correct data");
  79. ok(compareBuffers(resultBuffer2, testBuffer), "Correct data");
  80. finishTest();
  81. yield undefined;
  82. }
  83. </script>
  84. <script type="text/javascript;version=1.7" src="file.js"></script>
  85. <script type="text/javascript;version=1.7" src="helpers.js"></script>
  86. </head>
  87. <body onload="runTest();"></body>
  88. </html>