test_filehandle_readonly_exceptions.html 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. request = mutableFile.open("readwrite").write({});
  27. request.onsuccess = grabEventAndContinueHandler;
  28. event = yield undefined;
  29. is(event.target.fileHandle.mode, "readwrite", "Correct mode");
  30. try {
  31. mutableFile.open().write({});
  32. ok(false, "Writing to a readonly file handle should fail!");
  33. }
  34. catch (e) {
  35. ok(true, "Writing to a readonly file handle failed");
  36. }
  37. try {
  38. mutableFile.open().append({});
  39. ok(false, "Appending to a readonly file handle should fail!");
  40. }
  41. catch (e) {
  42. ok(true, "Appending to a readonly file handle failed");
  43. }
  44. try {
  45. mutableFile.open().truncate({});
  46. ok(false, "Truncating a readonly file handle should fail!");
  47. }
  48. catch (e) {
  49. ok(true, "Truncating a readonly file handle failed");
  50. }
  51. try {
  52. mutableFile.open().flush({});
  53. ok(false, "Flushing a readonly file handle should fail!");
  54. }
  55. catch (e) {
  56. ok(true, "Flushing a readonly file handle failed");
  57. }
  58. finishTest();
  59. yield undefined;
  60. }
  61. </script>
  62. <script type="text/javascript;version=1.7" src="helpers.js"></script>
  63. </head>
  64. <body onload="runTest();"></body>
  65. </html>