1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
<!DOCTYPE html>
<title>Test events opening a second database when one connection is open already</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db, db_got_versionchange, db2,
events = [],
t = async_test(document.title, {timeout: 10000});
t.step(function() {
var openrq = indexedDB.open('db', 3);
// 1
openrq.onupgradeneeded = t.step_func(function(e) {
events.push("open." + e.type);
e.target.result.createObjectStore('store');
});
// 2
openrq.onsuccess = t.step_func(function(e) {
db = e.target.result;
events.push("open." + e.type);
// 3
db.onversionchange = t.step_func(function(e) {
events.push("db." + e.type);
assert_equals(e.oldVersion, 3, "old version");
assert_equals(e.newVersion, 4, "new version");
db.close();
});
// Errors
db.onerror = fail(t, "db.error");
db.abort = fail(t, "db.abort");
setTimeout(t.step_func(OpenSecond), 10);
});
// Errors
openrq.onerror = fail(t, "open.error");
openrq.onblocked = fail(t, "open.blocked");
});
function OpenSecond (e) {
assert_equals(db2, undefined);
assert_equals(db + "", "[object IDBDatabase]");
assert_array_equals(db.objectStoreNames, [ "store" ]);
var openrq2 = indexedDB.open('db', 4);
// 4
openrq2.onupgradeneeded = t.step_func(function(e) {
db2 = e.target.result;
events.push("open2." + e.type);
assert_equals(db2 + "", "[object IDBDatabase]");
// Errors
db2.onversionchange = fail(t, "db2.versionchange");
db2.onerror = fail(t, "db2.error");
db2.abort = fail(t, "db2.abort");
});
// 5
openrq2.onsuccess = t.step_func(function(e) {
events.push("open2." + e.type);
assert_array_equals(events,
[ "open.upgradeneeded",
"open.success",
"db.versionchange",
"open2.upgradeneeded",
"open2.success",
]);
setTimeout(function() { t.done(); }, 10);
});
// Errors
openrq2.onerror = fail(t, "open2.error");
openrq2.onblocked = fail(t, "open2.blocked");
}
// Cleanup
add_completion_callback(function(tests) {
if (db2) db2.close();
indexedDB.deleteDatabase('db');
})
</script>
|