test_filehandle_location.html 2.8 KB

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