Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to check search engine changing in tor retained across the sessions #833

Merged
merged 1 commit into from
Nov 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions browser/search_engine_provider_controller_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ IN_PROC_BROWSER_TEST_F(SearchEngineProviderControllerTest,

// Checks the default search engine of the tor profile.
IN_PROC_BROWSER_TEST_F(SearchEngineProviderControllerTest,
CheckDefaultTorProfileSearchProviderTest) {
PRE_CheckDefaultTorProfileSearchProviderTest) {
ScopedTorLaunchPreventerForTest prevent_tor_process;

brave::NewOffTheRecordWindowTor(browser());
Expand All @@ -101,10 +101,36 @@ IN_PROC_BROWSER_TEST_F(SearchEngineProviderControllerTest,

auto* service = TemplateURLServiceFactory::GetForProfile(tor_profile);

std::string default_provider = IsRegionForQwant(tor_profile) ? "Qwant"
: "DuckDuckGo";
int default_provider_id = IsRegionForQwant(tor_profile) ?
TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_QWANT :
TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_DUCKDUCKGO;

//Check tor profile's search provider is set to ddg.
EXPECT_EQ(service->GetDefaultSearchProvider()->data().short_name(),
base::ASCIIToUTF16(default_provider));
EXPECT_EQ(service->GetDefaultSearchProvider()->data().prepopulate_id,
default_provider_id);

// Change provider to check whether it is retained in the next sessions.
auto data = TemplateURLPrepopulateData::GetPrepopulatedEngine(
tor_profile->GetPrefs(),
TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_BING);
TemplateURL other_url(*data);
service->SetUserSelectedDefaultSearchProvider(&other_url);
}

// Check changed provider in tor profile is retained across the sessions.
IN_PROC_BROWSER_TEST_F(SearchEngineProviderControllerTest,
CheckDefaultTorProfileSearchProviderTest) {
ScopedTorLaunchPreventerForTest prevent_tor_process;

brave::NewOffTheRecordWindowTor(browser());
content::RunAllTasksUntilIdle();

Profile* tor_profile = BrowserList::GetInstance()->GetLastActive()->profile();
EXPECT_TRUE(tor_profile->IsTorProfile());

int expected_provider_id =
TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_BING;
auto* service = TemplateURLServiceFactory::GetForProfile(tor_profile);
EXPECT_EQ(service->GetDefaultSearchProvider()->data().prepopulate_id,
expected_provider_id);
}