diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/resources/local_ntp/local_ntp.html | 2 | ||||
-rw-r--r-- | chrome/browser/resources/local_ntp/local_ntp.js | 32 | ||||
-rw-r--r-- | chrome/browser/search/instant_service.cc | 2 | ||||
-rw-r--r-- | chrome/browser/search/local_ntp_source.cc | 80 | ||||
-rw-r--r-- | chrome/browser/search/local_ntp_source.h | 6 | ||||
-rw-r--r-- | chrome/browser/search/search.cc | 9 | ||||
-rw-r--r-- | chrome/browser/search/search.h | 5 | ||||
-rw-r--r-- | chrome/browser/search/search_unittest.cc | 28 | ||||
-rw-r--r-- | chrome/browser/ui/browser_instant_controller.cc | 9 | ||||
-rw-r--r-- | chrome/browser/ui/search/instant_extended_interactive_uitest.cc | 173 | ||||
-rw-r--r-- | chrome/browser/ui/search/instant_page.cc | 3 | ||||
-rw-r--r-- | chrome/browser/ui/search/instant_page_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/search/search_tab_helper.cc | 3 | ||||
-rw-r--r-- | chrome/common/url_constants.cc | 2 | ||||
-rw-r--r-- | chrome/common/url_constants.h | 1 | ||||
-rw-r--r-- | chrome/test/data/local_ntp_browsertest.html | 2 | ||||
-rw-r--r-- | chrome/test/data/local_ntp_browsertest.js | 6 |
17 files changed, 211 insertions, 154 deletions
diff --git a/chrome/browser/resources/local_ntp/local_ntp.html b/chrome/browser/resources/local_ntp/local_ntp.html index b1c3360..be9955b 100644 --- a/chrome/browser/resources/local_ntp/local_ntp.html +++ b/chrome/browser/resources/local_ntp/local_ntp.html @@ -4,7 +4,7 @@ Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> <head> - <script src="chrome-search://local-ntp/translated-strings.js"></script> + <script src="chrome-search://local-ntp/config.js"></script> <script src="chrome-search://local-ntp/local-ntp.js"></script> <link rel="stylesheet" href="chrome-search://local-ntp/local-ntp.css"></link> <meta name="google" value="notranslate"> diff --git a/chrome/browser/resources/local_ntp/local_ntp.js b/chrome/browser/resources/local_ntp/local_ntp.js index 8dd4c6d..e63fbaa 100644 --- a/chrome/browser/resources/local_ntp/local_ntp.js +++ b/chrome/browser/resources/local_ntp/local_ntp.js @@ -9,10 +9,9 @@ /** * Controls rendering the new tab page for InstantExtended. - * @param {Object} location window.location or a mock. * @return {Object} A limited interface for testing the local NTP. */ -function LocalNTP(location) { +function LocalNTP() { <include src="../../../../ui/webui/resources/js/assert.js"> @@ -616,7 +615,7 @@ function createTile(page, position) { tileElement, 'div', CLASSES.BLACKLIST_BUTTON); var blacklistFunction = generateBlacklistFunction(rid); blacklistButton.addEventListener('click', blacklistFunction); - blacklistButton.title = templateData.removeThumbnailTooltip; + blacklistButton.title = configData.translatedStrings.removeThumbnailTooltip; // When a tile is focused, have delete also blacklist the page. registerKeyHandler(tileElement, KEYCODE.DELETE, blacklistFunction); @@ -918,16 +917,6 @@ function getEmbeddedSearchApiHandle() { return null; } - -/** - * @return {boolean} True if this is a Google page and not some other search - * provider. Used to determine whether to show the logo and fakebox. - */ -function isGooglePage() { - return location.href.indexOf('isGoogle') != -1; -} - - /** * Extract the desired navigation behavior from a click button. * @param {number} button The Event#button property of a click event. @@ -958,7 +947,7 @@ function init() { tilesContainer.appendChild(row); } - if (isGooglePage()) { + if (configData.isGooglePage) { var logo = document.createElement('div'); logo.id = IDS.LOGO; @@ -974,7 +963,7 @@ function init() { document.body.classList.add(CLASSES.NON_GOOGLE_PAGE); } - var recentTabsText = templateData.recentTabs; + var recentTabsText = configData.translatedStrings.recentTabs; if (recentTabsText) { var recentTabsLink = document.createElement('span'); recentTabsLink.id = IDS.RECENT_TABS; @@ -989,16 +978,19 @@ function init() { } var notificationMessage = $(IDS.NOTIFICATION_MESSAGE); - notificationMessage.textContent = templateData.thumbnailRemovedNotification; + notificationMessage.textContent = + configData.translatedStrings.thumbnailRemovedNotification; var undoLink = $(IDS.UNDO_LINK); undoLink.addEventListener('click', onUndo); registerKeyHandler(undoLink, KEYCODE.ENTER, onUndo); - undoLink.textContent = templateData.undoThumbnailRemove; + undoLink.textContent = configData.translatedStrings.undoThumbnailRemove; var restoreAllLink = $(IDS.RESTORE_ALL_LINK); restoreAllLink.addEventListener('click', onRestoreAll); registerKeyHandler(restoreAllLink, KEYCODE.ENTER, onUndo); - restoreAllLink.textContent = templateData.restoreThumbnailsShort; - $(IDS.ATTRIBUTION_TEXT).textContent = templateData.attributionIntro; + restoreAllLink.textContent = + configData.translatedStrings.restoreThumbnailsShort; + $(IDS.ATTRIBUTION_TEXT).textContent = + configData.translatedStrings.attributionIntro; var notificationCloseButton = $(IDS.NOTIFICATION_CLOSE_BUTTON); notificationCloseButton.addEventListener('click', hideNotification); @@ -1060,5 +1052,5 @@ return { } if (!window.localNTPUnitTest) { - LocalNTP(location).listen(); + LocalNTP().listen(); } diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc index b1c842d..20fb466 100644 --- a/chrome/browser/search/instant_service.cc +++ b/chrome/browser/search/instant_service.cc @@ -93,7 +93,7 @@ InstantService::InstantService(Profile* profile) content::URLDataSource::Add(profile, new ThumbnailSource(profile)); content::URLDataSource::Add(profile, new FaviconSource( profile, FaviconSource::FAVICON)); - content::URLDataSource::Add(profile, new LocalNtpSource()); + content::URLDataSource::Add(profile, new LocalNtpSource(profile)); content::URLDataSource::Add(profile, new MostVisitedIframeSource()); } diff --git a/chrome/browser/search/local_ntp_source.cc b/chrome/browser/search/local_ntp_source.cc index 84f6381..e95bd57 100644 --- a/chrome/browser/search/local_ntp_source.cc +++ b/chrome/browser/search/local_ntp_source.cc @@ -4,13 +4,18 @@ #include "chrome/browser/search/local_ntp_source.h" +#include "base/json/json_string_value_serializer.h" #include "base/logging.h" #include "base/memory/ref_counted_memory.h" +#include "base/memory/scoped_ptr.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/values.h" #include "chrome/browser/search/instant_io_context.h" #include "chrome/browser/search/search.h" +#include "chrome/browser/search_engines/template_url_prepopulate_data.h" +#include "chrome/browser/search_engines/template_url_service.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/common/url_constants.h" #include "grit/browser_resources.h" #include "grit/generated_resources.h" @@ -26,7 +31,7 @@ namespace { // Signifies a locally constructed resource, i.e. not from grit/. const int kLocalResource = -1; -const char kTranslatedStringsFilename[] = "translated-strings.js"; +const char kConfigDataFilename[] = "config.js"; const struct Resource{ const char* filename; @@ -35,7 +40,7 @@ const struct Resource{ } kResources[] = { { "local-ntp.html", IDR_LOCAL_NTP_HTML, "text/html" }, { "local-ntp.js", IDR_LOCAL_NTP_JS, "application/javascript" }, - { kTranslatedStringsFilename, kLocalResource, "application/javascript" }, + { kConfigDataFilename, kLocalResource, "application/javascript" }, { "local-ntp.css", IDR_LOCAL_NTP_CSS, "text/css" }, { "images/close_2.png", IDR_CLOSE_2, "image/png" }, { "images/close_2_hover.png", IDR_CLOSE_2_H, "image/png" }, @@ -60,6 +65,22 @@ std::string StripParameters(const std::string& path) { return path.substr(0, path.find("?")); } +bool DefaultSearchProviderIsGoogle(Profile* profile) { + if (!profile) + return false; + + TemplateURLService* template_url_service = + TemplateURLServiceFactory::GetForProfile(profile); + if (!template_url_service) + return false; + + const TemplateURL* default_provider = + template_url_service->GetDefaultSearchProvider(); + return default_provider && + (TemplateURLPrepopulateData::GetEngineType(default_provider->url()) == + SEARCH_ENGINE_GOOGLE); +} + // Adds a localized string keyed by resource id to the dictionary. void AddString(base::DictionaryValue* dictionary, const std::string& key, @@ -67,30 +88,51 @@ void AddString(base::DictionaryValue* dictionary, dictionary->SetString(key, l10n_util::GetStringUTF16(resource_id)); } -// Returns a JS dictionary of translated strings for the local NTP. -std::string GetTranslatedStrings() { - base::DictionaryValue translated_strings; +// Populates |translated_strings| dictionary for the local NTP. +scoped_ptr<DictionaryValue> GetTranslatedStrings() { + scoped_ptr<base::DictionaryValue> translated_strings( + new base::DictionaryValue()); + if (chrome::ShouldShowRecentTabsOnNTP()) - AddString(&translated_strings, "recentTabs", IDS_RECENT_TABS_MENU); - AddString(&translated_strings, "thumbnailRemovedNotification", + AddString(translated_strings.get(), "recentTabs", IDS_RECENT_TABS_MENU); + + AddString(translated_strings.get(), "thumbnailRemovedNotification", IDS_NEW_TAB_THUMBNAIL_REMOVED_NOTIFICATION); - AddString(&translated_strings, "removeThumbnailTooltip", + AddString(translated_strings.get(), "removeThumbnailTooltip", IDS_NEW_TAB_REMOVE_THUMBNAIL_TOOLTIP); - AddString(&translated_strings, "undoThumbnailRemove", + AddString(translated_strings.get(), "undoThumbnailRemove", IDS_NEW_TAB_UNDO_THUMBNAIL_REMOVE); - AddString(&translated_strings, "restoreThumbnailsShort", + AddString(translated_strings.get(), "restoreThumbnailsShort", IDS_NEW_TAB_RESTORE_THUMBNAILS_SHORT_LINK); - AddString(&translated_strings, "attributionIntro", + AddString(translated_strings.get(), "attributionIntro", IDS_NEW_TAB_ATTRIBUTION_INTRO); - AddString(&translated_strings, "title", IDS_NEW_TAB_TITLE); - std::string translated_strings_js; - webui::AppendJsonJS(&translated_strings, &translated_strings_js); - return translated_strings_js; + AddString(translated_strings.get(), "title", IDS_NEW_TAB_TITLE); + + return translated_strings.Pass(); +} + +// Returns a JS dictionary of configuration data for the local NTP. +std::string GetConfigData(Profile* profile) { + base::DictionaryValue config_data; + config_data.Set("translatedStrings", GetTranslatedStrings().release()); + config_data.SetBoolean("isGooglePage", + DefaultSearchProviderIsGoogle(profile)); + + // Serialize the dictionary. + std::string js_text; + JSONStringValueSerializer serializer(&js_text); + serializer.Serialize(config_data); + + std::string config_data_js; + config_data_js.append("var configData = "); + config_data_js.append(js_text); + config_data_js.append(";"); + return config_data_js; } } // namespace -LocalNtpSource::LocalNtpSource() { +LocalNtpSource::LocalNtpSource(Profile* profile) : profile_(profile) { } LocalNtpSource::~LocalNtpSource() { @@ -106,9 +148,9 @@ void LocalNtpSource::StartDataRequest( int render_view_id, const content::URLDataSource::GotDataCallback& callback) { const std::string stripped_path = StripParameters(path); - if (stripped_path == kTranslatedStringsFilename) { - std::string translated_strings_js = GetTranslatedStrings(); - callback.Run(base::RefCountedString::TakeString(&translated_strings_js)); + if (stripped_path == kConfigDataFilename) { + std::string config_data_js = GetConfigData(profile_); + callback.Run(base::RefCountedString::TakeString(&config_data_js)); return; } for (size_t i = 0; i < arraysize(kResources); ++i) { diff --git a/chrome/browser/search/local_ntp_source.h b/chrome/browser/search/local_ntp_source.h index efa20504..410a2d1 100644 --- a/chrome/browser/search/local_ntp_source.h +++ b/chrome/browser/search/local_ntp_source.h @@ -9,11 +9,13 @@ #include "base/compiler_specific.h" #include "content/public/browser/url_data_source.h" +class Profile; + // Serves HTML and resources for the local new tab page i.e. // chrome-search://local-ntp/local-ntp.html class LocalNtpSource : public content::URLDataSource { public: - LocalNtpSource(); + explicit LocalNtpSource(Profile* profile); private: virtual ~LocalNtpSource(); @@ -30,6 +32,8 @@ class LocalNtpSource : public content::URLDataSource { const net::URLRequest* request) const OVERRIDE; virtual std::string GetContentSecurityPolicyFrameSrc() const OVERRIDE; + Profile* profile_; + DISALLOW_COPY_AND_ASSIGN(LocalNtpSource); }; diff --git a/chrome/browser/search/search.cc b/chrome/browser/search/search.cc index 2e62b2d..b38c8b7 100644 --- a/chrome/browser/search/search.cc +++ b/chrome/browser/search/search.cc @@ -15,7 +15,6 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search/instant_service.h" #include "chrome/browser/search/instant_service_factory.h" -#include "chrome/browser/search_engines/template_url_prepopulate_data.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/ui/browser.h" @@ -348,14 +347,6 @@ GURL GetInstantURL(Profile* profile, int start_margin) { } GURL GetLocalInstantURL(Profile* profile) { - const TemplateURL* default_provider = - GetDefaultSearchProviderTemplateURL(profile); - - if (default_provider && - (TemplateURLPrepopulateData::GetEngineType(default_provider->url()) == - SEARCH_ENGINE_GOOGLE)) { - return GURL(chrome::kChromeSearchLocalGoogleNtpUrl); - } return GURL(chrome::kChromeSearchLocalNtpUrl); } diff --git a/chrome/browser/search/search.h b/chrome/browser/search/search.h index dfc202e..c4338ec 100644 --- a/chrome/browser/search/search.h +++ b/chrome/browser/search/search.h @@ -97,9 +97,8 @@ bool NavEntryIsInstantNTP(const content::WebContents* contents, // lead to an infinite recursion. GURL GetInstantURL(Profile* profile, int start_margin); -// Returns the Local Instant URL of the default search engine. In particular, -// a Google search provider will include a special query parameter, indicating -// to the JS that Google-specific New Tab Page elements should be rendered. +// Returns the Local Instant URL of the New Tab Page. +// TODO(kmadhusu): Remove this function and update the call sites. GURL GetLocalInstantURL(Profile* profile); // Returns true if 'use_remote_ntp_on_startup' flag is enabled in field trials diff --git a/chrome/browser/search/search_unittest.cc b/chrome/browser/search/search_unittest.cc index ff99325..0172f2a 100644 --- a/chrome/browser/search/search_unittest.cc +++ b/chrome/browser/search/search_unittest.cc @@ -178,23 +178,19 @@ class SearchTest : public BrowserWithTestWindowTest { TemplateURLService* template_url_service = TemplateURLServiceFactory::GetForProfile(profile()); ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); - SetSearchProvider(false); + SetSearchProvider(); } - void SetSearchProvider(bool is_google) { + void SetSearchProvider() { TemplateURLService* template_url_service = TemplateURLServiceFactory::GetForProfile(profile()); TemplateURLData data; - if (is_google) { - data.SetURL("http://www.google.com/"); - data.instant_url = "http://www.google.com/"; - } else { - data.SetURL("http://foo.com/url?bar={searchTerms}"); - data.instant_url = "http://foo.com/instant?" - "{google:omniboxStartMarginParameter}foo=foo#foo=foo&strk"; - data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); - data.search_terms_replacement_key = "strk"; - } + data.SetURL("http://foo.com/url?bar={searchTerms}"); + data.instant_url = "http://foo.com/instant?" + "{google:omniboxStartMarginParameter}foo=foo#foo=foo&strk"; + data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); + data.search_terms_replacement_key = "strk"; + TemplateURL* template_url = new TemplateURL(profile(), data); // Takes ownership of |template_url|. template_url_service->Add(template_url); @@ -271,7 +267,6 @@ TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) { const SearchTestCase kTestCases[] = { {chrome::kChromeSearchLocalNtpUrl, true, ""}, - {chrome::kChromeSearchLocalGoogleNtpUrl, true, ""}, {"https://foo.com/instant?strk", true, ""}, {"https://foo.com/instant#strk", true, ""}, {"https://foo.com/instant?strk=0", true, ""}, @@ -308,7 +303,6 @@ const SearchTestCase kInstantNTPTestCases[] = { {"chrome://blank/", false, "Chrome scheme"}, {"chrome-search://foo", false, "Chrome-search scheme"}, {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"}, - {chrome::kChromeSearchLocalGoogleNtpUrl, true, "Local new tab page"}, {"https://bar.com/instant?strk=1", false, "Random non-search page"}, }; @@ -318,7 +312,6 @@ TEST_F(SearchTest, InstantNTPExtendedEnabled) { for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { const SearchTestCase& test = kInstantNTPTestCases[i]; NavigateAndCommitActiveTab(GURL(test.url)); - SetSearchProvider(test.url == chrome::kChromeSearchLocalGoogleNtpUrl); const content::WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); EXPECT_EQ(test.expected_result, IsInstantNTP(contents)) @@ -343,7 +336,6 @@ TEST_F(SearchTest, InstantNTPCustomNavigationEntry) { for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { const SearchTestCase& test = kInstantNTPTestCases[i]; NavigateAndCommitActiveTab(GURL(test.url)); - SetSearchProvider(test.url == chrome::kChromeSearchLocalGoogleNtpUrl); content::WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); content::NavigationController& controller = contents->GetController(); @@ -408,8 +400,6 @@ TEST_F(SearchTest, StartMarginCGI) { TEST_F(SearchTest, CommandLineOverrides) { EnableInstantExtendedAPIForTesting(); - // GetLocalInstantURL() should default to the non-Google local NTP. - SetSearchProvider(false); GURL local_instant_url(GetLocalInstantURL(profile())); EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); @@ -444,7 +434,7 @@ TEST_F(SearchTest, CommandLineOverrides) { // to get the Google version of the local NTP, even though search provider's // URL doesn't contain "google". local_instant_url = GetLocalInstantURL(profile()); - EXPECT_EQ(GURL(chrome::kChromeSearchLocalGoogleNtpUrl), local_instant_url); + EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); // If we specify extra search query params, they should be inserted into the // query portion of the instant URL. diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc index b1454e8..4adeb91 100644 --- a/chrome/browser/ui/browser_instant_controller.cc +++ b/chrome/browser/ui/browser_instant_controller.cc @@ -261,15 +261,6 @@ void BrowserInstantController::OnDefaultSearchProviderChanged( if (!contents) continue; - // A Local NTP always runs in the Instant process, so reloading it is - // neither useful nor necessary. However, the Local NTP does not reflect - // whether Google is the default search engine or not. This is achieved - // through a URL parameter, so reloading the existing URL won't fix that - // (i.e., the Local NTP may now show an incorrect search engine logo). - // TODO(kmadhusu): Fix. - if (contents->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl)) - continue; - if (!instant_service->IsInstantProcess( contents->GetRenderProcessHost()->GetID())) continue; diff --git a/chrome/browser/ui/search/instant_extended_interactive_uitest.cc b/chrome/browser/ui/search/instant_extended_interactive_uitest.cc index 2c25a3e..f9f51f4 100644 --- a/chrome/browser/ui/search/instant_extended_interactive_uitest.cc +++ b/chrome/browser/ui/search/instant_extended_interactive_uitest.cc @@ -872,66 +872,6 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_EscapeClearsOmnibox) { EXPECT_LT(0, on_esc_key_press_event_calls_); } -IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) { - 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()); - - // Navigating to the NTP should use the Instant render process. - ui_test_utils::NavigateToURLWithDisposition( - browser(), - GURL(chrome::kChromeUINewTabURL), - CURRENT_TAB, - ui_test_utils::BROWSER_TEST_NONE); - 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(); - - 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())); - - 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::NOTIFICATION_LOAD_STOP, - content::Source<content::NavigationController>( - &ntp_contents->GetController())); - service->SetDefaultSearchProvider(template_url); - observer.Wait(); - - // |ntp_contents| should not use the Instant render process. - EXPECT_FALSE(chrome::IsInstantNTP(ntp_contents)); - EXPECT_FALSE(instant_service->IsInstantProcess( - ntp_contents->GetRenderProcessHost()->GetID())); - // Make sure the URL remains the same. - EXPECT_EQ(ntp_url, ntp_contents->GetURL()); -} - // Test that renderer initiated navigations to an instant URL from a non // Instant page do not end up in an Instant process if they are bounced to the // browser. @@ -1740,3 +1680,116 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, EXPECT_TRUE(UpdateSearchState(active_tab)); EXPECT_EQ(1, on_most_visited_change_calls_); } + +IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) { + 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()); + + // 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), + CURRENT_TAB, + ui_test_utils::BROWSER_TEST_NONE); + new_tab_observer.Wait(); + + 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(); + + 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())); + + 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::NOTIFICATION_LOAD_STOP, + content::Source<content::NavigationController>( + &ntp_contents->GetController())); + service->SetDefaultSearchProvider(template_url); + observer.Wait(); + + // |ntp_contents| should not use the Instant render process. + EXPECT_FALSE(chrome::IsInstantNTP(ntp_contents)); + EXPECT_FALSE(instant_service->IsInstantProcess( + ntp_contents->GetRenderProcessHost()->GetID())); + // Make sure the URL remains the same. + EXPECT_EQ(ntp_url, ntp_contents->GetURL()); +} + +IN_PROC_BROWSER_TEST_F(InstantExtendedTest, + ReloadLocalNTPOnSearchProviderChange) { + // Setup Instant. + ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + FocusOmniboxAndWaitForInstantNTPSupport(); + + // Navigate to Local NTP. + content::WindowedNotificationObserver new_tab_observer( + content::NOTIFICATION_NAV_ENTRY_COMMITTED, + content::NotificationService::AllSources()); + ui_test_utils::NavigateToURLWithDisposition( + browser(), + GURL(chrome::kChromeSearchLocalNtpUrl), + CURRENT_TAB, + ui_test_utils::BROWSER_TEST_NONE); + new_tab_observer.Wait(); + + content::WebContents* ntp_contents = + browser()->tab_strip_model()->GetActiveWebContents(); + 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( + content::NOTIFICATION_LOAD_STOP, + content::Source<content::NavigationController>( + &ntp_contents->GetController())); + service->SetDefaultSearchProvider(template_url); + observer.Wait(); + + // Make sure the URL remains the same. + EXPECT_EQ(ntp_url, ntp_contents->GetURL()); +} diff --git a/chrome/browser/ui/search/instant_page.cc b/chrome/browser/ui/search/instant_page.cc index cfa47ad..39fc72c 100644 --- a/chrome/browser/ui/search/instant_page.cc +++ b/chrome/browser/ui/search/instant_page.cc @@ -39,8 +39,7 @@ const std::string& InstantPage::instant_url() const { bool InstantPage::IsLocal() const { return contents() && - (contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl) || - contents()->GetURL() == GURL(chrome::kChromeSearchLocalGoogleNtpUrl)); + contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl); } void InstantPage::InitializeFonts() { diff --git a/chrome/browser/ui/search/instant_page_unittest.cc b/chrome/browser/ui/search/instant_page_unittest.cc index effa9c6..e16c96d 100644 --- a/chrome/browser/ui/search/instant_page_unittest.cc +++ b/chrome/browser/ui/search/instant_page_unittest.cc @@ -129,8 +129,6 @@ TEST_F(InstantPageTest, IsLocal) { EXPECT_TRUE(page->IsLocal()); NavigateAndCommit(GURL("http://example.com")); EXPECT_FALSE(page->IsLocal()); - NavigateAndCommit(GURL(chrome::kChromeSearchLocalGoogleNtpUrl)); - EXPECT_TRUE(page->IsLocal()); } TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_Local) { diff --git a/chrome/browser/ui/search/search_tab_helper.cc b/chrome/browser/ui/search/search_tab_helper.cc index c81a1c8..281667f 100644 --- a/chrome/browser/ui/search/search_tab_helper.cc +++ b/chrome/browser/ui/search/search_tab_helper.cc @@ -40,8 +40,7 @@ bool IsSearchResults(const content::WebContents* contents) { // namespace and remove InstantPage::IsLocal(). bool IsLocal(const content::WebContents* contents) { return contents && - (contents->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl) || - contents->GetURL() == GURL(chrome::kChromeSearchLocalGoogleNtpUrl)); + contents->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl); } } // namespace diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc index e47b8f8..2460768 100644 --- a/chrome/common/url_constants.cc +++ b/chrome/common/url_constants.cc @@ -531,8 +531,6 @@ const char kChromeSearchScheme[] = "chrome-search"; const char kChromeSearchLocalNtpHost[] = "local-ntp"; const char kChromeSearchLocalNtpUrl[] = "chrome-search://local-ntp/local-ntp.html"; -const char kChromeSearchLocalGoogleNtpUrl[] = - "chrome-search://local-ntp/local-ntp.html?isGoogle"; const char kChromeSearchMostVisitedHost[] = "most-visited"; const char kChromeSearchMostVisitedUrl[] = "chrome-search://most-visited/"; diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index a2c99c4..e8a1491 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -451,7 +451,6 @@ extern const char kChromeSearchScheme[]; // Pages under chrome-search. extern const char kChromeSearchLocalNtpHost[]; extern const char kChromeSearchLocalNtpUrl[]; -extern const char kChromeSearchLocalGoogleNtpUrl[]; // Host and URL for most visited iframes used on the Instant Extended NTP. extern const char kChromeSearchMostVisitedHost[]; diff --git a/chrome/test/data/local_ntp_browsertest.html b/chrome/test/data/local_ntp_browsertest.html index 0c238c5..4b73647 100644 --- a/chrome/test/data/local_ntp_browsertest.html +++ b/chrome/test/data/local_ntp_browsertest.html @@ -5,7 +5,7 @@ found in the LICENSE file. --> <head> <script>window.localNTPUnitTest = true;</script> - <script src="chrome-search://local-ntp/translated-strings.js"></script> + <script src="chrome-search://local-ntp/config.js"></script> <script src="chrome-search://local-ntp/local-ntp.js"></script> <link rel="stylesheet" href="chrome-search://local-ntp/local-ntp.css"></link> <script src="local_ntp_browsertest.js"></script> diff --git a/chrome/test/data/local_ntp_browsertest.js b/chrome/test/data/local_ntp_browsertest.js index f05f870..57f5b7b 100644 --- a/chrome/test/data/local_ntp_browsertest.js +++ b/chrome/test/data/local_ntp_browsertest.js @@ -69,7 +69,8 @@ function runTests() { * Tests that Google NTPs show a fakebox and logo. */ function testShowsFakeboxAndLogoIfGoogle() { - var localNTP = LocalNTP({href: 'isGoogle'}); + var localNTP = LocalNTP(); + configData.isGooglePage = true; localNTP.init(); assert($('fakebox')); assert($('logo')); @@ -80,7 +81,8 @@ function testShowsFakeboxAndLogoIfGoogle() { * Tests that non-Google NTPs do not show a fakebox. */ function testDoesNotShowFakeboxIfNotGoogle() { - var localNTP = LocalNTP({href: ''}); + var localNTP = LocalNTP(); + configData.isGooglePage = false; localNTP.init(); assert(!$('fakebox')); assert(!$('logo')); |