| 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 "components/toolbar/toolbar_model.h" | 5 #include "components/toolbar/toolbar_model.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 10 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 11 #include "chrome/browser/search/search.h" | 11 #include "chrome/browser/search/search.h" |
| 12 #include "chrome/browser/search_engines/template_url_service_factory.h" | 12 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 13 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 13 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
| 14 #include "chrome/browser/ssl/security_state_model.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/test/base/browser_with_test_window_test.h" | 18 #include "chrome/test/base/browser_with_test_window_test.h" |
| 18 #include "components/google/core/browser/google_switches.h" | 19 #include "components/google/core/browser/google_switches.h" |
| 19 #include "components/search/search.h" | 20 #include "components/search/search.h" |
| 20 #include "components/toolbar/toolbar_model.h" | 21 #include "components/toolbar/toolbar_model.h" |
| 21 #include "components/variations/entropy_provider.h" | 22 #include "components/variations/entropy_provider.h" |
| 22 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
| 23 #include "content/public/common/ssl_status.h" | 24 #include "content/public/common/ssl_status.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 GURL("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), | 126 GURL("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), |
| 126 base::ASCIIToUTF16( | 127 base::ASCIIToUTF16( |
| 127 "https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), | 128 "https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), |
| 128 base::ASCIIToUTF16("ftp://tractorsupply.ie"), | 129 base::ASCIIToUTF16("ftp://tractorsupply.ie"), |
| 129 base::ASCIIToUTF16("ftp://tractorsupply.ie"), | 130 base::ASCIIToUTF16("ftp://tractorsupply.ie"), |
| 130 true, | 131 true, |
| 131 true | 132 true |
| 132 }, | 133 }, |
| 133 }; | 134 }; |
| 134 | 135 |
| 136 void SetSecurityStyle(content::NavigationController* controller, |
| 137 content::SecurityStyle new_style) { |
| 138 controller->GetVisibleEntry()->GetSSL().security_style = new_style; |
| 139 SecurityStateModel* model = |
| 140 SecurityStateModel::FromWebContents(controller->GetWebContents()); |
| 141 ASSERT_TRUE(model); |
| 142 model->SecurityStateChanged(); |
| 143 } |
| 144 |
| 135 } // namespace | 145 } // namespace |
| 136 | 146 |
| 137 | 147 |
| 138 // ToolbarModelTest ----------------------------------------------------------- | 148 // ToolbarModelTest ----------------------------------------------------------- |
| 139 | 149 |
| 140 class ToolbarModelTest : public BrowserWithTestWindowTest { | 150 class ToolbarModelTest : public BrowserWithTestWindowTest { |
| 141 public: | 151 public: |
| 142 ToolbarModelTest(); | 152 ToolbarModelTest(); |
| 143 ToolbarModelTest(Browser::Type browser_type, | 153 ToolbarModelTest(Browser::Type browser_type, |
| 144 chrome::HostDesktopType host_desktop_type, | 154 chrome::HostDesktopType host_desktop_type, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 EXPECT_EQ(expected_text, toolbar_model->GetText()); | 208 EXPECT_EQ(expected_text, toolbar_model->GetText()); |
| 199 EXPECT_EQ(would_perform_search_term_replacement, | 209 EXPECT_EQ(would_perform_search_term_replacement, |
| 200 toolbar_model->WouldPerformSearchTermReplacement(false)); | 210 toolbar_model->WouldPerformSearchTermReplacement(false)); |
| 201 EXPECT_EQ(should_display_url, toolbar_model->ShouldDisplayURL()); | 211 EXPECT_EQ(should_display_url, toolbar_model->ShouldDisplayURL()); |
| 202 | 212 |
| 203 // Check after commit. | 213 // Check after commit. |
| 204 CommitPendingLoad(controller); | 214 CommitPendingLoad(controller); |
| 205 // Fake a secure connection for HTTPS URLs, or the toolbar will refuse to | 215 // Fake a secure connection for HTTPS URLs, or the toolbar will refuse to |
| 206 // extract search terms. | 216 // extract search terms. |
| 207 if (url.SchemeIsCryptographic()) { | 217 if (url.SchemeIsCryptographic()) { |
| 208 controller->GetVisibleEntry()->GetSSL().security_style = | 218 ASSERT_NO_FATAL_FAILURE( |
| 209 content::SECURITY_STYLE_AUTHENTICATED; | 219 SetSecurityStyle(controller, content::SECURITY_STYLE_AUTHENTICATED)); |
| 210 } | 220 } |
| 211 EXPECT_EQ(expected_text, toolbar_model->GetText()); | 221 EXPECT_EQ(expected_text, toolbar_model->GetText()); |
| 212 EXPECT_EQ(would_perform_search_term_replacement, | 222 EXPECT_EQ(would_perform_search_term_replacement, |
| 213 toolbar_model->WouldPerformSearchTermReplacement(false)); | 223 toolbar_model->WouldPerformSearchTermReplacement(false)); |
| 214 EXPECT_EQ(should_display_url, toolbar_model->ShouldDisplayURL()); | 224 EXPECT_EQ(should_display_url, toolbar_model->ShouldDisplayURL()); |
| 215 | 225 |
| 216 // Now pretend the user started modifying the omnibox. | 226 // Now pretend the user started modifying the omnibox. |
| 217 toolbar_model->set_input_in_progress(true); | 227 toolbar_model->set_input_in_progress(true); |
| 218 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); | 228 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); |
| 219 EXPECT_EQ(would_perform_search_term_replacement, | 229 EXPECT_EQ(would_perform_search_term_replacement, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 search::EnableQueryExtractionForTesting(); | 294 search::EnableQueryExtractionForTesting(); |
| 285 AddTab(browser(), GURL(url::kAboutBlankURL)); | 295 AddTab(browser(), GURL(url::kAboutBlankURL)); |
| 286 | 296 |
| 287 // While loading, we should be willing to extract search terms. | 297 // While loading, we should be willing to extract search terms. |
| 288 content::NavigationController* controller = | 298 content::NavigationController* controller = |
| 289 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); | 299 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); |
| 290 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"), | 300 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"), |
| 291 content::Referrer(), ui::PAGE_TRANSITION_LINK, | 301 content::Referrer(), ui::PAGE_TRANSITION_LINK, |
| 292 std::string()); | 302 std::string()); |
| 293 ToolbarModel* toolbar_model = browser()->toolbar_model(); | 303 ToolbarModel* toolbar_model = browser()->toolbar_model(); |
| 294 controller->GetVisibleEntry()->GetSSL().security_style = | 304 ASSERT_NO_FATAL_FAILURE( |
| 295 content::SECURITY_STYLE_UNKNOWN; | 305 SetSecurityStyle(controller, content::SECURITY_STYLE_UNKNOWN)); |
| 296 EXPECT_TRUE(toolbar_model->WouldPerformSearchTermReplacement(false)); | 306 EXPECT_TRUE(toolbar_model->WouldPerformSearchTermReplacement(false)); |
| 297 | 307 |
| 298 // When done loading, we shouldn't extract search terms if we didn't get an | 308 // When done loading, we shouldn't extract search terms if we didn't get an |
| 299 // authenticated connection. | 309 // authenticated connection. |
| 300 CommitPendingLoad(controller); | 310 CommitPendingLoad(controller); |
| 301 controller->GetVisibleEntry()->GetSSL().security_style = | 311 ASSERT_NO_FATAL_FAILURE( |
| 302 content::SECURITY_STYLE_UNKNOWN; | 312 SetSecurityStyle(controller, content::SECURITY_STYLE_UNKNOWN)); |
| 303 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); | 313 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); |
| 304 } | 314 } |
| 305 | 315 |
| 306 // When the Google base URL is overridden on the command line, we should extract | 316 // When the Google base URL is overridden on the command line, we should extract |
| 307 // search terms from URLs that start with that base URL even when they're not | 317 // search terms from URLs that start with that base URL even when they're not |
| 308 // secure. | 318 // secure. |
| 309 TEST_F(ToolbarModelTest, GoogleBaseURL) { | 319 TEST_F(ToolbarModelTest, GoogleBaseURL) { |
| 310 search::EnableQueryExtractionForTesting(); | 320 search::EnableQueryExtractionForTesting(); |
| 311 AddTab(browser(), GURL(url::kAboutBlankURL)); | 321 AddTab(browser(), GURL(url::kAboutBlankURL)); |
| 312 | 322 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 365 |
| 356 // Disabling URL replacement should reset to only showing URLs. | 366 // Disabling URL replacement should reset to only showing URLs. |
| 357 browser()->toolbar_model()->set_url_replacement_enabled(false); | 367 browser()->toolbar_model()->set_url_replacement_enabled(false); |
| 358 for (size_t i = 0; i < arraysize(test_items); ++i) { | 368 for (size_t i = 0; i < arraysize(test_items); ++i) { |
| 359 const TestItem& test_item = test_items[i]; | 369 const TestItem& test_item = test_items[i]; |
| 360 NavigateAndCheckText(test_item.url, | 370 NavigateAndCheckText(test_item.url, |
| 361 test_item.expected_text_url_replacement_inactive, | 371 test_item.expected_text_url_replacement_inactive, |
| 362 false, test_item.should_display_url); | 372 false, test_item.should_display_url); |
| 363 } | 373 } |
| 364 } | 374 } |
| OLD | NEW |