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; | |
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 try { | |
927 valueControl.convertValueToArray_('d0x'); | |
928 } catch (e) { | |
929 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.
| |
930 } | |
931 | |
932 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.
| |
933 }); | |
934 | |
935 test('ValueControl_ConvertValue_Hexadecimal_ThreeValues', function() { | |
936 var valueControl = value_control.ValueControl(); | |
937 valueControl.load(device1.address, service1.id, characteristic1); | |
938 valueControl.typeSelect_.selectedIndex = 0; | |
939 var valueArr = valueControl.convertValueToArray_('0x616263'); | |
940 | |
941 expectDeepEquals([aCode, bCode, cCode], valueArr); | |
942 }); | |
943 | |
944 test('ValueControl_ConvertValue_UTF8_EmptyString', function() { | |
945 var valueControl = value_control.ValueControl(); | |
946 valueControl.load(device1.address, service1.id, characteristic1); | |
947 valueControl.typeSelect_.selectedIndex = 1; | |
948 var valueArr = valueControl.convertValueToArray_(''); | |
949 | |
950 expectEquals(0, valueArr.length); | |
951 }); | |
952 | |
953 test('ValueControl_ConvertValue_UTF8_ThreeValues', function() { | |
954 var valueControl = value_control.ValueControl(); | |
955 valueControl.load(device1.address, service1.id, characteristic1); | |
956 valueControl.typeSelect_.selectedIndex = 1; | |
957 var valueArr = valueControl.convertValueToArray_('abc'); | |
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 var valueArr = valueControl.convertValueToArray_(''); | |
967 | |
968 expectEquals(0, valueArr.length); | |
969 }); | |
970 | |
971 test('ValueControl_ConvertValue_Decimal_ThreeValues_Fail', function() { | |
972 var valueControl = value_control.ValueControl(); | |
973 valueControl.load(device1.address, service1.id, characteristic1); | |
974 valueControl.typeSelect_.selectedIndex = 2; | |
975 | |
976 try { | |
977 var valueArr = valueControl.convertValueToArray_('97-+-99' /* a-+-c */); | |
978 } catch (e) { | |
979 return; | |
980 } | |
981 | |
982 assertNotReached(); | |
983 }); | |
984 | |
985 test('ValueControl_ConvertValue_Decimal_ThreeValues', function() { | |
986 var valueControl = value_control.ValueControl(); | |
987 valueControl.load(device1.address, service1.id, characteristic1); | |
988 valueControl.typeSelect_.selectedIndex = 2; | |
989 var valueArr = valueControl.convertValueToArray_('97-98-99' /* abc */); | |
990 | |
991 expectDeepEquals([aCode, bCode, cCode], valueArr); | |
992 }); | |
993 | |
994 }); | |
995 | |
805 // Run all registered tests. | 996 // Run all registered tests. |
806 mocha.run(); | 997 mocha.run(); |
807 }); | 998 }); |
OLD | NEW |