PageRenderTime 63ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/testing/web-platform/tests/IndexedDB/transaction-abort-index-metadata-revert.html

https://github.com/rillian/firefox
HTML | 276 lines | 259 code | 17 blank | 0 comment | 0 complexity | 6e1bc83257734957fe065a1e56adcdc4 MD5 | raw file
  1. <!DOCTYPE html>
  2. <title>IndexedDB: aborting transactions reverts index metadata</title>
  3. <link rel="help" href="https://w3c.github.io/IndexedDB/#abort-transaction">
  4. <link rel="author" href="pwnall@chromium.org" title="Victor Costan">
  5. <script src="/resources/testharness.js"></script>
  6. <script src="/resources/testharnessreport.js"></script>
  7. <script src="support-promises.js"></script>
  8. <script>
  9. promise_test(testCase => {
  10. let store = null, index = null;
  11. return createDatabase(testCase, (database, transaction) => {
  12. createBooksStore(testCase, database);
  13. }).then(database => {
  14. database.close();
  15. }).then(() => migrateDatabase(testCase, 2, (database, transaction) => {
  16. store = createNotBooksStore(testCase, database);
  17. index = store.index('not_by_author');
  18. assert_array_equals(
  19. store.indexNames, ['not_by_author', 'not_by_title'],
  20. 'IDBObjectStore.indexNames should include newly created indexes ' +
  21. 'before the transaction is aborted');
  22. transaction.abort();
  23. assert_throws(
  24. 'InvalidStateError', () => index.get('query'),
  25. 'IDBIndex.get should throw InvalidStateError, indicating that ' +
  26. 'the index is marked for deletion, immediately after ' +
  27. 'IDBTransaction.abort() returns');
  28. assert_array_equals(
  29. store.indexNames, [],
  30. 'IDBObjectStore.indexNames should stop including the newly ' +
  31. 'created indexes immediately after IDBTransaction.abort() returns');
  32. })).then(() => {
  33. assert_throws(
  34. 'InvalidStateError', () => index.get('query'),
  35. 'IDBIndex.get should throw InvalidStateError, indicating that ' +
  36. 'the index is marked for deletion, after the transaction is ' +
  37. 'aborted');
  38. assert_array_equals(
  39. store.indexNames, [],
  40. 'IDBObjectStore.indexNames should stop including the newly ' +
  41. 'created indexes after the transaction is aborted');
  42. });
  43. }, 'Created stores get their indexes marked as deleted after the transaction ' +
  44. 'that created them aborts');
  45. promise_test(testCase => {
  46. let store = null, index = null;
  47. return createDatabase(testCase, (database, transaction) => {
  48. createBooksStore(testCase, database);
  49. createNotBooksStore(testCase, database);
  50. }).then(database => {
  51. database.close();
  52. }).then(() => migrateDatabase(testCase, 2, (database, transaction) => {
  53. store = transaction.objectStore('not_books');
  54. index = store.index('not_by_author');
  55. database.deleteObjectStore('not_books');
  56. assert_throws(
  57. 'InvalidStateError', () => index.get('query'),
  58. 'IDBIndex.get should throw InvalidStateError, indicating that ' +
  59. 'the index is marked for deletion, immediately after ' +
  60. 'IDBDatabase.deleteObjectStore() returns');
  61. assert_array_equals(
  62. store.indexNames, [],
  63. 'IDBObjectStore.indexNames should be empty immediately after ' +
  64. 'IDBDatabase.deleteObjectStore() returns');
  65. transaction.abort();
  66. assert_throws(
  67. 'TransactionInactiveError', () => index.get('query'),
  68. 'IDBIndex.get should throw TransactionInactiveError, indicating ' +
  69. 'that the index is no longer marked for deletion, immediately ' +
  70. 'after IDBTransaction.abort() returns');
  71. assert_array_equals(
  72. store.indexNames, ['not_by_author', 'not_by_title'],
  73. 'IDBObjectStore.indexNames should include the deleted indexes ' +
  74. 'immediately after IDBTransaction.abort() returns');
  75. })).then(() => {
  76. assert_throws(
  77. 'TransactionInactiveError', () => index.get('query'),
  78. 'IDBIndex.get should throw TransactionInactiveError, indicating ' +
  79. 'that the index is no longer marked for deletion, after the ' +
  80. 'transaction is aborted');
  81. assert_array_equals(
  82. store.indexNames, ['not_by_author', 'not_by_title'],
  83. 'IDBObjectStore.indexNames should include the deleted indexes ' +
  84. 'after the transaction is aborted');
  85. });
  86. }, 'Deleted stores get their indexes marked as not-deleted after the ' +
  87. 'transaction that deleted them aborts');
  88. promise_test(testCase => {
  89. let store = null, index = null;
  90. return createDatabase(testCase, (database, transaction) => {
  91. createBooksStore(testCase, database);
  92. }).then(database => {
  93. database.close();
  94. }).then(() => migrateDatabase(testCase, 2, (database, transaction) => {
  95. store = createNotBooksStore(testCase, database);
  96. index = store.index('not_by_author');
  97. assert_array_equals(
  98. store.indexNames, ['not_by_author', 'not_by_title'],
  99. 'IDBObjectStore.indexNames should include newly created indexes ' +
  100. 'before the transaction is aborted');
  101. database.deleteObjectStore('not_books');
  102. assert_throws(
  103. 'InvalidStateError', () => index.get('query'),
  104. 'IDBIndex.get should throw InvalidStateError, indicating that ' +
  105. 'the index is marked for deletion, immediately after ' +
  106. 'IDBDatabase.deleteObjectStore() returns');
  107. assert_array_equals(
  108. store.indexNames, [],
  109. 'IDBObjectStore.indexNames should be empty immediately after ' +
  110. 'IDBDatabase.deleteObjectStore() returns');
  111. transaction.abort();
  112. assert_throws(
  113. 'InvalidStateError', () => index.get('query'),
  114. 'IDBIndex.get should throw InvalidStateError, indicating that ' +
  115. 'the index is still marked for deletion, immediately after ' +
  116. 'IDBTransaction.abort() returns');
  117. assert_array_equals(
  118. store.indexNames, [],
  119. 'IDBObjectStore.indexNames should not include the newly ' +
  120. 'created indexes immediately after IDBTransaction.abort() returns');
  121. })).then(() => {
  122. assert_throws(
  123. 'InvalidStateError', () => index.get('query'),
  124. 'IDBIndex.get should throw InvalidStateError, indicating that ' +
  125. 'the index is still marked for deletion, after the transaction ' +
  126. 'is aborted');
  127. assert_array_equals(
  128. store.indexNames, [],
  129. 'IDBObjectStore.indexNames should not include the newly ' +
  130. 'created indexes after the transaction is aborted');
  131. });
  132. }, 'Created+deleted stores still have their indexes marked as deleted after ' +
  133. 'the transaction aborts');
  134. promise_test(testCase => {
  135. let store = null, index = null;
  136. return createDatabase(testCase, (database, transaction) => {
  137. createBooksStore(testCase, database);
  138. createNotBooksStore(testCase, database);
  139. }).then(database => {
  140. database.close();
  141. }).then(() => migrateDatabase(testCase, 2, (database, transaction) => {
  142. store = transaction.objectStore('not_books');
  143. index = store.createIndex('not_by_isbn', 'isbn');
  144. assert_array_equals(
  145. store.indexNames, ['not_by_author', 'not_by_isbn', 'not_by_title'],
  146. 'IDBObjectStore.indexNames should include newly created indexes ' +
  147. 'before the transaction is aborted');
  148. transaction.abort();
  149. assert_throws(
  150. 'InvalidStateError', () => index.get('query'),
  151. 'IDBIndex.get should throw InvalidStateError, indicating that ' +
  152. 'the index is marked for deletion, immediately after ' +
  153. 'IDBTransaction.abort() returns');
  154. assert_array_equals(
  155. store.indexNames, ['not_by_author', 'not_by_title'],
  156. 'IDBObjectStore.indexNames should stop including the newly ' +
  157. 'created index immediately after IDBTransaction.abort() returns');
  158. })).then(() => {
  159. assert_throws(
  160. 'InvalidStateError', () => index.get('query'),
  161. 'IDBIndex.get should throw InvalidStateError, indicating that ' +
  162. 'the index is marked for deletion, after the transaction is ' +
  163. 'aborted');
  164. assert_array_equals(
  165. store.indexNames, ['not_by_author', 'not_by_title'],
  166. 'IDBObjectStore.indexNames should stop including the newly ' +
  167. 'created index after the transaction is aborted');
  168. });
  169. }, 'Created indexes get marked as deleted after their transaction aborts');
  170. promise_test(testCase => {
  171. let store = null, index = null;
  172. return createDatabase(testCase, (database, transaction) => {
  173. createBooksStore(testCase, database);
  174. createNotBooksStore(testCase, database);
  175. }).then(database => {
  176. database.close();
  177. }).then(() => migrateDatabase(testCase, 2, (database, transaction) => {
  178. store = transaction.objectStore('not_books');
  179. index = store.index('not_by_author');
  180. store.deleteIndex('not_by_author');
  181. assert_throws(
  182. 'InvalidStateError', () => index.get('query'),
  183. 'IDBIndex.get should throw InvalidStateError, indicating that ' +
  184. 'the index is marked for deletion, immediately after ' +
  185. 'IDBObjectStore.deleteIndex() returns');
  186. assert_array_equals(
  187. store.indexNames, ['not_by_title'],
  188. 'IDBObjectStore.indexNames should not include the deleted index ' +
  189. 'immediately after IDBObjectStore.deleteIndex() returns');
  190. transaction.abort();
  191. assert_throws(
  192. 'TransactionInactiveError', () => index.get('query'),
  193. 'IDBIndex.get should throw TransactionInactiveError, indicating ' +
  194. 'that the index is no longer marked for deletion, immediately ' +
  195. 'after IDBTransaction.abort() returns');
  196. assert_array_equals(
  197. store.indexNames, ['not_by_author', 'not_by_title'],
  198. 'IDBObjectStore.indexNames should include the deleted indexes ' +
  199. 'immediately after IDBTransaction.abort() returns');
  200. })).then(() => {
  201. assert_throws(
  202. 'TransactionInactiveError', () => index.get('query'),
  203. 'IDBIndex.get should throw TransactionInactiveError, indicating ' +
  204. 'that the index is no longer marked for deletion, after the ' +
  205. 'transaction is aborted');
  206. assert_array_equals(
  207. store.indexNames, ['not_by_author', 'not_by_title'],
  208. 'IDBObjectStore.indexNames should include the deleted indexes ' +
  209. 'after the transaction is aborted');
  210. });
  211. }, 'Deleted indexes get marked as not-deleted after the transaction aborts');
  212. promise_test(testCase => {
  213. let store = null, index = null;
  214. return createDatabase(testCase, (database, transaction) => {
  215. createBooksStore(testCase, database);
  216. createNotBooksStore(testCase, database);
  217. }).then(database => {
  218. database.close();
  219. }).then(() => migrateDatabase(testCase, 2, (database, transaction) => {
  220. store = transaction.objectStore('not_books');
  221. index = store.createIndex('not_by_isbn', 'isbn');
  222. assert_array_equals(
  223. store.indexNames, ['not_by_author', 'not_by_isbn', 'not_by_title'],
  224. 'IDBObjectStore.indexNames should include newly created indexes ' +
  225. 'before the transaction is aborted');
  226. store.deleteIndex('not_by_isbn');
  227. assert_throws(
  228. 'InvalidStateError', () => index.get('query'),
  229. 'IDBIndex.get should throw InvalidStateError, indicating that ' +
  230. 'the index is marked for deletion, immediately after ' +
  231. 'IDBObjectStore.deleteIndex() returns');
  232. assert_array_equals(
  233. store.indexNames, ['not_by_author', 'not_by_title'],
  234. 'IDBObjectStore.indexNames should not include the deleted index ' +
  235. 'immediately after IDBObjectStore.deleteIndex() returns');
  236. transaction.abort();
  237. assert_throws(
  238. 'InvalidStateError', () => index.get('query'),
  239. 'IDBIndex.get should throw InvalidStateError, indicating that ' +
  240. 'the index is still marked for deletion, immediately after ' +
  241. 'IDBTransaction.abort() returns');
  242. assert_array_equals(
  243. store.indexNames, ['not_by_author', 'not_by_title'],
  244. 'IDBObjectStore.indexNames should stop including the newly ' +
  245. 'created index immediately after IDBTransaction.abort() returns');
  246. })).then(() => {
  247. assert_throws(
  248. 'InvalidStateError', () => index.get('query'),
  249. 'IDBIndex.get should throw InvalidStateError, indicating that ' +
  250. 'the index is marked for deletion, after the transaction is ' +
  251. 'aborted');
  252. assert_array_equals(
  253. store.indexNames, ['not_by_author', 'not_by_title'],
  254. 'IDBObjectStore.indexNames should stop including the newly ' +
  255. 'created index after the transaction is aborted');
  256. });
  257. }, 'Created+deleted indexes are still marked as deleted after their ' +
  258. 'transaction aborts');
  259. </script>