1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test that blocked events get delivered properly with the new open api");
11 request = evalAndLog("indexedDB.deleteDatabase(dbname)");
12 request.onsuccess = deleteSuccess;
13 request.onerror = unexpectedErrorCallback;
16 function deleteSuccess(evt) {
18 evalAndLog("request = indexedDB.open(dbname, 2)");
19 request.onsuccess = firstSuccessEventHandler;
20 request.onblocked = unexpectedBlockedCallback;
21 request.onerror = unexpectedErrorCallback;
22 gotFirstUpgradeNeededEvent = false;
23 request.onupgradeneeded = firstUpgradeNeededCallback;
26 function firstUpgradeNeededCallback(evt)
29 evalAndLog("gotFirstUpgradeNeededEvent = true");
30 shouldBe("event.oldVersion", "0");
31 shouldBe("event.newVersion", "2");
32 shouldBeEqualToString("String(event)", "[object IDBVersionChangeEvent]");
35 gotBlockedEvent = false;
36 function firstSuccessEventHandler(evt)
39 shouldBeTrue("gotFirstUpgradeNeededEvent");
40 evalAndLog("connection1 = event.target.result");
41 evalAndLog("connection1.onversionchange = versionChangeHandler");
42 shouldBeEqualToString("String(connection1)", "[object IDBDatabase]");
43 evalAndLog("request = indexedDB.open(dbname, 3)");
44 request.onsuccess = secondSuccessCallback;
45 request.onerror = unexpectedErrorCallback;
46 request.onblocked = blockedEventHandler;
47 request.onupgradeneeded = secondUpgradeNeededEventHandler;
50 var sawVersionChangeEvent = false;
51 function versionChangeHandler(evt)
54 evalAndLog("sawVersionChangeEvent = true");
55 shouldBeEqualToString("event.type", "versionchange");
56 shouldBeEqualToString("String(event)", "[object IDBVersionChangeEvent]");
57 shouldBe("event.target", "connection1");
58 shouldBe("event.oldVersion", "2");
59 shouldBe("event.newVersion", "3");
62 function blockedEventHandler(evt)
65 shouldBeTrue("sawVersionChangeEvent");
66 evalAndLog("gotBlockedEvent = true");
67 shouldBeEqualToString("String(event)", "[object IDBVersionChangeEvent]");
68 shouldBe("event.oldVersion", "2");
69 shouldBe("event.newVersion", "3");
70 shouldBeEqualToString("event.type", "blocked");
71 evalAndLog("connection1.close()");
74 gotSecondUpgradeNeededEvent = false;
75 function secondUpgradeNeededEventHandler(evt)
78 shouldBeTrue("gotBlockedEvent");
79 evalAndLog("gotSecondUpgradeNeededEvent = true");
82 function secondSuccessCallback(evt)
85 shouldBeTrue("gotSecondUpgradeNeededEvent");