b55e6324b349987750816d49efb9eb908a845724
[gecko.git] / idb_binary_key_conversion.htm
blobb55e6324b349987750816d49efb9eb908a845724
1 <!DOCTYPE html>
2 <meta charset=utf-8>
3 <title>Verify the coversion of various types of BufferSource</title>
4 <link rel="author" title="Mozilla" href="https://www.mozilla.org">
5 <link rel="help" href="http://w3c.github.io/IndexedDB/#key-construct">
6 <script src=/resources/testharness.js></script>
7 <script src=/resources/testharnessreport.js></script>
9 <script>
10 test(function() {
11 let binary = new ArrayBuffer(0);
12 let key = IDBKeyRange.lowerBound(binary).lower;
14 assert_true(key instanceof ArrayBuffer);
15 assert_equals(key.byteLength, 0);
16 assert_equals(key.byteLength, binary.byteLength);
17 }, "Empty ArrayBuffer");
19 test(function() {
20 let binary = new ArrayBuffer(4);
21 let dataView = new DataView(binary);
22 dataView.setUint32(0, 1234567890);
24 let key = IDBKeyRange.lowerBound(binary).lower;
26 assert_true(key instanceof ArrayBuffer);
27 assert_equals(key.byteLength, 4);
28 assert_equals(dataView.getUint32(0), new DataView(key).getUint32(0));
29 }, "ArrayBuffer");
31 test(function() {
32 let binary = new ArrayBuffer(4);
33 let dataView = new DataView(binary);
34 dataView.setUint32(0, 1234567890);
36 let key = IDBKeyRange.lowerBound(dataView).lower;
38 assert_true(key instanceof ArrayBuffer);
39 assert_equals(key.byteLength, 4);
40 assert_equals(dataView.getUint32(0), new DataView(key).getUint32(0));
41 }, "DataView");
43 test(function() {
44 let binary = new ArrayBuffer(4);
45 let dataView = new DataView(binary);
46 let int8Array = new Int8Array(binary);
47 int8Array.set([16, -32, 64, -128]);
49 let key = IDBKeyRange.lowerBound(int8Array).lower;
50 let keyInInt8Array = new Int8Array(key);
52 assert_true(key instanceof ArrayBuffer);
53 assert_equals(key.byteLength, 4);
54 for(let i = 0; i < int8Array.length; i++) {
55 assert_equals(keyInInt8Array[i], int8Array[i]);
57 }, "TypedArray(Int8Array)");
59 test(function() {
60 let binary = new ArrayBuffer(4);
61 let dataView = new DataView(binary);
62 let int8Array = new Int8Array(binary);
63 int8Array.set([16, -32, 64, -128]);
65 let key = IDBKeyRange.lowerBound([int8Array]).lower;
67 assert_true(key instanceof Array);
68 assert_true(key[0] instanceof ArrayBuffer);
69 assert_equals(key[0].byteLength, 4);
71 let keyInInt8Array = new Int8Array(key[0]);
73 for(let i = 0; i < int8Array.length; i++) {
74 assert_equals(keyInInt8Array[i], int8Array[i]);
76 }, "Array of TypedArray(Int8Array)");
77 </script>
79 <div id=log></div>