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

Side by Side Diff: chrome/test/data/webui/bluetooth_internals_browsertest.js

Issue 2627243002: bluetooth: Add control for reading/writing of characteristics to internals page. (Closed)
Patch Set: Add expectThrows, check thrown exceptions Created 3 years, 11 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Tests for chrome://bluetooth-internals 6 * @fileoverview Tests for chrome://bluetooth-internals
7 */ 7 */
8 8
9 /** @const {string} Path to source root. */ 9 /** @const {string} Path to source root. */
10 var ROOT_PATH = '../../../../'; 10 var ROOT_PATH = '../../../../';
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 /** 283 /**
284 * Returns a copy of fake service info object (variant 2). 284 * Returns a copy of fake service info object (variant 2).
285 * @return {!Object} 285 * @return {!Object}
286 */ 286 */
287 fakeServiceInfo2: function() { 287 fakeServiceInfo2: function() {
288 return { 288 return {
289 uuid: '0000180d-0000-1000-8000-00805f9b34fb', 289 uuid: '0000180d-0000-1000-8000-00805f9b34fb',
290 is_primary: true, 290 is_primary: true,
291 } 291 }
292 }, 292 },
293
294 /**
295 * Returns a copy of fake characteristic info object with all properties
296 * and all permissions bits set.
297 * @return {!Object}
298 */
299 fakeCharacteristicInfo1: function() {
300 return {
301 id: 'characteristic1',
302 uuid: '00002a19-0000-1000-8000-00805f9b34fb',
303 properties: Number.MAX_SAFE_INTEGER,
304 permissions: Number.MAX_SAFE_INTEGER,
305 last_known_value: [],
306 };
307 },
293 }; 308 };
294 309
295 TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() { 310 TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() {
296 /** @const */ var PageManager = cr.ui.pageManager.PageManager; 311 /** @const */ var PageManager = cr.ui.pageManager.PageManager;
297 312
298 var adapterFactory = null; 313 var adapterFactory = null;
299 var adapterFieldSet = null; 314 var adapterFieldSet = null;
300 var deviceTable = null; 315 var deviceTable = null;
301 var sidebarNode = null; 316 var sidebarNode = null;
302 var pageNames = ['adapter', 'devices']; 317 var pageNames = ['adapter', 'devices'];
303 318
304 var fakeAdapterInfo = this.fakeAdapterInfo; 319 var fakeAdapterInfo = this.fakeAdapterInfo;
305 var fakeDeviceInfo1 = this.fakeDeviceInfo1; 320 var fakeDeviceInfo1 = this.fakeDeviceInfo1;
306 var fakeDeviceInfo2 = this.fakeDeviceInfo2; 321 var fakeDeviceInfo2 = this.fakeDeviceInfo2;
307 var fakeDeviceInfo3 = this.fakeDeviceInfo3; 322 var fakeDeviceInfo3 = this.fakeDeviceInfo3;
308 var fakeServiceInfo1 = this.fakeServiceInfo1; 323 var fakeServiceInfo1 = this.fakeServiceInfo1;
309 var fakeServiceInfo2 = this.fakeServiceInfo2; 324 var fakeServiceInfo2 = this.fakeServiceInfo2;
325 var fakeCharacteristicInfo1 = this.fakeCharacteristicInfo1;
310 326
311 // Before tests are run, make sure setup completes. 327 // Before tests are run, make sure setup completes.
312 var setupPromise = this.setupResolver.promise.then(function() { 328 var setupPromise = this.setupResolver.promise.then(function() {
313 adapterFactory = this.adapterFactory; 329 adapterFactory = this.adapterFactory;
314 }.bind(this)); 330 }.bind(this));
315 331
316 suite('BluetoothInternalsUITest', function() { 332 suite('BluetoothInternalsUITest', function() {
317 var EXPECTED_DEVICES = 2; 333 var EXPECTED_DEVICES = 2;
318 334
319 suiteSetup(function() { 335 suiteSetup(function() {
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 811
796 // Second link is 'Forget'. 812 // Second link is 'Forget'.
797 deviceLinks[1].click(); 813 deviceLinks[1].click();
798 expectEquals('#devices', window.location.hash); 814 expectEquals('#devices', window.location.hash);
799 detailsPage = $(deviceDetailsPageId); 815 detailsPage = $(deviceDetailsPageId);
800 expectFalse(!!detailsPage); 816 expectFalse(!!detailsPage);
801 }); 817 });
802 }); 818 });
803 }); 819 });
804 820
821 suite('BluetoothInternalsUnitTests', function() {
822 /* Value Control Unit Tests */
823 var aCode = 'a'.charCodeAt(0);
824 var bCode = 'b'.charCodeAt(0);
825 var cCode = 'c'.charCodeAt(0);
826
827 var device1 = fakeDeviceInfo1();
828 var service1 = fakeServiceInfo1();
829 var characteristic1 = fakeCharacteristicInfo1();
830
831 test('ValueControl_SetValue_Hexadecimal_EmptyArray', function() {
832 var valueControl = value_control.ValueControl();
833 valueControl.load(device1.address, service1.id, characteristic1);
834 valueControl.typeSelect_.selectedIndex = 0;
835 valueControl.setValue([]);
836
837 expectEquals('', valueControl.valueInput_.value);
838 });
839
840 test('ValueControl_SetValue_Hexadecimal_OneValue', function() {
841 var valueControl = value_control.ValueControl();
842 valueControl.load(device1.address, service1.id, characteristic1);
843 valueControl.typeSelect_.selectedIndex = 0;
844 valueControl.setValue([aCode]);
845
846 expectEquals('0x61', valueControl.valueInput_.value);
847 });
848
849 test('ValueControl_SetValue_Hexadecimal_ThreeValues', function() {
850 var valueControl = value_control.ValueControl();
851 valueControl.load(device1.address, service1.id, characteristic1);
852 valueControl.typeSelect_.selectedIndex = 0;
853 valueControl.setValue([aCode, bCode, cCode]);
854
855 expectEquals('0x616263', valueControl.valueInput_.value);
856 });
857
858 test('ValueControl_SetValue_UTF8_EmptyArray', function() {
859 var valueControl = value_control.ValueControl();
860 valueControl.load(device1.address, service1.id, characteristic1);
861 valueControl.typeSelect_.selectedIndex = 1;
862 valueControl.setValue([]);
863
864 expectEquals('', valueControl.valueInput_.value);
865 });
866
867 test('ValueControl_SetValue_UTF8_OneValue', function() {
868 var valueControl = value_control.ValueControl();
869 valueControl.load(device1.address, service1.id, characteristic1);
870 valueControl.typeSelect_.selectedIndex = 1;
871 valueControl.setValue([aCode]);
872
873 expectEquals('a', valueControl.valueInput_.value);
874 });
875
876 test('ValueControl_SetValue_UTF8_ThreeValues', function() {
877 var valueControl = value_control.ValueControl();
878 valueControl.load(device1.address, service1.id, characteristic1);
879 valueControl.typeSelect_.selectedIndex = 1;
880 valueControl.setValue([aCode, bCode, cCode]);
881
882 expectEquals('abc', valueControl.valueInput_.value);
883 });
884
885 test('ValueControl_SetValue_Decimal_EmptyArray', function() {
886 var valueControl = value_control.ValueControl();
887 valueControl.load(device1.address, service1.id, characteristic1);
888 valueControl.typeSelect_.selectedIndex = 2;
889 valueControl.setValue([]);
890
891 expectEquals('', valueControl.valueInput_.value);
892 });
893
894 test('ValueControl_SetValue_Decimal_OneValue', function() {
895 var valueControl = value_control.ValueControl();
896 valueControl.load(device1.address, service1.id, characteristic1);
897 valueControl.typeSelect_.selectedIndex = 2;
898 valueControl.setValue([aCode]);
899
900 expectEquals(String(aCode), valueControl.valueInput_.value);
901 });
902
903 test('ValueControl_SetValue_Decimal_ThreeValues', function() {
904 var valueControl = value_control.ValueControl();
905 valueControl.load(device1.address, service1.id, characteristic1);
906 valueControl.typeSelect_.selectedIndex = 2;
907 valueControl.setValue([aCode, bCode, cCode]);
908
909 expectEquals('97-98-99', valueControl.valueInput_.value);
910 });
911
912 test('ValueControl_ConvertValue_Hexadecimal_EmptyString', function() {
913 var valueControl = value_control.ValueControl();
914 valueControl.load(device1.address, service1.id, characteristic1);
915 valueControl.typeSelect_.selectedIndex = 0;
916 var valueArr = valueControl.convertValueToArray_('');
917
918 expectEquals(0, valueArr.length);
919 });
920
921 test('ValueControl_ConvertValue_Hexadecimal_BadHexPrefix', function() {
922 var valueControl = value_control.ValueControl();
923 valueControl.load(device1.address, service1.id, characteristic1);
924 valueControl.typeSelect_.selectedIndex = 0;
925
926 expectThrows(
927 valueControl.convertValueToArray_.bind(valueControl, 'd0x'),
928 'Expected value to start with "0x"');
929 });
930
931 test('ValueControl_ConvertValue_Hexadecimal_ThreeValues', function() {
932 var valueControl = value_control.ValueControl();
933 valueControl.load(device1.address, service1.id, characteristic1);
934 valueControl.typeSelect_.selectedIndex = 0;
935 var valueArr = valueControl.convertValueToArray_('0x616263');
936
937 expectDeepEquals([aCode, bCode, cCode], valueArr);
938 });
939
940 test('ValueControl_ConvertValue_UTF8_EmptyString', function() {
941 var valueControl = value_control.ValueControl();
942 valueControl.load(device1.address, service1.id, characteristic1);
943 valueControl.typeSelect_.selectedIndex = 1;
944 var valueArr = valueControl.convertValueToArray_('');
945
946 expectEquals(0, valueArr.length);
947 });
948
949 test('ValueControl_ConvertValue_UTF8_ThreeValues', function() {
950 var valueControl = value_control.ValueControl();
951 valueControl.load(device1.address, service1.id, characteristic1);
952 valueControl.typeSelect_.selectedIndex = 1;
953 var valueArr = valueControl.convertValueToArray_('abc');
954
955 expectDeepEquals([aCode, bCode, cCode], valueArr);
956 });
957
958 test('ValueControl_ConvertValue_Decimal_EmptyString', function() {
959 var valueControl = value_control.ValueControl();
960 valueControl.load(device1.address, service1.id, characteristic1);
961 valueControl.typeSelect_.selectedIndex = 2;
962 var valueArr = valueControl.convertValueToArray_('');
963
964 expectEquals(0, valueArr.length);
965 });
966
967 test('ValueControl_ConvertValue_Decimal_ThreeValues_Fail', function() {
968 var valueControl = value_control.ValueControl();
969 valueControl.load(device1.address, service1.id, characteristic1);
970 valueControl.typeSelect_.selectedIndex = 2;
971
972 expectThrows(
973 valueControl.convertValueToArray_.bind(
974 valueControl, '97-+-99' /* a-+-c */),
975 'Value can only contain numbers and hyphens');
976 });
977
978 test('ValueControl_ConvertValue_Decimal_ThreeValues', function() {
979 var valueControl = value_control.ValueControl();
980 valueControl.load(device1.address, service1.id, characteristic1);
981 valueControl.typeSelect_.selectedIndex = 2;
982 var valueArr = valueControl.convertValueToArray_('97-98-99' /* abc */);
983
984 expectDeepEquals([aCode, bCode, cCode], valueArr);
985 });
986
987 });
988
805 // Run all registered tests. 989 // Run all registered tests.
806 mocha.run(); 990 mocha.run();
807 }); 991 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698