diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-09-18 14:34:04 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-10-04 11:15:27 +0000 |
commit | e6430e577f105ad8813c92e75c54660c4985026e (patch) | |
tree | 88115e5d1fb471fea807111924dcccbeadbf9e4f /chromium/third_party/libaddressinput | |
parent | 53d399fe6415a96ea6986ec0d402a9c07da72453 (diff) | |
download | qtwebengine-chromium-e6430e577f105ad8813c92e75c54660c4985026e.tar.gz |
BASELINE: Update Chromium to 61.0.3163.99
Change-Id: I8452f34574d88ca2b27af9bd56fc9ff3f16b1367
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/third_party/libaddressinput')
8 files changed, 123 insertions, 31 deletions
diff --git a/chromium/third_party/libaddressinput/chromium/chrome_address_validator.cc b/chromium/third_party/libaddressinput/chromium/chrome_address_validator.cc index f76bcbd15fd..232ef1e0e5f 100644 --- a/chromium/third_party/libaddressinput/chromium/chrome_address_validator.cc +++ b/chromium/third_party/libaddressinput/chromium/chrome_address_validator.cc @@ -60,18 +60,39 @@ void AddressValidator::LoadRules(const std::string& region_code) { supplier_->LoadRules(region_code, *rules_loaded_); } -std::vector<std::string> AddressValidator::GetRegionSubKeys( - const std::string& region_code) { +std::vector<std::pair<std::string, std::string>> +AddressValidator::GetRegionSubKeys(const std::string& region_code, + const std::string& language) { + std::vector<std::pair<std::string, std::string>> subkeys_codes_names; if (!AreRulesLoadedForRegion(region_code)) - return std::vector<std::string>(); + return subkeys_codes_names; auto rules = supplier_->GetRulesForRegion(region_code); auto rule_iterator = rules.find("data/" + region_code); - + // This happens if the rules are bad. if (rule_iterator == rules.end() || !rule_iterator->second) - return std::vector<std::string>(); - - return rule_iterator->second->GetSubKeys(); + return subkeys_codes_names; + + auto subkeys_codes = rule_iterator->second->GetSubKeys(); + + // If the device language is available, show the names in that language. + // Otherwise, show the default names. + std::string lang_suffix = ""; + if (rules.find("data/" + region_code + "--" + language) != rules.end()) + lang_suffix = "--" + language; // ex: --fr + + for (auto subkey_code : subkeys_codes) { + auto rule = rules.find("data/" + region_code + '/' + subkey_code + + lang_suffix); // exp: data/CA/QC--fr + // This happens if the rules are bad. + if (rule == rules.end() || !rule_iterator->second) + continue; + auto subkey_name = rule->second->GetName(); + if (subkey_name.empty()) // For some cases, the name is not available. + subkey_name = subkey_code; + subkeys_codes_names.push_back(make_pair(subkey_code, subkey_name)); + } + return subkeys_codes_names; } AddressValidator::Status AddressValidator::ValidateAddress( diff --git a/chromium/third_party/libaddressinput/chromium/chrome_address_validator.h b/chromium/third_party/libaddressinput/chromium/chrome_address_validator.h index 7a2c7c6f72b..ef1f434996f 100644 --- a/chromium/third_party/libaddressinput/chromium/chrome_address_validator.h +++ b/chromium/third_party/libaddressinput/chromium/chrome_address_validator.h @@ -10,6 +10,7 @@ #include <map> #include <memory> #include <string> +#include <utility> #include <vector> #include "base/macros.h" @@ -95,11 +96,13 @@ class AddressValidator { virtual void LoadRules(const std::string& region_code); // Returns the list of sub-regions (recorded as sub-keys) of the region - // (recorded as rule) indicated by |region_code|. So, if the |region_code| is + // (recorded as rule) indicated by |region_code|, while the device language + // is set to |language|. So, if the |region_code| is // a country code, sub-region means the country's admin area. // This function should be called when the rules are loaded. - virtual std::vector<std::string> GetRegionSubKeys( - const std::string& region_code); + virtual std::vector<std::pair<std::string, std::string>> GetRegionSubKeys( + const std::string& region_code, + const std::string& language); // Validates the |address| and populates |problems| with the validation // problems, filtered according to the |filter| parameter. diff --git a/chromium/third_party/libaddressinput/chromium/chrome_address_validator_unittest.cc b/chromium/third_party/libaddressinput/chromium/chrome_address_validator_unittest.cc index bc4c9d8ac13..4116f5da91e 100644 --- a/chromium/third_party/libaddressinput/chromium/chrome_address_validator_unittest.cc +++ b/chromium/third_party/libaddressinput/chromium/chrome_address_validator_unittest.cc @@ -52,6 +52,7 @@ using ::i18n::addressinput::UNEXPECTED_FIELD; using ::i18n::addressinput::UNKNOWN_VALUE; using ::i18n::addressinput::USES_P_O_BOX; +// This class should always succeed in getting the rules. class AddressValidatorTest : public testing::Test, LoadRulesListener { protected: AddressValidatorTest() @@ -62,6 +63,10 @@ class AddressValidatorTest : public testing::Test, LoadRulesListener { validator_->LoadRules("US"); } + void set_expected_status(AddressValidator::Status expected_status) { + expected_status_ = expected_status; + } + virtual ~AddressValidatorTest() {} const std::unique_ptr<AddressValidator> validator_; @@ -75,9 +80,11 @@ class AddressValidatorTest : public testing::Test, LoadRulesListener { FieldProblemMap dummy; AddressValidator::Status status = validator_->ValidateAddress(address_data, NULL, &dummy); - ASSERT_EQ(success, status == AddressValidator::SUCCESS); + ASSERT_EQ(expected_status_, status); } + AddressValidator::Status expected_status_ = AddressValidator::SUCCESS; + DISALLOW_COPY_AND_ASSIGN(AddressValidatorTest); }; @@ -113,21 +120,83 @@ AddressValidator* LargeAddressValidatorTest::validator_ = NULL; TEST_F(AddressValidatorTest, SubKeysLoaded) { const std::string country_code = "US"; - const std::string first_state = "AL"; + const std::string state_code = "AL"; + const std::string state_name = "Alabama"; + const std::string language = "en"; + + validator_->LoadRules(country_code); + std::vector<std::pair<std::string, std::string>> sub_keys = + validator_->GetRegionSubKeys(country_code, language); + ASSERT_FALSE(sub_keys.empty()); + ASSERT_EQ(state_code, sub_keys[0].first); + ASSERT_EQ(state_name, sub_keys[0].second); +} + +TEST_F(AddressValidatorTest, SubKeysLoaded_DefaultLanguage) { + const std::string country_code = "CA"; + const std::string province_code = "BC"; + const std::string province_name = "British Columbia"; + const std::string language = "en"; + + validator_->LoadRules(country_code); + std::vector<std::pair<std::string, std::string>> sub_keys = + validator_->GetRegionSubKeys(country_code, language); + ASSERT_FALSE(sub_keys.empty()); + ASSERT_EQ(province_code, sub_keys[1].first); + ASSERT_EQ(province_name, sub_keys[1].second); +} + +TEST_F(AddressValidatorTest, SubKeysLoaded_NonDefaultLanguage) { + const std::string country_code = "CA"; + const std::string province_code = "BC"; + const std::string province_name = "Colombie-Britannique"; + const std::string language = "fr"; + + validator_->LoadRules(country_code); + std::vector<std::pair<std::string, std::string>> sub_keys = + validator_->GetRegionSubKeys(country_code, language); + ASSERT_FALSE(sub_keys.empty()); + ASSERT_EQ(province_code, sub_keys[1].first); + ASSERT_EQ(province_name, sub_keys[1].second); +} + +TEST_F(AddressValidatorTest, SubKeysLoaded_LanguageNotAvailable) { + const std::string country_code = "CA"; + const std::string province_code = "BC"; + const std::string province_name = "British Columbia"; + const std::string language = "es"; validator_->LoadRules(country_code); - std::vector<std::string> sub_keys = - validator_->GetRegionSubKeys(country_code); + std::vector<std::pair<std::string, std::string>> sub_keys = + validator_->GetRegionSubKeys(country_code, language); ASSERT_FALSE(sub_keys.empty()); - ASSERT_EQ(sub_keys[0], first_state); + ASSERT_EQ(province_code, sub_keys[1].first); + ASSERT_EQ(province_name, sub_keys[1].second); } -TEST_F(AddressValidatorTest, SubKeysNotLoaded) { - const std::string country_code = "ZZ"; +TEST_F(AddressValidatorTest, SubKeysLoaded_NamesNotAvailable) { + const std::string country_code = "ES"; + const std::string province_code = "A Coruña"; + const std::string province_name = "A Coruña"; + const std::string language = "es"; + + validator_->LoadRules(country_code); + std::vector<std::pair<std::string, std::string>> sub_keys = + validator_->GetRegionSubKeys(country_code, language); + ASSERT_FALSE(sub_keys.empty()); + ASSERT_EQ(province_code, sub_keys[0].first); + ASSERT_EQ(province_name, sub_keys[0].second); +} + +TEST_F(AddressValidatorTest, SubKeysNotExist) { + const std::string country_code = "OZ"; + const std::string language = "en"; + + set_expected_status(AddressValidator::RULES_UNAVAILABLE); validator_->LoadRules(country_code); - std::vector<std::string> sub_keys = - validator_->GetRegionSubKeys(country_code); + std::vector<std::pair<std::string, std::string>> sub_keys = + validator_->GetRegionSubKeys(country_code, language); ASSERT_TRUE(sub_keys.empty()); } @@ -747,7 +816,7 @@ TEST_F(AddressValidatorTest, ValidateRequiredFieldsWithoutRules) { } TEST_F(AddressValidatorTest, - DoNotValidateRequiredFieldsWithoutRulesWhenErorrIsFiltered) { + DoNotValidateRequiredFieldsWithoutRulesWhenErrorIsFiltered) { // Do not load the rules for JP. AddressData address; address.region_code = "JP"; diff --git a/chromium/third_party/libaddressinput/chromium/chrome_storage_impl.cc b/chromium/third_party/libaddressinput/chromium/chrome_storage_impl.cc index 2504eee9af3..8228805b0bb 100644 --- a/chromium/third_party/libaddressinput/chromium/chrome_storage_impl.cc +++ b/chromium/third_party/libaddressinput/chromium/chrome_storage_impl.cc @@ -39,10 +39,8 @@ void ChromeStorageImpl::Get(const std::string& key, void ChromeStorageImpl::OnPrefValueChanged(const std::string& key) {} void ChromeStorageImpl::OnInitializationCompleted(bool succeeded) { - for (std::vector<Request*>::iterator iter = outstanding_requests_.begin(); - iter != outstanding_requests_.end(); ++iter) { - DoGet((*iter)->key, (*iter)->callback); - } + for (const auto& request : outstanding_requests_) + DoGet(request->key, request->callback); outstanding_requests_.clear(); } @@ -50,7 +48,7 @@ void ChromeStorageImpl::OnInitializationCompleted(bool succeeded) { void ChromeStorageImpl::DoGet(const std::string& key, const Storage::Callback& data_ready) { if (!backing_store_->IsInitializationComplete()) { - outstanding_requests_.push_back(new Request(key, data_ready)); + outstanding_requests_.push_back(base::MakeUnique<Request>(key, data_ready)); return; } diff --git a/chromium/third_party/libaddressinput/chromium/chrome_storage_impl.h b/chromium/third_party/libaddressinput/chromium/chrome_storage_impl.h index 6a08adc59e2..328784d57bb 100644 --- a/chromium/third_party/libaddressinput/chromium/chrome_storage_impl.h +++ b/chromium/third_party/libaddressinput/chromium/chrome_storage_impl.h @@ -6,10 +6,11 @@ #define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_STORAGE_IMPL_H_ #include <list> +#include <memory> #include <string> +#include <vector> #include "base/macros.h" -#include "base/memory/scoped_vector.h" #include "base/scoped_observer.h" #include "components/prefs/pref_store.h" #include "third_party/libaddressinput/src/cpp/include/libaddressinput/storage.h" @@ -50,7 +51,7 @@ class ChromeStorageImpl : public ::i18n::addressinput::Storage, WriteablePrefStore* backing_store_; // weak // Get requests that haven't yet been serviced. - ScopedVector<Request> outstanding_requests_; + std::vector<std::unique_ptr<Request>> outstanding_requests_; ScopedObserver<PrefStore, ChromeStorageImpl> scoped_observer_; diff --git a/chromium/third_party/libaddressinput/chromium/resources/address_input_strings_ar.xtb b/chromium/third_party/libaddressinput/chromium/resources/address_input_strings_ar.xtb index ab71b9cdfd8..7b6723f8bf5 100644 --- a/chromium/third_party/libaddressinput/chromium/resources/address_input_strings_ar.xtb +++ b/chromium/third_party/libaddressinput/chromium/resources/address_input_strings_ar.xtb @@ -26,7 +26,7 @@ <translation id="6403469950615936250">لم يتم التعرف على تنسيق الرمز البريدي هذا. مثال الرمز البريدي الصالح: <ph name="EXAMPLE" />. إذا لم تكن على دراية بالرمز البريدي، يمكنك التعرف عليه <ph name="BEGIN_LINK" />هنا<ph name="END_LINK" />.</translation> <translation id="6735419622867539268"><ph name="FIELD_VALUE" /> لم يتم التعرف عليه كقيمة معروفة لهذا الحقل.</translation> <translation id="6768780634682399515">الرمز البريدي في أيرلندا</translation> -<translation id="6777217372746654521">يبدو أن هذا العنوان يحتوي على صندوق بريد. الرجاء استخدام عنوان شارع أو عنوان مبنى.</translation> +<translation id="6777217372746654521">يبدو أن هذا العنوان يحتوي على صندوق بريد. يُرجى استخدام عنوان شارع أو عنوان مبنى.</translation> <translation id="6839929833149231406">المنطقة</translation> <translation id="684852933191805996">بلدة</translation> <translation id="6970216967273061347">المنطقة</translation> diff --git a/chromium/third_party/libaddressinput/chromium/resources/address_input_strings_ko.xtb b/chromium/third_party/libaddressinput/chromium/resources/address_input_strings_ko.xtb index 2c75d616195..37165f4b2c7 100644 --- a/chromium/third_party/libaddressinput/chromium/resources/address_input_strings_ko.xtb +++ b/chromium/third_party/libaddressinput/chromium/resources/address_input_strings_ko.xtb @@ -13,7 +13,7 @@ <translation id="43113324827158664">이 입력란은 비워둘 수 없습니다.</translation> <translation id="4376888869070172068">인식할 수 없는 우편번호 형식입니다.</translation> <translation id="4518701284698680367">우편번호를 입력해야 합니다(예: <ph name="EXAMPLE" />). 우편번호를 모르십니까? <ph name="BEGIN_LINK" />여기<ph name="END_LINK" />에서 확인하세요.</translation> -<translation id="5089810972385038852">주</translation> +<translation id="5089810972385038852">시/도</translation> <translation id="5095208057601539847">주/도</translation> <translation id="5327248766486351172">이름</translation> <translation id="5937097533660449554">주</translation> diff --git a/chromium/third_party/libaddressinput/chromium/resources/address_input_strings_uk.xtb b/chromium/third_party/libaddressinput/chromium/resources/address_input_strings_uk.xtb index d07db61176b..1ad7e320123 100644 --- a/chromium/third_party/libaddressinput/chromium/resources/address_input_strings_uk.xtb +++ b/chromium/third_party/libaddressinput/chromium/resources/address_input_strings_uk.xtb @@ -10,7 +10,7 @@ <translation id="3713769522066937702">Формат поштового індексу не розпізнано. Приклад дійсного поштового індексу: <ph name="EXAMPLE" />. Не знаєте свій поштовий індекс? Знайдіть його <ph name="BEGIN_LINK" />тут<ph name="END_LINK" />.</translation> <translation id="3882422586004212847">Формат поштового індексу не розпізнано. Приклад дійсного поштового індексу: <ph name="EXAMPLE" />.</translation> <translation id="3885155851504623709">Община</translation> -<translation id="43113324827158664">Це поле не може бути порожнім.</translation> +<translation id="43113324827158664">Це поле потрібно заповнити.</translation> <translation id="4376888869070172068">Формат поштового індексу не розпізнано.</translation> <translation id="4518701284698680367">Потрібно вказати поштовий індекс, наприклад, <ph name="EXAMPLE" />. Не знаєте свій поштовий індекс? Знайдіть його <ph name="BEGIN_LINK" />тут<ph name="END_LINK" />.</translation> <translation id="5089810972385038852">Штат</translation> @@ -32,7 +32,7 @@ <translation id="6970216967273061347">Район або округ</translation> <translation id="7087282848513945231">Округ або графство</translation> <translation id="7139724024395191329">Емірат</translation> -<translation id="7393381084163773901">Адреса (вулиця)</translation> +<translation id="7393381084163773901">Адреса</translation> <translation id="7602447984296396718">Схоже, поштовий індекс не відповідає іншим частинам адреси.</translation> <translation id="7738983109397305830">Схоже, поштовий індекс не відповідає решті адреси. Не знаєте свій поштовий індекс? Знайдіть його <ph name="BEGIN_LINK" />тут<ph name="END_LINK" />.</translation> <translation id="777702478322588152">Префектура</translation> |