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 "chrome/browser/ui/toolbar/toolbar_model.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 6 | 6 |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 10 #include "base/metrics/field_trial.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 9 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 13 #include "chrome/browser/search/search.h" | 10 #include "chrome/browser/search/search.h" |
| 14 #include "chrome/browser/search_engines/search_terms_data.h" | 11 #include "chrome/browser/search_engines/search_terms_data.h" |
| 15 #include "chrome/browser/search_engines/template_url.h" | |
| 16 #include "chrome/browser/search_engines/template_url_service.h" | |
| 17 #include "chrome/browser/search_engines/template_url_service_factory.h" | 12 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 18 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 15 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 21 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/test/base/browser_with_test_window_test.h" | 17 #include "chrome/test/base/browser_with_test_window_test.h" |
| 23 #include "components/variations/entropy_provider.h" | |
| 24 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 25 #include "content/public/browser/render_process_host.h" | |
| 26 #include "content/public/browser/web_contents.h" | |
| 27 #include "content/public/common/ssl_status.h" | 19 #include "content/public/common/ssl_status.h" |
| 28 #include "content/public/common/url_constants.h" | 20 #include "content/public/common/url_constants.h" |
| 29 #include "net/base/escape.h" | |
| 30 | 21 |
| 31 using base::ASCIIToUTF16; | |
| 32 | 22 |
| 33 // Test data ------------------------------------------------------------------ | 23 // Test data ------------------------------------------------------------------ |
| 34 | 24 |
| 35 namespace { | 25 namespace { |
| 36 | 26 |
| 37 struct TestItem { | 27 struct TestItem { |
| 38 GURL url; | 28 GURL url; |
| 39 // The expected text to display when both forms of URL replacement are | 29 // The expected text to display when both forms of URL replacement are |
| 40 // inactive. | 30 // inactive. |
| 41 base::string16 expected_text_url_replacement_inactive; | 31 base::string16 expected_text_url_replacement_inactive; |
| 42 // The expected text to display when query extraction is active. | 32 // The expected text to display when query extraction is active. |
| 43 base::string16 expected_text_query_extraction; | 33 base::string16 expected_text_query_extraction; |
| 44 // The expected text to display when the origin chip (URL removal) is active. | |
|
Justin Donnelly
2014/05/13 22:19:33
These tests still seem useful to me. Why remove t
Peter Kasting
2014/05/14 00:28:11
These tests were only being used with origin chip
Justin Donnelly
2014/05/14 16:31:43
From the point of view of these tests, v1 and v2 h
| |
| 45 base::string16 expected_text_origin_chip; | |
| 46 // The expected text to display when both query extraction and URL removal are | 34 // The expected text to display when both query extraction and URL removal are |
| 47 // active. | 35 // active. |
| 48 base::string16 expected_text_both; | 36 base::string16 expected_text_both; |
| 49 bool would_perform_search_term_replacement; | 37 bool would_perform_search_term_replacement; |
| 50 bool should_display_url; | 38 bool should_display_url; |
| 51 } test_items[] = { | 39 } test_items[] = { |
| 52 { | 40 { |
| 53 GURL("view-source:http://www.google.com"), | 41 GURL("view-source:http://www.google.com"), |
| 54 ASCIIToUTF16("view-source:www.google.com"), | 42 base::ASCIIToUTF16("view-source:www.google.com"), |
| 55 ASCIIToUTF16("view-source:www.google.com"), | 43 base::ASCIIToUTF16("view-source:www.google.com"), |
| 56 base::string16(), | |
| 57 base::string16(), | 44 base::string16(), |
| 58 false, | 45 false, |
| 59 true | 46 true |
| 60 }, | 47 }, |
| 61 { | 48 { |
| 62 GURL("view-source:chrome://newtab/"), | 49 GURL("view-source:chrome://newtab/"), |
| 63 ASCIIToUTF16("view-source:chrome://newtab"), | 50 base::ASCIIToUTF16("view-source:chrome://newtab"), |
| 64 ASCIIToUTF16("view-source:chrome://newtab"), | 51 base::ASCIIToUTF16("view-source:chrome://newtab"), |
| 65 base::string16(), | |
| 66 base::string16(), | 52 base::string16(), |
| 67 false, | 53 false, |
| 68 true | 54 true |
| 69 }, | 55 }, |
| 70 { | 56 { |
| 71 GURL("chrome-extension://monkey/balls.html"), | 57 GURL("chrome-extension://monkey/balls.html"), |
| 72 ASCIIToUTF16("chrome-extension://monkey/balls.html"), | 58 base::ASCIIToUTF16("chrome-extension://monkey/balls.html"), |
| 73 ASCIIToUTF16("chrome-extension://monkey/balls.html"), | 59 base::ASCIIToUTF16("chrome-extension://monkey/balls.html"), |
| 74 base::string16(), | |
| 75 base::string16(), | 60 base::string16(), |
| 76 false, | 61 false, |
| 77 true | 62 true |
| 78 }, | 63 }, |
| 79 { | 64 { |
| 80 GURL(content::kAboutBlankURL), | 65 GURL(content::kAboutBlankURL), |
| 81 ASCIIToUTF16(content::kAboutBlankURL), | 66 base::ASCIIToUTF16(content::kAboutBlankURL), |
| 82 ASCIIToUTF16(content::kAboutBlankURL), | 67 base::ASCIIToUTF16(content::kAboutBlankURL), |
| 83 base::string16(), | |
| 84 base::string16(), | 68 base::string16(), |
| 85 false, | 69 false, |
| 86 true | 70 true |
| 87 }, | 71 }, |
| 88 { | 72 { |
| 89 GURL("http://searchurl/?q=tractor+supply"), | 73 GURL("http://searchurl/?q=tractor+supply"), |
| 90 ASCIIToUTF16("searchurl/?q=tractor+supply"), | 74 base::ASCIIToUTF16("searchurl/?q=tractor+supply"), |
| 91 ASCIIToUTF16("searchurl/?q=tractor+supply"), | 75 base::ASCIIToUTF16("searchurl/?q=tractor+supply"), |
| 92 base::string16(), | |
| 93 base::string16(), | 76 base::string16(), |
| 94 false, | 77 false, |
| 95 true | 78 true |
| 96 }, | 79 }, |
| 97 { | 80 { |
| 98 GURL("http://google.com/search?q=tractor+supply&espv=1"), | 81 GURL("http://google.com/search?q=tractor+supply&espv=1"), |
| 99 ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"), | 82 base::ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"), |
| 100 ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"), | 83 base::ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"), |
| 101 base::string16(), | |
| 102 base::string16(), | 84 base::string16(), |
| 103 false, | 85 false, |
| 104 true | 86 true |
| 105 }, | 87 }, |
| 106 { | 88 { |
| 107 GURL("https://google.ca/search?q=tractor+supply"), | 89 GURL("https://google.ca/search?q=tractor+supply"), |
| 108 ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), | 90 base::ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), |
| 109 ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), | 91 base::ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), |
| 110 base::string16(), | |
| 111 base::string16(), | 92 base::string16(), |
| 112 false, | 93 false, |
| 113 true | 94 true |
| 114 }, | 95 }, |
| 115 { | 96 { |
| 116 GURL("https://google.com/search?q=tractor+supply"), | 97 GURL("https://google.com/search?q=tractor+supply"), |
| 117 ASCIIToUTF16("https://google.com/search?q=tractor+supply"), | 98 base::ASCIIToUTF16("https://google.com/search?q=tractor+supply"), |
| 118 ASCIIToUTF16("https://google.com/search?q=tractor+supply"), | 99 base::ASCIIToUTF16("https://google.com/search?q=tractor+supply"), |
| 119 base::string16(), | |
| 120 base::string16(), | 100 base::string16(), |
| 121 false, | 101 false, |
| 122 true | 102 true |
| 123 }, | 103 }, |
| 124 { | 104 { |
| 125 GURL("https://google.com/search?q=tractor+supply&espv=1"), | 105 GURL("https://google.com/search?q=tractor+supply&espv=1"), |
| 126 ASCIIToUTF16("https://google.com/search?q=tractor+supply&espv=1"), | 106 base::ASCIIToUTF16("https://google.com/search?q=tractor+supply&espv=1"), |
| 127 ASCIIToUTF16("tractor supply"), | 107 base::ASCIIToUTF16("tractor supply"), |
| 128 base::string16(), | 108 base::ASCIIToUTF16("tractor supply"), |
| 129 ASCIIToUTF16("tractor supply"), | |
| 130 true, | 109 true, |
| 131 true | 110 true |
| 132 }, | 111 }, |
| 133 { | 112 { |
| 134 GURL("https://google.com/search?q=tractorsupply.com&espv=1"), | 113 GURL("https://google.com/search?q=tractorsupply.com&espv=1"), |
| 135 ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"), | 114 base::ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"), |
| 136 ASCIIToUTF16("tractorsupply.com"), | 115 base::ASCIIToUTF16("tractorsupply.com"), |
| 137 base::string16(), | 116 base::ASCIIToUTF16("tractorsupply.com"), |
| 138 ASCIIToUTF16("tractorsupply.com"), | |
| 139 true, | 117 true, |
| 140 true | 118 true |
| 141 }, | 119 }, |
| 142 { | 120 { |
| 143 GURL("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), | 121 GURL("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), |
| 144 ASCIIToUTF16("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), | 122 base::ASCIIToUTF16( |
| 145 ASCIIToUTF16("ftp://tractorsupply.ie"), | 123 "https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), |
| 146 base::string16(), | 124 base::ASCIIToUTF16("ftp://tractorsupply.ie"), |
| 147 ASCIIToUTF16("ftp://tractorsupply.ie"), | 125 base::ASCIIToUTF16("ftp://tractorsupply.ie"), |
| 148 true, | 126 true, |
| 149 true | 127 true |
| 150 }, | 128 }, |
| 151 }; | 129 }; |
| 152 | 130 |
| 153 } // namespace | 131 } // namespace |
| 154 | 132 |
| 155 | 133 |
| 156 // ToolbarModelTest ----------------------------------------------------------- | 134 // ToolbarModelTest ----------------------------------------------------------- |
| 157 | 135 |
| 158 class ToolbarModelTest : public BrowserWithTestWindowTest { | 136 class ToolbarModelTest : public BrowserWithTestWindowTest { |
| 159 public: | 137 public: |
| 160 ToolbarModelTest(); | 138 ToolbarModelTest(); |
| 161 ToolbarModelTest(Browser::Type browser_type, | 139 ToolbarModelTest(Browser::Type browser_type, |
| 162 chrome::HostDesktopType host_desktop_type, | 140 chrome::HostDesktopType host_desktop_type, |
| 163 bool hosted_app); | 141 bool hosted_app); |
| 164 virtual ~ToolbarModelTest(); | 142 virtual ~ToolbarModelTest(); |
| 165 | 143 |
| 166 // BrowserWithTestWindowTest: | 144 // BrowserWithTestWindowTest: |
| 167 virtual void SetUp() OVERRIDE; | 145 virtual void SetUp() OVERRIDE; |
| 168 | 146 |
| 169 protected: | 147 protected: |
| 170 void NavigateAndCheckText(const GURL& url, | 148 void NavigateAndCheckText(const GURL& url, |
| 171 const base::string16& expected_text, | 149 const base::string16& expected_text, |
| 172 bool would_perform_search_term_replacement, | 150 bool would_perform_search_term_replacement, |
| 173 bool should_display_url); | 151 bool should_display_url); |
| 174 void EnableOriginChipFieldTrial(); | |
| 175 | 152 |
| 176 private: | 153 private: |
| 177 scoped_ptr<base::FieldTrialList> field_trial_list_; | |
| 178 | |
| 179 DISALLOW_COPY_AND_ASSIGN(ToolbarModelTest); | 154 DISALLOW_COPY_AND_ASSIGN(ToolbarModelTest); |
| 180 }; | 155 }; |
| 181 | 156 |
| 182 ToolbarModelTest::ToolbarModelTest() { | 157 ToolbarModelTest::ToolbarModelTest() { |
| 183 } | 158 } |
| 184 | 159 |
| 185 ToolbarModelTest::ToolbarModelTest( | 160 ToolbarModelTest::ToolbarModelTest( |
| 186 Browser::Type browser_type, | 161 Browser::Type browser_type, |
| 187 chrome::HostDesktopType host_desktop_type, | 162 chrome::HostDesktopType host_desktop_type, |
| 188 bool hosted_app) | 163 bool hosted_app) |
| 189 : BrowserWithTestWindowTest(browser_type, | 164 : BrowserWithTestWindowTest(browser_type, |
| 190 host_desktop_type, | 165 host_desktop_type, |
| 191 hosted_app) { | 166 hosted_app) { |
| 192 } | 167 } |
| 193 | 168 |
| 194 ToolbarModelTest::~ToolbarModelTest() { | 169 ToolbarModelTest::~ToolbarModelTest() { |
| 195 } | 170 } |
| 196 | 171 |
| 197 void ToolbarModelTest::SetUp() { | 172 void ToolbarModelTest::SetUp() { |
| 198 BrowserWithTestWindowTest::SetUp(); | 173 BrowserWithTestWindowTest::SetUp(); |
| 199 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 174 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 200 profile(), &TemplateURLServiceFactory::BuildInstanceFor); | 175 profile(), &TemplateURLServiceFactory::BuildInstanceFor); |
| 201 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( | 176 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( |
| 202 profile(), &AutocompleteClassifierFactory::BuildInstanceFor); | 177 profile(), &AutocompleteClassifierFactory::BuildInstanceFor); |
| 203 UIThreadSearchTermsData::SetGoogleBaseURL("http://google.com/"); | 178 UIThreadSearchTermsData::SetGoogleBaseURL("http://google.com/"); |
| 204 } | 179 } |
| 205 | 180 |
| 206 void ToolbarModelTest::EnableOriginChipFieldTrial() { | |
| 207 field_trial_list_.reset(new base::FieldTrialList( | |
| 208 new metrics::SHA1EntropyProvider("platypus"))); | |
| 209 base::FieldTrialList::CreateFieldTrial( | |
| 210 "EmbeddedSearch", "Group1 espv:2 origin_chip:1"); | |
| 211 } | |
| 212 | |
| 213 void ToolbarModelTest::NavigateAndCheckText( | 181 void ToolbarModelTest::NavigateAndCheckText( |
| 214 const GURL& url, | 182 const GURL& url, |
| 215 const base::string16& expected_text, | 183 const base::string16& expected_text, |
| 216 bool would_perform_search_term_replacement, | 184 bool would_perform_search_term_replacement, |
| 217 bool should_display_url) { | 185 bool should_display_url) { |
| 218 // Check while loading. | 186 // Check while loading. |
| 219 content::NavigationController* controller = | 187 content::NavigationController* controller = |
| 220 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); | 188 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); |
| 221 controller->LoadURL(url, content::Referrer(), content::PAGE_TRANSITION_LINK, | 189 controller->LoadURL(url, content::Referrer(), content::PAGE_TRANSITION_LINK, |
| 222 std::string()); | 190 std::string()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 // Disabling URL replacement should reset to only showing URLs. | 266 // Disabling URL replacement should reset to only showing URLs. |
| 299 browser()->toolbar_model()->set_url_replacement_enabled(false); | 267 browser()->toolbar_model()->set_url_replacement_enabled(false); |
| 300 for (size_t i = 0; i < arraysize(test_items); ++i) { | 268 for (size_t i = 0; i < arraysize(test_items); ++i) { |
| 301 const TestItem& test_item = test_items[i]; | 269 const TestItem& test_item = test_items[i]; |
| 302 NavigateAndCheckText(test_item.url, | 270 NavigateAndCheckText(test_item.url, |
| 303 test_item.expected_text_url_replacement_inactive, | 271 test_item.expected_text_url_replacement_inactive, |
| 304 false, test_item.should_display_url); | 272 false, test_item.should_display_url); |
| 305 } | 273 } |
| 306 } | 274 } |
| 307 | 275 |
| 308 // Test that we remove or replace URLs appropriately when the origin chip is | |
| 309 // enabled. | |
| 310 TEST_F(ToolbarModelTest, ShouldDisplayURL_OriginChip) { | |
| 311 EnableOriginChipFieldTrial(); | |
| 312 AddTab(browser(), GURL(content::kAboutBlankURL)); | |
| 313 | |
| 314 // Check each case with the origin chip enabled but query extraction disabled. | |
| 315 EXPECT_TRUE(chrome::ShouldDisplayOriginChip()); | |
| 316 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()); | |
| 317 for (size_t i = 0; i < arraysize(test_items); ++i) { | |
| 318 const TestItem& test_item = test_items[i]; | |
| 319 NavigateAndCheckText(test_item.url, test_item.expected_text_origin_chip, | |
| 320 false, test_item.should_display_url); | |
| 321 } | |
| 322 | |
| 323 // Check with both enabled. | |
| 324 chrome::EnableQueryExtractionForTesting(); | |
| 325 EXPECT_TRUE(chrome::IsQueryExtractionEnabled()); | |
| 326 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled()); | |
| 327 for (size_t i = 0; i < arraysize(test_items); ++i) { | |
| 328 const TestItem& test_item = test_items[i]; | |
| 329 NavigateAndCheckText(test_item.url, test_item.expected_text_both, | |
| 330 test_item.would_perform_search_term_replacement, | |
| 331 test_item.should_display_url); | |
| 332 } | |
| 333 | |
| 334 // Disabling URL replacement should reset to only showing URLs. | |
| 335 browser()->toolbar_model()->set_url_replacement_enabled(false); | |
| 336 for (size_t i = 0; i < arraysize(test_items); ++i) { | |
| 337 const TestItem& test_item = test_items[i]; | |
| 338 NavigateAndCheckText(test_item.url, | |
| 339 test_item.expected_text_url_replacement_inactive, | |
| 340 false, test_item.should_display_url); | |
| 341 } | |
| 342 } | |
| 343 | |
| 344 // Verify that search terms are extracted while the page is loading. | 276 // Verify that search terms are extracted while the page is loading. |
| 345 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) { | 277 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) { |
| 346 chrome::EnableQueryExtractionForTesting(); | 278 chrome::EnableQueryExtractionForTesting(); |
| 347 AddTab(browser(), GURL(content::kAboutBlankURL)); | 279 AddTab(browser(), GURL(content::kAboutBlankURL)); |
| 348 | 280 |
| 349 // While loading, we should be willing to extract search terms. | 281 // While loading, we should be willing to extract search terms. |
| 350 content::NavigationController* controller = | 282 content::NavigationController* controller = |
| 351 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); | 283 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); |
| 352 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"), | 284 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"), |
| 353 content::Referrer(), content::PAGE_TRANSITION_LINK, | 285 content::Referrer(), content::PAGE_TRANSITION_LINK, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 370 // secure. | 302 // secure. |
| 371 TEST_F(ToolbarModelTest, GoogleBaseURL) { | 303 TEST_F(ToolbarModelTest, GoogleBaseURL) { |
| 372 chrome::EnableQueryExtractionForTesting(); | 304 chrome::EnableQueryExtractionForTesting(); |
| 373 AddTab(browser(), GURL(content::kAboutBlankURL)); | 305 AddTab(browser(), GURL(content::kAboutBlankURL)); |
| 374 | 306 |
| 375 // If the Google base URL wasn't specified on the command line, then if it's | 307 // If the Google base URL wasn't specified on the command line, then if it's |
| 376 // HTTP, we should not extract search terms. | 308 // HTTP, we should not extract search terms. |
| 377 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); | 309 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); |
| 378 NavigateAndCheckText( | 310 NavigateAndCheckText( |
| 379 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), | 311 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), |
| 380 ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), false, true); | 312 base::ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), false, |
| 313 true); | |
| 381 | 314 |
| 382 // The same URL, when specified on the command line, should allow search term | 315 // The same URL, when specified on the command line, should allow search term |
| 383 // extraction. | 316 // extraction. |
| 384 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); | 317 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); |
| 385 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, | 318 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, |
| 386 "http://www.foo.com/"); | 319 "http://www.foo.com/"); |
| 387 NavigateAndCheckText( | 320 NavigateAndCheckText( |
| 388 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), | 321 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), |
| 389 ASCIIToUTF16("tractor supply"), true, true); | 322 base::ASCIIToUTF16("tractor supply"), true, true); |
| 390 } | 323 } |
| 391 | |
| 392 // Popup windows don't have an origin chip, so test that URL display in a popup | |
| 393 // ignores whether the origin chip is enabled and only respects the query | |
| 394 // extraction flag. | |
| 395 TEST_F(PopupToolbarModelTest, ShouldDisplayURL) { | |
| 396 AddTab(browser(), GURL(content::kAboutBlankURL)); | |
| 397 | |
| 398 // Check with neither query extraction nor the origin chip enabled. | |
| 399 EXPECT_FALSE(chrome::ShouldDisplayOriginChip()); | |
| 400 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()); | |
| 401 for (size_t i = 0; i < arraysize(test_items); ++i) { | |
| 402 const TestItem& test_item = test_items[i]; | |
| 403 NavigateAndCheckText(test_item.url, | |
| 404 test_item.expected_text_url_replacement_inactive, | |
| 405 false, test_item.should_display_url); | |
| 406 } | |
| 407 | |
| 408 // Check with the origin chip enabled. | |
| 409 EnableOriginChipFieldTrial(); | |
| 410 EXPECT_TRUE(chrome::ShouldDisplayOriginChip()); | |
| 411 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()); | |
| 412 for (size_t i = 0; i < arraysize(test_items); ++i) { | |
| 413 const TestItem& test_item = test_items[i]; | |
| 414 NavigateAndCheckText(test_item.url, | |
| 415 test_item.expected_text_url_replacement_inactive, | |
| 416 false, test_item.should_display_url); | |
| 417 } | |
| 418 | |
| 419 // With both origin chip and query extraction enabled, only search term | |
| 420 // replacement should be performed. | |
| 421 chrome::EnableQueryExtractionForTesting(); | |
| 422 EXPECT_TRUE(chrome::IsQueryExtractionEnabled()); | |
| 423 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled()); | |
| 424 for (size_t i = 0; i < arraysize(test_items); ++i) { | |
| 425 const TestItem& test_item = test_items[i]; | |
| 426 NavigateAndCheckText(test_item.url, | |
| 427 test_item.expected_text_query_extraction, | |
| 428 test_item.would_perform_search_term_replacement, | |
| 429 test_item.should_display_url); | |
| 430 } | |
| 431 | |
| 432 // Disabling URL replacement should reset to only showing URLs. | |
| 433 browser()->toolbar_model()->set_url_replacement_enabled(false); | |
| 434 for (size_t i = 0; i < arraysize(test_items); ++i) { | |
| 435 const TestItem& test_item = test_items[i]; | |
| 436 NavigateAndCheckText(test_item.url, | |
| 437 test_item.expected_text_url_replacement_inactive, | |
| 438 false, test_item.should_display_url); | |
| 439 } | |
| 440 } | |
| OLD | NEW |