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..4416b63f92899a9aaa05a187943f5a690e74a8f8 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,180 @@ 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; |
|
dpapad
2017/01/25 19:20:07
The setup for this test is repeated in every singl
mbrunson
2017/01/25 22:14:44
Done.
|
| + 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; |
| + valueControl.value_.setValueFromHex(''); |
| + var valueArr = valueControl.value_.getArray(); |
| + |
| + 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; |
| + |
| + expectThrows( |
|
dpapad
2017/01/25 19:20:07
Probably more readable as
expectThrows(
functio
mbrunson
2017/01/25 22:14:44
Done.
|
| + valueControl.value_.setValueFromHex.bind(valueControl.value_, 'd0x'), |
| + 'Expected new value to start with "0x"'); |
| + }); |
| + |
| + test('ValueControl_ConvertValue_Hexadecimal_ThreeValues', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 0; |
| + valueControl.value_.setValueFromHex('0x616263'); |
| + var valueArr = valueControl.value_.getArray(); |
| + |
| + 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; |
| + valueControl.value_.setValueFromUTF8(''); |
| + var valueArr = valueControl.value_.getArray(); |
| + |
| + 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; |
| + valueControl.value_.setValueFromUTF8('abc'); |
| + var valueArr = valueControl.value_.getArray(); |
| + |
| + 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; |
| + valueControl.value_.setValueFromDecimal(''); |
| + var valueArr = valueControl.value_.getArray(); |
| + |
| + 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; |
| + |
| + expectThrows( |
| + valueControl.value_.setValueFromDecimal.bind( |
| + valueControl, '97-+-99' /* a-+-c */), |
| + 'New value can only contain numbers and hyphens'); |
| + }); |
| + |
| + test('ValueControl_ConvertValue_Decimal_ThreeValues', function() { |
| + var valueControl = value_control.ValueControl(); |
| + valueControl.load(device1.address, service1.id, characteristic1); |
| + valueControl.typeSelect_.selectedIndex = 2; |
| + valueControl.value_.setValueFromDecimal('97-98-99' /* abc */); |
| + var valueArr = valueControl.value_.getArray(); |
| + |
| + expectDeepEquals([aCode, bCode, cCode], valueArr); |
| + }); |
| + |
| + }); |
| + |
| // Run all registered tests. |
| mocha.run(); |
| }); |