Chromium Code Reviews| Index: chrome/test/data/webui/bluetooth_internals_browsertest.js |
| diff --git a/chrome/test/data/webui/bluetooth_internals_browsertest.js b/chrome/test/data/webui/bluetooth_internals_browsertest.js |
| index 159dcd894e6f153ca5c377ceb89c76d64a41f307..c74ce98b9e5d8ba5d9d1aceac65bcb1f770b9d27 100644 |
| --- a/chrome/test/data/webui/bluetooth_internals_browsertest.js |
| +++ b/chrome/test/data/webui/bluetooth_internals_browsertest.js |
| @@ -290,6 +290,21 @@ BluetoothInternalsTest.prototype = { |
| is_primary: true, |
| } |
| }, |
| + |
| + /** |
| + * Returns a copy of fake characteristic info object with all properties |
| + * and all permissions bits set. |
| + * @return {!Object} |
| + */ |
| + fakeCharacteristicInfo1: function() { |
| + return { |
| + id: 'characteristic1', |
| + uuid: '00002a19-0000-1000-8000-00805f9b34fb', |
| + properties: Number.MAX_SAFE_INTEGER, |
| + permissions: Number.MAX_SAFE_INTEGER, |
| + last_known_value: [], |
| + }; |
| + }, |
| }; |
| TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() { |
| @@ -307,6 +322,7 @@ TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() { |
| var fakeDeviceInfo3 = this.fakeDeviceInfo3; |
| var fakeServiceInfo1 = this.fakeServiceInfo1; |
| var fakeServiceInfo2 = this.fakeServiceInfo2; |
| + var fakeCharacteristicInfo1 = this.fakeCharacteristicInfo1; |
| // Before tests are run, make sure setup completes. |
| var setupPromise = this.setupResolver.promise.then(function() { |
| @@ -802,6 +818,181 @@ TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() { |
| }); |
| }); |
| + suite('BluetoothInternalsUnitTests', function() { |
| + /* Value Control Unit Tests */ |
| + var aCode = 'a'.charCodeAt(0); |
| + var bCode = 'b'.charCodeAt(0); |
| + var cCode = 'c'.charCodeAt(0); |
| + |
| + var device1 = fakeDeviceInfo1(); |
| + var service1 = fakeServiceInfo1(); |
| + var characteristic1 = fakeCharacteristicInfo1(); |
| + |
| + test('ValueControl_SetValue_Hexadecimal_EmptyArray', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 0; |
| + valueControl.setValue([]); |
| + |
| + expectEquals('', valueControl.valueInput_.value); |
| + }); |
| + |
| + test('ValueControl_SetValue_Hexadecimal_OneValue', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 0; |
| + valueControl.setValue([aCode]); |
| + |
| + expectEquals('0x61', valueControl.valueInput_.value); |
| + }); |
| + |
| + test('ValueControl_SetValue_Hexadecimal_ThreeValues', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 0; |
| + valueControl.setValue([aCode, bCode, cCode]); |
| + |
| + expectEquals('0x616263', valueControl.valueInput_.value); |
| + }); |
| + |
| + test('ValueControl_SetValue_UTF8_EmptyArray', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 1; |
| + valueControl.setValue([]); |
| + |
| + expectEquals('', valueControl.valueInput_.value); |
| + }); |
| + |
| + test('ValueControl_SetValue_UTF8_OneValue', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 1; |
| + valueControl.setValue([aCode]); |
| + |
| + expectEquals('a', valueControl.valueInput_.value); |
| + }); |
| + |
| + test('ValueControl_SetValue_UTF8_ThreeValues', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 1; |
| + valueControl.setValue([aCode, bCode, cCode]); |
| + |
| + expectEquals('abc', valueControl.valueInput_.value); |
| + }); |
| + |
| + test('ValueControl_SetValue_Decimal_EmptyArray', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 2; |
| + valueControl.setValue([]); |
| + |
| + expectEquals('', valueControl.valueInput_.value); |
| + }); |
| + |
| + test('ValueControl_SetValue_Decimal_OneValue', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 2; |
| + valueControl.setValue([aCode]); |
| + |
| + expectEquals(String(aCode), valueControl.valueInput_.value); |
| + }); |
| + |
| + test('ValueControl_SetValue_Decimal_ThreeValues', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 2; |
| + valueControl.setValue([aCode, bCode, cCode]); |
| + |
| + expectEquals('97-98-99', valueControl.valueInput_.value); |
| + }); |
| + |
| + test('ValueControl_ConvertValue_Hexadecimal_EmptyString', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 0; |
| + var valueArr = valueControl.convertValueToArray_(''); |
| + |
| + expectEquals(0, valueArr.length); |
| + }); |
| + |
| + test('ValueControl_ConvertValue_Hexadecimal_BadHexPrefix', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 0; |
| + |
| + try { |
| + valueControl.convertValueToArray_('d0x'); |
| + } catch (e) { |
| + return; |
|
ortuno
2017/01/24 02:09:17
Can you assert that the error is the one you expec
mbrunson
2017/01/24 04:21:54
Done.
|
| + } |
| + |
| + expectNotReached(); |
|
ortuno
2017/01/24 02:09:17
Sad that there is no expectThrow()
mbrunson
2017/01/24 04:21:54
Added it to test_api.js. Done.
|
| + }); |
| + |
| + test('ValueControl_ConvertValue_Hexadecimal_ThreeValues', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 0; |
| + var valueArr = valueControl.convertValueToArray_('0x616263'); |
| + |
| + expectDeepEquals([aCode, bCode, cCode], valueArr); |
| + }); |
| + |
| + test('ValueControl_ConvertValue_UTF8_EmptyString', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 1; |
| + var valueArr = valueControl.convertValueToArray_(''); |
| + |
| + expectEquals(0, valueArr.length); |
| + }); |
| + |
| + test('ValueControl_ConvertValue_UTF8_ThreeValues', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 1; |
| + var valueArr = valueControl.convertValueToArray_('abc'); |
| + |
| + expectDeepEquals([aCode, bCode, cCode], valueArr); |
| + }); |
| + |
| + test('ValueControl_ConvertValue_Decimal_EmptyString', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 2; |
| + var valueArr = valueControl.convertValueToArray_(''); |
| + |
| + expectEquals(0, valueArr.length); |
| + }); |
| + |
| + test('ValueControl_ConvertValue_Decimal_ThreeValues_Fail', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 2; |
| + |
| + try { |
| + var valueArr = valueControl.convertValueToArray_('97-+-99' /* a-+-c */); |
| + } catch (e) { |
| + return; |
| + } |
| + |
| + assertNotReached(); |
| + }); |
| + |
| + test('ValueControl_ConvertValue_Decimal_ThreeValues', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 2; |
| + var valueArr = valueControl.convertValueToArray_('97-98-99' /* abc */); |
| + |
| + expectDeepEquals([aCode, bCode, cCode], valueArr); |
| + }); |
| + |
| + }); |
| + |
| // Run all registered tests. |
| mocha.run(); |
| }); |