1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test IndexedDB transaction internal active flag.");
8 indexedDBTest(prepareDatabase, runTransaction);
9 function prepareDatabase()
11 db = event.target.result;
12 event.target.transaction.onabort = unexpectedAbortCallback;
13 evalAndLog("store = db.createObjectStore('store')");
14 evalAndLog("store.createIndex('index', 'keypath')");
17 function runTransaction()
20 debug("runTransaction():");
21 evalAndLog("transaction = db.transaction('store', 'readwrite')");
24 debug("Verify that transactions are created with |active| flag set:");
25 evalAndLog("store = transaction.objectStore('store')");
26 evalAndLog("index = store.index('index')");
27 for (i = 0; i < statements.length; ++i) {
28 shouldNotThrow(statements[i]);
32 debug("Transaction shouldn't be active inside a non-IDB-event callback");
33 evalAndLog("setTimeout(testTimeout, 0)");
35 timeoutComplete = false;
37 // Keep transaction alive until timeout callback completes - don't log
38 // anything here as this could run a variable number of times depending
41 if (timeoutComplete) {
45 busyRequest = transaction.objectStore('store').get(0);
46 busyRequest.onerror = unexpectedErrorCallback;
47 busyRequest.onsuccess = function () {
53 transaction.oncomplete = transactionComplete;
60 "store.get(IDBKeyRange.only(0))",
62 "store.delete(IDBKeyRange.only(0))",
65 "store.count(IDBKeyRange.only(0))",
68 "store.openCursor(0)",
69 "store.openCursor(0, 'next')",
70 "store.openCursor(IDBKeyRange.only(0))",
71 "store.openCursor(IDBKeyRange.only(0), 'next')",
73 "index.get(IDBKeyRange.only(0))",
75 "index.getKey(IDBKeyRange.only(0))",
78 "index.count(IDBKeyRange.only(0))",
80 "index.openCursor(0)",
81 "index.openCursor(0, 'next')",
82 "index.openCursor(IDBKeyRange.only(0))",
83 "index.openCursor(IDBKeyRange.only(0), 'next')",
84 "index.openKeyCursor()",
85 "index.openKeyCursor(0)",
86 "index.openKeyCursor(0, 'next')",
87 "index.openKeyCursor(IDBKeyRange.only(0))",
88 "index.openKeyCursor(IDBKeyRange.only(0), 'next')"
91 function testTimeout()
94 debug("testTimeout():");
95 evalAndLog("store = transaction.objectStore('store')");
96 evalAndLog("index = store.index('index')");
97 for (i = 0; i < statements.length; ++i) {
98 evalAndExpectException(statements[i], "0", "'TransactionInactiveError'");
100 timeoutComplete = true;
103 function testEventCallback()
106 debug("testEventCallback():");
108 debug("Transaction should be active inside a non-IDB-event callback");
109 evalAndLog("store = transaction.objectStore('store')");
110 evalAndLog("index = store.index('index')");
111 for (i = 0; i < statements.length; ++i) {
112 shouldNotThrow(statements[i]);
116 function transactionComplete()
119 debug("transactionComplete():");
120 evalAndExpectException("store = transaction.objectStore('store')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");