test_filehandle_disabled_pref.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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"
  9. src="/tests/SimpleTest/SimpleTest.js">
  10. </script>
  11. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  12. <script type="text/javascript;version=1.7">
  13. function testSteps()
  14. {
  15. const databaseName = window.location.pathname;
  16. const databaseVersion = 1;
  17. const objectStoreName = "foo";
  18. const mutableFileName = "bar";
  19. const mutableFileKey = 42;
  20. info("opening database");
  21. let request = indexedDB.open(databaseName, databaseVersion);
  22. request.onerror = errorHandler;
  23. request.onupgradeneeded = grabEventAndContinueHandler;
  24. request.onsuccess = unexpectedSuccessHandler;
  25. let event = yield undefined;
  26. info("creating object store");
  27. let db = event.target.result;
  28. db.onerror = errorHandler;
  29. db.onversionchange = function(event) {
  30. is(event.oldVersion, databaseVersion, "got correct oldVersion");
  31. is(event.newVersion, null, "got correct newVersion");
  32. db.close();
  33. };
  34. let objectStore = db.createObjectStore(objectStoreName,
  35. { autoIncrement: true });
  36. request.onupgradeneeded = unexpectedSuccessHandler;
  37. request.onsuccess = grabEventAndContinueHandler;
  38. event = yield undefined;
  39. info("creating mutable file");
  40. request = db.createMutableFile(mutableFileName);
  41. request.onsuccess = grabEventAndContinueHandler;
  42. event = yield undefined;
  43. let mutableFile = event.target.result;
  44. verifyMutableFile(mutableFile, getFile(mutableFileName, "", ""));
  45. yield undefined;
  46. objectStore = db.transaction([objectStoreName], "readwrite")
  47. .objectStore(objectStoreName);
  48. info("adding mutable file");
  49. request = objectStore.add(mutableFile, mutableFileKey);
  50. request.onsuccess = grabEventAndContinueHandler;
  51. event = yield undefined;
  52. info("getting mutable file");
  53. request = objectStore.get(mutableFileKey);
  54. request.onsuccess = grabEventAndContinueHandler;
  55. event = yield undefined;
  56. verifyMutableFile(event.target.result,
  57. getFile(mutableFileName, "", ""));
  58. yield undefined;
  59. info("opening database");
  60. request = indexedDB.open(databaseName, databaseVersion);
  61. request.onerror = errorHandler;
  62. request.onupgradeneeded = unexpectedSuccessHandler;
  63. request.onsuccess = grabEventAndContinueHandler;
  64. event = yield undefined;
  65. let db2 = event.target.result;
  66. db2.onerror = errorHandler;
  67. db2.onversionchange = function(event) {
  68. is(event.oldVersion, databaseVersion, "got correct oldVersion");
  69. is(event.newVersion, null, "got correct newVersion");
  70. db2.close();
  71. };
  72. objectStore = db2.transaction([objectStoreName], "readwrite")
  73. .objectStore(objectStoreName);
  74. info("adding mutable file");
  75. request = objectStore.add(mutableFile);
  76. request.onsuccess = grabEventAndContinueHandler;
  77. event = yield undefined;
  78. info("getting mutable file");
  79. request = objectStore.get(event.target.result);
  80. request.onsuccess = grabEventAndContinueHandler;
  81. event = yield undefined;
  82. verifyMutableFile(event.target.result,
  83. getFile(mutableFileName, "", ""));
  84. yield undefined;
  85. info("setting file handle pref");
  86. SpecialPowers.pushPrefEnv({ set: [["dom.fileHandle.enabled", false]] },
  87. continueToNextStep);
  88. yield undefined;
  89. info("opening database");
  90. request = indexedDB.open(databaseName, databaseVersion);
  91. request.onerror = errorHandler;
  92. request.onupgradeneeded = unexpectedSuccessHandler;
  93. request.onsuccess = grabEventAndContinueHandler;
  94. event = yield undefined;
  95. let db3 = event.target.result;
  96. db3.onerror = errorHandler;
  97. db3.onversionchange = function(event) {
  98. is(event.oldVersion, databaseVersion, "got correct oldVersion");
  99. is(event.newVersion, null, "got correct newVersion");
  100. db3.close();
  101. };
  102. info("creating mutable file");
  103. try {
  104. db3.createMutableFile(mutableFileName);
  105. ok(false, "Should have thrown!");
  106. }
  107. catch (e) {
  108. ok(e instanceof DOMException, "Got exception.");
  109. is(e.name, "InvalidStateError", "Good error.");
  110. is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
  111. }
  112. objectStore = db3.transaction([objectStoreName], "readwrite")
  113. .objectStore(objectStoreName);
  114. info("adding mutable file");
  115. try {
  116. objectStore.add(mutableFile);
  117. ok(false, "Should have thrown!");
  118. }
  119. catch (e) {
  120. ok(e instanceof DOMException, "Got exception.");
  121. is(e.name, "DataCloneError", "Good error.");
  122. is(e.code, DOMException.DATA_CLONE_ERR, "Good error code.");
  123. }
  124. info("getting mutable file");
  125. request = objectStore.get(mutableFileKey);
  126. request.onsuccess = grabEventAndContinueHandler;
  127. event = yield undefined;
  128. try {
  129. let result = request.result;
  130. ok(false, "Should have thrown!");
  131. }
  132. catch (e) {
  133. ok(e instanceof DOMException, "Got exception.");
  134. is(e.name, "InvalidStateError", "Good error.");
  135. is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
  136. }
  137. info("deleting database");
  138. request = indexedDB.deleteDatabase(databaseName);
  139. request.onerror = errorHandler;
  140. request.onsuccess = grabEventAndContinueHandler;
  141. event = yield undefined;
  142. info("resetting file handle pref");
  143. SpecialPowers.popPrefEnv(continueToNextStep);
  144. yield undefined;
  145. finishTest();
  146. yield undefined;
  147. }
  148. </script>
  149. <script type="text/javascript;version=1.7" src="helpers.js"></script>
  150. <script type="text/javascript;version=1.7" src="file.js"></script>
  151. </head>
  152. <body onload="runTest();"></body>
  153. </html>