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

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

Issue 731423002: Remove OriginChip code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix gyp file and bad merge Created 5 years, 10 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
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 "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"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 ToolbarModelTest(); 141 ToolbarModelTest();
142 ToolbarModelTest(Browser::Type browser_type, 142 ToolbarModelTest(Browser::Type browser_type,
143 chrome::HostDesktopType host_desktop_type, 143 chrome::HostDesktopType host_desktop_type,
144 bool hosted_app); 144 bool hosted_app);
145 ~ToolbarModelTest() override; 145 ~ToolbarModelTest() override;
146 146
147 // BrowserWithTestWindowTest: 147 // BrowserWithTestWindowTest:
148 void SetUp() override; 148 void SetUp() override;
149 149
150 protected: 150 protected:
151 void EnableOriginChipFieldTrial();
152 void NavigateAndCheckText(const GURL& url, 151 void NavigateAndCheckText(const GURL& url,
153 const base::string16& expected_text, 152 const base::string16& expected_text,
154 bool would_perform_search_term_replacement, 153 bool would_perform_search_term_replacement,
155 bool should_display_url); 154 bool should_display_url);
156 155
157 private: 156 private:
158 scoped_ptr<base::FieldTrialList> field_trial_list_; 157 scoped_ptr<base::FieldTrialList> field_trial_list_;
159 158
160 DISALLOW_COPY_AND_ASSIGN(ToolbarModelTest); 159 DISALLOW_COPY_AND_ASSIGN(ToolbarModelTest);
161 }; 160 };
(...skipping 15 matching lines...) Expand all
177 176
178 void ToolbarModelTest::SetUp() { 177 void ToolbarModelTest::SetUp() {
179 BrowserWithTestWindowTest::SetUp(); 178 BrowserWithTestWindowTest::SetUp();
180 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 179 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
181 profile(), &TemplateURLServiceFactory::BuildInstanceFor); 180 profile(), &TemplateURLServiceFactory::BuildInstanceFor);
182 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( 181 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse(
183 profile(), &AutocompleteClassifierFactory::BuildInstanceFor); 182 profile(), &AutocompleteClassifierFactory::BuildInstanceFor);
184 UIThreadSearchTermsData::SetGoogleBaseURL("http://google.com/"); 183 UIThreadSearchTermsData::SetGoogleBaseURL("http://google.com/");
185 } 184 }
186 185
187 void ToolbarModelTest::EnableOriginChipFieldTrial() {
188 field_trial_list_.reset(new base::FieldTrialList(
189 new metrics::SHA1EntropyProvider("platypus")));
190 base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
191 "Group1 espv:2 origin_chip:1");
192 }
193
194 void ToolbarModelTest::NavigateAndCheckText( 186 void ToolbarModelTest::NavigateAndCheckText(
195 const GURL& url, 187 const GURL& url,
196 const base::string16& expected_text, 188 const base::string16& expected_text,
197 bool would_perform_search_term_replacement, 189 bool would_perform_search_term_replacement,
198 bool should_display_url) { 190 bool should_display_url) {
199 // Check while loading. 191 // Check while loading.
200 content::NavigationController* controller = 192 content::NavigationController* controller =
201 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); 193 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
202 controller->LoadURL(url, content::Referrer(), ui::PAGE_TRANSITION_LINK, 194 controller->LoadURL(url, content::Referrer(), ui::PAGE_TRANSITION_LINK,
203 std::string()); 195 std::string());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 // Disabling URL replacement should reset to only showing URLs. 271 // Disabling URL replacement should reset to only showing URLs.
280 browser()->toolbar_model()->set_url_replacement_enabled(false); 272 browser()->toolbar_model()->set_url_replacement_enabled(false);
281 for (size_t i = 0; i < arraysize(test_items); ++i) { 273 for (size_t i = 0; i < arraysize(test_items); ++i) {
282 const TestItem& test_item = test_items[i]; 274 const TestItem& test_item = test_items[i];
283 NavigateAndCheckText(test_item.url, 275 NavigateAndCheckText(test_item.url,
284 test_item.expected_text_url_replacement_inactive, 276 test_item.expected_text_url_replacement_inactive,
285 false, test_item.should_display_url); 277 false, test_item.should_display_url);
286 } 278 }
287 } 279 }
288 280
289 // Test that we remove or replace URLs appropriately when the origin chip is
290 // enabled.
291 TEST_F(ToolbarModelTest, ShouldDisplayURL_OriginChip) {
292 EnableOriginChipFieldTrial();
293 AddTab(browser(), GURL(url::kAboutBlankURL));
294
295 // Check each case with the origin chip enabled but query extraction disabled.
296 EXPECT_TRUE(chrome::ShouldDisplayOriginChip());
297 EXPECT_FALSE(chrome::IsQueryExtractionEnabled());
298 for (size_t i = 0; i < arraysize(test_items); ++i) {
299 const TestItem& test_item = test_items[i];
300 NavigateAndCheckText(test_item.url, base::string16(), false,
301 test_item.should_display_url);
302 }
303
304 // Check with both enabled.
305 chrome::EnableQueryExtractionForTesting();
306 EXPECT_TRUE(chrome::IsQueryExtractionEnabled());
307 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled());
308 for (size_t i = 0; i < arraysize(test_items); ++i) {
309 const TestItem& test_item = test_items[i];
310 NavigateAndCheckText(test_item.url, test_item.expected_text_both,
311 test_item.would_perform_search_term_replacement,
312 test_item.should_display_url);
313 }
314
315 // Disabling URL replacement should reset to only showing URLs.
316 browser()->toolbar_model()->set_url_replacement_enabled(false);
317 for (size_t i = 0; i < arraysize(test_items); ++i) {
318 const TestItem& test_item = test_items[i];
319 NavigateAndCheckText(test_item.url,
320 test_item.expected_text_url_replacement_inactive,
321 false, test_item.should_display_url);
322 }
323 }
324
325 // Verify that search terms are extracted while the page is loading. 281 // Verify that search terms are extracted while the page is loading.
326 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) { 282 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) {
327 chrome::EnableQueryExtractionForTesting(); 283 chrome::EnableQueryExtractionForTesting();
328 AddTab(browser(), GURL(url::kAboutBlankURL)); 284 AddTab(browser(), GURL(url::kAboutBlankURL));
329 285
330 // While loading, we should be willing to extract search terms. 286 // While loading, we should be willing to extract search terms.
331 content::NavigationController* controller = 287 content::NavigationController* controller =
332 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); 288 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
333 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"), 289 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"),
334 content::Referrer(), ui::PAGE_TRANSITION_LINK, 290 content::Referrer(), ui::PAGE_TRANSITION_LINK,
(...skipping 29 matching lines...) Expand all
364 // The same URL, when specified on the command line, should allow search term 320 // The same URL, when specified on the command line, should allow search term
365 // extraction. 321 // extraction.
366 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); 322 UIThreadSearchTermsData::SetGoogleBaseURL(std::string());
367 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 323 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
368 switches::kGoogleBaseURL, "http://www.foo.com/"); 324 switches::kGoogleBaseURL, "http://www.foo.com/");
369 NavigateAndCheckText( 325 NavigateAndCheckText(
370 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), 326 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"),
371 base::ASCIIToUTF16("tractor supply"), true, true); 327 base::ASCIIToUTF16("tractor supply"), true, true);
372 } 328 }
373 329
374 // Popup windows don't have an origin chip, so test that URL display in a popup 330 // Test that URL display in a popup respects the query extraction flag.
375 // ignores whether the origin chip is enabled and only respects the query
376 // extraction flag.
377 TEST_F(PopupToolbarModelTest, ShouldDisplayURL) { 331 TEST_F(PopupToolbarModelTest, ShouldDisplayURL) {
378 AddTab(browser(), GURL(url::kAboutBlankURL)); 332 AddTab(browser(), GURL(url::kAboutBlankURL));
379 333
380 // Check with neither query extraction nor the origin chip enabled. 334 // Check with query extraction disabled.
381 EXPECT_FALSE(chrome::ShouldDisplayOriginChip());
382 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()); 335 EXPECT_FALSE(chrome::IsQueryExtractionEnabled());
383 for (size_t i = 0; i < arraysize(test_items); ++i) { 336 for (size_t i = 0; i < arraysize(test_items); ++i) {
384 const TestItem& test_item = test_items[i]; 337 const TestItem& test_item = test_items[i];
385 NavigateAndCheckText(test_item.url,
386 test_item.expected_text_url_replacement_inactive,
387 false, test_item.should_display_url);
388 }
389
390 // Check with the origin chip enabled.
391 EnableOriginChipFieldTrial();
392 EXPECT_TRUE(chrome::ShouldDisplayOriginChip());
393 EXPECT_FALSE(chrome::IsQueryExtractionEnabled());
394 for (size_t i = 0; i < arraysize(test_items); ++i) {
395 const TestItem& test_item = test_items[i];
396 NavigateAndCheckText(test_item.url, 338 NavigateAndCheckText(test_item.url,
397 test_item.expected_text_url_replacement_inactive, 339 test_item.expected_text_url_replacement_inactive,
398 false, test_item.should_display_url); 340 false, test_item.should_display_url);
399 } 341 }
400 342
401 // With both origin chip and query extraction enabled, only search term 343 // With query extraction enabled, search term replacement should be performed.
402 // replacement should be performed.
403 chrome::EnableQueryExtractionForTesting(); 344 chrome::EnableQueryExtractionForTesting();
404 EXPECT_TRUE(chrome::IsQueryExtractionEnabled()); 345 EXPECT_TRUE(chrome::IsQueryExtractionEnabled());
405 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled()); 346 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled());
406 for (size_t i = 0; i < arraysize(test_items); ++i) { 347 for (size_t i = 0; i < arraysize(test_items); ++i) {
407 const TestItem& test_item = test_items[i]; 348 const TestItem& test_item = test_items[i];
408 NavigateAndCheckText(test_item.url, 349 NavigateAndCheckText(test_item.url,
409 test_item.expected_text_query_extraction, 350 test_item.expected_text_query_extraction,
410 test_item.would_perform_search_term_replacement, 351 test_item.would_perform_search_term_replacement,
411 test_item.should_display_url); 352 test_item.should_display_url);
412 } 353 }
413 354
414 // Disabling URL replacement should reset to only showing URLs. 355 // Disabling URL replacement should reset to only showing URLs.
415 browser()->toolbar_model()->set_url_replacement_enabled(false); 356 browser()->toolbar_model()->set_url_replacement_enabled(false);
416 for (size_t i = 0; i < arraysize(test_items); ++i) { 357 for (size_t i = 0; i < arraysize(test_items); ++i) {
417 const TestItem& test_item = test_items[i]; 358 const TestItem& test_item = test_items[i];
418 NavigateAndCheckText(test_item.url, 359 NavigateAndCheckText(test_item.url,
419 test_item.expected_text_url_replacement_inactive, 360 test_item.expected_text_url_replacement_inactive,
420 false, test_item.should_display_url); 361 false, test_item.should_display_url);
421 } 362 }
422 } 363 }
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