Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / transaction-active-flag.js
blob2f7f1504517f2595a8f2bb74b91797e610fe62cd
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()
19     debug("");
20     debug("runTransaction():");
21     evalAndLog("transaction = db.transaction('store', 'readwrite')");
23     debug("");
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]);
29     }
31     debug("");
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
39     // on the port.
40     function busy() {
41         if (timeoutComplete) {
42             testEventCallback();
43             return;
44         }
45         busyRequest = transaction.objectStore('store').get(0);
46         busyRequest.onerror = unexpectedErrorCallback;
47         busyRequest.onsuccess = function () {
48             busy();
49         };
50     }
51     busy();
53     transaction.oncomplete = transactionComplete;
56 var statements = [
57     "store.add(0, 0)",
58     "store.put(0, 0)",
59     "store.get(0)",
60     "store.get(IDBKeyRange.only(0))",
61     "store.delete(0)",
62     "store.delete(IDBKeyRange.only(0))",
63     "store.count()",
64     "store.count(0)",
65     "store.count(IDBKeyRange.only(0))",
66     "store.clear()",
67     "store.openCursor()",
68     "store.openCursor(0)",
69     "store.openCursor(0, 'next')",
70     "store.openCursor(IDBKeyRange.only(0))",
71     "store.openCursor(IDBKeyRange.only(0), 'next')",
72     "index.get(0)",
73     "index.get(IDBKeyRange.only(0))",
74     "index.getKey(0)",
75     "index.getKey(IDBKeyRange.only(0))",
76     "index.count()",
77     "index.count(0)",
78     "index.count(IDBKeyRange.only(0))",
79     "index.openCursor()",
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()
93     debug("");
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'");
99     }
100     timeoutComplete = true;
103 function testEventCallback()
105     debug("");
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]);
113     }
116 function transactionComplete()
118     debug("");
119     debug("transactionComplete():");
120     evalAndExpectException("store = transaction.objectStore('store')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
121     finishJSTest();