Skip to content

Commit

Permalink
Uplift of #27791 (squashed) to beta
Browse files Browse the repository at this point in the history
  • Loading branch information
brave-builds committed Feb 25, 2025
1 parent 0b5b40b commit 622a538
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
13 changes: 11 additions & 2 deletions components/brave_vpn/common/brave_vpn_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string_view, std::string_view>(
{{"au-au", "ocn-aus"}, {"eu-at", "eu-at"},
Expand Down Expand Up @@ -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;
}

Expand Down
14 changes: 14 additions & 0 deletions components/brave_vpn/common/brave_vpn_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 622a538

Please sign in to comment.