| OLD | NEW |
| 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 } | 4 } |
| 4 | 5 |
| 5 function callback(){}; | 6 async_test(function(t) { |
| 7 var dbname = location.pathname + ' - ' + 'empty transaction'; |
| 8 var openRequest = indexedDB.open(dbname); |
| 9 var callback_count = 0; |
| 10 var obs = new IDBObserver(t.step_func(function() { callback_count++; }), {oper
ationTypes: ['put']}); |
| 11 openRequest.onupgradeneeded = t.step_func(function() { |
| 12 createDatabase(openRequest.result, ['store']); |
| 13 }); |
| 14 openRequest.onsuccess = t.step_func(function() { |
| 15 var db = openRequest.result; |
| 16 var tx1 = db.transaction('store', 'readwrite'); |
| 17 var tx2 = db.transaction('store', 'readwrite'); |
| 18 obs.observe(db, tx1); |
| 19 tx2.objectStore('store').put(1,1); |
| 20 tx1.oncomplete = t.step_func(function() { |
| 21 countCallbacks(callback_count, 0); |
| 22 }); |
| 23 tx2.oncomplete = t.step_func(function() { |
| 24 countCallbacks(callback_count, 1); |
| 25 t.done(); |
| 26 }); |
| 27 }); |
| 28 }, 'Registering observe call with empty transaction'); |
| 6 | 29 |
| 7 async_test(function(t) { | 30 async_test(function(t) { |
| 8 var description = 'observer addition and removal test'; | 31 var dbname = location.pathname + ' - ' + 'observer in version change'; |
| 9 var dbname = location.pathname + ' - ' + description; | |
| 10 var openRequest = indexedDB.open(dbname); | 32 var openRequest = indexedDB.open(dbname); |
| 11 var obs1 = new IDBObserver(callback, {transaction: true, values: true}); | 33 var callback_count = 0; |
| 12 var obs2 = new IDBObserver(callback, {transaction: true, values: true}); | 34 var obs; |
| 35 openRequest.onupgradeneeded = t.step_func(function() { |
| 36 createDatabase(openRequest.result, ['store']); |
| 37 obs = new IDBObserver(t.step_func(function() { callback_count++; }), { ope
rationTypes: ['put'] }); |
| 38 }); |
| 39 openRequest.onsuccess = t.step_func(function() { |
| 40 var db = openRequest.result; |
| 41 var tx1 = db.transaction('store', 'readwrite'); |
| 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 tx1.oncomplete = t.step_func(function() { |
| 47 countCallbacks(callback_count, 0); |
| 48 }); |
| 49 tx2.oncomplete = t.step_func(function() { |
| 50 countCallbacks(callback_count, 1); |
| 51 t.done(); |
| 52 }); |
| 53 }); |
| 54 }, 'Create IDBObserver during version change'); |
| 13 | 55 |
| 56 async_test(function(t) { |
| 57 var dbname = location.pathname + ' - ' + 'ignore observe call'; |
| 58 var openRequest = indexedDB.open(dbname); |
| 59 var callback_count = 0; |
| 60 var obs = new IDBObserver(t.step_func(function() { callback_count++; }), { ope
rationTypes: ['put'] }); |
| 14 openRequest.onupgradeneeded = t.step_func(function() { | 61 openRequest.onupgradeneeded = t.step_func(function() { |
| 15 var db = openRequest.result; | 62 var db = openRequest.result; |
| 16 db.createObjectStore('store'); | 63 db.createObjectStore('store'); |
| 64 obs.observe(db, openRequest.transaction); |
| 17 }); | 65 }); |
| 18 openRequest.onsuccess = t.step_func(function() { | 66 openRequest.onsuccess = t.step_func(function() { |
| 19 var db = openRequest.result; | 67 var db = openRequest.result; |
| 20 var tx = db.transaction('store', 'readwrite'); | 68 var tx = db.transaction('store', 'readwrite'); |
| 21 var store = tx.objectStore('store'); | 69 tx.objectStore('store').put(1,1); |
| 22 var put_request = store.put(1,1); | 70 tx.oncomplete = t.step_func(function() { |
| 23 obs1.observe(db, tx); | 71 countCallbacks(callback_count, 0); |
| 24 obs1.unobserve(db); | 72 t.done(); |
| 25 obs1.observe(db, tx); | 73 }); |
| 26 obs2.observe(db, tx); | 74 }); |
| 27 tx.oncomplete = t.step_func(function(){ | 75 }, 'Observe call during version change ignored'); |
| 28 obs1.unobserve(db); | |
| 29 t.done(); | |
| 30 }); | |
| 31 }); | |
| 32 }, 'observer addition and removal test'); | |
| 33 | 76 |
| 34 done(); | 77 async_test(function(t) { |
| 78 var dbname = location.pathname + ' - ' + 'abort associated transaction'; |
| 79 var openRequest = indexedDB.open(dbname); |
| 80 var callback_count = 0; |
| 81 var obs = new IDBObserver(t.step_func(function() { callback_count++; }), { ope
rationTypes: ['put'] }); |
| 82 openRequest.onupgradeneeded = t.step_func(function() { |
| 83 createDatabase(openRequest.result, ['store']); |
| 84 }); |
| 85 openRequest.onsuccess = t.step_func(function() { |
| 86 var db = openRequest.result; |
| 87 var tx1 = db.transaction('store', 'readwrite'); |
| 88 var tx2 = db.transaction('store', 'readwrite'); |
| 89 tx1.objectStore('store').get(1); |
| 90 tx2.objectStore('store').put(1,1); |
| 91 obs.observe(db, tx1); |
| 92 tx1.abort(); |
| 93 tx1.oncomplete = t.step_func(function() { |
| 94 countCallbacks(callback_count, 0); |
| 95 }); |
| 96 tx2.oncomplete = t.step_func(function() { |
| 97 countCallbacks(callback_count, 0); |
| 98 t.done(); |
| 99 }); |
| 100 }); |
| 101 }, 'Abort transaction associated with observer'); |
| 35 | 102 |
| 103 async_test(function(t) { |
| 104 var dbname = location.pathname + ' - ' + 'abort transaction'; |
| 105 var openRequest = indexedDB.open(dbname); |
| 106 var callback_count = 0; |
| 107 var obs = new IDBObserver(t.step_func(function() { callback_count++; }), { ope
rationTypes: ['put'] }); |
| 108 openRequest.onupgradeneeded = t.step_func(function() { |
| 109 createDatabase(openRequest.result, ['store']); |
| 110 }); |
| 111 openRequest.onsuccess = t.step_func(function() { |
| 112 var db = openRequest.result; |
| 113 var tx1 = db.transaction('store', 'readwrite'); |
| 114 var tx2 = db.transaction('store', 'readwrite'); |
| 115 var tx3 = db.transaction('store', 'readwrite'); |
| 116 tx1.objectStore('store').get(1); |
| 117 tx2.objectStore('store').put(1,1); |
| 118 tx3.objectStore('store').put(1,1); |
| 119 obs.observe(db, tx1); |
| 120 tx2.abort(); |
| 121 tx1.oncomplete = t.step_func(function() { |
| 122 countCallbacks(callback_count, 0); |
| 123 }); |
| 124 tx2.oncomplete = t.unreached_func('transaction should not complete'); |
| 125 tx2.onabort = t.step_func(function() { |
| 126 countCallbacks(callback_count, 0); |
| 127 }); |
| 128 tx3.oncomplete = t.step_func(function() { |
| 129 countCallbacks(callback_count, 1); |
| 130 t.done(); |
| 131 }); |
| 132 }); |
| 133 }, 'Abort transaction observer is recording'); |
| 134 |
| 135 done(); |
| OLD | NEW |