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); | |
cmumford
2015/04/27 17:14:23
expected is first.
jsbell
2015/04/27 22:39:47
Not per testharness.js docs:
* https://github.com
cmumford
2015/04/27 22:44:23
Yep - you're totally correct. I naively trusted th
| |
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'); | |
cmumford
2015/04/27 17:14:23
param order.
| |
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, | |
cmumford
2015/04/27 17:14:23
Nit: Do you want to swap the expected/actual order
| |
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 idb_test( | |
55 'Binary key: ' + type, | |
56 function(t, db) { | |
57 db.createObjectStore('store'); | |
58 }, | |
59 function(t, db) { | |
60 var key = new self[type](buffer); | |
61 assert_key_valid(key, type + ' should be a valid key'); | |
62 assert_key_equals(key, buffer, | |
63 'Keys should be equal regardless of type'); | |
64 check_key(t, db, key); | |
65 } | |
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 idb_test( | |
83 'Value test: ' + type, | |
84 function(t, db) { | |
85 db.createObjectStore('store'); | |
86 }, | |
87 function(t, db) { | |
88 assert_key_valid(value, type + ' should be a valid key'); | |
89 check_key(t, db, value); | |
90 t.done(); | |
91 } | |
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 |