| OLD | NEW |
| 1 function delete_then_open(t, db_name, upgrade_func, body_func) { |
| 2 var delete_request = indexedDB.deleteDatabase(db_name); |
| 3 delete_request.onerror = t.unreached_func('deleteDatabase should not fail'); |
| 4 delete_request.onsuccess = t.step_func(function(e) { |
| 5 var open_request = indexedDB.open(db_name); |
| 6 open_request.onupgradeneeded = t.step_func(function() { |
| 7 upgrade_func(t, open_request.result, open_request); |
| 8 }); |
| 9 open_request.onsuccess = t.step_func(function() { |
| 10 body_func(t, open_request.result); |
| 11 }); |
| 12 }); |
| 13 } |
| 14 |
| 1 function indexeddb_test(upgrade_func, body_func, description) { | 15 function indexeddb_test(upgrade_func, body_func, description) { |
| 2 async_test(function(t) { | 16 async_test(function(t) { |
| 3 var dbName = 'db' + self.location.pathname + '-' + description; | 17 var db_name = 'db' + self.location.pathname + '-' + description; |
| 4 var delete_request = indexedDB.deleteDatabase(dbName); | 18 delete_then_open(t, db_name, upgrade_func, body_func); |
| 5 delete_request.onerror = t.unreached_func('deleteDatabase should not fail'); | |
| 6 delete_request.onsuccess = t.step_func(function(e) { | |
| 7 var open_request = indexedDB.open(dbName); | |
| 8 open_request.onerror = t.unreached_func('open should not fail'); | |
| 9 open_request.onupgradeneeded = t.step_func(function(e) { | |
| 10 upgrade_func(t, open_request.result, open_request); | |
| 11 }); | |
| 12 open_request.onsuccess = t.step_func(function(e) { | |
| 13 body_func(t, open_request.result); | |
| 14 }); | |
| 15 }); | |
| 16 }, description); | 19 }, description); |
| 17 } | 20 } |
| 18 | 21 |
| 19 function assert_key_equals(a, b, message) { | 22 function assert_key_equals(a, b, message) { |
| 20 assert_equals(indexedDB.cmp(a, b), 0, message); | 23 assert_equals(indexedDB.cmp(a, b), 0, message); |
| 21 } | 24 } |
| 22 | 25 |
| 23 // Call with a Test and an array of expected results in order. Returns | 26 // Call with a Test and an array of expected results in order. Returns |
| 24 // a function; call the function when a result arrives and when the | 27 // a function; call the function when a result arrives and when the |
| 25 // expected number appear the order will be asserted and test | 28 // expected number appear the order will be asserted and test |
| 26 // completed. | 29 // completed. |
| 27 function expect(t, expected) { | 30 function expect(t, expected) { |
| 28 var results = []; | 31 var results = []; |
| 29 return result => { | 32 return result => { |
| 30 results.push(result); | 33 results.push(result); |
| 31 if (results.length === expected.length) { | 34 if (results.length === expected.length) { |
| 32 assert_array_equals(results, expected); | 35 assert_array_equals(results, expected); |
| 33 t.done(); | 36 t.done(); |
| 34 } | 37 } |
| 35 }; | 38 }; |
| 36 } | 39 } |
| 40 |
| 41 // Creates a barrier that one calls |
| 42 function create_barrier(callback) { |
| 43 var count = 0; |
| 44 var called = false; |
| 45 return function(t) { |
| 46 assert_false(called, "Barrier already used."); |
| 47 ++count; |
| 48 return t.step_func(function() { |
| 49 --count; |
| 50 if (count === 0) { |
| 51 assert_false(called, "Barrier already used."); |
| 52 called = true; |
| 53 callback(); |
| 54 } |
| 55 }); |
| 56 } |
| 57 } |
| OLD | NEW |