|
10 | 10 | #include "brave/browser/profile_resetter/brave_profile_resetter.h"
|
11 | 11 | #include "brave/browser/profiles/brave_profile_manager.h"
|
12 | 12 | #include "brave/browser/profiles/profile_util.h"
|
| 13 | +#include "brave/browser/search_engines/pref_names.h" |
13 | 14 | #include "brave/browser/search_engines/search_engine_provider_service_factory.h"
|
14 | 15 | #include "brave/browser/search_engines/search_engine_provider_util.h"
|
15 | 16 | #include "brave/browser/ui/browser_commands.h"
|
|
35 | 36 | #include "chrome/test/base/ui_test_utils.h"
|
36 | 37 | #include "components/country_codes/country_codes.h"
|
37 | 38 | #include "components/prefs/pref_service.h"
|
| 39 | +#include "components/regional_capabilities/regional_capabilities_switches.h" |
38 | 40 | #include "components/search_engines/search_engine_choice/search_engine_choice_service.h"
|
39 | 41 | #include "components/search_engines/search_engines_pref_names.h"
|
40 | 42 | #include "components/search_engines/search_engines_test_util.h"
|
@@ -279,6 +281,76 @@ INSTANTIATE_TEST_SUITE_P(
|
279 | 281 | {"ko_KR", true, false},
|
280 | 282 | {"ko_KR", false, false}}));
|
281 | 283 |
|
| 284 | +class MigrateSearchEnginePrefsInJPTest : public InProcessBrowserTest { |
| 285 | + public: |
| 286 | + MigrateSearchEnginePrefsInJPTest() = default; |
| 287 | + ~MigrateSearchEnginePrefsInJPTest() override = default; |
| 288 | + |
| 289 | + void SetUpCommandLine(base::CommandLine* command_line) override { |
| 290 | + InProcessBrowserTest::SetUpCommandLine(command_line); |
| 291 | + |
| 292 | + command_line->AppendSwitchASCII(switches::kSearchEngineChoiceCountry, "JP"); |
| 293 | + } |
| 294 | + |
| 295 | + TemplateURLService* service() { |
| 296 | + return TemplateURLServiceFactory::GetForProfile(browser()->profile()); |
| 297 | + } |
| 298 | + |
| 299 | + PrefService* prefs() { return browser()->profile()->GetPrefs(); } |
| 300 | + |
| 301 | + private: |
| 302 | + const brave_l10n::test::ScopedDefaultLocale default_locale{"ja_JP"}; |
| 303 | +}; |
| 304 | + |
| 305 | +IN_PROC_BROWSER_TEST_F(MigrateSearchEnginePrefsInJPTest, |
| 306 | + PRE_PRE_DefaultSearchProviderUpdateTest) { |
| 307 | + EXPECT_TRUE(VerifyTemplateURLServiceLoad(service())); |
| 308 | + |
| 309 | + // To simulate existing user at next launch, set 31 |
| 310 | + // as we set yahoo as a default in jp at 31. |
| 311 | + // At the next launch, default provider will be yahoo with this setting. |
| 312 | + prefs()->SetInteger(prefs::kBraveDefaultSearchVersion, 31); |
| 313 | + |
| 314 | + // To run migration code again at the next launch. |
| 315 | + prefs()->ClearPref(kMigratedSearchDefaultInJP); |
| 316 | + prefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); |
| 317 | +} |
| 318 | + |
| 319 | +// To verify migration code doesn't touch search suggestions if current provider |
| 320 | +// is yahoo jp. |
| 321 | +IN_PROC_BROWSER_TEST_F(MigrateSearchEnginePrefsInJPTest, |
| 322 | + PRE_DefaultSearchProviderUpdateTest) { |
| 323 | + EXPECT_TRUE(VerifyTemplateURLServiceLoad(service())); |
| 324 | + |
| 325 | + const int provider_id = |
| 326 | + service()->GetDefaultSearchProvider()->prepopulate_id(); |
| 327 | + EXPECT_EQ(provider_id, |
| 328 | + static_cast<int>( |
| 329 | + TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_YAHOO_JP)); |
| 330 | + EXPECT_TRUE(prefs()->GetBoolean(prefs::kSearchSuggestEnabled)); |
| 331 | + |
| 332 | + // To simulate existing user at next launch, set older version than 31 |
| 333 | + // as we set yahoo as a default in jp at 31. |
| 334 | + // At the next launch, default provider will be non-yahoo by setting old |
| 335 | + // version number. |
| 336 | + prefs()->SetInteger(prefs::kBraveDefaultSearchVersion, 30); |
| 337 | + |
| 338 | + // To make migration code run at the next launch, clear related prefs. |
| 339 | + prefs()->ClearPref(kMigratedSearchDefaultInJP); |
| 340 | +} |
| 341 | + |
| 342 | +IN_PROC_BROWSER_TEST_F(MigrateSearchEnginePrefsInJPTest, |
| 343 | + DefaultSearchProviderUpdateTest) { |
| 344 | + EXPECT_TRUE(VerifyTemplateURLServiceLoad(service())); |
| 345 | + |
| 346 | + const int provider_id = |
| 347 | + service()->GetDefaultSearchProvider()->prepopulate_id(); |
| 348 | + EXPECT_EQ(provider_id, |
| 349 | + static_cast<int>( |
| 350 | + TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_YAHOO_JP)); |
| 351 | + EXPECT_FALSE(prefs()->GetBoolean(prefs::kSearchSuggestEnabled)); |
| 352 | +} |
| 353 | + |
282 | 354 | #if BUILDFLAG(ENABLE_EXTENSIONS)
|
283 | 355 |
|
284 | 356 | namespace extensions {
|
|
0 commit comments