-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a versioning mechanism for default search engines and backfill pr…
…ofiles missing this version. Fixes brave/brave-browser#12231
- Loading branch information
Showing
13 changed files
with
187 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2019 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/browser/profiles/profile_util.h" | ||
|
||
#include "base/files/file_path.h" | ||
#include "base/files/scoped_temp_dir.h" | ||
#include "brave/common/pref_names.h" | ||
#include "brave/components/search_engines/brave_prepopulated_engines.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/profiles/profile_manager.h" | ||
#include "chrome/test/base/scoped_testing_local_state.h" | ||
#include "chrome/test/base/test_browser_window.h" | ||
#include "chrome/test/base/testing_browser_process.h" | ||
#include "chrome/test/base/testing_profile.h" | ||
#include "chrome/test/base/testing_profile_manager.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "content/public/test/browser_task_environment.h" | ||
#include "content/public/test/test_utils.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
class BraveProfileUtilTest : public testing::Test { | ||
public: | ||
BraveProfileUtilTest() | ||
: testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {} | ||
~BraveProfileUtilTest() override {} | ||
|
||
protected: | ||
void SetUp() override { | ||
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | ||
ASSERT_TRUE(testing_profile_manager_.SetUp(temp_dir_.GetPath())); | ||
} | ||
|
||
Profile* GetProfile() { return ProfileManager::GetActiveUserProfile(); } | ||
|
||
PrefService* GetPrefs() { | ||
return ProfileManager::GetActiveUserProfile()->GetPrefs(); | ||
} | ||
|
||
content::BrowserTaskEnvironment task_environment_; | ||
TestingProfileManager testing_profile_manager_; | ||
base::ScopedTempDir temp_dir_; | ||
}; | ||
|
||
// No entry yet. Check initialized value | ||
TEST_F(BraveProfileUtilTest, SetDefaultSearchVersionExistingProfileNoEntryYet) { | ||
const PrefService::Preference* pref = | ||
GetPrefs()->FindPreference(kBraveDefaultSearchVersion); | ||
EXPECT_TRUE(pref->IsDefaultValue()); | ||
brave::SetDefaultSearchVersion(GetProfile(), false); | ||
ASSERT_EQ(GetPrefs()->GetInteger(kBraveDefaultSearchVersion), | ||
TemplateURLPrepopulateData::kBraveFirstTrackedDataVersion); | ||
} | ||
|
||
TEST_F(BraveProfileUtilTest, SetDefaultSearchVersionNewProfileNoEntryYet) { | ||
const PrefService::Preference* pref = | ||
GetPrefs()->FindPreference(kBraveDefaultSearchVersion); | ||
EXPECT_TRUE(pref->IsDefaultValue()); | ||
brave::SetDefaultSearchVersion(GetProfile(), true); | ||
ASSERT_EQ(GetPrefs()->GetInteger(kBraveDefaultSearchVersion), | ||
TemplateURLPrepopulateData::kBraveCurrentDataVersion); | ||
} | ||
|
||
// Entry there; ensure value is kept | ||
TEST_F(BraveProfileUtilTest, | ||
SetDefaultSearchVersionExistingProfileHasEntryKeepsValue) { | ||
GetPrefs()->SetInteger(kBraveDefaultSearchVersion, 1); | ||
const PrefService::Preference* pref = | ||
GetPrefs()->FindPreference(kBraveDefaultSearchVersion); | ||
EXPECT_FALSE(pref->IsDefaultValue()); | ||
brave::SetDefaultSearchVersion(GetProfile(), false); | ||
ASSERT_EQ(GetPrefs()->GetInteger(kBraveDefaultSearchVersion), 1); | ||
} | ||
|
||
TEST_F(BraveProfileUtilTest, | ||
SetDefaultSearchVersionNewProfileHasEntryKeepsValue) { | ||
// This is an anomaly case; new profile won't ever have a hard set value | ||
GetPrefs()->SetInteger(kBraveDefaultSearchVersion, 1); | ||
const PrefService::Preference* pref = | ||
GetPrefs()->FindPreference(kBraveDefaultSearchVersion); | ||
EXPECT_FALSE(pref->IsDefaultValue()); | ||
brave::SetDefaultSearchVersion(GetProfile(), true); | ||
ASSERT_EQ(GetPrefs()->GetInteger(kBraveDefaultSearchVersion), 1); | ||
} |
Oops, something went wrong.