| 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..1de514c40847ac2349517f7f2afa28f8e38fa522 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,174 @@ 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;
|
| +
|
| + expectThrows(
|
| + valueControl.convertValueToArray_.bind(valueControl, 'd0x'),
|
| + 'Expected 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;
|
| + 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;
|
| +
|
| + expectThrows(
|
| + valueControl.convertValueToArray_.bind(
|
| + valueControl, '97-+-99' /* a-+-c */),
|
| + '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;
|
| + var valueArr = valueControl.convertValueToArray_('97-98-99' /* abc */);
|
| +
|
| + expectDeepEquals([aCode, bCode, cCode], valueArr);
|
| + });
|
| +
|
| + });
|
| +
|
| // Run all registered tests.
|
| mocha.run();
|
| });
|
|
|