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;
void BrowserInstantController::OnSearchEngineBaseURLChanged(
SearchEngineBaseURLTracker::ChangeReason change_reason) {
InstantService* instant_service =
InstantServiceFactory::GetForProfile(profile());
if (!instant_service)
return;
TabStripModel* tab_model = browser_->tab_strip_model();
int count = tab_model->count();
for (int index = 0; index < count; ++index) {
......@@ -103,29 +98,32 @@ void BrowserInstantController::OnSearchEngineBaseURLChanged(
if (!contents)
continue;
bool is_ntp = contents->GetMainFrame()->GetSiteInstance()->GetSiteURL() ==
GURL(chrome::kChromeUINewTabPageURL);
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();
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;
bool google_base_url_domain_changed =
change_reason ==
SearchEngineBaseURLTracker::ChangeReason::GOOGLE_BASE_URL;
if (google_base_url_domain_changed) {
GURL local_ntp_url(chrome::kChromeSearchLocalNtpUrl);
// Replace the server NTP with the local NTP (or reload the local NTP).
content::NavigationController::LoadURLParams params(local_ntp_url);
// When default search engine is changed navigate to chrome://newtab which
// will redirect to the new tab page associated with the search engine.
GURL url(chrome::kChromeUINewTabURL);
content::NavigationController::LoadURLParams params(url);
params.should_replace_current_entry = true;
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 {
const char* description;
const char* start_url;
bool start_in_instant_process;
bool should_reload;
bool end_in_local_ntp;
bool end_in_instant_process;
bool end_in_ntp;
};
// Test cases for when Google is the initial, but not final provider.
const TabReloadTestCase kTabReloadTestCasesFinalProviderNotGoogle[] = {
{"Local NTP", chrome::kChromeSearchLocalNtpUrl, true, true, true, true},
{"Remote SERP", "https://www.google.com/url?bar=search+terms", false, false,
false, false},
{"Other NTP", "https://bar.com/newtab", false, false, false, false}};
{"Local NTP", chrome::kChromeSearchLocalNtpUrl, true, true},
{"NTP", chrome::kChromeUINewTabPageURL, false, true},
{"Remote SERP", "https://www.google.com/url?bar=search+terms", false,
false},
{"Other NTP", "https://bar.com/newtab", false, false}};
class FakeWebContentsObserver : public content::WebContentsObserver {
public:
......@@ -121,14 +120,6 @@ TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) {
const TabReloadTestCase& test =
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.
// RunUntilIdle() ensures that tasks posted by TabReloader::Reload run.
base::RunLoop().RunUntilIdle();
......@@ -138,14 +129,8 @@ TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) {
observer->WaitForNavigationStart();
}
// WaitForLoadStop ensures that all relevant navigation callbacks caused by
// TabReloader::Run complete.
// 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())
if (test.end_in_ntp) {
EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), observer->current_url())
<< 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