OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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; | |
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.
| |
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 valueControl.value_.setValueFromHex(''); | |
917 var valueArr = valueControl.value_.getArray(); | |
918 | |
919 expectEquals(0, valueArr.length); | |
920 }); | |
921 | |
922 test('ValueControl_ConvertValue_Hexadecimal_BadHexPrefix', function() { | |
923 var valueControl = value_control.ValueControl(); | |
924 valueControl.load(device1.address, service1.id, characteristic1); | |
925 valueControl.typeSelect_.selectedIndex = 0; | |
926 | |
927 expectThrows( | |
dpapad
2017/01/25 19:20:07
Probably more readable as
expectThrows(
functio
mbrunson
2017/01/25 22:14:44
Done.
| |
928 valueControl.value_.setValueFromHex.bind(valueControl.value_, 'd0x'), | |
929 'Expected new value to start with "0x"'); | |
930 }); | |
931 | |
932 test('ValueControl_ConvertValue_Hexadecimal_ThreeValues', function() { | |
933 var valueControl = value_control.ValueControl(); | |
934 valueControl.load(device1.address, service1.id, characteristic1); | |
935 valueControl.typeSelect_.selectedIndex = 0; | |
936 valueControl.value_.setValueFromHex('0x616263'); | |
937 var valueArr = valueControl.value_.getArray(); | |
938 | |
939 expectDeepEquals([aCode, bCode, cCode], valueArr); | |
940 }); | |
941 | |
942 test('ValueControl_ConvertValue_UTF8_EmptyString', function() { | |
943 var valueControl = value_control.ValueControl(); | |
944 valueControl.load(device1.address, service1.id, characteristic1); | |
945 valueControl.typeSelect_.selectedIndex = 1; | |
946 valueControl.value_.setValueFromUTF8(''); | |
947 var valueArr = valueControl.value_.getArray(); | |
948 | |
949 expectEquals(0, valueArr.length); | |
950 }); | |
951 | |
952 test('ValueControl_ConvertValue_UTF8_ThreeValues', function() { | |
953 var valueControl = value_control.ValueControl(); | |
954 valueControl.load(device1.address, service1.id, characteristic1); | |
955 valueControl.typeSelect_.selectedIndex = 1; | |
956 valueControl.value_.setValueFromUTF8('abc'); | |
957 var valueArr = valueControl.value_.getArray(); | |
958 | |
959 expectDeepEquals([aCode, bCode, cCode], valueArr); | |
960 }); | |
961 | |
962 test('ValueControl_ConvertValue_Decimal_EmptyString', function() { | |
963 var valueControl = value_control.ValueControl(); | |
964 valueControl.load(device1.address, service1.id, characteristic1); | |
965 valueControl.typeSelect_.selectedIndex = 2; | |
966 valueControl.value_.setValueFromDecimal(''); | |
967 var valueArr = valueControl.value_.getArray(); | |
968 | |
969 expectEquals(0, valueArr.length); | |
970 }); | |
971 | |
972 test('ValueControl_ConvertValue_Decimal_ThreeValues_Fail', function() { | |
973 var valueControl = value_control.ValueControl(); | |
974 valueControl.load(device1.address, service1.id, characteristic1); | |
975 valueControl.typeSelect_.selectedIndex = 2; | |
976 | |
977 expectThrows( | |
978 valueControl.value_.setValueFromDecimal.bind( | |
979 valueControl, '97-+-99' /* a-+-c */), | |
980 'New value can only contain numbers and hyphens'); | |
981 }); | |
982 | |
983 test('ValueControl_ConvertValue_Decimal_ThreeValues', function() { | |
984 var valueControl = value_control.ValueControl(); | |
985 valueControl.load(device1.address, service1.id, characteristic1); | |
986 valueControl.typeSelect_.selectedIndex = 2; | |
987 valueControl.value_.setValueFromDecimal('97-98-99' /* abc */); | |
988 var valueArr = valueControl.value_.getArray(); | |
989 | |
990 expectDeepEquals([aCode, bCode, cCode], valueArr); | |
991 }); | |
992 | |
993 }); | |
994 | |
805 // Run all registered tests. | 995 // Run all registered tests. |
806 mocha.run(); | 996 mocha.run(); |
807 }); | 997 }); |
OLD | NEW |