Commit 6965e0b1 authored by Vidhan's avatar Vidhan Committed by Commit Bot

[Autofill][States] Test AlternativeStateNameMapUpdater with UTF8 strings

Added tests for inserting the states data consisting of UTf8 strings in
AlternativeStateNameMapUpdater.

Bug: 1111960
Change-Id: Iee96de3ceb3b6c3726d7bffc685aab29293c23f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2513215Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Reviewed-by: default avatarChristoph Schwering <schwering@google.com>
Commit-Queue: Vidhan Jain <vidhanj@google.com>
Cr-Commit-Position: refs/heads/master@{#823557}
parent f41dd2c9
......@@ -52,11 +52,12 @@ void PopulateAlternativeStateNameMapForTesting(
}
}
std::string CreateStatesProtoAsString(std::string country_code) {
std::string CreateStatesProtoAsString(const std::string& country_code,
const TestStateEntry& test_state_entry) {
StatesInCountry states_data;
states_data.set_country_code(std::move(country_code));
StateEntry* entry = states_data.add_states();
PopulateStateEntry(TestStateEntry(), entry);
PopulateStateEntry(test_state_entry, entry);
std::string serialized_output;
bool proto_is_serialized = states_data.SerializeToString(&serialized_output);
......
......@@ -37,7 +37,9 @@ void PopulateAlternativeStateNameMapForTesting(
const std::vector<TestStateEntry>& test_state_entries = {TestStateEntry()});
// Returns a StateEntry instance serialized as string.
std::string CreateStatesProtoAsString(std::string country_code = "DE");
std::string CreateStatesProtoAsString(
const std::string& country_code = "DE",
const TestStateEntry& test_state_entry = TestStateEntry());
} // namespace test
} // namespace autofill
......
......@@ -99,6 +99,49 @@ TEST_F(AlternativeStateNameMapUpdaterTest, TestLoadStatesData) {
base::nullopt);
}
// Tests that the AlternativeStateNameMap is populated when
// |StateNameMapUpdater::LoadStatesData()| is called and there are UTF8 strings.
TEST_F(AlternativeStateNameMapUpdaterTest, TestLoadStatesDataUTF8) {
test::ClearAlternativeStateNameMapForTesting();
base::WriteFile(
GetPath().AppendASCII("ES"),
test::CreateStatesProtoAsString(
"ES", {.canonical_name = "Paraná",
.abbreviations = {"PR"},
.alternative_names = {"Parana", "State of Parana"}}));
WritePathToPref(GetPath());
base::RunLoop run_loop;
alternative_state_name_map_updater.LoadStatesData(
{{AlternativeStateNameMap::CountryCode("ES"),
{AlternativeStateNameMap::StateName(ASCIIToUTF16("Parana"))}}},
pref_service_.get(), run_loop.QuitClosure());
run_loop.Run();
base::Optional<StateEntry> entry1 =
AlternativeStateNameMap::GetInstance()->GetEntry(
AlternativeStateNameMap::CountryCode("ES"),
AlternativeStateNameMap::StateName(base::UTF8ToUTF16("Paraná")));
EXPECT_NE(entry1, base::nullopt);
EXPECT_EQ(entry1->canonical_name(), "Paraná");
EXPECT_THAT(entry1->abbreviations(),
testing::UnorderedElementsAreArray({"PR"}));
EXPECT_THAT(entry1->alternative_names(), testing::UnorderedElementsAreArray(
{"Parana", "State of Parana"}));
base::Optional<StateEntry> entry2 =
AlternativeStateNameMap::GetInstance()->GetEntry(
AlternativeStateNameMap::CountryCode("ES"),
AlternativeStateNameMap::StateName(base::UTF8ToUTF16("Parana")));
EXPECT_NE(entry2, base::nullopt);
EXPECT_EQ(entry2->canonical_name(), "Paraná");
EXPECT_THAT(entry2->abbreviations(),
testing::UnorderedElementsAreArray({"PR"}));
EXPECT_THAT(entry2->alternative_names(), testing::UnorderedElementsAreArray(
{"Parana", "State of Parana"}));
}
// Tests the |StateNameMapUpdater::ContainsState()| functionality.
TEST_F(AlternativeStateNameMapUpdaterTest, ContainsState) {
EXPECT_TRUE(AlternativeStateNameMapUpdater::ContainsStateForTesting(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment