Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: third_party/WebKit/LayoutTests/storage/indexeddb/resources/observer.js

Issue 1362953003: Fire window.onerror for uncaught IndexedDB errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 if (this.importScripts) { 1 if (this.importScripts) {
2 importScripts('../../../resources/testharness.js'); 2 importScripts('../../../resources/testharness.js');
3 importScripts('generic-idb-operations.js'); 3 importScripts('generic-idb-operations.js');
4 } 4 }
5 5
6 async_test(function(t) { 6 async_test(function(t) {
7 var dbname = location.pathname + ' - ' + 'empty transaction'; 7 var dbname = location.pathname + ' - ' + 'empty transaction';
8 indexedDB.deleteDatabase(dbname);
8 var openRequest = indexedDB.open(dbname); 9 var openRequest = indexedDB.open(dbname);
9 var callback_count = 0; 10 var callback_count = 0;
10 var obs = new IDBObserver(t.step_func(function() { callback_count++; })); 11 var obs = new IDBObserver(t.step_func(function() { callback_count++; }));
11 12
12 openRequest.onupgradeneeded = t.step_func(function() { 13 openRequest.onupgradeneeded = t.step_func(function() {
13 openRequest.result.createObjectStore('store'); 14 openRequest.result.createObjectStore('store');
14 }); 15 });
15 openRequest.onsuccess = t.step_func(function() { 16 openRequest.onsuccess = t.step_func(function() {
16 var db = openRequest.result; 17 var db = openRequest.result;
17 var tx1 = db.transaction('store', 'readwrite'); 18 var tx1 = db.transaction('store', 'readwrite');
18 var tx2 = db.transaction('store', 'readwrite'); 19 var tx2 = db.transaction('store', 'readwrite');
19 obs.observe(db, tx1, {operationTypes: ['put']}); 20 obs.observe(db, tx1, {operationTypes: ['put']});
20 tx2.objectStore('store').put(1, 1); 21 tx2.objectStore('store').put(1, 1);
21 tx1.oncomplete = t.step_func(function() { 22 tx1.oncomplete = t.step_func(function() {
22 countCallbacks(callback_count, 0); 23 countCallbacks(callback_count, 0);
23 }); 24 });
24 tx2.oncomplete = t.step_func(function() { 25 tx2.oncomplete = t.step_func(function() {
25 countCallbacks(callback_count, 1); 26 countCallbacks(callback_count, 1);
26 t.done(); 27 t.done();
27 }); 28 });
28 tx1.onerror = t.unreached_func('transaction should not fail'); 29 tx1.onerror = t.unreached_func('transaction should not fail');
29 tx2.onerror = t.unreached_func('transaction should not fail'); 30 tx2.onerror = t.unreached_func('transaction should not fail');
30 }); 31 });
31 }, 'Registering observe call with empty transaction'); 32 }, 'Registering observe call with empty transaction');
32 33
33 async_test(function(t) { 34 async_test(function(t) {
34 var dbname = location.pathname + ' - ' + 'observer in version change'; 35 var dbname = location.pathname + ' - ' + 'observer in version change';
36 indexedDB.deleteDatabase(dbname);
35 var openRequest = indexedDB.open(dbname); 37 var openRequest = indexedDB.open(dbname);
36 var callback_count = 0; 38 var callback_count = 0;
37 var obs; 39 var obs;
38 openRequest.onupgradeneeded = t.step_func(function() { 40 openRequest.onupgradeneeded = t.step_func(function() {
39 openRequest.result.createObjectStore('store'); 41 openRequest.result.createObjectStore('store');
40 obs = new IDBObserver(t.step_func(function(changes) { callback_count++; }) ); 42 obs = new IDBObserver(t.step_func(function(changes) { callback_count++; }) );
41 }); 43 });
42 openRequest.onsuccess = t.step_func(function() { 44 openRequest.onsuccess = t.step_func(function() {
43 var db = openRequest.result; 45 var db = openRequest.result;
44 var tx1 = db.transaction('store', 'readwrite'); 46 var tx1 = db.transaction('store', 'readwrite');
45 var tx2 = db.transaction('store', 'readwrite'); 47 var tx2 = db.transaction('store', 'readwrite');
46 tx1.objectStore('store').get(1); 48 tx1.objectStore('store').get(1);
47 tx2.objectStore('store').put(1, 1); 49 tx2.objectStore('store').put(1, 1);
48 obs.observe(db, tx1, { operationTypes: ['put'] }); 50 obs.observe(db, tx1, { operationTypes: ['put'] });
49 tx1.oncomplete = t.step_func(function() { 51 tx1.oncomplete = t.step_func(function() {
50 countCallbacks(callback_count, 0); 52 countCallbacks(callback_count, 0);
51 }); 53 });
52 tx2.oncomplete = t.step_func(function() { 54 tx2.oncomplete = t.step_func(function() {
53 countCallbacks(callback_count, 1); 55 countCallbacks(callback_count, 1);
54 t.done(); 56 t.done();
55 }); 57 });
56 tx1.onerror = t.unreached_func('transaction should not fail'); 58 tx1.onerror = t.unreached_func('transaction should not fail');
57 tx2.onerror = t.unreached_func('transaction should not fail'); 59 tx2.onerror = t.unreached_func('transaction should not fail');
58 }); 60 });
59 }, 'Create IDBObserver during version change'); 61 }, 'Create IDBObserver during version change');
60 62
61 async_test(function(t) { 63 async_test(function(t) {
62 var dbname = location.pathname + ' - ' + 'ignore observe call'; 64 var dbname = location.pathname + ' - ' + 'ignore observe call';
65 indexedDB.deleteDatabase(dbname);
63 var openRequest = indexedDB.open(dbname); 66 var openRequest = indexedDB.open(dbname);
64 var callback_count = 0; 67 var callback_count = 0;
65 var obs = new IDBObserver(t.step_func(function() { callback_count++; })); 68 var obs = new IDBObserver(t.step_func(function() { callback_count++; }));
66 openRequest.onupgradeneeded = t.step_func(function() { 69 openRequest.onupgradeneeded = t.step_func(function() {
67 var db = openRequest.result; 70 var db = openRequest.result;
68 db.createObjectStore('store'); 71 db.createObjectStore('store');
69 obs.observe(db, openRequest.transaction, { operationTypes: ['put'] }); 72 obs.observe(db, openRequest.transaction, { operationTypes: ['put'] });
70 }); 73 });
71 openRequest.onsuccess = t.step_func(function() { 74 openRequest.onsuccess = t.step_func(function() {
72 var db = openRequest.result; 75 var db = openRequest.result;
73 var tx = db.transaction('store', 'readwrite'); 76 var tx = db.transaction('store', 'readwrite');
74 tx.objectStore('store').put(1, 1); 77 tx.objectStore('store').put(1, 1);
75 tx.oncomplete = t.step_func(function() { 78 tx.oncomplete = t.step_func(function() {
76 countCallbacks(callback_count, 0); 79 countCallbacks(callback_count, 0);
77 t.done(); 80 t.done();
78 }); 81 });
79 tx.onerror = t.unreached_func('transaction should not fail'); 82 tx.onerror = t.unreached_func('transaction should not fail');
80 }); 83 });
81 }, 'Observe call during version change ignored'); 84 }, 'Observe call during version change ignored');
82 85
83 async_test(function(t) { 86 async_test(function(t) {
84 var dbname = location.pathname + ' - ' + 'abort associated transaction'; 87 var dbname = location.pathname + ' - ' + 'abort associated transaction';
88 indexedDB.deleteDatabase(dbname);
85 var openRequest = indexedDB.open(dbname); 89 var openRequest = indexedDB.open(dbname);
86 var callback_count = 0; 90 var callback_count = 0;
87 var obs = new IDBObserver(t.step_func(function() { callback_count++; })); 91 var obs = new IDBObserver(t.step_func(function() { callback_count++; }));
88 openRequest.onupgradeneeded = t.step_func(function() { 92 openRequest.onupgradeneeded = t.step_func(function() {
89 openRequest.result.createObjectStore('store'); 93 openRequest.result.createObjectStore('store');
90 }); 94 });
91 openRequest.onsuccess = t.step_func(function() { 95 openRequest.onsuccess = t.step_func(function() {
92 var db = openRequest.result; 96 var db = openRequest.result;
97
98 // Prevent propagation to global error handler.
99 db.onerror = e => { e.preventDefault(); };
100
93 var tx1 = db.transaction('store', 'readwrite'); 101 var tx1 = db.transaction('store', 'readwrite');
94 var tx2 = db.transaction('store', 'readwrite'); 102 var tx2 = db.transaction('store', 'readwrite');
95 tx1.objectStore('store').get(1); 103 tx1.objectStore('store').get(1);
96 tx2.objectStore('store').put(1, 1); 104 tx2.objectStore('store').put(1, 1);
97 obs.observe(db, tx1, { operationTypes: ['put'] }); 105 obs.observe(db, tx1, { operationTypes: ['put'] });
98 tx1.abort(); 106 tx1.abort();
99 107
100 tx1.onabort = t.step_func(function(){ 108 tx1.onabort = t.step_func(function(){
101 countCallbacks(callback_count, 0); 109 countCallbacks(callback_count, 0);
102 }); 110 });
103 tx1.oncomplete = t.unreached_func('transaction should not complete'); 111 tx1.oncomplete = t.unreached_func('transaction should not complete');
104 tx2.oncomplete = t.step_func(function() { 112 tx2.oncomplete = t.step_func(function() {
105 countCallbacks(callback_count, 0); 113 countCallbacks(callback_count, 0);
106 t.done(); 114 t.done();
107 }); 115 });
108 tx2.onerror = t.unreached_func('transaction error should not fail'); 116 tx2.onerror = t.unreached_func('transaction error should not fail');
109 }); 117 });
110 }, 'Abort transaction associated with observer'); 118 }, 'Abort transaction associated with observer');
111 119
112 async_test(function(t) { 120 async_test(function(t) {
113 var dbname = location.pathname + ' - ' + 'abort transaction'; 121 var dbname = location.pathname + ' - ' + 'abort transaction';
122 indexedDB.deleteDatabase(dbname);
114 var openRequest = indexedDB.open(dbname); 123 var openRequest = indexedDB.open(dbname);
115 var callback_count = 0; 124 var callback_count = 0;
116 var obs = new IDBObserver(t.step_func(function() { callback_count++; })); 125 var obs = new IDBObserver(t.step_func(function() { callback_count++; }));
117 openRequest.onupgradeneeded = t.step_func(function() { 126 openRequest.onupgradeneeded = t.step_func(function() {
118 openRequest.result.createObjectStore('store'); 127 openRequest.result.createObjectStore('store');
119 }); 128 });
120 openRequest.onsuccess = t.step_func(function() { 129 openRequest.onsuccess = t.step_func(function() {
121 var db = openRequest.result; 130 var db = openRequest.result;
131
132 // Prevent propagation to global error handler.
133 db.onerror = e => { e.preventDefault(); };
134
122 var tx1 = db.transaction('store', 'readwrite'); 135 var tx1 = db.transaction('store', 'readwrite');
123 var tx2 = db.transaction('store', 'readwrite'); 136 var tx2 = db.transaction('store', 'readwrite');
124 var tx3 = db.transaction('store', 'readwrite'); 137 var tx3 = db.transaction('store', 'readwrite');
125 tx1.objectStore('store').get(1); 138 tx1.objectStore('store').get(1);
126 tx2.objectStore('store').put(1, 1); 139 tx2.objectStore('store').put(1, 1);
127 tx3.objectStore('store').put(1, 1); 140 tx3.objectStore('store').put(1, 1);
128 obs.observe(db, tx1, { operationTypes: ['put'] }); 141 obs.observe(db, tx1, { operationTypes: ['put'] });
129 tx2.abort(); 142 tx2.abort();
130 tx1.oncomplete = t.step_func(function() { 143 tx1.oncomplete = t.step_func(function() {
131 countCallbacks(callback_count, 0); 144 countCallbacks(callback_count, 0);
132 }); 145 });
133 tx2.oncomplete = t.unreached_func('transaction should not complete'); 146 tx2.oncomplete = t.unreached_func('transaction should not complete');
134 tx2.onabort = t.step_func(function() { 147 tx2.onabort = t.step_func(function() {
135 countCallbacks(callback_count, 0); 148 countCallbacks(callback_count, 0);
136 }); 149 });
137 tx3.oncomplete = t.step_func(function() { 150 tx3.oncomplete = t.step_func(function() {
138 countCallbacks(callback_count, 1); 151 countCallbacks(callback_count, 1);
139 t.done(); 152 t.done();
140 }); 153 });
141 tx1.onerror = t.unreached_func('transaction should not fail'); 154 tx1.onerror = t.unreached_func('transaction should not fail');
142 tx3.onerror = t.unreached_func('transaction should not fail'); 155 tx3.onerror = t.unreached_func('transaction should not fail');
143 }); 156 });
144 }, 'Abort transaction recorded by observer'); 157 }, 'Abort transaction recorded by observer');
145 158
146 done(); 159 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698