blob: 3288506c5058851af2174d4f897542fe5fd749b0 [file] [log] [blame]
Odin Hørthe Omdal74babb42012-07-02 14:11:491<!DOCTYPE html>
Odin Hørthe Omdal41424a72012-08-15 18:21:142<title>Blocked event</title>
Xie Yunxiaoe027b492014-04-09 07:20:333<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
Odin Hørthe Omdal74babb42012-07-02 14:11:494<script src="/resources/testharness.js"></script>
5<script src="/resources/testharnessreport.js"></script>
6<script src="support.js"></script>
7
8<div id="log"></div>
9
10<script>
11
12 var db, db_got_versionchange, db2,
13 events = [],
Odin Hørthe Omdal8732d852012-10-08 09:40:5514 t = async_test(document.title, {timeout: 10000});
Odin Hørthe Omdal74babb42012-07-02 14:11:4915
16 t.step(function() {
17 var openrq = indexedDB.open('db', 3);
18
19 // 1
20 openrq.onupgradeneeded = t.step_func(function(e) {
21 events.push("open." + e.type);
Odin Hørthe Omdal74babb42012-07-02 14:11:4922 e.target.result.createObjectStore('store');
23 });
24
25 // 2
26 openrq.onsuccess = t.step_func(function(e) {
27 db = e.target.result;
28
29 events.push("open." + e.type);
Odin Hørthe Omdal74babb42012-07-02 14:11:4930
31 // 3
32 db.onversionchange = t.step_func(function(e) {
33 events.push("db." + e.type);
Zhiqiang Zhang24f22982013-12-17 08:20:0234
Odin Hørthe Omdal74babb42012-07-02 14:11:4935 assert_equals(e.oldVersion, 3, "old version");
Odin Hørthe Omdal41424a72012-08-15 18:21:1436 assert_equals(e.newVersion, 4, "new version");
37 // Do not close db here (as we should)
Odin Hørthe Omdal74babb42012-07-02 14:11:4938 });
39
40 // Errors
41 db.onerror = fail(t, "db.error");
42 db.abort = fail(t, "db.abort");
43
44 setTimeout(t.step_func(OpenSecond), 10);
45 });
46
47 // Errors
48 openrq.onerror = fail(t, "open.error");
49 openrq.onblocked = fail(t, "open.blocked");
50
51 });
52
53 function OpenSecond (e) {
54 assert_equals(db2, undefined);
55 assert_equals(db + "", "[object IDBDatabase]");
56 assert_array_equals(db.objectStoreNames, [ "store" ]);
57
Odin Hørthe Omdal74babb42012-07-02 14:11:4958 var openrq2 = indexedDB.open('db', 4);
59
60 // 4
Odin Hørthe Omdal41424a72012-08-15 18:21:1461 openrq2.onblocked = t.step_func(function(e) {
62 events.push("open2." + e.type);
63 // We're closing connection from the other open()
64 db.close();
65 });
66
67 // 5
Odin Hørthe Omdal74babb42012-07-02 14:11:4968 openrq2.onupgradeneeded = t.step_func(function(e) {
69 db2 = e.target.result;
70
71 events.push("open2." + e.type);
Odin Hørthe Omdal74babb42012-07-02 14:11:4972
73 assert_equals(db2 + "", "[object IDBDatabase]");
74
75 // Errors
76 db2.onversionchange = fail(t, "db2.versionchange");
77 db2.onerror = fail(t, "db2.error");
78 db2.abort = fail(t, "db2.abort");
79 });
80
Odin Hørthe Omdal41424a72012-08-15 18:21:1481 // 6
Odin Hørthe Omdal74babb42012-07-02 14:11:4982 openrq2.onsuccess = t.step_func(function(e) {
83 events.push("open2." + e.type);
Odin Hørthe Omdal74babb42012-07-02 14:11:4984
85 assert_array_equals(events,
86 [ "open.upgradeneeded",
87 "open.success",
88 "db.versionchange",
Odin Hørthe Omdal41424a72012-08-15 18:21:1489 "open2.blocked",
Odin Hørthe Omdal74babb42012-07-02 14:11:4990 "open2.upgradeneeded",
91 "open2.success",
92 ]);
93
94 setTimeout(function() { t.done(); }, 10);
95 });
96
97 // Errors
98 openrq2.onerror = fail(t, "open2.error");
Odin Hørthe Omdal74babb42012-07-02 14:11:4999 }
100
101
102 // Cleanup
103 add_completion_callback(function(tests) {
Odin Hørthe Omdal41424a72012-08-15 18:21:14104 if (db2) db2.close();
Odin Hørthe Omdal74babb42012-07-02 14:11:49105 indexedDB.deleteDatabase('db');
Odin Hørthe Omdal74babb42012-07-02 14:11:49106 })
107
108</script>