OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../../resources/js-test.js"></script> | 2 <title>IndexedDB: Verify transaction activation behavior around microtasks</titl
e> |
3 <script src="resources/shared.js"></script> | 3 <script src="../../resources/testharness.js"></script> |
4 <script src="resources/key-type-binary.js"></script> | 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script src="resources/testharness-helpers.js"></script> |
| 6 <script> |
| 7 var sample = [0x44, 0x33, 0x22, 0x11, 0xFF, 0xEE, 0xDD, 0xCC]; |
| 8 var buffer = new Uint8Array(sample).buffer; |
| 9 |
| 10 function assert_key_valid(a, message) { |
| 11 assert_equals(indexedDB.cmp(a, a), 0, message); |
| 12 } |
| 13 |
| 14 function assert_buffer_equals(a, b, message) { |
| 15 assert_array_equals( |
| 16 [].slice.call(new Uint8Array(a)), |
| 17 [].slice.call(new Uint8Array(b)), |
| 18 message); |
| 19 } |
| 20 |
| 21 function check_key(t, db, key) { |
| 22 var tx = db.transaction('store', 'readwrite'); |
| 23 var store = tx.objectStore('store'); |
| 24 |
| 25 // Verify put with key |
| 26 var req = store.put('value', key); |
| 27 req.onerror = t.unreached_func('put should succeed'); |
| 28 |
| 29 // Verify get with key |
| 30 req = store.get(key); |
| 31 req.onerror = t.unreached_func('get should succeed'); |
| 32 req.onsuccess = t.step_func(function() { |
| 33 assert_equals(req.result, 'value', 'get with key should succeed'); |
| 34 |
| 35 // Verify iteration returning key |
| 36 req = store.openCursor(); |
| 37 req.onerror = t.unreached_func('openCursor should succeed'); |
| 38 req.onsuccess = t.step_func(function() { |
| 39 assert_not_equals(req.result, null, 'cursor should be present'); |
| 40 var found_key = req.result.key; |
| 41 assert_true(found_key instanceof ArrayBuffer, |
| 42 'Key should be an ArrayBuffer'); |
| 43 assert_key_equals(found_key, key, |
| 44 'Key should be equal to put key'); |
| 45 assert_buffer_equals( |
| 46 found_key, buffer, 'Buffers should be equal to put buffer'); |
| 47 |
| 48 t.done(); |
| 49 }); |
| 50 }); |
| 51 } |
| 52 |
| 53 function type_test(type) { |
| 54 indexeddb_test( |
| 55 function(t, db) { |
| 56 db.createObjectStore('store'); |
| 57 }, |
| 58 function(t, db) { |
| 59 var key = new self[type](buffer); |
| 60 assert_key_valid(key, type + ' should be a valid key'); |
| 61 assert_key_equals(key, buffer, |
| 62 'Keys should be equal regardless of type'); |
| 63 check_key(t, db, key); |
| 64 }, |
| 65 'Binary key: ' + type |
| 66 ); |
| 67 } |
| 68 |
| 69 [ |
| 70 'Uint8Array', |
| 71 'Uint8ClampedArray', |
| 72 'Int8Array', |
| 73 'Uint16Array', |
| 74 'Int16Array', |
| 75 'Uint32Array', |
| 76 'Int32Array', |
| 77 'Float32Array', |
| 78 'Float64Array' |
| 79 ].forEach(function(type) { type_test(type); }); |
| 80 |
| 81 function value_test(type, value) { |
| 82 indexeddb_test( |
| 83 function(t, db) { |
| 84 db.createObjectStore('store'); |
| 85 }, |
| 86 function(t, db) { |
| 87 assert_key_valid(value, type + ' should be a valid key'); |
| 88 check_key(t, db, value); |
| 89 t.done(); |
| 90 }, |
| 91 'Value test: ' + type |
| 92 ); |
| 93 } |
| 94 |
| 95 value_test('ArrayBuffer', buffer); |
| 96 value_test('DataView', new DataView(buffer)); |
| 97 value_test('Offset DataView', new DataView(buffer), 3, 3); |
| 98 value_test('Offset Uint8Array', new Uint8Array(buffer), 3, 3); |
| 99 </script> |
OLD | NEW |