OLD | NEW |
---|---|
(Empty) | |
1 if (this.importScripts) { | |
2 importScripts('../../../resources/testharness.js'); | |
3 importScripts('../../../resources/generic-idb-operations.js'); | |
4 } | |
5 | |
6 async_test(function(t) { | |
7 var dbname = location.pathname + ' - ' + 'unobserve before tx completes'; | |
8 var openRequest = indexedDB.open(dbname); | |
9 var obs = new IDBObserver(t.unreached_func('Observer callback should not be fi red'), { operationTypes: ['put'] }); | |
10 | |
11 openRequest.onupgradeneeded = t.step_func(function() { | |
12 createDatabase(openRequest.result, ['store']); | |
13 }); | |
14 openRequest.onsuccess = t.step_func(function() { | |
cmumford
2016/07/21 15:00:56
Add onerror.
| |
15 var db = openRequest.result; | |
16 var tx1 = db.transaction('store'); | |
17 var tx2 = db.transaction('store', 'readwrite'); | |
18 tx1.objectStore('store').get(1); | |
19 tx2.objectStore('store').put(1, 1); | |
20 obs.observe(db, tx1); | |
21 | |
22 tx1.onerror = t.unreached_func('transaction should not fail'); | |
23 tx2.oncomplete = t.step_func(function() { | |
24 t.done(); | |
25 }); | |
26 tx2.onerror = t.unreached_func('transaction should not fail') | |
27 obs.unobserve(db); | |
28 }); | |
29 }, 'Unobserve before associated transaction completes'); | |
30 | |
31 async_test(function(t) { | |
32 var dbname = location.pathname + ' - ' + 'unobserve after tx completes'; | |
33 var openRequest = indexedDB.open(dbname); | |
34 var obs = new IDBObserver(t.unreached_func('Observer callback should not be fi red'), { operationTypes: ['put'] }); | |
35 | |
36 openRequest.onupgradeneeded = t.step_func(function() { | |
37 createDatabase(openRequest.result, ['store']); | |
38 }); | |
39 openRequest.onsuccess = t.step_func(function() { | |
40 var db = openRequest.result; | |
41 var tx1 = db.transaction('store'); | |
42 var tx2 = db.transaction('store', 'readwrite'); | |
43 tx1.objectStore('store').get(1); | |
44 tx2.objectStore('store').put(1, 1); | |
45 obs.observe(db, tx1); | |
46 | |
47 tx1.oncomplete = t.step_func(function() { | |
48 obs.unobserve(db); | |
49 }); | |
50 tx1.onerror = t.unreached_func('transaction should not fail'); | |
51 tx2.oncomplete = t.step_func(function() { | |
52 t.done(); | |
53 }); | |
54 tx2.onerror = t.unreached_func('transaction should not fail'); | |
55 }); | |
56 }, 'Unobserve after associated transaction completes'); | |
57 | |
58 async_test(function(t) { | |
59 var dbname = location.pathname + ' - ' + 'unobserve multiple observers'; | |
60 var openRequest = indexedDB.open(dbname); | |
61 var obs = new IDBObserver(t.unreached_func('Observer callback should not be fi red'), { operationTypes: ['put'] }); | |
62 openRequest.onupgradeneeded = t.step_func(function() { | |
63 createDatabase(openRequest.result, ['store']); | |
64 }); | |
65 openRequest.onsuccess = t.step_func(function() { | |
66 var db = openRequest.result; | |
67 var tx1 = db.transaction('store'); | |
68 var tx2 = db.transaction('store', 'readwrite'); | |
69 | |
70 tx2.objectStore('store').put(1, 1); | |
71 obs.observe(db, tx1); | |
72 obs.observe(db, tx1); // Multiple observe calls registered. | |
73 obs.observe(db, tx2); // Multiple observe calls registered. | |
74 obs.unobserve(db); | |
75 | |
76 tx1.onerror = t.unreached_func('transaction should not fail'); | |
77 tx2.onerror = t.unreached_func('transaction should not fail'); | |
78 tx2.oncomplete = t.step_func(function() { | |
79 t.done(); | |
80 }) | |
81 }); | |
82 }, 'Unobserve multiple observe calls on same database'); | |
83 | |
84 async_test(function(t) { | |
85 var dbname = location.pathname + ' - ' + 'unobserve non existant observers'; | |
86 var openRequest = indexedDB.open(dbname); | |
87 var obs = new IDBObserver(t.unreached_func('Observer callback should not be fi red'), { operationTypes: ['put'] }); | |
88 openRequest.onupgradeneeded = t.step_func(function() { | |
89 createDatabase(openRequest.result, ['store']); | |
90 }); | |
91 openRequest.onsuccess = t.step_func(function() { | |
92 var db = openRequest.result; | |
93 obs.unobserve(db); | |
94 t.done(); | |
95 }); | |
96 }, 'Unobserve non existant observer'); | |
97 | |
98 async_test(function(t) { | |
99 var dbname = location.pathname + ' - ' + 'connection close'; | |
100 var cnt1 = 0, cnt2 = 0; | |
101 var openRequest1 = indexedDB.open(dbname); | |
102 var obs1 = new IDBObserver(t.step_func(function() { cnt1++; }), { operationTyp es: ['put'] }); | |
103 var obs2 = new IDBObserver(t.step_func(function() { cnt2++; }), { operationTyp es: ['put'] }); | |
104 | |
105 openRequest1.onupgradeneeded = t.step_func(function() { | |
106 createDatabase(openRequest1.result, ['store']); | |
107 }); | |
108 openRequest1.onsuccess = t.step_func(function() { | |
109 var db1 = openRequest1.result; | |
110 var tx1 = db1.transaction('store', 'readwrite'); | |
111 var tx2 = db1.transaction('store', 'readwrite'); | |
112 tx1.objectStore('store').get(1); | |
113 tx2.objectStore('store').put(1, 1); | |
114 obs1.observe(db1, tx1); | |
115 obs2.observe(db1, tx2); | |
116 | |
117 tx1.oncomplete = t.step_func(function() { | |
118 countCallbacks(cnt1, 0); | |
119 countCallbacks(cnt2, 0); | |
120 }) | |
121 tx2.oncomplete = t.step_func(function() { | |
122 countCallbacks(cnt1, 1); | |
123 countCallbacks(cnt2, 0); | |
124 | |
125 db1.close(); | |
126 var openRequest2 = indexedDB.open(dbname); | |
127 openRequest2.onsuccess = t.step_func(function() { | |
128 var db2 = openRequest2.result; | |
129 var tx3 = db2.transaction('store', 'readwrite'); | |
130 tx3.objectStore('store').put(1, 1); | |
131 tx3.oncomplete = t.step_func(function() { | |
132 countCallbacks(cnt1, 1); | |
133 countCallbacks(cnt2, 0); | |
134 t.done(); | |
135 }); | |
136 tx3.onerror = t.unreached_func('transaction should not fail'); | |
137 }); | |
138 }); | |
139 tx1.onerror = t.unreached_func('transaction should not fail'); | |
140 tx2.onerror = t.unreached_func('transaction should not fail'); | |
141 }); | |
142 }, 'Remove observers on database close'); | |
143 | |
144 done(); | |
OLD | NEW |