1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test IndexedDB's transaction and objectStore calls");
8 indexedDBTest(prepareDatabase, created);
9 function prepareDatabase()
11 db = event.target.result;
12 event.target.transaction.onabort = unexpectedAbortCallback;
14 evalAndLog("db.createObjectStore('a')");
15 evalAndLog("db.createObjectStore('b')");
16 evalAndLog("db.createObjectStore('store').createIndex('index', 'some_path')");
22 trans = evalAndLog("trans = db.transaction(['a'])");
23 evalAndLog("trans.objectStore('a')");
24 evalAndExpectException("trans.objectStore('b')", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
25 evalAndExpectException("trans.objectStore('x')", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
28 trans = evalAndLog("trans = db.transaction(['a'])");
29 evalAndLog("trans.objectStore('a')");
30 evalAndExpectException("trans.objectStore('b')", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
31 evalAndExpectException("trans.objectStore('x')", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
34 trans = evalAndLog("trans = db.transaction(['b'])");
35 evalAndLog("trans.objectStore('b')");
36 evalAndExpectException("trans.objectStore('a')", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
37 evalAndExpectException("trans.objectStore('x')", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
40 trans = evalAndLog("trans = db.transaction(['a', 'b'])");
41 evalAndLog("trans.objectStore('a')");
42 evalAndLog("trans.objectStore('b')");
43 evalAndExpectException("trans.objectStore('x')", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
46 trans = evalAndLog("trans = db.transaction(['b', 'a'])");
47 evalAndLog("trans.objectStore('a')");
48 evalAndLog("trans.objectStore('b')");
49 evalAndExpectException("trans.objectStore('x')", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
52 debug("Passing a string as the first argument is a shortcut for just one object store:");
53 trans = evalAndLog("trans = db.transaction('a')");
54 evalAndLog("trans.objectStore('a')");
55 evalAndExpectException("trans.objectStore('b')", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
56 evalAndExpectException("trans.objectStore('x')", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
59 shouldThrow("trans = db.transaction()");
62 evalAndExpectException("db.transaction(['x'])", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
63 evalAndExpectException("db.transaction(['x'])", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
64 evalAndExpectException("db.transaction(['a', 'x'])", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
65 evalAndExpectException("db.transaction(['x', 'x'])", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
66 evalAndExpectException("db.transaction(['a', 'x', 'b'])", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
69 debug("Exception thrown when no stores specified:");
70 evalAndExpectException("db.transaction([])", "DOMException.INVALID_ACCESS_ERR");
73 debug("{} coerces to a string - so no match, but not a type error:");
74 evalAndExpectException("db.transaction({})", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
75 evalAndExpectException("db.transaction({mode:0})", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
78 debug("Overriding the default string coercion makes these work:");
79 evalAndLog("db.transaction({toString:function(){return 'a';}})");
80 evalAndLog("db.transaction([{toString:function(){return 'a';}}])");
81 debug("... but you still need to specify a real store:");
82 evalAndExpectException("db.transaction([{toString:function(){return 'x';}}])", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
83 evalAndExpectException("db.transaction([{toString:function(){return 'x';}}])", "DOMException.NOT_FOUND_ERR", "'NotFoundError'");
86 trans = evalAndLog("trans = db.transaction(['store'])");
87 shouldBeNonNull("trans");
88 trans.onabort = unexpectedAbortCallback;
89 trans.onerror = unexpectedErrorCallback;
90 trans.oncomplete = afterComplete;
91 evalAndLog("store = trans.objectStore('store')");
92 shouldBeNonNull("store");
93 evalAndLog("store.get('some_key')");
96 function afterComplete()
98 debug("transaction complete, ensuring methods fail");
99 shouldBeNonNull("trans");
100 shouldBeNonNull("store");
101 evalAndExpectException("trans.objectStore('store')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
102 evalAndExpectException("store.index('index')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");