Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/metrics/field_trial.h" | |
| 12 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 13 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 15 #include "chrome/browser/search/search.h" | |
| 16 #include "chrome/browser/search_engines/template_url_service_factory.h" | 14 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 17 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 15 #include "chrome/browser/search_engines/ui_thread_search_terms_data.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/common/chrome_switches.h" | |
| 21 #include "chrome/test/base/browser_with_test_window_test.h" | 18 #include "chrome/test/base/browser_with_test_window_test.h" |
| 22 #include "components/google/core/browser/google_switches.h" | |
| 23 #include "components/search/search.h" | |
| 24 #include "components/search_engines/template_url_service.h" | 19 #include "components/search_engines/template_url_service.h" |
| 25 #include "components/toolbar/toolbar_model.h" | 20 #include "components/toolbar/toolbar_model.h" |
| 26 #include "components/variations/entropy_provider.h" | |
| 27 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 28 #include "content/public/common/content_constants.h" | 22 #include "content/public/common/content_constants.h" |
| 29 #include "content/public/common/ssl_status.h" | 23 #include "content/public/common/ssl_status.h" |
| 30 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
| 31 #include "ui/gfx/text_elider.h" | 25 #include "ui/gfx/text_elider.h" |
| 32 | 26 |
| 33 // Test data ------------------------------------------------------------------ | 27 // Test data ------------------------------------------------------------------ |
| 34 | 28 |
| 35 namespace { | 29 namespace { |
| 36 | 30 |
| 37 struct TestItem { | 31 struct TestItem { |
| 38 GURL url; | 32 GURL url; |
| 39 // The expected text to display when both forms of URL replacement are | 33 base::string16 expected_text; |
| 40 // inactive. | |
| 41 base::string16 expected_text_url_replacement_inactive; | |
| 42 // The expected text to display when query extraction is active. | |
| 43 base::string16 expected_text_query_extraction; | |
| 44 // The expected text to display when both query extraction and URL removal are | |
| 45 // active. | |
| 46 base::string16 expected_text_both; | |
| 47 bool would_perform_search_term_replacement; | |
| 48 bool should_display_url; | |
| 49 } test_items[] = { | 34 } test_items[] = { |
| 50 { | 35 { |
| 51 GURL("view-source:http://www.google.com"), | 36 GURL("view-source:http://www.google.com"), |
| 52 base::ASCIIToUTF16("view-source:www.google.com"), | 37 base::ASCIIToUTF16("view-source:www.google.com") |
| 53 base::ASCIIToUTF16("view-source:www.google.com"), | |
| 54 base::string16(), | |
| 55 false, | |
| 56 true | |
| 57 }, | 38 }, |
| 58 { | 39 { |
| 59 GURL("view-source:chrome://newtab/"), | 40 GURL("view-source:chrome://newtab/"), |
| 60 base::ASCIIToUTF16("view-source:chrome://newtab"), | 41 base::ASCIIToUTF16("view-source:chrome://newtab") |
| 61 base::ASCIIToUTF16("view-source:chrome://newtab"), | |
| 62 base::string16(), | |
| 63 false, | |
| 64 true | |
| 65 }, | 42 }, |
| 66 { | 43 { |
| 67 GURL("chrome-extension://monkey/balls.html"), | 44 GURL("chrome-extension://monkey/balls.html"), |
| 68 base::ASCIIToUTF16("chrome-extension://monkey/balls.html"), | 45 base::ASCIIToUTF16("chrome-extension://monkey/balls.html") |
| 69 base::ASCIIToUTF16("chrome-extension://monkey/balls.html"), | |
| 70 base::string16(), | |
| 71 false, | |
| 72 true | |
| 73 }, | 46 }, |
| 74 { | 47 { |
| 75 GURL(url::kAboutBlankURL), | 48 GURL(url::kAboutBlankURL), |
| 76 base::ASCIIToUTF16(url::kAboutBlankURL), | 49 base::ASCIIToUTF16(url::kAboutBlankURL) |
| 77 base::ASCIIToUTF16(url::kAboutBlankURL), | |
| 78 base::string16(), | |
| 79 false, | |
| 80 true | |
| 81 }, | 50 }, |
| 82 { | 51 { |
| 83 GURL("http://searchurl/?q=tractor+supply"), | 52 GURL("http://searchurl/?q=tractor+supply"), |
| 84 base::ASCIIToUTF16("searchurl/?q=tractor+supply"), | 53 base::ASCIIToUTF16("searchurl/?q=tractor+supply") |
| 85 base::ASCIIToUTF16("searchurl/?q=tractor+supply"), | |
| 86 base::string16(), | |
| 87 false, | |
| 88 true | |
| 89 }, | 54 }, |
| 90 { | 55 { |
| 91 GURL("http://google.com/search?q=tractor+supply&espv=1"), | 56 GURL("http://google.com/search?q=tractor+supply&espv=1"), |
| 92 base::ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"), | 57 base::ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1") |
| 93 base::ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"), | |
| 94 base::string16(), | |
| 95 false, | |
| 96 true | |
| 97 }, | 58 }, |
| 98 { | 59 { |
| 99 GURL("https://google.ca/search?q=tractor+supply"), | 60 GURL("https://google.ca/search?q=tractor+supply"), |
| 100 base::ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), | 61 base::ASCIIToUTF16("https://google.ca/search?q=tractor+supply") |
| 101 base::ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), | |
| 102 base::string16(), | |
| 103 false, | |
| 104 true | |
| 105 }, | 62 }, |
| 106 { | 63 { |
| 107 GURL("https://google.com/search?q=tractor+supply"), | 64 GURL("https://google.com/search?q=tractor+supply"), |
| 108 base::ASCIIToUTF16("https://google.com/search?q=tractor+supply"), | 65 base::ASCIIToUTF16("https://google.com/search?q=tractor+supply") |
| 109 base::ASCIIToUTF16("https://google.com/search?q=tractor+supply"), | |
| 110 base::string16(), | |
| 111 false, | |
| 112 true | |
| 113 }, | 66 }, |
| 114 { | 67 { |
| 115 GURL("https://google.com/search?q=tractor+supply&espv=1"), | 68 GURL("https://google.com/search?q=tractor+supply&espv=1"), |
| 116 base::ASCIIToUTF16("https://google.com/search?q=tractor+supply&espv=1"), | 69 base::ASCIIToUTF16("https://google.com/search?q=tractor+supply&espv=1") |
| 117 base::ASCIIToUTF16("tractor supply"), | |
| 118 base::ASCIIToUTF16("tractor supply"), | |
| 119 true, | |
| 120 true | |
| 121 }, | 70 }, |
| 122 { | 71 { |
| 123 GURL("https://google.com/search?q=tractorsupply.com&espv=1"), | 72 GURL("https://google.com/search?q=tractorsupply.com&espv=1"), |
| 124 base::ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"), | 73 base::ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1") |
| 125 base::ASCIIToUTF16("tractorsupply.com"), | |
| 126 base::ASCIIToUTF16("tractorsupply.com"), | |
| 127 true, | |
| 128 true | |
| 129 }, | 74 }, |
| 130 { | 75 { |
| 131 GURL("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), | 76 GURL("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), |
| 132 base::ASCIIToUTF16( | 77 base::ASCIIToUTF16( |
| 133 "https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), | 78 "https://google.com/search?q=ftp://tractorsupply.ie&espv=1") |
| 134 base::ASCIIToUTF16("ftp://tractorsupply.ie"), | |
| 135 base::ASCIIToUTF16("ftp://tractorsupply.ie"), | |
| 136 true, | |
| 137 true | |
| 138 }, | 79 }, |
| 139 }; | 80 }; |
| 140 | 81 |
| 141 } // namespace | 82 } // namespace |
| 142 | 83 |
| 143 | 84 |
| 144 // ToolbarModelTest ----------------------------------------------------------- | 85 // ToolbarModelTest ----------------------------------------------------------- |
| 145 | 86 |
| 146 class ToolbarModelTest : public BrowserWithTestWindowTest { | 87 class ToolbarModelTest : public BrowserWithTestWindowTest { |
| 147 public: | 88 public: |
| 148 ToolbarModelTest(); | 89 ToolbarModelTest(); |
| 149 ToolbarModelTest(Browser::Type browser_type, bool hosted_app); | 90 ToolbarModelTest(Browser::Type browser_type, bool hosted_app); |
| 150 ~ToolbarModelTest() override; | 91 ~ToolbarModelTest() override; |
| 151 | 92 |
| 152 // BrowserWithTestWindowTest: | 93 // BrowserWithTestWindowTest: |
| 153 void SetUp() override; | 94 void SetUp() override; |
| 154 | 95 |
| 155 protected: | 96 protected: |
| 156 void NavigateAndCheckText(const GURL& url, | 97 void NavigateAndCheckText(const GURL& url, |
| 157 const base::string16& expected_text, | 98 const base::string16& expected_text); |
| 158 bool would_perform_search_term_replacement, | |
| 159 bool should_display_url); | |
| 160 void NavigateAndCheckElided(const GURL& https_url); | 99 void NavigateAndCheckElided(const GURL& https_url); |
| 161 | 100 |
| 162 private: | 101 private: |
| 163 std::unique_ptr<base::FieldTrialList> field_trial_list_; | |
| 164 | |
| 165 DISALLOW_COPY_AND_ASSIGN(ToolbarModelTest); | 102 DISALLOW_COPY_AND_ASSIGN(ToolbarModelTest); |
| 166 }; | 103 }; |
| 167 | 104 |
| 168 ToolbarModelTest::ToolbarModelTest() { | 105 ToolbarModelTest::ToolbarModelTest() { |
| 169 } | 106 } |
| 170 | 107 |
| 171 ToolbarModelTest::ToolbarModelTest(Browser::Type browser_type, bool hosted_app) | 108 ToolbarModelTest::ToolbarModelTest(Browser::Type browser_type, bool hosted_app) |
| 172 : BrowserWithTestWindowTest(browser_type, hosted_app) {} | 109 : BrowserWithTestWindowTest(browser_type, hosted_app) {} |
| 173 | 110 |
| 174 ToolbarModelTest::~ToolbarModelTest() { | 111 ToolbarModelTest::~ToolbarModelTest() { |
| 175 } | 112 } |
| 176 | 113 |
| 177 void ToolbarModelTest::SetUp() { | 114 void ToolbarModelTest::SetUp() { |
| 178 BrowserWithTestWindowTest::SetUp(); | 115 BrowserWithTestWindowTest::SetUp(); |
| 179 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 116 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 180 profile(), &TemplateURLServiceFactory::BuildInstanceFor); | 117 profile(), &TemplateURLServiceFactory::BuildInstanceFor); |
| 181 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( | 118 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( |
| 182 profile(), &AutocompleteClassifierFactory::BuildInstanceFor); | 119 profile(), &AutocompleteClassifierFactory::BuildInstanceFor); |
| 183 UIThreadSearchTermsData::SetGoogleBaseURL("http://google.com/"); | 120 UIThreadSearchTermsData::SetGoogleBaseURL("http://google.com/"); |
| 184 } | 121 } |
| 185 | 122 |
| 186 void ToolbarModelTest::NavigateAndCheckText( | 123 void ToolbarModelTest::NavigateAndCheckText( |
| 187 const GURL& url, | 124 const GURL& url, |
| 188 const base::string16& expected_text, | 125 const base::string16& expected_text) { |
| 189 bool would_perform_search_term_replacement, | |
| 190 bool should_display_url) { | |
| 191 // Check while loading. | 126 // Check while loading. |
| 192 content::NavigationController* controller = | 127 content::NavigationController* controller = |
| 193 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); | 128 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); |
| 194 controller->LoadURL(url, content::Referrer(), ui::PAGE_TRANSITION_LINK, | 129 controller->LoadURL(url, content::Referrer(), ui::PAGE_TRANSITION_LINK, |
| 195 std::string()); | 130 std::string()); |
| 196 ToolbarModel* toolbar_model = browser()->toolbar_model(); | 131 ToolbarModel* toolbar_model = browser()->toolbar_model(); |
| 197 EXPECT_EQ(expected_text, toolbar_model->GetText()); | 132 EXPECT_EQ(expected_text, toolbar_model->GetText()); |
| 198 EXPECT_EQ(would_perform_search_term_replacement, | 133 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); |
| 199 toolbar_model->WouldPerformSearchTermReplacement(false)); | 134 EXPECT_TRUE(toolbar_model->ShouldDisplayURL()); |
| 200 EXPECT_EQ(should_display_url, toolbar_model->ShouldDisplayURL()); | |
| 201 | 135 |
| 202 // Check after commit. | 136 // Check after commit. |
| 203 CommitPendingLoad(controller); | 137 CommitPendingLoad(controller); |
| 204 // Fake a secure connection for HTTPS URLs, or the toolbar will refuse to | 138 // Fake a secure connection for HTTPS URLs, or the toolbar will refuse to |
| 205 // extract search terms. | 139 // extract search terms. |
| 206 if (url.SchemeIsCryptographic()) { | 140 if (url.SchemeIsCryptographic()) { |
| 207 controller->GetVisibleEntry()->GetSSL().security_style = | 141 controller->GetVisibleEntry()->GetSSL().security_style = |
| 208 content::SECURITY_STYLE_AUTHENTICATED; | 142 content::SECURITY_STYLE_AUTHENTICATED; |
| 209 } | 143 } |
| 210 EXPECT_EQ(expected_text, toolbar_model->GetText()); | 144 EXPECT_EQ(expected_text, toolbar_model->GetText()); |
| 211 EXPECT_EQ(would_perform_search_term_replacement, | 145 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); |
| 212 toolbar_model->WouldPerformSearchTermReplacement(false)); | 146 EXPECT_TRUE(toolbar_model->ShouldDisplayURL()); |
| 213 EXPECT_EQ(should_display_url, toolbar_model->ShouldDisplayURL()); | |
| 214 | 147 |
| 215 // Now pretend the user started modifying the omnibox. | 148 // Now pretend the user started modifying the omnibox. |
| 216 toolbar_model->set_input_in_progress(true); | 149 toolbar_model->set_input_in_progress(true); |
| 217 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); | 150 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); |
| 218 EXPECT_EQ(would_perform_search_term_replacement, | 151 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(true)); |
| 219 toolbar_model->WouldPerformSearchTermReplacement(true)); | |
| 220 | 152 |
| 221 // Tell the ToolbarModel that the user has stopped editing. This prevents | 153 // Tell the ToolbarModel that the user has stopped editing. This prevents |
| 222 // this function from having side effects. | 154 // this function from having side effects. |
| 223 toolbar_model->set_input_in_progress(false); | 155 toolbar_model->set_input_in_progress(false); |
| 224 } | 156 } |
| 225 | 157 |
| 226 void ToolbarModelTest::NavigateAndCheckElided(const GURL& url) { | 158 void ToolbarModelTest::NavigateAndCheckElided(const GURL& url) { |
| 227 // Check while loading. | 159 // Check while loading. |
| 228 content::NavigationController* controller = | 160 content::NavigationController* controller = |
| 229 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); | 161 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 253 }; | 185 }; |
| 254 | 186 |
| 255 PopupToolbarModelTest::PopupToolbarModelTest() | 187 PopupToolbarModelTest::PopupToolbarModelTest() |
| 256 : ToolbarModelTest(Browser::TYPE_POPUP, false) {} | 188 : ToolbarModelTest(Browser::TYPE_POPUP, false) {} |
| 257 | 189 |
| 258 PopupToolbarModelTest::~PopupToolbarModelTest() { | 190 PopupToolbarModelTest::~PopupToolbarModelTest() { |
| 259 } | 191 } |
| 260 | 192 |
| 261 // Actual tests --------------------------------------------------------------- | 193 // Actual tests --------------------------------------------------------------- |
| 262 | 194 |
| 263 // Test that we only replace URLs when query extraction and URL replacement | 195 // Test URL display. |
| 264 // are enabled. | 196 TEST_F(ToolbarModelTest, ShouldDisplayURL) { |
|
Marc Treib
2016/08/09 10:23:43
I'm not sure how much value this test still has wi
Peter Kasting
2016/08/09 20:55:13
I would keep the file, but I'd rip out PopupToolba
Marc Treib
2016/08/10 12:53:40
Done, mostly (except for sharing code between the
Peter Kasting
2016/08/20 02:21:19
The location bar works differently in popup window
| |
| 265 TEST_F(ToolbarModelTest, ShouldDisplayURL_QueryExtraction) { | |
| 266 AddTab(browser(), GURL(url::kAboutBlankURL)); | 197 AddTab(browser(), GURL(url::kAboutBlankURL)); |
| 267 | 198 |
| 268 // Before we enable instant extended, query extraction is disabled. | 199 for (const TestItem& test_item : test_items) { |
| 269 EXPECT_FALSE(search::IsQueryExtractionEnabled()) | 200 NavigateAndCheckText(test_item.url, test_item.expected_text); |
| 270 << "This test expects query extraction to be disabled."; | |
| 271 for (size_t i = 0; i < arraysize(test_items); ++i) { | |
| 272 const TestItem& test_item = test_items[i]; | |
| 273 NavigateAndCheckText(test_item.url, | |
| 274 test_item.expected_text_url_replacement_inactive, | |
| 275 false, test_item.should_display_url); | |
| 276 } | 201 } |
| 277 | |
| 278 search::EnableQueryExtractionForTesting(); | |
| 279 EXPECT_TRUE(search::IsQueryExtractionEnabled()); | |
| 280 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled()); | |
| 281 for (size_t i = 0; i < arraysize(test_items); ++i) { | |
| 282 const TestItem& test_item = test_items[i]; | |
| 283 NavigateAndCheckText(test_item.url, | |
| 284 test_item.expected_text_query_extraction, | |
| 285 test_item.would_perform_search_term_replacement, | |
| 286 test_item.should_display_url); | |
| 287 } | |
| 288 | |
| 289 // Disabling URL replacement should reset to only showing URLs. | |
| 290 browser()->toolbar_model()->set_url_replacement_enabled(false); | |
| 291 for (size_t i = 0; i < arraysize(test_items); ++i) { | |
| 292 const TestItem& test_item = test_items[i]; | |
| 293 NavigateAndCheckText(test_item.url, | |
| 294 test_item.expected_text_url_replacement_inactive, | |
| 295 false, test_item.should_display_url); | |
| 296 } | |
| 297 } | |
| 298 | |
| 299 // Verify that search terms are extracted while the page is loading. | |
| 300 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) { | |
| 301 search::EnableQueryExtractionForTesting(); | |
| 302 AddTab(browser(), GURL(url::kAboutBlankURL)); | |
| 303 | |
| 304 // While loading, we should be willing to extract search terms. | |
| 305 content::NavigationController* controller = | |
| 306 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); | |
| 307 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"), | |
| 308 content::Referrer(), ui::PAGE_TRANSITION_LINK, | |
| 309 std::string()); | |
| 310 ToolbarModel* toolbar_model = browser()->toolbar_model(); | |
| 311 controller->GetVisibleEntry()->GetSSL().security_style = | |
| 312 content::SECURITY_STYLE_UNKNOWN; | |
| 313 EXPECT_TRUE(toolbar_model->WouldPerformSearchTermReplacement(false)); | |
| 314 | |
| 315 // When done loading, we shouldn't extract search terms if we didn't get an | |
| 316 // authenticated connection. | |
| 317 CommitPendingLoad(controller); | |
| 318 controller->GetVisibleEntry()->GetSSL().security_style = | |
| 319 content::SECURITY_STYLE_UNKNOWN; | |
| 320 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); | |
| 321 } | |
| 322 | |
| 323 // When the Google base URL is overridden on the command line, we should extract | |
| 324 // search terms from URLs that start with that base URL even when they're not | |
| 325 // secure. | |
| 326 TEST_F(ToolbarModelTest, GoogleBaseURL) { | |
| 327 search::EnableQueryExtractionForTesting(); | |
| 328 AddTab(browser(), GURL(url::kAboutBlankURL)); | |
| 329 | |
| 330 // If the Google base URL wasn't specified on the command line, then if it's | |
| 331 // HTTP, we should not extract search terms. | |
| 332 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); | |
| 333 NavigateAndCheckText( | |
| 334 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), | |
| 335 base::ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), false, | |
| 336 true); | |
| 337 | |
| 338 // The same URL, when specified on the command line, should allow search term | |
| 339 // extraction. | |
| 340 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); | |
| 341 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 342 switches::kGoogleBaseURL, "http://www.foo.com/"); | |
| 343 | |
| 344 // For the default search engine to reflect the new Google base URL we just | |
| 345 // set, the TemplateURLService has to know the base URL changed. Normally the | |
| 346 // GoogleURLTracker is the source of such change notifications, but since here | |
| 347 // we're modifying the base URL value directly by changing the command-line | |
| 348 // flags, we need to manually tell TemplateURLService to check for changes. | |
| 349 TemplateURLServiceFactory::GetInstance()->GetForProfile(profile())-> | |
| 350 GoogleBaseURLChanged(); | |
| 351 | |
| 352 NavigateAndCheckText( | |
| 353 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), | |
| 354 base::ASCIIToUTF16("tractor supply"), true, true); | |
| 355 } | 202 } |
| 356 | 203 |
| 357 TEST_F(ToolbarModelTest, ShouldElideLongURLs) { | 204 TEST_F(ToolbarModelTest, ShouldElideLongURLs) { |
| 358 AddTab(browser(), GURL(url::kAboutBlankURL)); | 205 AddTab(browser(), GURL(url::kAboutBlankURL)); |
| 359 const std::string long_text(content::kMaxURLDisplayChars + 1024, '0'); | 206 const std::string long_text(content::kMaxURLDisplayChars + 1024, '0'); |
| 360 NavigateAndCheckElided( | 207 NavigateAndCheckElided( |
| 361 GURL(std::string("https://www.foo.com/?") + long_text)); | 208 GURL(std::string("https://www.foo.com/?") + long_text)); |
| 362 NavigateAndCheckElided(GURL(std::string("data:abc") + long_text)); | 209 NavigateAndCheckElided(GURL(std::string("data:abc") + long_text)); |
| 363 } | 210 } |
| 364 | 211 |
| 365 // Test that URL display in a popup respects the query extraction flag. | 212 // Test URL display in a popup. |
| 366 TEST_F(PopupToolbarModelTest, ShouldDisplayURL) { | 213 TEST_F(PopupToolbarModelTest, ShouldDisplayURL) { |
| 367 AddTab(browser(), GURL(url::kAboutBlankURL)); | 214 AddTab(browser(), GURL(url::kAboutBlankURL)); |
| 368 | 215 |
| 369 // Check with query extraction disabled. | 216 for (const TestItem& test_item : test_items) { |
| 370 EXPECT_FALSE(search::IsQueryExtractionEnabled()); | 217 NavigateAndCheckText(test_item.url, test_item.expected_text); |
| 371 for (size_t i = 0; i < arraysize(test_items); ++i) { | |
| 372 const TestItem& test_item = test_items[i]; | |
| 373 NavigateAndCheckText(test_item.url, | |
| 374 test_item.expected_text_url_replacement_inactive, | |
| 375 false, test_item.should_display_url); | |
| 376 } | |
| 377 | |
| 378 // With query extraction enabled, search term replacement should be performed. | |
| 379 search::EnableQueryExtractionForTesting(); | |
| 380 EXPECT_TRUE(search::IsQueryExtractionEnabled()); | |
| 381 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled()); | |
| 382 for (size_t i = 0; i < arraysize(test_items); ++i) { | |
| 383 const TestItem& test_item = test_items[i]; | |
| 384 NavigateAndCheckText(test_item.url, | |
| 385 test_item.expected_text_query_extraction, | |
| 386 test_item.would_perform_search_term_replacement, | |
| 387 test_item.should_display_url); | |
| 388 } | |
| 389 | |
| 390 // Disabling URL replacement should reset to only showing URLs. | |
| 391 browser()->toolbar_model()->set_url_replacement_enabled(false); | |
| 392 for (size_t i = 0; i < arraysize(test_items); ++i) { | |
| 393 const TestItem& test_item = test_items[i]; | |
| 394 NavigateAndCheckText(test_item.url, | |
| 395 test_item.expected_text_url_replacement_inactive, | |
| 396 false, test_item.should_display_url); | |
| 397 } | 218 } |
| 398 } | 219 } |
| OLD | NEW |