1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test the basics of IndexedDB's IDBDatabase.");
8 indexedDBTest(prepareDatabase, testSetVersionAbort);
9 function prepareDatabase()
11 db = event.target.result;
12 debug("Test that you can't open a transaction while in a versionchange transaction");
13 evalAndExpectException('db.transaction("doesntExist")',
14 "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
16 shouldBe("db.version", "1");
17 shouldBeEqualToString("db.name", dbname);
18 shouldBe("db.objectStoreNames", "[]");
19 shouldBe("db.objectStoreNames.length", "0");
20 shouldBe("db.objectStoreNames.contains('')", "false");
21 shouldBeUndefined("db.objectStoreNames[0]");
22 shouldBeNull("db.objectStoreNames.item(0)");
24 objectStore = evalAndLog('db.createObjectStore("test123")');
28 function checkObjectStore()
30 shouldBe("db.objectStoreNames", "['test123']");
31 shouldBe("db.objectStoreNames.length", "1");
32 shouldBe("db.objectStoreNames.contains('')", "false");
33 shouldBe("db.objectStoreNames.contains('test456')", "false");
34 shouldBe("db.objectStoreNames.contains('test123')", "true");
38 function testSetVersionAbort()
40 evalAndLog("db.close()");
41 evalAndLog("request = indexedDB.open(dbname, 2)");
42 request.onupgradeneeded = createAnotherObjectStore;
43 request.onblocked = unexpectedBlockedCallback;
44 request.onsuccess = unexpectedSuccessCallback;
47 function createAnotherObjectStore()
49 evalAndLog("db = event.target.result");
50 shouldBe("db.version", "2");
51 shouldBeEqualToString("db.name", dbname);
54 objectStore = evalAndLog('db.createObjectStore("test456")');
55 var setVersionTrans = evalAndLog("setVersionTrans = event.target.transaction");
56 shouldBeNonNull("setVersionTrans");
57 setVersionTrans.oncomplete = unexpectedCompleteCallback;
58 setVersionTrans.onabort = checkMetadata;
59 evalAndLog("setVersionTrans.abort()");
62 function checkMetadata()
64 shouldBe("db.version", "1");
71 evalAndLog("db.close()");
72 debug("Now that the connection is closed, transaction creation should fail");
73 evalAndExpectException("db.transaction('test123')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
74 debug("Call twice, make sure it's harmless");
75 evalAndLog("db.close()");