| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This just tests the interface. It does not test for specific results, only | 5 // This just tests the interface. It does not test for specific results, only |
| 6 // that callbacks are correctly invoked, expected parameters are correct, | 6 // that callbacks are correctly invoked, expected parameters are correct, |
| 7 // and failures are detected. | 7 // and failures are detected. |
| 8 | 8 |
| 9 var availableTests = [ | 9 var availableTests = [ |
| 10 function saveAddress() { | 10 function saveAddress() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 chrome.test.assertEq(address.fullNames[0], NAME); | 22 chrome.test.assertEq(address.fullNames[0], NAME); |
| 23 chrome.test.succeed(); | 23 chrome.test.succeed(); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 chrome.autofillPrivate.onAddressListChanged.addListener(handler); | 27 chrome.autofillPrivate.onAddressListChanged.addListener(handler); |
| 28 chrome.autofillPrivate.getAddressList(handler); | 28 chrome.autofillPrivate.getAddressList(handler); |
| 29 chrome.autofillPrivate.saveAddress({fullNames: [NAME]}); | 29 chrome.autofillPrivate.saveAddress({fullNames: [NAME]}); |
| 30 }, | 30 }, |
| 31 | 31 |
| 32 function getCountryList() { |
| 33 var handler = function(countries) { |
| 34 var numSeparators = 0; |
| 35 var countBeforeSeparator = 0; |
| 36 var countAfterSeparator = 0; |
| 37 |
| 38 var beforeSeparator = true; |
| 39 |
| 40 chrome.test.assertTrue(countries.length > 1, |
| 41 'Expected more than one country'); |
| 42 |
| 43 countries.forEach(function(country) { |
| 44 // Expecting to have both |name| and |countryCode| or neither. |
| 45 chrome.test.assertEq(!!country.name, !!country.countryCode); |
| 46 |
| 47 if (country.name) { |
| 48 if (beforeSeparator) |
| 49 ++countBeforeSeparator; |
| 50 else |
| 51 ++countAfterSeparator; |
| 52 } else { |
| 53 beforeSeparator = false; |
| 54 ++numSeparators; |
| 55 } |
| 56 }); |
| 57 |
| 58 chrome.test.assertEq(1, numSeparators); |
| 59 chrome.test.assertEq(1, countBeforeSeparator); |
| 60 chrome.test.assertTrue(countAfterSeparator > 1, |
| 61 'Expected more than one country after the separator'); |
| 62 |
| 63 chrome.test.succeed(); |
| 64 }; |
| 65 |
| 66 chrome.autofillPrivate.getCountryList(handler); |
| 67 }, |
| 68 |
| 32 function getAddressComponents() { | 69 function getAddressComponents() { |
| 33 var COUNTRY_CODE = 'US'; | 70 var COUNTRY_CODE = 'US'; |
| 34 | 71 |
| 35 var handler = function(components) { | 72 var handler = function(components) { |
| 36 chrome.test.assertTrue(!!components.components); | 73 chrome.test.assertTrue(!!components.components); |
| 37 chrome.test.assertTrue(!!components.components[0]); | 74 chrome.test.assertTrue(!!components.components[0]); |
| 38 chrome.test.assertTrue(!!components.components[0].row); | 75 chrome.test.assertTrue(!!components.components[0].row); |
| 39 chrome.test.assertTrue(!!components.components[0].row[0]); | 76 chrome.test.assertTrue(!!components.components[0].row[0]); |
| 40 chrome.test.assertTrue(!!components.components[0].row[0].field); | 77 chrome.test.assertTrue(!!components.components[0].row[0].field); |
| 41 chrome.test.assertTrue(!!components.components[0].row[0].fieldName); | 78 chrome.test.assertTrue(!!components.components[0].row[0].fieldName); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 indexOfNewNumber: 0, | 177 indexOfNewNumber: 0, |
| 141 countryCode: COUNTRY_CODE | 178 countryCode: COUNTRY_CODE |
| 142 }, handler1); | 179 }, handler1); |
| 143 }, | 180 }, |
| 144 ]; | 181 ]; |
| 145 | 182 |
| 146 var testToRun = window.location.search.substring(1); | 183 var testToRun = window.location.search.substring(1); |
| 147 chrome.test.runTests(availableTests.filter(function(op) { | 184 chrome.test.runTests(availableTests.filter(function(op) { |
| 148 return op.name == testToRun; | 185 return op.name == testToRun; |
| 149 })); | 186 })); |
| OLD | NEW |