1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test that specifying a version when opening a non-existent db causes an upgradeneeded event and that the version number is set correctly.");
11 request = evalAndLog("indexedDB.deleteDatabase(dbname)");
12 request.onsuccess = deleteSuccess;
13 request.onerror = unexpectedErrorCallback;
14 request.onblocked = unexpectedBlockedCallback;
17 function deleteSuccess(evt) {
18 debug("Should trigger:");
19 debug("4.1.4: If no database with the given name from the origin origin was found, or if it was deleted during the previous step, then create a database with name name, with 0 as version, and with no object stores. Let db be the new database.");
20 debug("4.1.6: Create a new connection to db and let connection represent it.");
21 debug("4.1.7: If the version of db is lower than version, then run the steps for running a \"versionchange\" transaction using connection, version, request and upgrade callback.");
22 debug("4.1.9: Return connection.");
24 evalAndLog("request = indexedDB.open(dbname, 7)");
25 shouldBeEqualToString("String(request)", "[object IDBOpenDBRequest]");
26 request.onsuccess = openSuccess;
27 request.onupgradeneeded = upgradeNeeded;
28 request.onblocked = unexpectedBlockedCallback;
32 var sawUpgradeNeeded = false;
33 var sawTransactionComplete = false;
34 function upgradeNeeded(evt)
37 testPassed("In the upgradeneeded event hander:");
38 debug("Test 4.8.9.1:");
39 evalAndLog("db = event.target.result");
40 shouldBeEqualToString("String(db)", "[object IDBDatabase]");
41 debug("Test 4.8.9.3:");
42 shouldBe("event.oldVersion", "0");
43 shouldBe("event.newVersion", "7");
44 shouldBeEqualToString("event.target.readyState", "done");
46 shouldBe("db.name", "dbname");
47 shouldBe("db.version", "7");
48 shouldBe("db.objectStoreNames.length", "0");
50 evalAndLog("transaction = event.target.transaction");
51 shouldBeEqualToString("String(transaction)", "[object IDBTransaction]");
52 evalAndLog('os = db.createObjectStore("someOS")');
53 transaction.onabort = unexpectedAbortCallback;
54 transaction.oncomplete = function(e) {
55 evalAndLog("sawTransactionComplete = true");
57 sawUpgradeNeeded = true;
60 function openSuccess(evt)
64 debug("openSuccess():");
65 debug("Test 4.1.7, that a versionchange transaction was run.");
66 shouldBe("sawUpgradeNeeded", "true");
67 shouldBeTrue("sawTransactionComplete");
68 db = evalAndLog("db = event.target.result");
69 debug("Kind of test 4.1.9:");
70 shouldBeEqualToString("String(db)", "[object IDBDatabase]");
71 shouldBe('db.version', "7");