1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Upgrade a database, open a second connection at the same version, ensure specifying a lower version causes an error");
12 request = evalAndLog("indexedDB.deleteDatabase(dbname)");
13 shouldBeEqualToString("String(request)", "[object IDBOpenDBRequest]");
14 request.onsuccess = deleteSuccess;
15 request.onerror = unexpectedErrorCallback;
18 function deleteSuccess(evt) {
20 debug("Call open with no version parameter:");
21 request = evalAndLog("indexedDB.open(dbname)");
22 request.onsuccess = openSuccess;
23 request.onerror = unexpectedErrorCallback;
24 request.onupgradeneeded = initialUpgradeNeeded;
25 request.onblocked = unexpectedBlockedCallback;
28 function initialUpgradeNeeded(evt)
33 function openSuccess(evt)
36 evalAndLog("connection1 = event.target.result");
37 shouldBe("connection1.version", "1");
38 evalAndLog("connection1.onversionchange = connection1VersionChangeCallback");
39 evalAndLog("request = indexedDB.open(dbname, 2)");
40 request.onupgradeneeded = connection2UpgradeNeeded;
41 request.onerror = unexpectedErrorCallback;
42 request.onblocked = unexpectedBlockedCallback;
43 request.onsuccess = connection2Success;
46 function connection1VersionChangeCallback(evt)
49 evalAndLog("connection1.close()");
52 function connection2UpgradeNeeded(evt)
55 evalAndLog("connection2 = event.target.result");
56 shouldBeEqualToString("String(connection2)", "[object IDBDatabase]");
57 shouldBeEqualToString("String(request.transaction)", "[object IDBTransaction]");
58 shouldBe("event.oldVersion", "1");
59 shouldBe("event.newVersion", "2");
60 evalAndLog("request.transaction.oncomplete = transactionCompleted");
61 request.transaction.onabort = unexpectedAbortCallback;
64 var didTransactionComplete = false;
65 function transactionCompleted(evt)
68 evalAndLog("didTransactionComplete = true");
71 function connection2Success(evt)
74 shouldBeTrue("didTransactionComplete");
75 shouldBe("event.target.result", "connection2");
76 debug("The next connection opens the database at the same version so connection2 shouldn't get a versionchange event.");
77 evalAndLog("connection2.onversionchange = unexpectedVersionChangeCallback");
78 shouldBeEqualToString("String(connection2)", "[object IDBDatabase]");
79 shouldBeNull("request.transaction");
80 shouldBe("connection2.version", "2");
81 evalAndLog("request = indexedDB.open(dbname, 2)");
82 evalAndLog("request.onsuccess = connection3Success");
83 evalAndLog("request.onblocked = unexpectedBlockedCallback");
84 request.onerror = unexpectedErrorCallback;
87 function connection3Success(evt)
90 evalAndLog("event.target.result.close()");
91 evalAndLog("connection2.close()");
92 evalAndLog("connection3 = event.target.result");
93 shouldBe("connection3.version", "2");
94 evalAndLog("request = indexedDB.open(dbname, 1)");
95 evalAndLog("request.onerror = errorWhenTryingLowVersion");
96 request.onblocked = unexpectedBlockedCallback;
97 request.onsuccess = unexpectedSuccessCallback;
98 request.onupgradeneeded = unexpectedUpgradeNeededCallback;
101 function errorWhenTryingLowVersion(evt)
104 debug("request.error.message = " + request.error.message);
105 evalAndLog("request = indexedDB.open(dbname, 4)");
106 request.onblocked = unexpectedBlockedCallback;
107 request.onerror = unexpectedErrorCallback;
108 evalAndLog("request.onupgradeneeded = connection4UpgradeNeeded");
109 evalAndLog("request.onsuccess = connection4Success");
112 var gotConnection4UpgradeNeeded = false;
113 function connection4UpgradeNeeded(evt)
116 evalAndLog("gotConnection4UpgradeNeeded = true");
117 shouldBe("event.oldVersion", "2");
118 shouldBe("event.newVersion", "4");
121 function connection4Success(evt)
124 shouldBeTrue("gotConnection4UpgradeNeeded");
125 evalAndLog("connection4 = event.target.result");
126 shouldBe("connection4.version", "4");
127 evalAndLog("connection4.close()");
128 evalAndLog("request = indexedDB.open(dbname)");
129 evalAndLog("request.onsuccess = connection5Success");
130 request.onblocked = unexpectedBlockedCallback;
131 request.onupgradeneeded = unexpectedUpgradeNeededCallback;
132 request.onerror = unexpectedUpgradeNeededCallback;
135 function connection5Success(evt)
138 evalAndLog("db = event.target.result");
139 shouldBe("db.version", "4");