Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Unified Diff: chrome/browser/ui/search/instant_extended_interactive_uitest.cc

Issue 20388003: Reload Instant NTP and Instant-process tabs on search url change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added ui and unit tests Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/search/instant_extended_interactive_uitest.cc
diff --git a/chrome/browser/ui/search/instant_extended_interactive_uitest.cc b/chrome/browser/ui/search/instant_extended_interactive_uitest.cc
index 74a916b052dc6df563c3097a2a86c2181eb11553..d4c497daf2990cb53519cdbec1bad411edb9bd57 100644
--- a/chrome/browser/ui/search/instant_extended_interactive_uitest.cc
+++ b/chrome/browser/ui/search/instant_extended_interactive_uitest.cc
@@ -26,6 +26,7 @@
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
+#include "chrome/browser/google/google_url_tracker.h"
#include "chrome/browser/history/history_db_task.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
@@ -35,6 +36,7 @@
#include "chrome/browser/search/instant_service.h"
#include "chrome/browser/search/instant_service_factory.h"
#include "chrome/browser/search/search.h"
+#include "chrome/browser/search/search_test_utils.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/task_manager/task_manager.h"
@@ -62,7 +64,9 @@
#include "components/sessions/serialized_navigation_entry.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
+#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_source.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/site_instance.h"
@@ -1553,16 +1557,23 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) {
EXPECT_EQ(1, instant_service->GetInstantProcessCount());
// Navigating to the NTP should use the Instant render process.
- content::WindowedNotificationObserver new_tab_observer(
- content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- content::NotificationService::AllSources());
ui_test_utils::NavigateToURLWithDisposition(
browser(),
- GURL(chrome::kChromeUINewTabURL),
+ GURL(chrome::kChromeSearchLocalNtpUrl),
CURRENT_TAB,
- ui_test_utils::BROWSER_TEST_NONE);
- new_tab_observer.Wait();
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
+ content::WebContents* local_ntp_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ EXPECT_TRUE(chrome::IsInstantNTP(local_ntp_contents));
+ EXPECT_TRUE(instant_service->IsInstantProcess(
+ local_ntp_contents->GetRenderProcessHost()->GetID()));
+ GURL local_ntp_url = local_ntp_contents->GetURL();
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ GURL(chrome::kChromeUINewTabURL),
+ NEW_FOREGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
content::WebContents* ntp_contents =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_TRUE(chrome::IsInstantNTP(ntp_contents));
@@ -1577,27 +1588,27 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) {
EXPECT_FALSE(instant_service->IsInstantProcess(
active_tab->GetRenderProcessHost()->GetID()));
- TemplateURLData data;
- data.short_name = ASCIIToUTF16("t");
- data.SetURL("http://defaultturl/q={searchTerms}");
- data.suggestions_url = "http://defaultturl2/q={searchTerms}";
- data.instant_url = "http://does/not/exist";
- data.alternate_urls.push_back(data.instant_url + "#q={searchTerms}");
- data.search_terms_replacement_key = "strk";
-
- TemplateURL* template_url = new TemplateURL(browser()->profile(), data);
- TemplateURLService* service =
- TemplateURLServiceFactory::GetForProfile(browser()->profile());
- ui_test_utils::WaitForTemplateURLServiceToLoad(service);
- service->Add(template_url); // Takes ownership of |template_url|.
-
- // Change the default search provider.
- content::WindowedNotificationObserver observer(
+ content::WindowedNotificationObserver ntp_observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<content::NavigationController>(
&ntp_contents->GetController()));
- service->SetDefaultSearchProvider(template_url);
- observer.Wait();
+ content::WindowedNotificationObserver local_ntp_observer(
+ content::NOTIFICATION_LOAD_STOP,
+ content::Source<content::NavigationController>(
+ &local_ntp_contents->GetController()));
+
+ // Change the default search provider.
+ search_test_utils::SetDefaultInstantTemplateUrl(browser()->profile(), false);
+
+ ntp_observer.Wait();
+ local_ntp_observer.Wait();
+
+ // |local_ntp_contents| should use the Instant render process.
+ EXPECT_TRUE(chrome::IsInstantNTP(local_ntp_contents));
+ EXPECT_TRUE(instant_service->IsInstantProcess(
+ local_ntp_contents->GetRenderProcessHost()->GetID()));
+ // Make sure the URL remains the same.
+ EXPECT_EQ(local_ntp_url, local_ntp_contents->GetURL());
// |ntp_contents| should not use the Instant render process.
EXPECT_FALSE(chrome::IsInstantNTP(ntp_contents));
@@ -1607,49 +1618,78 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) {
EXPECT_EQ(ntp_url, ntp_contents->GetURL());
}
-IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
- ReloadLocalNTPOnSearchProviderChange) {
+IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnGoogleBaseURLChanged) {
+ InstantService* instant_service =
+ InstantServiceFactory::GetForProfile(browser()->profile());
+ ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
+
// Setup Instant.
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
FocusOmniboxAndWaitForInstantNTPSupport();
+ EXPECT_EQ(1, instant_service->GetInstantProcessCount());
- // Navigate to Local NTP.
- content::WindowedNotificationObserver new_tab_observer(
- content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- content::NotificationService::AllSources());
+ // Navigating to the NTP should use the Instant render process.
ui_test_utils::NavigateToURLWithDisposition(
browser(),
GURL(chrome::kChromeSearchLocalNtpUrl),
CURRENT_TAB,
- ui_test_utils::BROWSER_TEST_NONE);
- new_tab_observer.Wait();
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
+ content::WebContents* local_ntp_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ EXPECT_TRUE(chrome::IsInstantNTP(local_ntp_contents));
+ EXPECT_TRUE(instant_service->IsInstantProcess(
+ local_ntp_contents->GetRenderProcessHost()->GetID()));
+ GURL local_ntp_url = local_ntp_contents->GetURL();
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ GURL(chrome::kChromeUINewTabURL),
+ NEW_FOREGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
content::WebContents* ntp_contents =
browser()->tab_strip_model()->GetActiveWebContents();
+ EXPECT_TRUE(chrome::IsInstantNTP(ntp_contents));
+ EXPECT_TRUE(instant_service->IsInstantProcess(
+ ntp_contents->GetRenderProcessHost()->GetID()));
GURL ntp_url = ntp_contents->GetURL();
- TemplateURLData data;
- data.short_name = ASCIIToUTF16("t");
- data.SetURL("http://defaultturl/q={searchTerms}");
- data.suggestions_url = "http://defaultturl2/q={searchTerms}";
- data.instant_url = "http://does/not/exist";
- data.alternate_urls.push_back(data.instant_url + "#q={searchTerms}");
- data.search_terms_replacement_key = "strk";
-
- TemplateURL* template_url = new TemplateURL(browser()->profile(), data);
- TemplateURLService* service =
- TemplateURLServiceFactory::GetForProfile(browser()->profile());
- ui_test_utils::WaitForTemplateURLServiceToLoad(service);
- service->Add(template_url); // Takes ownership of |template_url|.
-
- // Change the default search provider. This will reload the local NTP and the
- // page URL will remain the same.
- content::WindowedNotificationObserver observer(
+ AddBlankTabAndShow(browser());
+ content::WebContents* active_tab =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ EXPECT_FALSE(chrome::IsInstantNTP(active_tab));
+ EXPECT_FALSE(instant_service->IsInstantProcess(
+ active_tab->GetRenderProcessHost()->GetID()));
+
+ content::WindowedNotificationObserver ntp_observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<content::NavigationController>(
&ntp_contents->GetController()));
- service->SetDefaultSearchProvider(template_url);
- observer.Wait();
+ content::WindowedNotificationObserver local_ntp_observer(
+ content::NOTIFICATION_LOAD_STOP,
+ content::Source<content::NavigationController>(
+ &local_ntp_contents->GetController()));
+
+ // Change the Google Base URL
samarth 2013/08/02 21:51:15 Can you not do this in a unit test? Everything els
Anuj 2013/08/09 07:22:00 Done.
+ PrefService* profile_prefs = browser()->profile()->GetPrefs();
+ profile_prefs->SetString(prefs::kLastPromptedGoogleURL,
+ std::string("https://www.google.com"));
+ GoogleURLTracker::UpdatedDetails details(GURL("https://www.google.com/"),
+ GURL("https://www.google.es/"));
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
+ content::Source<Profile>(browser()->profile()->GetOriginalProfile()),
+ content::Details<GoogleURLTracker::UpdatedDetails>(&details));
+
+ // Ensure both local_ntp and ntp tabs reload.
+ ntp_observer.Wait();
+ local_ntp_observer.Wait();
+
+ // |local_ntp_contents| should use the Instant render process.
+ EXPECT_TRUE(chrome::IsInstantNTP(local_ntp_contents));
+ EXPECT_TRUE(instant_service->IsInstantProcess(
+ local_ntp_contents->GetRenderProcessHost()->GetID()));
+ // Make sure the URL remains the same.
+ EXPECT_EQ(local_ntp_url, local_ntp_contents->GetURL());
// Make sure the URL remains the same.
EXPECT_EQ(ntp_url, ntp_contents->GetURL());

Powered by Google App Engine
This is Rietveld 408576698