Commit 3446e95e authored by Esmael El-Moslimany's avatar Esmael El-Moslimany Committed by Commit Bot

NTP: load chrome://newtab on NTP tabs when DSE changes

When the default search engine is changed, chrome://newtab is loaded on
the tabs with a NTP loaded. chrome://newtab will redirect to the NTP
associated with the new default search engine.

Bug: 1129499
Change-Id: I03360bb781c7bf94e2db65f282ee163386dd26cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2423169Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Commit-Queue: Esmael Elmoslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809479}
parent c164e0d2
...@@ -91,11 +91,6 @@ BrowserInstantController::~BrowserInstantController() = default; ...@@ -91,11 +91,6 @@ BrowserInstantController::~BrowserInstantController() = default;
void BrowserInstantController::OnSearchEngineBaseURLChanged( void BrowserInstantController::OnSearchEngineBaseURLChanged(
SearchEngineBaseURLTracker::ChangeReason change_reason) { SearchEngineBaseURLTracker::ChangeReason change_reason) {
InstantService* instant_service =
InstantServiceFactory::GetForProfile(profile());
if (!instant_service)
return;
TabStripModel* tab_model = browser_->tab_strip_model(); TabStripModel* tab_model = browser_->tab_strip_model();
int count = tab_model->count(); int count = tab_model->count();
for (int index = 0; index < count; ++index) { for (int index = 0; index < count; ++index) {
...@@ -103,29 +98,32 @@ void BrowserInstantController::OnSearchEngineBaseURLChanged( ...@@ -103,29 +98,32 @@ void BrowserInstantController::OnSearchEngineBaseURLChanged(
if (!contents) if (!contents)
continue; continue;
// Send the new NTP URL to the renderer. bool is_ntp = contents->GetMainFrame()->GetSiteInstance()->GetSiteURL() ==
content::RenderProcessHost* rph = contents->GetMainFrame()->GetProcess(); GURL(chrome::kChromeUINewTabPageURL);
instant_service->SendNewTabPageURLToRenderer(rph);
if (!is_ntp) {
InstantService* instant_service =
InstantServiceFactory::GetForProfile(profile());
if (instant_service) {
// Send the new NTP URL to the renderer.
content::RenderProcessHost* rph =
contents->GetMainFrame()->GetProcess();
instant_service->SendNewTabPageURLToRenderer(rph);
is_ntp = instant_service->IsInstantProcess(rph->GetID());
}
}
if (!instant_service->IsInstantProcess(rph->GetID())) if (!is_ntp)
continue; continue;
bool google_base_url_domain_changed = // When default search engine is changed navigate to chrome://newtab which
change_reason == // will redirect to the new tab page associated with the search engine.
SearchEngineBaseURLTracker::ChangeReason::GOOGLE_BASE_URL; GURL url(chrome::kChromeUINewTabURL);
if (google_base_url_domain_changed) { content::NavigationController::LoadURLParams params(url);
GURL local_ntp_url(chrome::kChromeSearchLocalNtpUrl); params.should_replace_current_entry = true;
// Replace the server NTP with the local NTP (or reload the local NTP). params.referrer = content::Referrer();
content::NavigationController::LoadURLParams params(local_ntp_url); params.transition_type = ui::PAGE_TRANSITION_RELOAD;
params.should_replace_current_entry = true; contents->GetController().LoadURLWithParams(params);
params.referrer = content::Referrer();
params.transition_type = ui::PAGE_TRANSITION_RELOAD;
contents->GetController().LoadURLWithParams(params);
} else {
// Reload the contents to ensure that it gets assigned to a
// non-privileged renderer.
TabReloader::Reload(contents);
}
} }
} }
......
...@@ -39,17 +39,16 @@ struct TabReloadTestCase { ...@@ -39,17 +39,16 @@ struct TabReloadTestCase {
const char* description; const char* description;
const char* start_url; const char* start_url;
bool start_in_instant_process; bool start_in_instant_process;
bool should_reload; bool end_in_ntp;
bool end_in_local_ntp;
bool end_in_instant_process;
}; };
// Test cases for when Google is the initial, but not final provider. // Test cases for when Google is the initial, but not final provider.
const TabReloadTestCase kTabReloadTestCasesFinalProviderNotGoogle[] = { const TabReloadTestCase kTabReloadTestCasesFinalProviderNotGoogle[] = {
{"Local NTP", chrome::kChromeSearchLocalNtpUrl, true, true, true, true}, {"Local NTP", chrome::kChromeSearchLocalNtpUrl, true, true},
{"Remote SERP", "https://www.google.com/url?bar=search+terms", false, false, {"NTP", chrome::kChromeUINewTabPageURL, false, true},
false, false}, {"Remote SERP", "https://www.google.com/url?bar=search+terms", false,
{"Other NTP", "https://bar.com/newtab", false, false, false, false}}; false},
{"Other NTP", "https://bar.com/newtab", false, false}};
class FakeWebContentsObserver : public content::WebContentsObserver { class FakeWebContentsObserver : public content::WebContentsObserver {
public: public:
...@@ -121,14 +120,6 @@ TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) { ...@@ -121,14 +120,6 @@ TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) {
const TabReloadTestCase& test = const TabReloadTestCase& test =
kTabReloadTestCasesFinalProviderNotGoogle[i]; kTabReloadTestCasesFinalProviderNotGoogle[i];
if (test.should_reload) {
// Validate final instant state.
EXPECT_EQ(test.end_in_instant_process,
search::ShouldAssignURLToInstantRenderer(
observer->current_url(), profile()))
<< test.description;
}
// Ensure only the expected tabs(contents) reloaded. // Ensure only the expected tabs(contents) reloaded.
// RunUntilIdle() ensures that tasks posted by TabReloader::Reload run. // RunUntilIdle() ensures that tasks posted by TabReloader::Reload run.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -138,14 +129,8 @@ TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) { ...@@ -138,14 +129,8 @@ TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) {
observer->WaitForNavigationStart(); observer->WaitForNavigationStart();
} }
// WaitForLoadStop ensures that all relevant navigation callbacks caused by if (test.end_in_ntp) {
// TabReloader::Run complete. EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), observer->current_url())
// content::WaitForLoadStop(observer->web_contents());
EXPECT_EQ(test.should_reload ? 1 : 0, observer->num_reloads())
<< test.description;
if (test.end_in_local_ntp) {
EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), observer->current_url())
<< test.description; << test.description;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment