idl-BluetoothUUID.window.js (7903B)
1 // META: script=/resources/testdriver.js?feature=bidi 2 // META: script=/resources/testdriver-vendor.js 3 'use strict' 4 5 var base_uuid = '00000000-0000-1000-8000-00805f9b34fb' 6 7 test(() => { 8 let base_alias = 0x0 9 assert_equals(BluetoothUUID.getService(base_alias), base_uuid); 10 assert_equals(BluetoothUUID.getCharacteristic(base_alias), base_uuid); 11 assert_equals(BluetoothUUID.getDescriptor(base_alias), base_uuid); 12 }, '0x0 should produce valid UUID.'); 13 14 test(() => { 15 assert_equals(BluetoothUUID.getService(NaN), base_uuid); 16 assert_equals(BluetoothUUID.getCharacteristic(NaN), base_uuid); 17 assert_equals(BluetoothUUID.getDescriptor(NaN), base_uuid); 18 }, 'NaN returns basic uuid'); 19 20 test( 21 () => { 22 let max_uuid = 'ffffffff-0000-1000-8000-00805f9b34fb'; 23 let nine_digits = 0xfffffffff; 24 let thirteen_digits = 0xfffffffffffff; 25 let fourteen_digits = 0xffffffffffffff; 26 assert_equals(BluetoothUUID.getService(nine_digits), max_uuid); 27 assert_equals(BluetoothUUID.getCharacteristic(nine_digits), max_uuid); 28 assert_equals(BluetoothUUID.getDescriptor(nine_digits), max_uuid); 29 assert_equals(BluetoothUUID.getService(thirteen_digits), max_uuid); 30 assert_equals(BluetoothUUID.getCharacteristic(thirteen_digits), max_uuid); 31 assert_equals(BluetoothUUID.getDescriptor(thirteen_digits), max_uuid); 32 assert_equals(BluetoothUUID.getService(fourteen_digits), base_uuid); 33 assert_equals( 34 BluetoothUUID.getCharacteristic(fourteen_digits), base_uuid); 35 assert_equals(BluetoothUUID.getDescriptor(fourteen_digits), base_uuid); 36 }, 37 'Values between 0xfffffffff (8 digits) and 0xffffffffffffff (14 digits)' + 38 'should return max UUID'); 39 40 test(() => { 41 assert_equals(BluetoothUUID.getService(Infinity), base_uuid); 42 assert_equals(BluetoothUUID.getCharacteristic(Infinity), base_uuid); 43 assert_equals(BluetoothUUID.getDescriptor(Infinity), base_uuid); 44 }, 'Infinity returns base UUID'); 45 46 test(() => { 47 let deadbeef_alias = 0xDEADBEEF; 48 let deadbeef_uuid = 'deadbeef-0000-1000-8000-00805f9b34fb'; 49 assert_equals(BluetoothUUID.getService(deadbeef_alias), deadbeef_uuid); 50 assert_equals(BluetoothUUID.getCharacteristic(deadbeef_alias), deadbeef_uuid); 51 assert_equals(BluetoothUUID.getDescriptor(deadbeef_alias), deadbeef_uuid); 52 }, '0xdeadbeef should produce valid UUID.'); 53 54 test(() => { 55 let adeadbeef_alias = 0xADEADBEEF; 56 let adeadbeef_uuid = 'deadbeef-0000-1000-8000-00805f9b34fb'; 57 assert_equals(BluetoothUUID.getService(adeadbeef_alias), adeadbeef_uuid); 58 assert_equals( 59 BluetoothUUID.getCharacteristic(adeadbeef_alias), adeadbeef_uuid); 60 assert_equals(BluetoothUUID.getDescriptor(adeadbeef_alias), adeadbeef_uuid); 61 }, 'Only first 32bits should be used.'); 62 63 test(() => { 64 let basic_uuid = '1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d'; 65 assert_equals(BluetoothUUID.getService(basic_uuid), basic_uuid); 66 assert_equals(BluetoothUUID.getCharacteristic(basic_uuid), basic_uuid); 67 assert_equals(BluetoothUUID.getDescriptor(basic_uuid), basic_uuid); 68 }, 'A valid UUID String should return the same UUID.'); 69 70 test(() => { 71 let all_caps_uuid = '1A2B3C4D-5E6F-7A8B-9C0D-1E2F3A4B5C6D'; 72 assert_throws_js(TypeError, () => BluetoothUUID.getService(all_caps_uuid)); 73 assert_throws_js( 74 TypeError, () => BluetoothUUID.getCharacteristic(all_caps_uuid)); 75 assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(all_caps_uuid)); 76 }, 'A UUID String with uppercase letters is an invalid UUID.'); 77 78 test(() => { 79 let string_alias = 'deadbeef'; 80 assert_throws_js(TypeError, () => BluetoothUUID.getService(string_alias)); 81 assert_throws_js( 82 TypeError, () => BluetoothUUID.getCharacteristic(string_alias)); 83 assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(string_alias)); 84 }, 'A 32bit *String* alias is invalid.'); 85 86 test(() => { 87 let invalid_character_uuid = '0000000g-0000-1000-8000-00805f9b34fb'; 88 assert_throws_js( 89 TypeError, () => BluetoothUUID.getService(invalid_character_uuid)); 90 assert_throws_js( 91 TypeError, () => BluetoothUUID.getCharacteristic(invalid_character_uuid)); 92 assert_throws_js( 93 TypeError, () => BluetoothUUID.getDescriptor(invalid_character_uuid)); 94 }, 'A UUID with invalid characters is an invalid UUID.'); 95 96 test(() => { 97 assert_equals( 98 BluetoothUUID.getService('alert_notification'), 99 '00001811-0000-1000-8000-00805f9b34fb'); 100 assert_equals( 101 BluetoothUUID.getCharacteristic('aerobic_heart_rate_lower_limit'), 102 '00002a7e-0000-1000-8000-00805f9b34fb'); 103 assert_equals( 104 BluetoothUUID.getDescriptor('gatt.characteristic_extended_properties'), 105 '00002900-0000-1000-8000-00805f9b34fb'); 106 }, 'A valid UUID from a name.'); 107 108 test(() => { 109 assert_throws_js(TypeError, () => { 110 BluetoothUUID.getService('aerobic_heart_rate_lower_limit'); 111 }); 112 assert_throws_js(TypeError, () => { 113 BluetoothUUID.getService('gatt.characteristic_extended_properties'); 114 }); 115 assert_throws_js(TypeError, () => { 116 BluetoothUUID.getCharacteristic('alert_notification'); 117 }); 118 assert_throws_js(TypeError, () => { 119 BluetoothUUID.getCharacteristic('gatt.characteristic_extended_properties'); 120 }); 121 assert_throws_js(TypeError, () => { 122 BluetoothUUID.getDescriptor('alert_notification'); 123 }); 124 assert_throws_js(TypeError, () => { 125 BluetoothUUID.getDescriptor('aerobic_heart_rate_lower_limit'); 126 }); 127 }, 'Make sure attributes don\'t share a map'); 128 129 test(() => { 130 let wrong_name = 'wrong_name'; 131 assert_throws_js(TypeError, () => BluetoothUUID.getService(wrong_name)); 132 assert_throws_js( 133 TypeError, () => BluetoothUUID.getCharacteristic(wrong_name)); 134 assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(wrong_name)); 135 }, 'Invalid Descriptor name'); 136 137 test(() => { 138 let object = {}; 139 let array = []; 140 let func = () => {}; 141 142 // cannonicalUUID 143 assert_throws_js(TypeError, () => BluetoothUUID.canonicalUUID(object)); 144 // [] converts to '', which converts to 0 before the range check. 145 assert_equals(BluetoothUUID.canonicalUUID(array), base_uuid); 146 assert_throws_js(TypeError, () => BluetoothUUID.canonicalUUID(func)); 147 assert_throws_js(TypeError, () => BluetoothUUID.canonicalUUID(undefined)); 148 assert_equals(BluetoothUUID.canonicalUUID(null), base_uuid); 149 assert_equals(BluetoothUUID.canonicalUUID(false), base_uuid); 150 assert_equals( 151 BluetoothUUID.canonicalUUID(true), BluetoothUUID.canonicalUUID(1)); 152 assert_throws_js(TypeError, () => BluetoothUUID.canonicalUUID(NaN)); 153 154 // getService 155 assert_throws_js(TypeError, () => BluetoothUUID.getService(object)); 156 assert_throws_js(TypeError, () => BluetoothUUID.getService(array)); 157 assert_throws_js(TypeError, () => BluetoothUUID.getService(func)); 158 assert_throws_js(TypeError, () => BluetoothUUID.getService(undefined)); 159 assert_throws_js(TypeError, () => BluetoothUUID.getService(null)); 160 assert_throws_js(TypeError, () => BluetoothUUID.getService(false)); 161 162 // getCharacteristic 163 assert_throws_js(TypeError, () => BluetoothUUID.getCharacteristic(object)); 164 assert_throws_js(TypeError, () => BluetoothUUID.getCharacteristic(array)); 165 assert_throws_js(TypeError, () => BluetoothUUID.getCharacteristic(func)); 166 assert_throws_js(TypeError, () => BluetoothUUID.getCharacteristic(undefined)); 167 assert_throws_js(TypeError, () => BluetoothUUID.getCharacteristic(null)); 168 assert_throws_js(TypeError, () => BluetoothUUID.getCharacteristic(false)); 169 170 // getDescriptor 171 assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(object)); 172 assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(array)); 173 assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(func)); 174 assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(undefined)); 175 assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(null)); 176 assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(false)); 177 }, 'Non-number and non-strings');