From 398bf5ef0fa42e7b118ac4139eaea2ce10fc033a Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Tue, 11 Oct 2022 16:28:51 -0500 Subject: [PATCH] Refactor test scoped default locale --- browser/brave_ads/ads_service_browsertest.cc | 9 ++- components/brave_ads/test/BUILD.gn | 1 + .../rewards_service_impl_jp_unittest.cc | 7 +- .../browser/rewards_service_impl_unittest.cc | 7 +- components/brave_rewards/test/BUILD.gn | 2 +- .../brave_search_default_host_unittest.cc | 4 +- components/brave_today/browser/test/BUILD.gn | 2 +- .../brave_today/browser/urls_unittest.cc | 20 +++--- components/l10n/common/BUILD.gn | 22 ++++++- components/l10n/common/default_locale.cc | 33 ++++++++++ components/l10n/common/default_locale.h | 18 +++++ components/l10n/common/locale_util.cc | 65 +------------------ components/l10n/common/locale_util.h | 14 +--- .../l10n/common/locale_util_unittest.cc | 43 ++++++------ .../l10n/common/test/scoped_default_locale.cc | 21 ++++++ .../l10n/common/test/scoped_default_locale.h | 33 ++++++++++ .../ntp_widget_utils_region_unittest.cc | 8 +-- components/omnibox/browser/BUILD.gn | 2 +- .../omnibox/browser/promotion_unittest.cc | 7 +- test/BUILD.gn | 2 + .../user_data/locale_user_data_unittest.cc | 8 +-- ...nfirmation_url_request_builder_unittest.cc | 26 +++----- ...ision_targeting_exclusion_rule_unittest.cc | 7 +- .../internal/base/unittest/unittest_base.cc | 3 +- .../internal/base/unittest/unittest_base.h | 8 ++- .../diagnostic_manager_unittest.cc | 5 +- .../locale_diagnostic_entry_unittest.cc | 5 +- .../subdivision_targeting_unittest.cc | 8 +-- 28 files changed, 216 insertions(+), 174 deletions(-) create mode 100644 components/l10n/common/default_locale.cc create mode 100644 components/l10n/common/default_locale.h create mode 100644 components/l10n/common/test/scoped_default_locale.cc create mode 100644 components/l10n/common/test/scoped_default_locale.h diff --git a/browser/brave_ads/ads_service_browsertest.cc b/browser/brave_ads/ads_service_browsertest.cc index afa6c12203f..7be59b61eac 100644 --- a/browser/brave_ads/ads_service_browsertest.cc +++ b/browser/brave_ads/ads_service_browsertest.cc @@ -26,7 +26,7 @@ #include "brave/components/brave_rewards/browser/rewards_service_impl.h" #include "brave/components/brave_rewards/browser/test/common/rewards_browsertest_util.h" #include "brave/components/constants/brave_paths.h" -#include "brave/components/l10n/common/locale_util.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/test/base/in_process_browser_test.h" @@ -201,7 +201,7 @@ class BraveAdsBrowserTest : public InProcessBrowserTest, } scoped_default_locale_ = - std::make_unique(it->second); + std::make_unique(it->second); } void MaybeMockLocaleForBraveAdsUpgradePath() { @@ -239,7 +239,7 @@ class BraveAdsBrowserTest : public InProcessBrowserTest, } scoped_default_locale_ = - std::make_unique(locale); + std::make_unique(locale); } void MaybeMockUserProfilePreferencesForBraveAdsUpgradePath() { @@ -343,8 +343,7 @@ class BraveAdsBrowserTest : public InProcessBrowserTest, std::string wallet_; std::string parameters_; - std::unique_ptr - scoped_default_locale_; + std::unique_ptr scoped_default_locale_; }; IN_PROC_BROWSER_TEST_F(BraveAdsBrowserTest, BraveAdsLocaleIsSupported) { diff --git a/components/brave_ads/test/BUILD.gn b/components/brave_ads/test/BUILD.gn index 43d66b2629f..a96cb4d821f 100644 --- a/components/brave_ads/test/BUILD.gn +++ b/components/brave_ads/test/BUILD.gn @@ -454,6 +454,7 @@ source_set("brave_ads_unit_tests") { "//brave/components/brave_rewards/test:brave_rewards_unit_tests", "//brave/components/challenge_bypass_ristretto", "//brave/components/l10n/common", + "//brave/components/l10n/common:test_support", "//brave/components/version_info:version_info", "//brave/vendor/bat-native-ads", "//brave/vendor/bat-native-ledger", diff --git a/components/brave_rewards/browser/rewards_service_impl_jp_unittest.cc b/components/brave_rewards/browser/rewards_service_impl_jp_unittest.cc index 0f66fe09eb6..b7957f23990 100644 --- a/components/brave_rewards/browser/rewards_service_impl_jp_unittest.cc +++ b/components/brave_rewards/browser/rewards_service_impl_jp_unittest.cc @@ -19,7 +19,7 @@ #include "brave/components/brave_rewards/common/pref_names.h" #include "brave/components/brave_rewards/common/rewards_flags.h" #include "brave/components/greaselion/browser/buildflags/buildflags.h" -#include "brave/components/l10n/common/locale_util.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" #include "chrome/browser/profiles/profile.h" #include "chrome/test/base/testing_browser_process.h" #include "components/prefs/pref_service.h" @@ -43,7 +43,7 @@ class RewardsServiceJPTest : public testing::Test { void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); scoped_default_locale_ = - std::make_unique("ja_JP"); + std::make_unique("ja_JP"); profile_ = CreateBraveRewardsProfile(temp_dir_.GetPath()); ASSERT_TRUE(profile_); #if BUILDFLAG(ENABLE_GREASELION) @@ -92,8 +92,7 @@ class RewardsServiceJPTest : public testing::Test { std::unique_ptr profile_; raw_ptr rewards_service_ = nullptr; base::ScopedTempDir temp_dir_; - std::unique_ptr - scoped_default_locale_; + std::unique_ptr scoped_default_locale_; }; #if BUILDFLAG(ENABLE_GEMINI_WALLET) diff --git a/components/brave_rewards/browser/rewards_service_impl_unittest.cc b/components/brave_rewards/browser/rewards_service_impl_unittest.cc index 492e1732cb2..f45d3a0e3fa 100644 --- a/components/brave_rewards/browser/rewards_service_impl_unittest.cc +++ b/components/brave_rewards/browser/rewards_service_impl_unittest.cc @@ -18,7 +18,7 @@ #include "brave/components/brave_rewards/common/features.h" #include "brave/components/brave_rewards/common/pref_names.h" #include "brave/components/greaselion/browser/buildflags/buildflags.h" -#include "brave/components/l10n/common/locale_util.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" #include "chrome/browser/profiles/profile.h" #include "chrome/test/base/testing_browser_process.h" #include "components/prefs/pref_service.h" @@ -74,7 +74,7 @@ class RewardsServiceTest : public testing::Test { void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); scoped_default_locale_ = - std::make_unique("en_US"); + std::make_unique("en_US"); profile_ = CreateBraveRewardsProfile(temp_dir_.GetPath()); ASSERT_TRUE(profile_.get()); #if BUILDFLAG(ENABLE_GREASELION) @@ -124,8 +124,7 @@ class RewardsServiceTest : public testing::Test { raw_ptr rewards_service_ = nullptr; std::unique_ptr observer_; base::ScopedTempDir temp_dir_; - std::unique_ptr - scoped_default_locale_; + std::unique_ptr scoped_default_locale_; }; #if BUILDFLAG(ENABLE_GEMINI_WALLET) diff --git a/components/brave_rewards/test/BUILD.gn b/components/brave_rewards/test/BUILD.gn index 90190ee0387..ef528fe0e52 100644 --- a/components/brave_rewards/test/BUILD.gn +++ b/components/brave_rewards/test/BUILD.gn @@ -25,7 +25,7 @@ source_set("brave_rewards_unit_tests") { "//brave/components/brave_rewards/resources:static_resources_grit", "//brave/components/challenge_bypass_ristretto", "//brave/components/greaselion/browser/buildflags:buildflags", - "//brave/components/l10n/common", + "//brave/components/l10n/common:test_support", "//brave/vendor/bat-native-ledger", "//brave/vendor/bat-native-ledger:publishers_proto", "//brave/vendor/bat-native-rapidjson", diff --git a/components/brave_search/browser/brave_search_default_host_unittest.cc b/components/brave_search/browser/brave_search_default_host_unittest.cc index cd49763452b..f1a931cd547 100644 --- a/components/brave_search/browser/brave_search_default_host_unittest.cc +++ b/components/brave_search/browser/brave_search_default_host_unittest.cc @@ -19,7 +19,7 @@ #include "brave/components/brave_search/common/features.h" #include "brave/components/brave_search_conversion/features.h" #include "brave/components/brave_search_conversion/utils.h" -#include "brave/components/l10n/common/locale_util.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" #include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_service.h" #include "components/prefs/testing_pref_service.h" @@ -152,7 +152,7 @@ TEST_F(BraveSearchDefaultHostTest, DisallowsAfterMaxTimesAsked) { TEST_F(BraveSearchDefaultHostTest, CanSetDefaultAlwaysTestWithSearchPromotion) { base::test::ScopedFeatureList feature_list; - brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{"en_US"}; + brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_US"}; auto host = GetAPIHost("search.test.com"); // Add a search provider for the host diff --git a/components/brave_today/browser/test/BUILD.gn b/components/brave_today/browser/test/BUILD.gn index 43617e1303d..a7d616058c1 100644 --- a/components/brave_today/browser/test/BUILD.gn +++ b/components/brave_today/browser/test/BUILD.gn @@ -27,7 +27,7 @@ source_set("brave_news_unit_tests") { "//brave/components/brave_today/browser", "//brave/components/brave_today/common", "//brave/components/brave_today/common:mojom", - "//brave/components/l10n/common", + "//brave/components/l10n/common:test_support", "//chrome/browser", "//chrome/test:test_support", "//content/test:test_support", diff --git a/components/brave_today/browser/urls_unittest.cc b/components/brave_today/browser/urls_unittest.cc index c67078c5c58..e89b28109ac 100644 --- a/components/brave_today/browser/urls_unittest.cc +++ b/components/brave_today/browser/urls_unittest.cc @@ -8,7 +8,7 @@ #include "base/test/mock_callback.h" #include "base/test/scoped_feature_list.h" #include "brave/components/brave_today/common/features.h" -#include "brave/components/l10n/common/locale_util.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/googletest/src/googletest/include/gtest/gtest.h" @@ -22,14 +22,14 @@ TEST_F(BraveNewsUrlsTest, BraveNewsV2IsDisabled) { TEST_F(BraveNewsUrlsTest, BraveNewsUsesV1ByDefault) { { - brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{"en_US"}; + brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_US"}; std::string region = brave_today::GetRegionUrlPart(); EXPECT_EQ(brave_today::GetV1RegionUrlPart(), region); EXPECT_EQ("", region); } { - brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{"ja_JP"}; + brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"ja_JP"}; std::string region = brave_today::GetRegionUrlPart(); EXPECT_EQ(brave_today::GetV1RegionUrlPart(), region); EXPECT_EQ("ja", region); @@ -37,7 +37,7 @@ TEST_F(BraveNewsUrlsTest, BraveNewsUsesV1ByDefault) { // Unknown/unsupported locale. { - brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{"na_NA"}; + brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"na_NA"}; std::string region = brave_today::GetRegionUrlPart(); EXPECT_EQ(brave_today::GetV1RegionUrlPart(), region); EXPECT_EQ("", region); @@ -49,17 +49,17 @@ TEST_F(BraveNewsUrlsTest, BraveNewsV2FlagUsesGlobalFeeds) { features.InitAndEnableFeature(brave_today::features::kBraveNewsV2Feature); { - brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{"en_US"}; + brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_US"}; EXPECT_EQ("global.", brave_today::GetRegionUrlPart()); } { - brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{"ja_JP"}; + brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"ja_JP"}; EXPECT_EQ("global.", brave_today::GetRegionUrlPart()); } { - brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{"na_NA"}; + brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"na_NA"}; EXPECT_EQ("global.", brave_today::GetRegionUrlPart()); } } @@ -69,17 +69,17 @@ TEST_F(BraveNewsUrlsTest, BraveNewsV2FlagDoesNotAffectV1Region) { features.InitAndEnableFeature(brave_today::features::kBraveNewsV2Feature); { - brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{"en_US"}; + brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_US"}; EXPECT_EQ("", brave_today::GetV1RegionUrlPart()); } { - brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{"ja-JP"}; + brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"ja-JP"}; EXPECT_EQ("ja", brave_today::GetV1RegionUrlPart()); } { - brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{"na-NA"}; + brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"na-NA"}; EXPECT_EQ("", brave_today::GetV1RegionUrlPart()); } } diff --git a/components/l10n/common/BUILD.gn b/components/l10n/common/BUILD.gn index eb5ba3b0238..aca40d282c2 100644 --- a/components/l10n/common/BUILD.gn +++ b/components/l10n/common/BUILD.gn @@ -1,5 +1,8 @@ static_library("common") { - friend = [ ":unit_tests" ] + friend = [ + ":test_support", + ":unit_tests", + ] public = [ "locale_util.h", @@ -9,6 +12,8 @@ static_library("common") { ] sources = [ + "default_locale.cc", + "default_locale.h", "locale_subtag_info.cc", "locale_subtag_info.h", "locale_subtag_parser_util.cc", @@ -33,6 +38,20 @@ static_library("common") { ] } +static_library("test_support") { + testonly = true + + sources = [ + "test/scoped_default_locale.cc", + "test/scoped_default_locale.h", + ] + + deps = [ + "//base", + "//brave/components/l10n/common", + ] +} + source_set("unit_tests") { testonly = true @@ -47,6 +66,7 @@ source_set("unit_tests") { deps = [ "//base", "//brave/components/l10n/common", + "//brave/components/l10n/common:test_support", "//brave/components/resources:strings_grit", "//testing/gmock", "//testing/gtest", diff --git a/components/l10n/common/default_locale.cc b/components/l10n/common/default_locale.cc new file mode 100644 index 00000000000..79730fedba9 --- /dev/null +++ b/components/l10n/common/default_locale.cc @@ -0,0 +1,33 @@ +/* Copyright (c) 2022 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/components/l10n/common/default_locale.h" + +#include "base/no_destructor.h" +#include "brave/components/l10n/browser/default_locale_util.h" + +namespace brave_l10n { + +namespace { + +constexpr char kFallbackLocale[] = "en_US"; + +std::string& MutableDefaultLocaleString() { + static base::NoDestructor locale( + MaybeGetDefaultLocaleString().value_or(kFallbackLocale)); + return *locale; +} + +} // namespace + +const std::string& DefaultLocaleString() { + return MutableDefaultLocaleString(); +} + +std::string& MutableDefaultLocaleStringForTesting() { + return MutableDefaultLocaleString(); +} + +} // namespace brave_l10n diff --git a/components/l10n/common/default_locale.h b/components/l10n/common/default_locale.h new file mode 100644 index 00000000000..06b00f32995 --- /dev/null +++ b/components/l10n/common/default_locale.h @@ -0,0 +1,18 @@ +/* Copyright (c) 2022 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_COMPONENTS_L10N_COMMON_DEFAULT_LOCALE_H_ +#define BRAVE_COMPONENTS_L10N_COMMON_DEFAULT_LOCALE_H_ + +#include + +namespace brave_l10n { + +const std::string& DefaultLocaleString(); +std::string& MutableDefaultLocaleStringForTesting(); + +} // namespace brave_l10n + +#endif // BRAVE_COMPONENTS_L10N_COMMON_DEFAULT_LOCALE_H_ diff --git a/components/l10n/common/locale_util.cc b/components/l10n/common/locale_util.cc index f2011d3439a..c39fc0cddb8 100644 --- a/components/l10n/common/locale_util.cc +++ b/components/l10n/common/locale_util.cc @@ -5,8 +5,7 @@ #include "brave/components/l10n/common/locale_util.h" -#include "base/no_destructor.h" -#include "brave/components/l10n/browser/default_locale_util.h" +#include "brave/components/l10n/common/default_locale.h" #include "brave/components/l10n/common/locale_subtag_info.h" #include "brave/components/l10n/common/locale_subtag_parser_util.h" @@ -14,41 +13,13 @@ namespace brave_l10n { namespace { -constexpr char kFallbackLocale[] = "en_US"; constexpr char kFallbackLanguageCode[] = "en"; constexpr char kFallbackCountryCode[] = "US"; -absl::optional& DefaultLocaleForTesting() { - static base::NoDestructor> locale; - return *locale; -} - } // namespace -ScopedDefaultLocaleForTesting::ScopedDefaultLocaleForTesting( - const std::string& locale) { - last_locale_ = DefaultLocaleForTesting(); - DefaultLocaleForTesting() = locale; -} - -ScopedDefaultLocaleForTesting::~ScopedDefaultLocaleForTesting() { - DefaultLocaleForTesting() = last_locale_; -} - -std::string GetDefaultLocaleString() { - const absl::optional locale_for_testing = - DefaultLocaleForTesting(); - if (locale_for_testing) { - return *locale_for_testing; - } - - const absl::optional default_locale = - MaybeGetDefaultLocaleString(); - if (!default_locale) { - return kFallbackLocale; - } - - return *default_locale; +const std::string& GetDefaultLocaleString() { + return DefaultLocaleString(); } std::string GetISOLanguageCode(const std::string& locale) { @@ -61,12 +32,6 @@ std::string GetISOLanguageCode(const std::string& locale) { } std::string GetDefaultISOLanguageCodeString() { - const absl::optional locale_for_testing = - DefaultLocaleForTesting(); - if (locale_for_testing) { - return GetISOLanguageCode(*locale_for_testing); - } - return GetISOLanguageCode(GetDefaultLocaleString()); } @@ -80,12 +45,6 @@ absl::optional GetISOScriptCode(const std::string& locale) { } absl::optional GetDefaultISOScriptCodeString() { - const absl::optional locale_for_testing = - DefaultLocaleForTesting(); - if (locale_for_testing) { - return GetISOScriptCode(*locale_for_testing); - } - return GetISOScriptCode(GetDefaultLocaleString()); } @@ -99,12 +58,6 @@ std::string GetISOCountryCode(const std::string& locale) { } std::string GetDefaultISOCountryCodeString() { - const absl::optional locale_for_testing = - DefaultLocaleForTesting(); - if (locale_for_testing) { - return GetISOCountryCode(*locale_for_testing); - } - return GetISOCountryCode(GetDefaultLocaleString()); } @@ -118,12 +71,6 @@ absl::optional GetCharSet(const std::string& locale) { } absl::optional GetDefaultCharSetString() { - const absl::optional locale_for_testing = - DefaultLocaleForTesting(); - if (locale_for_testing) { - return GetCharSet(*locale_for_testing); - } - return GetCharSet(GetDefaultLocaleString()); } @@ -137,12 +84,6 @@ absl::optional GetVariant(const std::string& locale) { } absl::optional GetDefaultVariantString() { - const absl::optional locale_for_testing = - DefaultLocaleForTesting(); - if (locale_for_testing) { - return GetVariant(*locale_for_testing); - } - return GetVariant(GetDefaultLocaleString()); } diff --git a/components/l10n/common/locale_util.h b/components/l10n/common/locale_util.h index a1bb1bf879c..a6e826afa97 100644 --- a/components/l10n/common/locale_util.h +++ b/components/l10n/common/locale_util.h @@ -12,24 +12,12 @@ namespace brave_l10n { -// Set the current default locale for testing, restoring the original locale -// upon destruction. -class ScopedDefaultLocaleForTesting final { - public: - explicit ScopedDefaultLocaleForTesting(const std::string& locale); - - ~ScopedDefaultLocaleForTesting(); - - private: - absl::optional last_locale_; -}; - // IMPORTANT: When the locale should match the application locale or an eligible // string pack for localization use the canonicalized // l10n_util::GetApplicationLocale. // Returns the current default locale of the device as a string. -std::string GetDefaultLocaleString(); +const std::string& GetDefaultLocaleString(); // Returns a lowercase two-letter ISO 639-1 language code for the given locale, // falling back to "en" if the locale does not contain a language code. See diff --git a/components/l10n/common/locale_util_unittest.cc b/components/l10n/common/locale_util_unittest.cc index 78dc14bd693..5a5b87ee495 100644 --- a/components/l10n/common/locale_util_unittest.cc +++ b/components/l10n/common/locale_util_unittest.cc @@ -5,6 +5,7 @@ #include "brave/components/l10n/common/locale_util.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -12,12 +13,12 @@ namespace brave_l10n { -TEST(LocaleUtilTest, ScopedDefaultLocaleForTesting) { - const ScopedDefaultLocaleForTesting scoped_default_locale_us("en_KY"); +TEST(LocaleUtilTest, ScopedDefaultLocale) { + const test::ScopedDefaultLocale scoped_default_locale_us("en_KY"); ASSERT_EQ("en_KY", GetDefaultLocaleString()); { - const ScopedDefaultLocaleForTesting scoped_default_locale_gb("en_GB"); + const test::ScopedDefaultLocale scoped_default_locale_gb("en_GB"); ASSERT_EQ("en_GB", GetDefaultLocaleString()); } @@ -25,37 +26,37 @@ TEST(LocaleUtilTest, ScopedDefaultLocaleForTesting) { } TEST(LocaleUtilTest, GetDefaultLocaleString) { - const ScopedDefaultLocaleForTesting scoped_default_locale("en_Latn_US.UTF-8"); + const test::ScopedDefaultLocale scoped_default_locale("en_Latn_US.UTF-8"); EXPECT_EQ("en_Latn_US.UTF-8", GetDefaultLocaleString()); } TEST(LocaleUtilTest, GetDefaultISOLanguageCodeString) { - const ScopedDefaultLocaleForTesting scoped_default_locale("en_Latn_US.UTF-8"); + const test::ScopedDefaultLocale scoped_default_locale("en_Latn_US.UTF-8"); EXPECT_EQ("en", GetDefaultISOLanguageCodeString()); } TEST(LocaleUtilTest, GetFallbackDefaultISOLanguageCodeString) { - const ScopedDefaultLocaleForTesting scoped_default_locale({}); + const test::ScopedDefaultLocale scoped_default_locale({}); EXPECT_EQ("en", GetDefaultISOLanguageCodeString()); } TEST(LocaleUtilTest, GetISOLanguageCodeForLocale) { - const ScopedDefaultLocaleForTesting scoped_default_locale("ja_JP"); + const test::ScopedDefaultLocale scoped_default_locale("ja_JP"); EXPECT_EQ("en", GetISOLanguageCode("en_Latn_US.UTF-8@currency=USD")); } TEST(LocaleUtilTest, GetDefaultISOScriptCodeString) { - const ScopedDefaultLocaleForTesting scoped_default_locale("en_Latn_US.UTF-8"); + const test::ScopedDefaultLocale scoped_default_locale("en_Latn_US.UTF-8"); EXPECT_EQ("Latn", GetDefaultISOScriptCodeString()); } TEST(LocaleUtilTest, GetUnspecifiedDefaultISOScriptCodeString) { - const ScopedDefaultLocaleForTesting scoped_default_locale({}); + const test::ScopedDefaultLocale scoped_default_locale({}); EXPECT_FALSE(GetDefaultISOScriptCodeString()); } TEST(LocaleUtilTest, GetISOScriptCodeForLocale) { - const ScopedDefaultLocaleForTesting scoped_default_locale("ja_JP"); + const test::ScopedDefaultLocale scoped_default_locale("ja_JP"); EXPECT_EQ("Latn", GetISOScriptCode("en_Latn_US.UTF-8@currency=USD")); } @@ -64,42 +65,42 @@ TEST(LocaleUtilTest, GetUnspecifiedISOScriptCodeForLocale) { } TEST(LocaleUtilTest, GetDefaultISOCountryCodeString) { - const ScopedDefaultLocaleForTesting scoped_default_locale("en_Latn_US.UTF-8"); + const test::ScopedDefaultLocale scoped_default_locale("en_Latn_US.UTF-8"); EXPECT_EQ("US", GetDefaultISOCountryCodeString()); } TEST(LocaleUtilTest, GetFallbackDefaultISOCountryCodeString) { - const ScopedDefaultLocaleForTesting scoped_default_locale({}); + const test::ScopedDefaultLocale scoped_default_locale({}); EXPECT_EQ("US", GetDefaultISOCountryCodeString()); } TEST(LocaleUtilTest, GetISOCountryCodeForLocale) { - const ScopedDefaultLocaleForTesting scoped_default_locale("ja_JP"); + const test::ScopedDefaultLocale scoped_default_locale("ja_JP"); EXPECT_EQ("US", GetISOCountryCode("en_Latn_US.UTF-8@currency=USD")); } TEST(LocaleUtilTest, GetDefaultUNM49CodeString) { - const ScopedDefaultLocaleForTesting scoped_default_locale("en_001"); + const test::ScopedDefaultLocale scoped_default_locale("en_001"); EXPECT_EQ("001", GetDefaultISOCountryCodeString()); } TEST(LocaleUtilTest, GetUNM49CodeForLocaleString) { - const ScopedDefaultLocaleForTesting scoped_default_locale("ja_JP"); + const test::ScopedDefaultLocale scoped_default_locale("ja_JP"); EXPECT_EQ("001", GetISOCountryCode("en_001")); } TEST(LocaleUtilTest, GetDefaultCharSetString) { - const ScopedDefaultLocaleForTesting scoped_default_locale("en_Latn_US.UTF-8"); + const test::ScopedDefaultLocale scoped_default_locale("en_Latn_US.UTF-8"); EXPECT_EQ("UTF-8", GetDefaultCharSetString()); } TEST(LocaleUtilTest, GetUnspecifiedDefaultCharSetString) { - const ScopedDefaultLocaleForTesting scoped_default_locale({}); + const test::ScopedDefaultLocale scoped_default_locale({}); EXPECT_FALSE(GetDefaultCharSetString()); } TEST(LocaleUtilTest, GetCharSetForLocale) { - const ScopedDefaultLocaleForTesting scoped_default_locale("ja_JP"); + const test::ScopedDefaultLocale scoped_default_locale("ja_JP"); EXPECT_EQ("UTF-8", GetCharSet("en_Latn_US.UTF-8@currency=USD")); } @@ -108,18 +109,18 @@ TEST(LocaleUtilTest, GetUnspecifiedCharSetForLocale) { } TEST(LocaleUtilTest, GetDefaultVariantString) { - const ScopedDefaultLocaleForTesting scoped_default_locale( + const test::ScopedDefaultLocale scoped_default_locale( "en_Latn_US.UTF-8@currency=USD"); EXPECT_EQ("currency=USD", GetDefaultVariantString()); } TEST(LocaleUtilTest, GetUnspecifiedDefaultVariantString) { - const ScopedDefaultLocaleForTesting scoped_default_locale({}); + const test::ScopedDefaultLocale scoped_default_locale({}); EXPECT_FALSE(GetDefaultVariantString()); } TEST(LocaleUtilTest, GetVariantForLocale) { - const ScopedDefaultLocaleForTesting scoped_default_locale("ja_JP"); + const test::ScopedDefaultLocale scoped_default_locale("ja_JP"); EXPECT_EQ("currency=USD", GetVariant("en_Latn_US.UTF-8@currency=USD")); } diff --git a/components/l10n/common/test/scoped_default_locale.cc b/components/l10n/common/test/scoped_default_locale.cc new file mode 100644 index 00000000000..8a965400571 --- /dev/null +++ b/components/l10n/common/test/scoped_default_locale.cc @@ -0,0 +1,21 @@ +/* Copyright (c) 2022 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/components/l10n/common/test/scoped_default_locale.h" + +#include "brave/components/l10n/common/default_locale.h" + +namespace brave_l10n::test { + +ScopedDefaultLocale::ScopedDefaultLocale(const std::string& locale) { + last_locale_ = MutableDefaultLocaleStringForTesting(); + MutableDefaultLocaleStringForTesting() = locale; +} + +ScopedDefaultLocale::~ScopedDefaultLocale() { + MutableDefaultLocaleStringForTesting() = last_locale_; +} + +} // namespace brave_l10n::test diff --git a/components/l10n/common/test/scoped_default_locale.h b/components/l10n/common/test/scoped_default_locale.h new file mode 100644 index 00000000000..d1ca94b3312 --- /dev/null +++ b/components/l10n/common/test/scoped_default_locale.h @@ -0,0 +1,33 @@ +/* Copyright (c) 2022 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_COMPONENTS_L10N_COMMON_TEST_SCOPED_DEFAULT_LOCALE_H_ +#define BRAVE_COMPONENTS_L10N_COMMON_TEST_SCOPED_DEFAULT_LOCALE_H_ + +#include + +namespace brave_l10n::test { + +// Set the current default locale for testing, restoring the original locale +// upon destruction. +class ScopedDefaultLocale final { + public: + explicit ScopedDefaultLocale(const std::string& locale); + + ScopedDefaultLocale(const ScopedDefaultLocale& other) = delete; + ScopedDefaultLocale& operator=(const ScopedDefaultLocale& other) = delete; + + ScopedDefaultLocale(ScopedDefaultLocale&& other) noexcept = delete; + ScopedDefaultLocale& operator=(ScopedDefaultLocale&& other) noexcept = delete; + + ~ScopedDefaultLocale(); + + private: + std::string last_locale_; +}; + +} // namespace brave_l10n::test + +#endif // BRAVE_COMPONENTS_L10N_COMMON_TEST_SCOPED_DEFAULT_LOCALE_H_ diff --git a/components/ntp_widget_utils/browser/ntp_widget_utils_region_unittest.cc b/components/ntp_widget_utils/browser/ntp_widget_utils_region_unittest.cc index 18663a2e32a..6b6002a61af 100644 --- a/components/ntp_widget_utils/browser/ntp_widget_utils_region_unittest.cc +++ b/components/ntp_widget_utils/browser/ntp_widget_utils_region_unittest.cc @@ -7,7 +7,7 @@ #include "brave/components/ntp_widget_utils/browser/ntp_widget_utils_region.h" -#include "brave/components/l10n/common/locale_util.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "components/country_codes/country_codes.h" @@ -112,20 +112,20 @@ TEST_F(NTPWidgetUtilsRegionUtilTest, TestRegionUnAllowedDenyList) { TEST_F(NTPWidgetUtilsRegionUtilTest, TestFindLocaleInListOne) { { // Base test with default english locale - brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{"en_US"}; + brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_US"}; EXPECT_EQ(::ntp_widget_utils::FindLocale({"en", "fr", "ja"}, "en"), "en"); } { // Test that FindLocale returns set locale if it's in the provided list - brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{"ja_JP"}; + brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"ja_JP"}; EXPECT_EQ(::ntp_widget_utils::FindLocale({"en", "fr", "ja"}, "en"), "ja"); } { // Test that FindLocale returns the provided default locale if it's not in // the provided list - brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{"ar_DZ"}; + brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"ar_DZ"}; EXPECT_EQ(::ntp_widget_utils::FindLocale({"en", "fr", "ja"}, "en"), "en"); } } diff --git a/components/omnibox/browser/BUILD.gn b/components/omnibox/browser/BUILD.gn index 651ab6811b4..74821daef43 100644 --- a/components/omnibox/browser/BUILD.gn +++ b/components/omnibox/browser/BUILD.gn @@ -25,7 +25,7 @@ source_set("unit_tests") { "//base/test:test_support", "//brave/components/brave_search_conversion", "//brave/components/constants", - "//brave/components/l10n/common", + "//brave/components/l10n/common:test_support", "//brave/components/search_engines", "//chrome/test:test_support", "//components/bookmarks/browser", diff --git a/components/omnibox/browser/promotion_unittest.cc b/components/omnibox/browser/promotion_unittest.cc index daea96cdacb..67133dbc407 100644 --- a/components/omnibox/browser/promotion_unittest.cc +++ b/components/omnibox/browser/promotion_unittest.cc @@ -11,7 +11,7 @@ #include "brave/components/brave_search_conversion/types.h" #include "brave/components/brave_search_conversion/utils.h" #include "brave/components/constants/pref_names.h" -#include "brave/components/l10n/common/locale_util.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" #include "brave/components/omnibox/browser/brave_omnibox_prefs.h" #include "brave/components/omnibox/browser/promotion_provider.h" #include "brave/components/omnibox/browser/promotion_utils.h" @@ -48,7 +48,7 @@ class OmniboxPromotionTest : public testing::Test { false); scoped_default_locale_ = - std::make_unique("en_US"); + std::make_unique("en_US"); } void CreateController(bool incognito) { @@ -97,8 +97,7 @@ class OmniboxPromotionTest : public testing::Test { TestSchemeClassifier classifier_; TestingPrefServiceSimple pref_service_; std::unique_ptr controller_; - std::unique_ptr - scoped_default_locale_; + std::unique_ptr scoped_default_locale_; }; // Promotion match should not be added for private profile. diff --git a/test/BUILD.gn b/test/BUILD.gn index efe839c9f01..a6ceb24678c 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -235,6 +235,7 @@ test("brave_unit_tests") { "//brave/components/ipfs/test:brave_ipfs_unit_tests", "//brave/components/json:brave_json_unit_tests", "//brave/components/l10n/common", + "//brave/components/l10n/common:test_support", "//brave/components/l10n/common:unit_tests", "//brave/components/ntp_background_images/browser", "//brave/components/ntp_background_images/buildflags", @@ -904,6 +905,7 @@ test("brave_browser_tests") { "//brave/components/debounce/common", "//brave/components/ipfs/buildflags", "//brave/components/l10n/common", + "//brave/components/l10n/common:test_support", "//brave/components/ntp_background_images/buildflags", "//brave/components/playlist", "//brave/components/playlist/buildflags", diff --git a/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/locale_user_data_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/locale_user_data_unittest.cc index 7b30a15b147..34050d47782 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/locale_user_data_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/locale_user_data_unittest.cc @@ -8,7 +8,7 @@ #include "base/test/values_test_util.h" #include "bat/ads/internal/base/unittest/unittest_base.h" #include "bat/ads/internal/base/unittest/unittest_mock_util.h" -#include "brave/components/l10n/common/locale_util.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" // npm run test -- brave_unit_tests --filter=BatAds* @@ -49,8 +49,7 @@ TEST_F(BatAdsLocaleUserDataTest, GetLocaleForCountryNotInAnonymitySet) { // Arrange MockBuildChannel(BuildChannelType::kRelease); - const brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{ - "en_MC"}; + const brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_MC"}; // Act const base::Value::Dict user_data = GetLocale(); @@ -67,8 +66,7 @@ TEST_F(BatAdsLocaleUserDataTest, // Arrange MockBuildChannel(BuildChannelType::kRelease); - const brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{ - "en_CX"}; + const brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_CX"}; // Act const base::Value::Dict user_data = GetLocale(); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/account/utility/redeem_unblinded_token/create_confirmation_url_request_builder_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/account/utility/redeem_unblinded_token/create_confirmation_url_request_builder_unittest.cc index bf48dd4dbc3..d622dd523a4 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/account/utility/redeem_unblinded_token/create_confirmation_url_request_builder_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/account/utility/redeem_unblinded_token/create_confirmation_url_request_builder_unittest.cc @@ -12,7 +12,7 @@ #include "bat/ads/internal/flags/flag_manager_util.h" #include "bat/ads/internal/privacy/tokens/unblinded_tokens/unblinded_tokens_unittest_util.h" #include "bat/ads/sys_info.h" -#include "brave/components/l10n/common/locale_util.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" #include "url/gurl.h" // npm run test -- brave_unit_tests --filter=BatAds* @@ -71,8 +71,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, MockBuildChannel(BuildChannelType::kRelease); - const brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{ - "en_AS"}; + const brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_AS"}; const absl::optional confirmation = BuildConfirmation(); ASSERT_TRUE(confirmation); @@ -105,8 +104,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, MockBuildChannel(BuildChannelType::kRelease); - const brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{ - "en_KY"}; + const brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_KY"}; const absl::optional confirmation = BuildConfirmation(); ASSERT_TRUE(confirmation); @@ -170,8 +168,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, MockBuildChannel(BuildChannelType::kNightly); - const brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{ - "en_AS"}; + const brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_AS"}; const absl::optional confirmation = BuildConfirmation(); ASSERT_TRUE(confirmation); @@ -204,8 +201,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, MockBuildChannel(BuildChannelType::kNightly); - const brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{ - "en_KY"}; + const brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_KY"}; const absl::optional confirmation = BuildConfirmation(); ASSERT_TRUE(confirmation); @@ -269,8 +265,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, MockBuildChannel(BuildChannelType::kRelease); - const brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{ - "en_AS"}; + const brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_AS"}; const absl::optional confirmation = BuildConfirmation(); ASSERT_TRUE(confirmation); @@ -303,8 +298,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, MockBuildChannel(BuildChannelType::kRelease); - const brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{ - "en_KY"}; + const brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_KY"}; const absl::optional confirmation = BuildConfirmation(); ASSERT_TRUE(confirmation); @@ -368,8 +362,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, MockBuildChannel(BuildChannelType::kNightly); - const brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{ - "en_AS"}; + const brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_AS"}; const absl::optional confirmation = BuildConfirmation(); ASSERT_TRUE(confirmation); @@ -402,8 +395,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, MockBuildChannel(BuildChannelType::kNightly); - const brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{ - "en_KY"}; + const brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_KY"}; const absl::optional confirmation = BuildConfirmation(); ASSERT_TRUE(confirmation); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/exclusion_rules/subdivision_targeting_exclusion_rule_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/exclusion_rules/subdivision_targeting_exclusion_rule_unittest.cc index b4dd35a999d..9292ff1df54 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/exclusion_rules/subdivision_targeting_exclusion_rule_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/exclusion_rules/subdivision_targeting_exclusion_rule_unittest.cc @@ -12,7 +12,7 @@ #include "bat/ads/internal/base/unittest/unittest_mock_util.h" #include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" #include "bat/ads/pref_names.h" -#include "brave/components/l10n/common/locale_util.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" #include "net/http/http_status_code.h" // npm run test -- brave_unit_tests --filter=BatAds* @@ -41,7 +41,7 @@ class BatAdsSubdivisionTargetingExclusionRuleTest UnitTestBase::SetUp(); scoped_default_locale_ = - std::make_unique( + std::make_unique( base::StrCat({"en", "_", GetParam().country})); subdivision_targeting_ = @@ -81,8 +81,7 @@ class BatAdsSubdivisionTargetingExclusionRuleTest return base::StrCat({GetParam().country, "-XX"}); } - std::unique_ptr - scoped_default_locale_; + std::unique_ptr scoped_default_locale_; std::unique_ptr subdivision_targeting_; std::unique_ptr exclusion_rule_; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.cc b/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.cc index eaaefd5b4b7..ee3bd881be0 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.cc @@ -17,6 +17,7 @@ #include "bat/ads/internal/base/unittest/unittest_mock_util.h" #include "bat/ads/internal/base/unittest/unittest_time_util.h" #include "bat/ads/pref_names.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" using ::testing::NiceMock; @@ -27,7 +28,7 @@ UnitTestBase::UnitTestBase() ads_client_mock_(std::make_unique>()), platform_helper_mock_(std::make_unique>()), scoped_default_locale_( - std::make_unique( + std::make_unique( kDefaultLocale)) { CHECK(temp_dir_.CreateUniqueTempDir()); } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.h b/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.h index 6e00a9e8344..e8a94ed069e 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.h @@ -30,7 +30,6 @@ #include "bat/ads/internal/tabs/tab_manager.h" #include "bat/ads/internal/user_interaction/idle_detection/idle_detection_manager.h" #include "bat/ads/internal/user_interaction/user_activity/user_activity_manager.h" -#include "brave/components/l10n/common/locale_util.h" #include "testing/gmock/include/gmock/gmock.h" // IWYU pragma: keep #include "testing/gtest/include/gtest/gtest.h" // IWYU pragma: keep @@ -39,6 +38,10 @@ class Time; class TimeDelta; } // namespace base +namespace brave_l10n::test { +class ScopedDefaultLocale; +} // namespace brave_l10n::test + namespace ads { class Database; @@ -149,8 +152,7 @@ class UnitTestBase : public testing::Test { bool setup_called_ = false; bool teardown_called_ = false; - std::unique_ptr - scoped_default_locale_; + std::unique_ptr scoped_default_locale_; std::unique_ptr ads_; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/diagnostics/diagnostic_manager_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/diagnostics/diagnostic_manager_unittest.cc index acd1a3161dc..8026e8cd448 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/diagnostics/diagnostic_manager_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/diagnostics/diagnostic_manager_unittest.cc @@ -16,7 +16,7 @@ #include "bat/ads/internal/diagnostics/entries/last_unidle_time_diagnostic_util.h" #include "bat/ads/pref_names.h" #include "bat/ads/sys_info.h" -#include "brave/components/l10n/common/locale_util.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" // npm run test -- brave_unit_tests --filter=BatAds.* @@ -34,8 +34,7 @@ TEST_F(BatAdsDiagnosticManagerTest, DiagnosticManager) { SysInfo().device_id = "21b4677de1a9b4a197ab671a1481d3fcb24f826a4358a05aafbaee5a9a51b57e"; - const brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{ - "en_KY"}; + const brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_KY"}; SetCatalogId("da5dd0e8-71e9-4607-a45b-13e28b607a81"); SetCatalogLastUpdated(Now()); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/diagnostics/entries/locale_diagnostic_entry_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/diagnostics/entries/locale_diagnostic_entry_unittest.cc index 0ff8da1a85f..043ade15264 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/diagnostics/entries/locale_diagnostic_entry_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/diagnostics/entries/locale_diagnostic_entry_unittest.cc @@ -7,7 +7,7 @@ #include "bat/ads/internal/base/unittest/unittest_base.h" #include "bat/ads/internal/diagnostics/diagnostic_entry_types.h" -#include "brave/components/l10n/common/locale_util.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" // npm run test -- brave_unit_tests --filter=BatAds.* @@ -17,8 +17,7 @@ class BatAdsLocaleDiagnosticEntryTest : public UnitTestBase {}; TEST_F(BatAdsLocaleDiagnosticEntryTest, GetValue) { // Arrange - const brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{ - "en_KY"}; + const brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_KY"}; const LocaleDiagnosticEntry diagnostic_entry; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/geographic/subdivision/subdivision_targeting_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/geographic/subdivision/subdivision_targeting_unittest.cc index 3a928c320a0..c3fcbe83ce4 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/geographic/subdivision/subdivision_targeting_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/geographic/subdivision/subdivision_targeting_unittest.cc @@ -10,7 +10,7 @@ #include "bat/ads/internal/base/unittest/unittest_base.h" #include "bat/ads/internal/base/unittest/unittest_mock_util.h" #include "bat/ads/pref_names.h" -#include "brave/components/l10n/common/locale_util.h" +#include "brave/components/l10n/common/test/scoped_default_locale.h" #include "net/http/http_status_code.h" // npm run test -- brave_unit_tests --filter=BatAds* @@ -85,8 +85,7 @@ TEST_F(BatAdsSubdivisionTargetingTest, TEST_F(BatAdsSubdivisionTargetingTest, MaybeFetchSubdivisionTargetingNotSupportedLocale) { // Arrange - const brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{ - "en_KY"}; + const brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_KY"}; // Act subdivision_targeting_->MaybeFetch(); @@ -100,8 +99,7 @@ TEST_F(BatAdsSubdivisionTargetingTest, TEST_F(BatAdsSubdivisionTargetingTest, MaybeAllowSubdivisionTargetingNotSupportedLocale) { // Arrange - const brave_l10n::ScopedDefaultLocaleForTesting scoped_default_locale{ - "en_KY"}; + const brave_l10n::test::ScopedDefaultLocale scoped_default_locale{"en_KY"}; // Act subdivision_targeting_->MaybeAllow();