diff --git a/components/brave_vpn/common/brave_vpn_utils.cc b/components/brave_vpn/common/brave_vpn_utils.cc index 51c3a0a81496..7d7c0b6531d1 100644 --- a/components/brave_vpn/common/brave_vpn_utils.cc +++ b/components/brave_vpn/common/brave_vpn_utils.cc @@ -56,7 +56,10 @@ void RegisterVPNLocalStatePrefs(PrefRegistrySimple* registry) { registry->RegisterListPref(prefs::kBraveVPNWidgetUsageWeeklyStorage); } -// Region name map between v1 and v2. +// Region name map between v1 and v2. Some region from region list v2 +// uses different name with v1. If previously selected region name +// uses different with v2, we can't proper region with it. So, map +// v1 name to v2's. constexpr auto kV1ToV2Map = base::MakeFixedFlatMap( {{"au-au", "ocn-aus"}, {"eu-at", "eu-at"}, @@ -108,7 +111,13 @@ std::string_view GetMigratedNameIfNeeded(PrefService* local_prefs, } auto it = kV1ToV2Map.find(name); - CHECK(it != kV1ToV2Map.end()); + // |kV1ToV2Map| doesn't include newly supported timezone names. + // Use |name| in that case. + // TODO(simonhong): Need to check this new name is aligned with + // v2 region list data. + if (it == kV1ToV2Map.end()) { + return name; + } return it->second; } diff --git a/components/brave_vpn/common/brave_vpn_utils_unittest.cc b/components/brave_vpn/common/brave_vpn_utils_unittest.cc index 64b88c183a43..fb05b6f8a6c2 100644 --- a/components/brave_vpn/common/brave_vpn_utils_unittest.cc +++ b/components/brave_vpn/common/brave_vpn_utils_unittest.cc @@ -226,6 +226,20 @@ TEST(BraveVPNUtilsUnitTest, InvalidSelectedRegionNameMigration) { EXPECT_EQ(2, local_state_pref_service.GetInteger( brave_vpn::prefs::kBraveVPNRegionListVersion)); } + +TEST(BraveVPNUtilsUnitTest, NewTimeZoneName) { + TestingPrefServiceSimple local_state_pref_service; + brave_vpn::RegisterLocalStatePrefs(local_state_pref_service.registry()); + EXPECT_EQ(1, local_state_pref_service.GetInteger( + brave_vpn::prefs::kBraveVPNRegionListVersion)); + brave_vpn::MigrateLocalStatePrefs(&local_state_pref_service); + EXPECT_EQ(2, local_state_pref_service.GetInteger( + brave_vpn::prefs::kBraveVPNRegionListVersion)); + + // Check passed timezone name is returned if it's not included in V1ToV2Map. + EXPECT_EQ("asia-new", brave_vpn::GetMigratedNameIfNeeded( + &local_state_pref_service, "asia-new")); +} #endif TEST(BraveVPNUtilsUnitTest, VPNPaymentsEnv) {