Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: third_party/WebKit/LayoutTests/bluetooth/idl-BluetoothUUID.html

Issue 2380843002: Throw a TypeError instead of a SyntaxError on invalid UUIDs. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script> 2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script> 3 <script src="../resources/testharnessreport.js"></script>
4 <script> 4 <script>
5 'use strict' 5 'use strict'
6 6
7 var base_uuid = '00000000-0000-1000-8000-00805f9b34fb' 7 var base_uuid = '00000000-0000-1000-8000-00805f9b34fb'
8 8
9 test(() => { 9 test(() => {
10 let base_alias = 0x0 10 let base_alias = 0x0
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 test(() => { 61 test(() => {
62 let basic_uuid = '1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d'; 62 let basic_uuid = '1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d';
63 assert_equals(BluetoothUUID.getService(basic_uuid), basic_uuid); 63 assert_equals(BluetoothUUID.getService(basic_uuid), basic_uuid);
64 assert_equals(BluetoothUUID.getCharacteristic(basic_uuid), basic_uuid); 64 assert_equals(BluetoothUUID.getCharacteristic(basic_uuid), basic_uuid);
65 assert_equals(BluetoothUUID.getDescriptor(basic_uuid), basic_uuid); 65 assert_equals(BluetoothUUID.getDescriptor(basic_uuid), basic_uuid);
66 }, 'A valid UUID String should return the same UUID.'); 66 }, 'A valid UUID String should return the same UUID.');
67 67
68 test(() => { 68 test(() => {
69 let all_caps_uuid = '1A2B3C4D-5E6F-7A8B-9C0D-1E2F3A4B5C6D'; 69 let all_caps_uuid = '1A2B3C4D-5E6F-7A8B-9C0D-1E2F3A4B5C6D';
70 assert_throws('SyntaxError', () => BluetoothUUID.getService(all_caps_uuid)); 70 assert_throws(TypeError(), () => BluetoothUUID.getService(all_caps_uuid));
71 assert_throws('SyntaxError', () => BluetoothUUID.getCharacteristic(all_caps_uu id)); 71 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(all_caps_uuid ));
72 assert_throws('SyntaxError', () => BluetoothUUID.getDescriptor(all_caps_uuid)) ; 72 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(all_caps_uuid));
73 }, 'A UUID String with uppercase letters is an invalid UUID.'); 73 }, 'A UUID String with uppercase letters is an invalid UUID.');
74 74
75 test(() => { 75 test(() => {
76 let string_alias = 'deadbeef'; 76 let string_alias = 'deadbeef';
77 assert_throws('SyntaxError', () => BluetoothUUID.getService(string_alias)); 77 assert_throws(TypeError(), () => BluetoothUUID.getService(string_alias));
78 assert_throws('SyntaxError', () => BluetoothUUID.getCharacteristic(string_alia s)); 78 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(string_alias) );
79 assert_throws('SyntaxError', () => BluetoothUUID.getDescriptor(string_alias)); 79 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(string_alias));
80 }, 'A 32bit *String* alias is invalid.'); 80 }, 'A 32bit *String* alias is invalid.');
81 81
82 test(() => { 82 test(() => {
83 let invalid_character_uuid = '0000000g-0000-1000-8000-00805f9b34fb'; 83 let invalid_character_uuid = '0000000g-0000-1000-8000-00805f9b34fb';
84 assert_throws('SyntaxError', () => BluetoothUUID.getService(invalid_character_ uuid)); 84 assert_throws(TypeError(), () => BluetoothUUID.getService(invalid_character_uu id));
85 assert_throws('SyntaxError', () => BluetoothUUID.getCharacteristic(invalid_cha racter_uuid)); 85 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(invalid_chara cter_uuid));
86 assert_throws('SyntaxError', () => BluetoothUUID.getDescriptor(invalid_charact er_uuid)); 86 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(invalid_character _uuid));
87 }, 'A UUID with invalid characters is an invalid UUID.'); 87 }, 'A UUID with invalid characters is an invalid UUID.');
88 88
89 test(() => { 89 test(() => {
90 assert_equals(BluetoothUUID.getService('alert_notification'), 90 assert_equals(BluetoothUUID.getService('alert_notification'),
91 '00001811-0000-1000-8000-00805f9b34fb'); 91 '00001811-0000-1000-8000-00805f9b34fb');
92 assert_equals(BluetoothUUID.getCharacteristic('aerobic_heart_rate_lower_limit' ), 92 assert_equals(BluetoothUUID.getCharacteristic('aerobic_heart_rate_lower_limit' ),
93 '00002a7e-0000-1000-8000-00805f9b34fb'); 93 '00002a7e-0000-1000-8000-00805f9b34fb');
94 assert_equals(BluetoothUUID.getDescriptor('gatt.characteristic_extended_proper ties'), 94 assert_equals(BluetoothUUID.getDescriptor('gatt.characteristic_extended_proper ties'),
95 '00002900-0000-1000-8000-00805f9b34fb'); 95 '00002900-0000-1000-8000-00805f9b34fb');
96 }, 'A valid UUID from a name.'); 96 }, 'A valid UUID from a name.');
97 97
98 test(() => { 98 test(() => {
99 assert_throws('SyntaxError', () => { 99 assert_throws(TypeError(), () => {
100 BluetoothUUID.getService('aerobic_heart_rate_lower_limit'); 100 BluetoothUUID.getService('aerobic_heart_rate_lower_limit');
101 }); 101 });
102 assert_throws('SyntaxError', () => { 102 assert_throws(TypeError(), () => {
103 BluetoothUUID.getService('gatt.characteristic_extended_properties'); 103 BluetoothUUID.getService('gatt.characteristic_extended_properties');
104 }); 104 });
105 assert_throws('SyntaxError', () => { 105 assert_throws(TypeError(), () => {
106 BluetoothUUID.getCharacteristic('alert_notification'); 106 BluetoothUUID.getCharacteristic('alert_notification');
107 }); 107 });
108 assert_throws('SyntaxError', () => { 108 assert_throws(TypeError(), () => {
109 BluetoothUUID.getCharacteristic('gatt.characteristic_extended_properties'); 109 BluetoothUUID.getCharacteristic('gatt.characteristic_extended_properties');
110 }); 110 });
111 assert_throws('SyntaxError', () => { 111 assert_throws(TypeError(), () => {
112 BluetoothUUID.getDescriptor('alert_notification'); 112 BluetoothUUID.getDescriptor('alert_notification');
113 }); 113 });
114 assert_throws('SyntaxError', () => { 114 assert_throws(TypeError(), () => {
115 BluetoothUUID.getDescriptor('aerobic_heart_rate_lower_limit'); 115 BluetoothUUID.getDescriptor('aerobic_heart_rate_lower_limit');
116 }); 116 });
117 }, 'Make sure attributes don\'t share a map'); 117 }, 'Make sure attributes don\'t share a map');
118 118
119 test(() => { 119 test(() => {
120 let wrong_name = 'wrong_name'; 120 let wrong_name = 'wrong_name';
121 assert_throws('SyntaxError', () => BluetoothUUID.getService(wrong_name)); 121 assert_throws(TypeError(), () => BluetoothUUID.getService(wrong_name));
122 assert_throws('SyntaxError', () => BluetoothUUID.getCharacteristic(wrong_name) ); 122 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(wrong_name));
123 assert_throws('SyntaxError', () => BluetoothUUID.getDescriptor(wrong_name)); 123 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(wrong_name));
124 }, 'Invalid Descriptor name'); 124 }, 'Invalid Descriptor name');
125 125
126 test(() => { 126 test(() => {
127 let object = {}; 127 let object = {};
128 let array = []; 128 let array = [];
129 let func = () => {}; 129 let func = () => {};
130 130
131 // cannonicalUUID 131 // cannonicalUUID
132 assert_throws(new TypeError, () => BluetoothUUID.canonicalUUID(object)); 132 assert_throws(new TypeError, () => BluetoothUUID.canonicalUUID(object));
133 // [] converts to '', which converts to 0 before the range check. 133 // [] converts to '', which converts to 0 before the range check.
134 assert_equals(BluetoothUUID.canonicalUUID(array), base_uuid); 134 assert_equals(BluetoothUUID.canonicalUUID(array), base_uuid);
135 assert_throws(new TypeError, () => BluetoothUUID.canonicalUUID(func)); 135 assert_throws(new TypeError, () => BluetoothUUID.canonicalUUID(func));
136 assert_throws(new TypeError, () => BluetoothUUID.canonicalUUID(undefined)); 136 assert_throws(new TypeError, () => BluetoothUUID.canonicalUUID(undefined));
137 assert_equals(BluetoothUUID.canonicalUUID(null), base_uuid); 137 assert_equals(BluetoothUUID.canonicalUUID(null), base_uuid);
138 assert_equals(BluetoothUUID.canonicalUUID(false), base_uuid); 138 assert_equals(BluetoothUUID.canonicalUUID(false), base_uuid);
139 assert_equals(BluetoothUUID.canonicalUUID(true), BluetoothUUID.canonicalUUID(1 )); 139 assert_equals(BluetoothUUID.canonicalUUID(true), BluetoothUUID.canonicalUUID(1 ));
140 assert_throws(new TypeError, () => BluetoothUUID.canonicalUUID(NaN)); 140 assert_throws(new TypeError, () => BluetoothUUID.canonicalUUID(NaN));
141 141
142 // getService 142 // getService
143 assert_throws('SyntaxError', () => BluetoothUUID.getService(object)); 143 assert_throws(TypeError(), () => BluetoothUUID.getService(object));
144 assert_throws('SyntaxError', () => BluetoothUUID.getService(array)); 144 assert_throws(TypeError(), () => BluetoothUUID.getService(array));
145 assert_throws('SyntaxError', () => BluetoothUUID.getService(func)); 145 assert_throws(TypeError(), () => BluetoothUUID.getService(func));
146 assert_throws('SyntaxError', () => BluetoothUUID.getService(undefined)); 146 assert_throws(TypeError(), () => BluetoothUUID.getService(undefined));
147 assert_throws('SyntaxError', () => BluetoothUUID.getService(null)); 147 assert_throws(TypeError(), () => BluetoothUUID.getService(null));
148 assert_throws('SyntaxError', () => BluetoothUUID.getService(false)); 148 assert_throws(TypeError(), () => BluetoothUUID.getService(false));
149 149
150 // getCharacteristic 150 // getCharacteristic
151 assert_throws('SyntaxError', () => BluetoothUUID.getCharacteristic(object)); 151 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(object));
152 assert_throws('SyntaxError', () => BluetoothUUID.getCharacteristic(array)); 152 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(array));
153 assert_throws('SyntaxError', () => BluetoothUUID.getCharacteristic(func)); 153 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(func));
154 assert_throws('SyntaxError', () => BluetoothUUID.getCharacteristic(undefined)) ; 154 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(undefined));
155 assert_throws('SyntaxError', () => BluetoothUUID.getCharacteristic(null)); 155 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(null));
156 assert_throws('SyntaxError', () => BluetoothUUID.getCharacteristic(false)); 156 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(false));
157 157
158 // getDescriptor 158 // getDescriptor
159 assert_throws('SyntaxError', () => BluetoothUUID.getDescriptor(object)); 159 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(object));
160 assert_throws('SyntaxError', () => BluetoothUUID.getDescriptor(array)); 160 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(array));
161 assert_throws('SyntaxError', () => BluetoothUUID.getDescriptor(func)); 161 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(func));
162 assert_throws('SyntaxError', () => BluetoothUUID.getDescriptor(undefined)); 162 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(undefined));
163 assert_throws('SyntaxError', () => BluetoothUUID.getDescriptor(null)); 163 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(null));
164 assert_throws('SyntaxError', () => BluetoothUUID.getDescriptor(false)); 164 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(false));
165 }, 'Non-number and non-strings'); 165 }, 'Non-number and non-strings');
166 </script> 166 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698