| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 12 #include "chrome/browser/search/instant_service.h" | |
| 13 #include "chrome/browser/search/instant_service_factory.h" | |
| 14 #include "chrome/browser/search/search.h" | 12 #include "chrome/browser/search/search.h" |
| 15 #include "chrome/browser/search_engines/template_url.h" | 13 #include "chrome/browser/search_engines/template_url.h" |
| 16 #include "chrome/browser/search_engines/template_url_service.h" | 14 #include "chrome/browser/search_engines/template_url_service.h" |
| 17 #include "chrome/browser/search_engines/template_url_service_factory.h" | 15 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 18 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 18 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 21 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/test/base/browser_with_test_window_test.h" | 20 #include "chrome/test/base/browser_with_test_window_test.h" |
| 23 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 142 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 145 profile(), &TemplateURLServiceFactory::BuildInstanceFor); | 143 profile(), &TemplateURLServiceFactory::BuildInstanceFor); |
| 146 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( | 144 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( |
| 147 profile(), &AutocompleteClassifierFactory::BuildInstanceFor); | 145 profile(), &AutocompleteClassifierFactory::BuildInstanceFor); |
| 148 } | 146 } |
| 149 virtual void TearDown() OVERRIDE { BrowserWithTestWindowTest::TearDown(); } | 147 virtual void TearDown() OVERRIDE { BrowserWithTestWindowTest::TearDown(); } |
| 150 | 148 |
| 151 protected: | 149 protected: |
| 152 | 150 |
| 153 void ResetDefaultTemplateURL() { | 151 void ResetDefaultTemplateURL() { |
| 152 ResetTemplateURLForInstant(GURL("http://does/not/exist")); |
| 153 } |
| 154 |
| 155 void ResetTemplateURLForInstant(const GURL& instant_url) { |
| 154 TemplateURLData data; | 156 TemplateURLData data; |
| 157 data.short_name = ASCIIToUTF16("Google"); |
| 155 data.SetURL("http://google.com/search?q={searchTerms}"); | 158 data.SetURL("http://google.com/search?q={searchTerms}"); |
| 156 data.instant_url = "http://does/not/exist"; | 159 data.instant_url = instant_url.spec(); |
| 157 data.search_terms_replacement_key = "{google:instantExtendedEnabledKey}"; | 160 data.search_terms_replacement_key = "{google:instantExtendedEnabledKey}"; |
| 158 TemplateURL* search_template_url = new TemplateURL(profile(), data); | 161 TemplateURL* search_template_url = new TemplateURL(profile(), data); |
| 159 TemplateURLService* template_url_service = | 162 TemplateURLService* template_url_service = |
| 160 TemplateURLServiceFactory::GetForProfile(profile()); | 163 TemplateURLServiceFactory::GetForProfile(profile()); |
| 161 template_url_service->Add(search_template_url); | 164 template_url_service->Add(search_template_url); |
| 162 template_url_service->SetDefaultSearchProvider(search_template_url); | 165 template_url_service->SetDefaultSearchProvider(search_template_url); |
| 163 ASSERT_NE(0, search_template_url->id()); | 166 ASSERT_NE(0, search_template_url->id()); |
| 164 template_url_service->Load(); | 167 template_url_service->Load(); |
| 165 } | 168 } |
| 166 | 169 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 search_terms_type, true); | 201 search_terms_type, true); |
| 199 } | 202 } |
| 200 } | 203 } |
| 201 | 204 |
| 202 private: | 205 private: |
| 203 void NavigateAndCheckTextImpl(const GURL& url, | 206 void NavigateAndCheckTextImpl(const GURL& url, |
| 204 bool can_replace, | 207 bool can_replace, |
| 205 const string16 expected_text, | 208 const string16 expected_text, |
| 206 ToolbarModel::SearchTermsType search_terms_type, | 209 ToolbarModel::SearchTermsType search_terms_type, |
| 207 bool should_display) { | 210 bool should_display) { |
| 211 // The URL being navigated to should be treated as the Instant URL. Else |
| 212 // there will be no search term extraction. |
| 213 ResetTemplateURLForInstant(url); |
| 214 |
| 208 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); | 215 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
| 209 browser()->OpenURL(OpenURLParams( | 216 browser()->OpenURL(OpenURLParams( |
| 210 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, | 217 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, |
| 211 false)); | 218 false)); |
| 212 | 219 |
| 213 // Query terms replacement requires that the renderer process be a | |
| 214 // recognized Instant renderer. Fake it. | |
| 215 InstantService* instant_service = | |
| 216 InstantServiceFactory::GetForProfile(profile()); | |
| 217 int process_id = contents->GetRenderProcessHost()->GetID(); | |
| 218 instant_service->AddInstantProcess(process_id); | |
| 219 | |
| 220 ToolbarModel* toolbar_model = browser()->toolbar_model(); | 220 ToolbarModel* toolbar_model = browser()->toolbar_model(); |
| 221 | 221 |
| 222 // Check while loading. | 222 // Check while loading. |
| 223 contents->GetController().GetVisibleEntry()->GetSSL().security_style = | 223 contents->GetController().GetVisibleEntry()->GetSSL().security_style = |
| 224 content::SECURITY_STYLE_AUTHENTICATED; | 224 content::SECURITY_STYLE_AUTHENTICATED; |
| 225 EXPECT_EQ(should_display, toolbar_model->ShouldDisplayURL()); | 225 EXPECT_EQ(should_display, toolbar_model->ShouldDisplayURL()); |
| 226 EXPECT_EQ(expected_text, toolbar_model->GetText(can_replace)); | 226 EXPECT_EQ(expected_text, toolbar_model->GetText(can_replace)); |
| 227 EXPECT_EQ(search_terms_type, toolbar_model->GetSearchTermsType()); | 227 EXPECT_EQ(search_terms_type, toolbar_model->GetSearchTermsType()); |
| 228 | 228 |
| 229 // Check after commit. | 229 // Check after commit. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 browser()->toolbar_model()->SetSupportsExtractionOfURLLikeSearchTerms(true); | 331 browser()->toolbar_model()->SetSupportsExtractionOfURLLikeSearchTerms(true); |
| 332 ResetDefaultTemplateURL(); | 332 ResetDefaultTemplateURL(); |
| 333 AddTab(browser(), GURL(chrome::kAboutBlankURL)); | 333 AddTab(browser(), GURL(chrome::kAboutBlankURL)); |
| 334 | 334 |
| 335 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); | 335 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
| 336 contents->GetController().LoadURL( | 336 contents->GetController().LoadURL( |
| 337 GURL("https://google.com/search?q=tractor+supply&espv=1"), | 337 GURL("https://google.com/search?q=tractor+supply&espv=1"), |
| 338 content::Referrer(), | 338 content::Referrer(), |
| 339 content::PAGE_TRANSITION_LINK, | 339 content::PAGE_TRANSITION_LINK, |
| 340 std::string()); | 340 std::string()); |
| 341 InstantService* instant_service = | |
| 342 InstantServiceFactory::GetForProfile(profile()); | |
| 343 int process_id = contents->GetRenderProcessHost()->GetID(); | |
| 344 instant_service->AddInstantProcess(process_id); | |
| 345 | 341 |
| 346 // While loading search term type should be normal. | 342 // While loading search term type should be normal. |
| 347 ToolbarModel* toolbar_model = browser()->toolbar_model(); | 343 ToolbarModel* toolbar_model = browser()->toolbar_model(); |
| 348 contents->GetController().GetVisibleEntry()->GetSSL().security_style = | 344 contents->GetController().GetVisibleEntry()->GetSSL().security_style = |
| 349 content::SECURITY_STYLE_UNKNOWN; | 345 content::SECURITY_STYLE_UNKNOWN; |
| 350 EXPECT_EQ(ToolbarModel::NORMAL_SEARCH_TERMS, | 346 EXPECT_EQ(ToolbarModel::NORMAL_SEARCH_TERMS, |
| 351 toolbar_model->GetSearchTermsType()); | 347 toolbar_model->GetSearchTermsType()); |
| 352 | 348 |
| 353 CommitPendingLoad(&contents->GetController()); | 349 CommitPendingLoad(&contents->GetController()); |
| 354 | 350 |
| 355 // When done loading search term type should not be normal. | 351 // When done loading search term type should not be normal. |
| 356 contents->GetController().GetVisibleEntry()->GetSSL().security_style = | 352 contents->GetController().GetVisibleEntry()->GetSSL().security_style = |
| 357 content::SECURITY_STYLE_UNKNOWN; | 353 content::SECURITY_STYLE_UNKNOWN; |
| 358 EXPECT_EQ(ToolbarModel::URL_LIKE_SEARCH_TERMS, | 354 EXPECT_EQ(ToolbarModel::URL_LIKE_SEARCH_TERMS, |
| 359 toolbar_model->GetSearchTermsType()); | 355 toolbar_model->GetSearchTermsType()); |
| 360 } | 356 } |
| OLD | NEW |