Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_model_unittest.cc

Issue 287543002: Remove origin chip v1 and "hide on input" v2 behavior. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 8 #include "base/metrics/field_trial.h"
11 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 10 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
13 #include "chrome/browser/search/search.h" 11 #include "chrome/browser/search/search.h"
14 #include "chrome/browser/search_engines/search_terms_data.h" 12 #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" 13 #include "chrome/browser/search_engines/template_url_service_factory.h"
18 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/browser/ui/toolbar/toolbar_model.h" 16 #include "chrome/browser/ui/toolbar/toolbar_model.h"
21 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
22 #include "chrome/test/base/browser_with_test_window_test.h" 18 #include "chrome/test/base/browser_with_test_window_test.h"
23 #include "components/variations/entropy_provider.h" 19 #include "components/variations/entropy_provider.h"
24 #include "content/public/browser/navigation_entry.h" 20 #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" 21 #include "content/public/common/ssl_status.h"
28 #include "content/public/common/url_constants.h" 22 #include "content/public/common/url_constants.h"
29 #include "net/base/escape.h"
30 23
31 using base::ASCIIToUTF16;
32 24
33 // Test data ------------------------------------------------------------------ 25 // Test data ------------------------------------------------------------------
34 26
35 namespace { 27 namespace {
36 28
37 struct TestItem { 29 struct TestItem {
38 GURL url; 30 GURL url;
39 // The expected text to display when both forms of URL replacement are 31 // The expected text to display when both forms of URL replacement are
40 // inactive. 32 // inactive.
41 base::string16 expected_text_url_replacement_inactive; 33 base::string16 expected_text_url_replacement_inactive;
42 // The expected text to display when query extraction is active. 34 // The expected text to display when query extraction is active.
43 base::string16 expected_text_query_extraction; 35 base::string16 expected_text_query_extraction;
44 // The expected text to display when the origin chip (URL removal) is active.
45 base::string16 expected_text_origin_chip;
46 // The expected text to display when both query extraction and URL removal are 36 // The expected text to display when both query extraction and URL removal are
47 // active. 37 // active.
48 base::string16 expected_text_both; 38 base::string16 expected_text_both;
49 bool would_perform_search_term_replacement; 39 bool would_perform_search_term_replacement;
50 bool should_display_url; 40 bool should_display_url;
51 } test_items[] = { 41 } test_items[] = {
52 { 42 {
53 GURL("view-source:http://www.google.com"), 43 GURL("view-source:http://www.google.com"),
54 ASCIIToUTF16("view-source:www.google.com"), 44 base::ASCIIToUTF16("view-source:www.google.com"),
55 ASCIIToUTF16("view-source:www.google.com"), 45 base::ASCIIToUTF16("view-source:www.google.com"),
56 base::string16(),
57 base::string16(), 46 base::string16(),
58 false, 47 false,
59 true 48 true
60 }, 49 },
61 { 50 {
62 GURL("view-source:chrome://newtab/"), 51 GURL("view-source:chrome://newtab/"),
63 ASCIIToUTF16("view-source:chrome://newtab"), 52 base::ASCIIToUTF16("view-source:chrome://newtab"),
64 ASCIIToUTF16("view-source:chrome://newtab"), 53 base::ASCIIToUTF16("view-source:chrome://newtab"),
65 base::string16(),
66 base::string16(), 54 base::string16(),
67 false, 55 false,
68 true 56 true
69 }, 57 },
70 { 58 {
71 GURL("chrome-extension://monkey/balls.html"), 59 GURL("chrome-extension://monkey/balls.html"),
72 ASCIIToUTF16("chrome-extension://monkey/balls.html"), 60 base::ASCIIToUTF16("chrome-extension://monkey/balls.html"),
73 ASCIIToUTF16("chrome-extension://monkey/balls.html"), 61 base::ASCIIToUTF16("chrome-extension://monkey/balls.html"),
74 base::string16(),
75 base::string16(), 62 base::string16(),
76 false, 63 false,
77 true 64 true
78 }, 65 },
79 { 66 {
80 GURL(content::kAboutBlankURL), 67 GURL(content::kAboutBlankURL),
81 ASCIIToUTF16(content::kAboutBlankURL), 68 base::ASCIIToUTF16(content::kAboutBlankURL),
82 ASCIIToUTF16(content::kAboutBlankURL), 69 base::ASCIIToUTF16(content::kAboutBlankURL),
83 base::string16(),
84 base::string16(), 70 base::string16(),
85 false, 71 false,
86 true 72 true
87 }, 73 },
88 { 74 {
89 GURL("http://searchurl/?q=tractor+supply"), 75 GURL("http://searchurl/?q=tractor+supply"),
90 ASCIIToUTF16("searchurl/?q=tractor+supply"), 76 base::ASCIIToUTF16("searchurl/?q=tractor+supply"),
91 ASCIIToUTF16("searchurl/?q=tractor+supply"), 77 base::ASCIIToUTF16("searchurl/?q=tractor+supply"),
92 base::string16(),
93 base::string16(), 78 base::string16(),
94 false, 79 false,
95 true 80 true
96 }, 81 },
97 { 82 {
98 GURL("http://google.com/search?q=tractor+supply&espv=1"), 83 GURL("http://google.com/search?q=tractor+supply&espv=1"),
99 ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"), 84 base::ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"),
100 ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"), 85 base::ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"),
101 base::string16(),
102 base::string16(), 86 base::string16(),
103 false, 87 false,
104 true 88 true
105 }, 89 },
106 { 90 {
107 GURL("https://google.ca/search?q=tractor+supply"), 91 GURL("https://google.ca/search?q=tractor+supply"),
108 ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), 92 base::ASCIIToUTF16("https://google.ca/search?q=tractor+supply"),
109 ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), 93 base::ASCIIToUTF16("https://google.ca/search?q=tractor+supply"),
110 base::string16(),
111 base::string16(), 94 base::string16(),
112 false, 95 false,
113 true 96 true
114 }, 97 },
115 { 98 {
116 GURL("https://google.com/search?q=tractor+supply"), 99 GURL("https://google.com/search?q=tractor+supply"),
117 ASCIIToUTF16("https://google.com/search?q=tractor+supply"), 100 base::ASCIIToUTF16("https://google.com/search?q=tractor+supply"),
118 ASCIIToUTF16("https://google.com/search?q=tractor+supply"), 101 base::ASCIIToUTF16("https://google.com/search?q=tractor+supply"),
119 base::string16(),
120 base::string16(), 102 base::string16(),
121 false, 103 false,
122 true 104 true
123 }, 105 },
124 { 106 {
125 GURL("https://google.com/search?q=tractor+supply&espv=1"), 107 GURL("https://google.com/search?q=tractor+supply&espv=1"),
126 ASCIIToUTF16("https://google.com/search?q=tractor+supply&espv=1"), 108 base::ASCIIToUTF16("https://google.com/search?q=tractor+supply&espv=1"),
127 ASCIIToUTF16("tractor supply"), 109 base::ASCIIToUTF16("tractor supply"),
128 base::string16(), 110 base::ASCIIToUTF16("tractor supply"),
129 ASCIIToUTF16("tractor supply"),
130 true, 111 true,
131 true 112 true
132 }, 113 },
133 { 114 {
134 GURL("https://google.com/search?q=tractorsupply.com&espv=1"), 115 GURL("https://google.com/search?q=tractorsupply.com&espv=1"),
135 ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"), 116 base::ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"),
136 ASCIIToUTF16("tractorsupply.com"), 117 base::ASCIIToUTF16("tractorsupply.com"),
137 base::string16(), 118 base::ASCIIToUTF16("tractorsupply.com"),
138 ASCIIToUTF16("tractorsupply.com"),
139 true, 119 true,
140 true 120 true
141 }, 121 },
142 { 122 {
143 GURL("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), 123 GURL("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"),
144 ASCIIToUTF16("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), 124 base::ASCIIToUTF16(
145 ASCIIToUTF16("ftp://tractorsupply.ie"), 125 "https://google.com/search?q=ftp://tractorsupply.ie&espv=1"),
146 base::string16(), 126 base::ASCIIToUTF16("ftp://tractorsupply.ie"),
147 ASCIIToUTF16("ftp://tractorsupply.ie"), 127 base::ASCIIToUTF16("ftp://tractorsupply.ie"),
148 true, 128 true,
149 true 129 true
150 }, 130 },
151 }; 131 };
152 132
153 } // namespace 133 } // namespace
154 134
155 135
156 // ToolbarModelTest ----------------------------------------------------------- 136 // ToolbarModelTest -----------------------------------------------------------
157 137
158 class ToolbarModelTest : public BrowserWithTestWindowTest { 138 class ToolbarModelTest : public BrowserWithTestWindowTest {
159 public: 139 public:
160 ToolbarModelTest(); 140 ToolbarModelTest();
161 ToolbarModelTest(Browser::Type browser_type, 141 ToolbarModelTest(Browser::Type browser_type,
162 chrome::HostDesktopType host_desktop_type, 142 chrome::HostDesktopType host_desktop_type,
163 bool hosted_app); 143 bool hosted_app);
164 virtual ~ToolbarModelTest(); 144 virtual ~ToolbarModelTest();
165 145
166 // BrowserWithTestWindowTest: 146 // BrowserWithTestWindowTest:
167 virtual void SetUp() OVERRIDE; 147 virtual void SetUp() OVERRIDE;
168 148
169 protected: 149 protected:
150 void EnableOriginChipFieldTrial();
170 void NavigateAndCheckText(const GURL& url, 151 void NavigateAndCheckText(const GURL& url,
171 const base::string16& expected_text, 152 const base::string16& expected_text,
172 bool would_perform_search_term_replacement, 153 bool would_perform_search_term_replacement,
173 bool should_display_url); 154 bool should_display_url);
174 void EnableOriginChipFieldTrial();
175 155
176 private: 156 private:
177 scoped_ptr<base::FieldTrialList> field_trial_list_; 157 scoped_ptr<base::FieldTrialList> field_trial_list_;
178 158
179 DISALLOW_COPY_AND_ASSIGN(ToolbarModelTest); 159 DISALLOW_COPY_AND_ASSIGN(ToolbarModelTest);
180 }; 160 };
181 161
182 ToolbarModelTest::ToolbarModelTest() { 162 ToolbarModelTest::ToolbarModelTest() {
183 } 163 }
184 164
(...skipping 14 matching lines...) Expand all
199 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 179 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
200 profile(), &TemplateURLServiceFactory::BuildInstanceFor); 180 profile(), &TemplateURLServiceFactory::BuildInstanceFor);
201 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( 181 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse(
202 profile(), &AutocompleteClassifierFactory::BuildInstanceFor); 182 profile(), &AutocompleteClassifierFactory::BuildInstanceFor);
203 UIThreadSearchTermsData::SetGoogleBaseURL("http://google.com/"); 183 UIThreadSearchTermsData::SetGoogleBaseURL("http://google.com/");
204 } 184 }
205 185
206 void ToolbarModelTest::EnableOriginChipFieldTrial() { 186 void ToolbarModelTest::EnableOriginChipFieldTrial() {
207 field_trial_list_.reset(new base::FieldTrialList( 187 field_trial_list_.reset(new base::FieldTrialList(
208 new metrics::SHA1EntropyProvider("platypus"))); 188 new metrics::SHA1EntropyProvider("platypus")));
209 base::FieldTrialList::CreateFieldTrial( 189 base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
210 "EmbeddedSearch", "Group1 espv:2 origin_chip:1"); 190 "Group1 espv:2 origin_chip:1");
211 } 191 }
212 192
213 void ToolbarModelTest::NavigateAndCheckText( 193 void ToolbarModelTest::NavigateAndCheckText(
214 const GURL& url, 194 const GURL& url,
215 const base::string16& expected_text, 195 const base::string16& expected_text,
216 bool would_perform_search_term_replacement, 196 bool would_perform_search_term_replacement,
217 bool should_display_url) { 197 bool should_display_url) {
218 // Check while loading. 198 // Check while loading.
219 content::NavigationController* controller = 199 content::NavigationController* controller =
220 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); 200 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // enabled. 289 // enabled.
310 TEST_F(ToolbarModelTest, ShouldDisplayURL_OriginChip) { 290 TEST_F(ToolbarModelTest, ShouldDisplayURL_OriginChip) {
311 EnableOriginChipFieldTrial(); 291 EnableOriginChipFieldTrial();
312 AddTab(browser(), GURL(content::kAboutBlankURL)); 292 AddTab(browser(), GURL(content::kAboutBlankURL));
313 293
314 // Check each case with the origin chip enabled but query extraction disabled. 294 // Check each case with the origin chip enabled but query extraction disabled.
315 EXPECT_TRUE(chrome::ShouldDisplayOriginChip()); 295 EXPECT_TRUE(chrome::ShouldDisplayOriginChip());
316 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()); 296 EXPECT_FALSE(chrome::IsQueryExtractionEnabled());
317 for (size_t i = 0; i < arraysize(test_items); ++i) { 297 for (size_t i = 0; i < arraysize(test_items); ++i) {
318 const TestItem& test_item = test_items[i]; 298 const TestItem& test_item = test_items[i];
319 NavigateAndCheckText(test_item.url, test_item.expected_text_origin_chip, 299 NavigateAndCheckText(test_item.url, base::string16(), false,
320 false, test_item.should_display_url); 300 test_item.should_display_url);
321 } 301 }
322 302
323 // Check with both enabled. 303 // Check with both enabled.
324 chrome::EnableQueryExtractionForTesting(); 304 chrome::EnableQueryExtractionForTesting();
325 EXPECT_TRUE(chrome::IsQueryExtractionEnabled()); 305 EXPECT_TRUE(chrome::IsQueryExtractionEnabled());
326 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled()); 306 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled());
327 for (size_t i = 0; i < arraysize(test_items); ++i) { 307 for (size_t i = 0; i < arraysize(test_items); ++i) {
328 const TestItem& test_item = test_items[i]; 308 const TestItem& test_item = test_items[i];
329 NavigateAndCheckText(test_item.url, test_item.expected_text_both, 309 NavigateAndCheckText(test_item.url, test_item.expected_text_both,
330 test_item.would_perform_search_term_replacement, 310 test_item.would_perform_search_term_replacement,
331 test_item.should_display_url); 311 test_item.should_display_url);
332 } 312 }
333 313
334 // Disabling URL replacement should reset to only showing URLs. 314 // Disabling URL replacement should reset to only showing URLs.
335 browser()->toolbar_model()->set_url_replacement_enabled(false); 315 browser()->toolbar_model()->set_url_replacement_enabled(false);
336 for (size_t i = 0; i < arraysize(test_items); ++i) { 316 for (size_t i = 0; i < arraysize(test_items); ++i) {
337 const TestItem& test_item = test_items[i]; 317 const TestItem& test_item = test_items[i];
338 NavigateAndCheckText(test_item.url, 318 NavigateAndCheckText(test_item.url,
339 test_item.expected_text_url_replacement_inactive, 319 test_item.expected_text_url_replacement_inactive,
340 false, test_item.should_display_url); 320 false, test_item.should_display_url);
341 } 321 }
342 } 322 }
343 323
344 // Verify that search terms are extracted while the page is loading. 324 // Verify that search terms are extracted while the page is loading.
345 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) { 325 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) {
346 chrome::EnableQueryExtractionForTesting(); 326 chrome::EnableQueryExtractionForTesting();
347 AddTab(browser(), GURL(content::kAboutBlankURL)); 327 AddTab(browser(), GURL(content::kAboutBlankURL));
348 328
349 // While loading, we should be willing to extract search terms. 329 // While loading, we should be willing to extract search terms.
350 content::NavigationController* controller = 330 content::NavigationController* controller =
351 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); 331 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
352 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"), 332 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"),
353 content::Referrer(), content::PAGE_TRANSITION_LINK, 333 content::Referrer(), content::PAGE_TRANSITION_LINK,
354 std::string()); 334 std::string());
(...skipping 15 matching lines...) Expand all
370 // secure. 350 // secure.
371 TEST_F(ToolbarModelTest, GoogleBaseURL) { 351 TEST_F(ToolbarModelTest, GoogleBaseURL) {
372 chrome::EnableQueryExtractionForTesting(); 352 chrome::EnableQueryExtractionForTesting();
373 AddTab(browser(), GURL(content::kAboutBlankURL)); 353 AddTab(browser(), GURL(content::kAboutBlankURL));
374 354
375 // If the Google base URL wasn't specified on the command line, then if it's 355 // If the Google base URL wasn't specified on the command line, then if it's
376 // HTTP, we should not extract search terms. 356 // HTTP, we should not extract search terms.
377 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); 357 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/");
378 NavigateAndCheckText( 358 NavigateAndCheckText(
379 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), 359 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"),
380 ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), false, true); 360 base::ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), false,
361 true);
381 362
382 // The same URL, when specified on the command line, should allow search term 363 // The same URL, when specified on the command line, should allow search term
383 // extraction. 364 // extraction.
384 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); 365 UIThreadSearchTermsData::SetGoogleBaseURL(std::string());
385 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, 366 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL,
386 "http://www.foo.com/"); 367 "http://www.foo.com/");
387 NavigateAndCheckText( 368 NavigateAndCheckText(
388 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), 369 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"),
389 ASCIIToUTF16("tractor supply"), true, true); 370 base::ASCIIToUTF16("tractor supply"), true, true);
390 } 371 }
391 372
392 // Popup windows don't have an origin chip, so test that URL display in a popup 373 // 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 374 // ignores whether the origin chip is enabled and only respects the query
394 // extraction flag. 375 // extraction flag.
395 TEST_F(PopupToolbarModelTest, ShouldDisplayURL) { 376 TEST_F(PopupToolbarModelTest, ShouldDisplayURL) {
396 AddTab(browser(), GURL(content::kAboutBlankURL)); 377 AddTab(browser(), GURL(content::kAboutBlankURL));
397 378
398 // Check with neither query extraction nor the origin chip enabled. 379 // Check with neither query extraction nor the origin chip enabled.
399 EXPECT_FALSE(chrome::ShouldDisplayOriginChip()); 380 EXPECT_FALSE(chrome::ShouldDisplayOriginChip());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 412
432 // Disabling URL replacement should reset to only showing URLs. 413 // Disabling URL replacement should reset to only showing URLs.
433 browser()->toolbar_model()->set_url_replacement_enabled(false); 414 browser()->toolbar_model()->set_url_replacement_enabled(false);
434 for (size_t i = 0; i < arraysize(test_items); ++i) { 415 for (size_t i = 0; i < arraysize(test_items); ++i) {
435 const TestItem& test_item = test_items[i]; 416 const TestItem& test_item = test_items[i];
436 NavigateAndCheckText(test_item.url, 417 NavigateAndCheckText(test_item.url,
437 test_item.expected_text_url_replacement_inactive, 418 test_item.expected_text_url_replacement_inactive,
438 false, test_item.should_display_url); 419 false, test_item.should_display_url);
439 } 420 }
440 } 421 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_model_impl.cc ('k') | chrome/browser/ui/views/frame/browser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698