test_filehandle_truncate.html 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.bin");
  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. is(fileHandle.location, 100000, "Correct location");
  32. for (let i = 0; i < 10; i++) {
  33. let location = fileHandle.location - 10000;
  34. fileHandle.location = location;
  35. request = fileHandle.truncate();
  36. request.onsuccess = grabEventAndContinueHandler;
  37. event = yield undefined;
  38. is(fileHandle.location, location, "Correct location");
  39. request = fileHandle.getMetadata({ size: true });
  40. request.onsuccess = grabEventAndContinueHandler;
  41. event = yield undefined;
  42. is(event.target.result.size, location, "Correct size");
  43. }
  44. request = fileHandle.write(testBuffer);
  45. request.onsuccess = grabEventAndContinueHandler;
  46. event = yield undefined;
  47. let location = fileHandle.location;
  48. for (let i = 0; i < 10; i++) {
  49. location -= 10000;
  50. request = fileHandle.truncate(location);
  51. request.onsuccess = grabEventAndContinueHandler;
  52. event = yield undefined;
  53. is(fileHandle.location, location, "Correct location");
  54. request = fileHandle.getMetadata({ size: true });
  55. request.onsuccess = grabEventAndContinueHandler;
  56. event = yield undefined;
  57. is(event.target.result.size, location, "Correct size");
  58. }
  59. finishTest();
  60. yield undefined;
  61. }
  62. </script>
  63. <script type="text/javascript;version=1.7" src="file.js"></script>
  64. <script type="text/javascript;version=1.7" src="helpers.js"></script>
  65. </head>
  66. <body onload="runTest();"></body>
  67. </html>