Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 if (this.importScripts) { | 1 if (this.importScripts) { |
| 2 importScripts('../../../resources/testharness.js'); | 2 importScripts('../../../resources/testharness.js'); |
| 3 importScripts('testharness-helpers.js'); | |
| 3 importScripts('generic-idb-operations.js'); | 4 importScripts('generic-idb-operations.js'); |
| 4 } | 5 } |
| 5 | 6 |
| 6 async_test(function(t) { | 7 async_test(function(t) { |
| 7 var dbname = location.pathname + ' - ' + 'empty transaction'; | 8 var dbname = location.pathname + ' - ' + 'empty transaction'; |
| 8 var openRequest = indexedDB.open(dbname); | 9 var obs = new IDBObserver(t.step_func(function() { |
|
pwnall
2017/01/10 01:41:11
I think you can save 2 lines by using fat arrows h
dmurph
2017/01/10 20:40:08
Done.
| |
| 9 var callback_count = 0; | 10 t.done(); |
| 10 var obs = new IDBObserver(t.step_func(function() { callback_count++; })); | 11 })); |
| 11 | 12 delete_then_open(t, dbname, function(t, db, request) { |
| 12 openRequest.onupgradeneeded = t.step_func(function() { | 13 db.createObjectStore('store'); |
| 13 openRequest.result.createObjectStore('store'); | 14 }, function(t, db) { |
| 14 }); | |
| 15 openRequest.onsuccess = t.step_func(function() { | |
| 16 var db = openRequest.result; | |
| 17 var tx1 = db.transaction('store', 'readwrite'); | 15 var tx1 = db.transaction('store', 'readwrite'); |
| 16 obs.observe(db, tx1, {operationTypes: ['put']}); | |
| 17 tx1.onerror = t.unreached_func('transaction should not fail'); | |
| 18 var tx2 = db.transaction('store', 'readwrite'); | 18 var tx2 = db.transaction('store', 'readwrite'); |
| 19 obs.observe(db, tx1, {operationTypes: ['put']}); | |
| 20 tx2.objectStore('store').put(1, 1); | 19 tx2.objectStore('store').put(1, 1); |
| 21 tx1.oncomplete = t.step_func(function() { | |
| 22 countCallbacks(callback_count, 0); | |
| 23 }); | |
| 24 tx2.oncomplete = t.step_func(function() { | |
| 25 countCallbacks(callback_count, 1); | |
| 26 t.done(); | |
| 27 }); | |
| 28 tx1.onerror = t.unreached_func('transaction should not fail'); | |
| 29 tx2.onerror = t.unreached_func('transaction should not fail'); | 20 tx2.onerror = t.unreached_func('transaction should not fail'); |
| 30 }); | 21 }); |
| 31 }, 'Registering observe call with empty transaction'); | 22 }, 'Registering observe call with empty transaction'); |
| 32 | 23 |
| 33 async_test(function(t) { | 24 async_test(function(t) { |
| 34 var dbname = location.pathname + ' - ' + 'observer in version change'; | 25 var dbname = location.pathname + ' - ' + 'observe in version change'; |
| 35 var openRequest = indexedDB.open(dbname); | 26 var obs = new IDBObserver(t.step_func(function(changes) { })); |
| 36 var callback_count = 0; | 27 |
| 37 var obs; | 28 delete_then_open(t, dbname, function(t, db, request) { |
| 38 openRequest.onupgradeneeded = t.step_func(function() { | 29 request.result.createObjectStore('store'); |
| 39 openRequest.result.createObjectStore('store'); | 30 assert_throws(null, function() { |
| 40 obs = new IDBObserver(t.step_func(function(changes) { callback_count++; }) ); | 31 obs.observe(db, request.transaction, { operationTypes: ['put'] }); |
| 41 }); | |
| 42 openRequest.onsuccess = t.step_func(function() { | |
| 43 var db = openRequest.result; | |
| 44 var tx1 = db.transaction('store', 'readwrite'); | |
| 45 var tx2 = db.transaction('store', 'readwrite'); | |
| 46 tx1.objectStore('store').get(1); | |
| 47 tx2.objectStore('store').put(1, 1); | |
| 48 obs.observe(db, tx1, { operationTypes: ['put'] }); | |
| 49 tx1.oncomplete = t.step_func(function() { | |
| 50 countCallbacks(callback_count, 0); | |
| 51 }); | 32 }); |
| 52 tx2.oncomplete = t.step_func(function() { | 33 t.done(); |
| 53 countCallbacks(callback_count, 1); | 34 }, function() {}); |
| 54 t.done(); | 35 }, 'Cannot observe during version change'); |
| 55 }); | |
| 56 tx1.onerror = t.unreached_func('transaction should not fail'); | |
| 57 tx2.onerror = t.unreached_func('transaction should not fail'); | |
| 58 }); | |
| 59 }, 'Create IDBObserver during version change'); | |
| 60 | |
| 61 async_test(function(t) { | |
| 62 var dbname = location.pathname + ' - ' + 'ignore observe call'; | |
| 63 var openRequest = indexedDB.open(dbname); | |
| 64 var callback_count = 0; | |
| 65 var obs = new IDBObserver(t.step_func(function() { callback_count++; })); | |
| 66 openRequest.onupgradeneeded = t.step_func(function() { | |
| 67 var db = openRequest.result; | |
| 68 db.createObjectStore('store'); | |
| 69 obs.observe(db, openRequest.transaction, { operationTypes: ['put'] }); | |
| 70 }); | |
| 71 openRequest.onsuccess = t.step_func(function() { | |
| 72 var db = openRequest.result; | |
| 73 var tx = db.transaction('store', 'readwrite'); | |
| 74 tx.objectStore('store').put(1, 1); | |
| 75 tx.oncomplete = t.step_func(function() { | |
| 76 countCallbacks(callback_count, 0); | |
| 77 t.done(); | |
| 78 }); | |
| 79 tx.onerror = t.unreached_func('transaction should not fail'); | |
| 80 }); | |
| 81 }, 'Observe call during version change ignored'); | |
| 82 | 36 |
| 83 async_test(function(t) { | 37 async_test(function(t) { |
| 84 var dbname = location.pathname + ' - ' + 'abort associated transaction'; | 38 var dbname = location.pathname + ' - ' + 'abort associated transaction'; |
| 85 var openRequest = indexedDB.open(dbname); | 39 var obs = new IDBObserver(t.unreached_func('Observe in aborted transaction sho uld be ignored')); |
| 86 var callback_count = 0; | 40 delete_then_open(t, dbname, function(t, db, request) { |
| 87 var obs = new IDBObserver(t.step_func(function() { callback_count++; })); | 41 request.result.createObjectStore('store'); |
| 88 openRequest.onupgradeneeded = t.step_func(function() { | 42 }, function(t, db) { |
| 89 openRequest.result.createObjectStore('store'); | |
| 90 }); | |
| 91 openRequest.onsuccess = t.step_func(function() { | |
| 92 var db = openRequest.result; | |
| 93 var tx1 = db.transaction('store', 'readwrite'); | 43 var tx1 = db.transaction('store', 'readwrite'); |
| 94 var tx2 = db.transaction('store', 'readwrite'); | |
| 95 tx1.objectStore('store').get(1); | 44 tx1.objectStore('store').get(1); |
| 96 tx2.objectStore('store').put(1, 1); | |
| 97 obs.observe(db, tx1, { operationTypes: ['put'] }); | 45 obs.observe(db, tx1, { operationTypes: ['put'] }); |
| 46 tx1.oncomplete = t.unreached_func('transaction should not complete'); | |
| 98 tx1.abort(); | 47 tx1.abort(); |
| 99 | 48 |
| 100 tx1.onabort = t.step_func(function(){ | 49 var tx2 = db.transaction('store', 'readwrite'); |
| 101 countCallbacks(callback_count, 0); | 50 tx2.objectStore('store').put(1, 1); |
| 102 }); | 51 tx2.onerror = t.unreached_func('transaction error should not fail'); |
| 103 tx1.oncomplete = t.unreached_func('transaction should not complete'); | |
| 104 tx2.oncomplete = t.step_func(function() { | 52 tx2.oncomplete = t.step_func(function() { |
| 105 countCallbacks(callback_count, 0); | |
| 106 t.done(); | 53 t.done(); |
| 107 }); | 54 }); |
| 108 tx2.onerror = t.unreached_func('transaction error should not fail'); | |
| 109 }); | 55 }); |
| 110 }, 'Abort transaction associated with observer'); | 56 }, 'Abort transaction associated with observer'); |
| 111 | 57 |
| 112 async_test(function(t) { | 58 async_test(function(t) { |
| 113 var dbname = location.pathname + ' - ' + 'abort transaction'; | 59 var dbname = location.pathname + ' - ' + 'abort transaction not recorded'; |
| 114 var openRequest = indexedDB.open(dbname); | |
| 115 var callback_count = 0; | 60 var callback_count = 0; |
| 116 var obs = new IDBObserver(t.step_func(function() { callback_count++; })); | 61 var obs = new IDBObserver(t.step_func(function(changes) { |
| 117 openRequest.onupgradeneeded = t.step_func(function() { | 62 assert_equals(changes.records.get('store')[0].key.lower, 1); |
| 118 openRequest.result.createObjectStore('store'); | 63 t.done(); |
| 119 }); | 64 })); |
| 120 openRequest.onsuccess = t.step_func(function() { | 65 |
| 121 var db = openRequest.result; | 66 delete_then_open(t, dbname, function(t, db, request) { |
| 67 request.result.createObjectStore('store'); | |
| 68 }, function(t, db) { | |
| 122 var tx1 = db.transaction('store', 'readwrite'); | 69 var tx1 = db.transaction('store', 'readwrite'); |
| 70 obs.observe(db, tx1, { operationTypes: ['put'] }); | |
| 71 tx1.onerror = t.unreached_func('transaction should not fail'); | |
| 72 | |
| 123 var tx2 = db.transaction('store', 'readwrite'); | 73 var tx2 = db.transaction('store', 'readwrite'); |
| 74 tx2.objectStore('store').put(2, 2); | |
| 75 tx2.oncomplete = t.unreached_func('transaction should not complete'); | |
| 76 tx2.abort(); | |
| 77 | |
| 124 var tx3 = db.transaction('store', 'readwrite'); | 78 var tx3 = db.transaction('store', 'readwrite'); |
| 125 tx1.objectStore('store').get(1); | |
| 126 tx2.objectStore('store').put(1, 1); | |
| 127 tx3.objectStore('store').put(1, 1); | 79 tx3.objectStore('store').put(1, 1); |
| 128 obs.observe(db, tx1, { operationTypes: ['put'] }); | |
| 129 tx2.abort(); | |
| 130 tx1.oncomplete = t.step_func(function() { | |
| 131 countCallbacks(callback_count, 0); | |
| 132 }); | |
| 133 tx2.oncomplete = t.unreached_func('transaction should not complete'); | |
| 134 tx2.onabort = t.step_func(function() { | |
| 135 countCallbacks(callback_count, 0); | |
| 136 }); | |
| 137 tx3.oncomplete = t.step_func(function() { | |
| 138 countCallbacks(callback_count, 1); | |
| 139 t.done(); | |
| 140 }); | |
| 141 tx1.onerror = t.unreached_func('transaction should not fail'); | |
| 142 tx3.onerror = t.unreached_func('transaction should not fail'); | 80 tx3.onerror = t.unreached_func('transaction should not fail'); |
| 143 }); | 81 }); |
| 144 }, 'Abort transaction recorded by observer'); | 82 }, 'Aborted transaction not recorded by observer'); |
| 145 | 83 |
| 146 done(); | 84 done(); |
| OLD | NEW |