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

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

Issue 1260033003: Partially componentize //chrome/browser/search/search.{h,cc} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation on iOS Created 5 years, 4 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 "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/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/test/base/browser_with_test_window_test.h" 17 #include "chrome/test/base/browser_with_test_window_test.h"
18 #include "components/google/core/browser/google_switches.h" 18 #include "components/google/core/browser/google_switches.h"
19 #include "components/search/search.h"
19 #include "components/toolbar/toolbar_model.h" 20 #include "components/toolbar/toolbar_model.h"
20 #include "components/variations/entropy_provider.h" 21 #include "components/variations/entropy_provider.h"
21 #include "content/public/browser/navigation_entry.h" 22 #include "content/public/browser/navigation_entry.h"
22 #include "content/public/common/ssl_status.h" 23 #include "content/public/common/ssl_status.h"
23 #include "content/public/common/url_constants.h" 24 #include "content/public/common/url_constants.h"
24 25
25 26
26 // Test data ------------------------------------------------------------------ 27 // Test data ------------------------------------------------------------------
27 28
28 namespace { 29 namespace {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } 242 }
242 243
243 // Actual tests --------------------------------------------------------------- 244 // Actual tests ---------------------------------------------------------------
244 245
245 // Test that we only replace URLs when query extraction and URL replacement 246 // Test that we only replace URLs when query extraction and URL replacement
246 // are enabled. 247 // are enabled.
247 TEST_F(ToolbarModelTest, ShouldDisplayURL_QueryExtraction) { 248 TEST_F(ToolbarModelTest, ShouldDisplayURL_QueryExtraction) {
248 AddTab(browser(), GURL(url::kAboutBlankURL)); 249 AddTab(browser(), GURL(url::kAboutBlankURL));
249 250
250 // Before we enable instant extended, query extraction is disabled. 251 // Before we enable instant extended, query extraction is disabled.
251 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()) 252 EXPECT_FALSE(search::IsQueryExtractionEnabled())
252 << "This test expects query extraction to be disabled."; 253 << "This test expects query extraction to be disabled.";
253 for (size_t i = 0; i < arraysize(test_items); ++i) { 254 for (size_t i = 0; i < arraysize(test_items); ++i) {
254 const TestItem& test_item = test_items[i]; 255 const TestItem& test_item = test_items[i];
255 NavigateAndCheckText(test_item.url, 256 NavigateAndCheckText(test_item.url,
256 test_item.expected_text_url_replacement_inactive, 257 test_item.expected_text_url_replacement_inactive,
257 false, test_item.should_display_url); 258 false, test_item.should_display_url);
258 } 259 }
259 260
260 chrome::EnableQueryExtractionForTesting(); 261 search::EnableQueryExtractionForTesting();
261 EXPECT_TRUE(chrome::IsQueryExtractionEnabled()); 262 EXPECT_TRUE(search::IsQueryExtractionEnabled());
262 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled()); 263 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled());
263 for (size_t i = 0; i < arraysize(test_items); ++i) { 264 for (size_t i = 0; i < arraysize(test_items); ++i) {
264 const TestItem& test_item = test_items[i]; 265 const TestItem& test_item = test_items[i];
265 NavigateAndCheckText(test_item.url, 266 NavigateAndCheckText(test_item.url,
266 test_item.expected_text_query_extraction, 267 test_item.expected_text_query_extraction,
267 test_item.would_perform_search_term_replacement, 268 test_item.would_perform_search_term_replacement,
268 test_item.should_display_url); 269 test_item.should_display_url);
269 } 270 }
270 271
271 // Disabling URL replacement should reset to only showing URLs. 272 // Disabling URL replacement should reset to only showing URLs.
272 browser()->toolbar_model()->set_url_replacement_enabled(false); 273 browser()->toolbar_model()->set_url_replacement_enabled(false);
273 for (size_t i = 0; i < arraysize(test_items); ++i) { 274 for (size_t i = 0; i < arraysize(test_items); ++i) {
274 const TestItem& test_item = test_items[i]; 275 const TestItem& test_item = test_items[i];
275 NavigateAndCheckText(test_item.url, 276 NavigateAndCheckText(test_item.url,
276 test_item.expected_text_url_replacement_inactive, 277 test_item.expected_text_url_replacement_inactive,
277 false, test_item.should_display_url); 278 false, test_item.should_display_url);
278 } 279 }
279 } 280 }
280 281
281 // Verify that search terms are extracted while the page is loading. 282 // Verify that search terms are extracted while the page is loading.
282 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) { 283 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) {
283 chrome::EnableQueryExtractionForTesting(); 284 search::EnableQueryExtractionForTesting();
284 AddTab(browser(), GURL(url::kAboutBlankURL)); 285 AddTab(browser(), GURL(url::kAboutBlankURL));
285 286
286 // While loading, we should be willing to extract search terms. 287 // While loading, we should be willing to extract search terms.
287 content::NavigationController* controller = 288 content::NavigationController* controller =
288 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); 289 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
289 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"), 290 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"),
290 content::Referrer(), ui::PAGE_TRANSITION_LINK, 291 content::Referrer(), ui::PAGE_TRANSITION_LINK,
291 std::string()); 292 std::string());
292 ToolbarModel* toolbar_model = browser()->toolbar_model(); 293 ToolbarModel* toolbar_model = browser()->toolbar_model();
293 controller->GetVisibleEntry()->GetSSL().security_style = 294 controller->GetVisibleEntry()->GetSSL().security_style =
294 content::SECURITY_STYLE_UNKNOWN; 295 content::SECURITY_STYLE_UNKNOWN;
295 EXPECT_TRUE(toolbar_model->WouldPerformSearchTermReplacement(false)); 296 EXPECT_TRUE(toolbar_model->WouldPerformSearchTermReplacement(false));
296 297
297 // When done loading, we shouldn't extract search terms if we didn't get an 298 // When done loading, we shouldn't extract search terms if we didn't get an
298 // authenticated connection. 299 // authenticated connection.
299 CommitPendingLoad(controller); 300 CommitPendingLoad(controller);
300 controller->GetVisibleEntry()->GetSSL().security_style = 301 controller->GetVisibleEntry()->GetSSL().security_style =
301 content::SECURITY_STYLE_UNKNOWN; 302 content::SECURITY_STYLE_UNKNOWN;
302 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); 303 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false));
303 } 304 }
304 305
305 // When the Google base URL is overridden on the command line, we should extract 306 // When the Google base URL is overridden on the command line, we should extract
306 // search terms from URLs that start with that base URL even when they're not 307 // search terms from URLs that start with that base URL even when they're not
307 // secure. 308 // secure.
308 TEST_F(ToolbarModelTest, GoogleBaseURL) { 309 TEST_F(ToolbarModelTest, GoogleBaseURL) {
309 chrome::EnableQueryExtractionForTesting(); 310 search::EnableQueryExtractionForTesting();
310 AddTab(browser(), GURL(url::kAboutBlankURL)); 311 AddTab(browser(), GURL(url::kAboutBlankURL));
311 312
312 // If the Google base URL wasn't specified on the command line, then if it's 313 // If the Google base URL wasn't specified on the command line, then if it's
313 // HTTP, we should not extract search terms. 314 // HTTP, we should not extract search terms.
314 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); 315 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/");
315 NavigateAndCheckText( 316 NavigateAndCheckText(
316 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), 317 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"),
317 base::ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), false, 318 base::ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), false,
318 true); 319 true);
319 320
320 // The same URL, when specified on the command line, should allow search term 321 // The same URL, when specified on the command line, should allow search term
321 // extraction. 322 // extraction.
322 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); 323 UIThreadSearchTermsData::SetGoogleBaseURL(std::string());
323 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 324 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
324 switches::kGoogleBaseURL, "http://www.foo.com/"); 325 switches::kGoogleBaseURL, "http://www.foo.com/");
325 NavigateAndCheckText( 326 NavigateAndCheckText(
326 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), 327 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"),
327 base::ASCIIToUTF16("tractor supply"), true, true); 328 base::ASCIIToUTF16("tractor supply"), true, true);
328 } 329 }
329 330
330 // Test that URL display in a popup respects the query extraction flag. 331 // Test that URL display in a popup respects the query extraction flag.
331 TEST_F(PopupToolbarModelTest, ShouldDisplayURL) { 332 TEST_F(PopupToolbarModelTest, ShouldDisplayURL) {
332 AddTab(browser(), GURL(url::kAboutBlankURL)); 333 AddTab(browser(), GURL(url::kAboutBlankURL));
333 334
334 // Check with query extraction disabled. 335 // Check with query extraction disabled.
335 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()); 336 EXPECT_FALSE(search::IsQueryExtractionEnabled());
336 for (size_t i = 0; i < arraysize(test_items); ++i) { 337 for (size_t i = 0; i < arraysize(test_items); ++i) {
337 const TestItem& test_item = test_items[i]; 338 const TestItem& test_item = test_items[i];
338 NavigateAndCheckText(test_item.url, 339 NavigateAndCheckText(test_item.url,
339 test_item.expected_text_url_replacement_inactive, 340 test_item.expected_text_url_replacement_inactive,
340 false, test_item.should_display_url); 341 false, test_item.should_display_url);
341 } 342 }
342 343
343 // With query extraction enabled, search term replacement should be performed. 344 // With query extraction enabled, search term replacement should be performed.
344 chrome::EnableQueryExtractionForTesting(); 345 search::EnableQueryExtractionForTesting();
345 EXPECT_TRUE(chrome::IsQueryExtractionEnabled()); 346 EXPECT_TRUE(search::IsQueryExtractionEnabled());
346 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled()); 347 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled());
347 for (size_t i = 0; i < arraysize(test_items); ++i) { 348 for (size_t i = 0; i < arraysize(test_items); ++i) {
348 const TestItem& test_item = test_items[i]; 349 const TestItem& test_item = test_items[i];
349 NavigateAndCheckText(test_item.url, 350 NavigateAndCheckText(test_item.url,
350 test_item.expected_text_query_extraction, 351 test_item.expected_text_query_extraction,
351 test_item.would_perform_search_term_replacement, 352 test_item.would_perform_search_term_replacement,
352 test_item.should_display_url); 353 test_item.should_display_url);
353 } 354 }
354 355
355 // Disabling URL replacement should reset to only showing URLs. 356 // Disabling URL replacement should reset to only showing URLs.
356 browser()->toolbar_model()->set_url_replacement_enabled(false); 357 browser()->toolbar_model()->set_url_replacement_enabled(false);
357 for (size_t i = 0; i < arraysize(test_items); ++i) { 358 for (size_t i = 0; i < arraysize(test_items); ++i) {
358 const TestItem& test_item = test_items[i]; 359 const TestItem& test_item = test_items[i];
359 NavigateAndCheckText(test_item.url, 360 NavigateAndCheckText(test_item.url,
360 test_item.expected_text_url_replacement_inactive, 361 test_item.expected_text_url_replacement_inactive,
361 false, test_item.should_display_url); 362 false, test_item.should_display_url);
362 } 363 }
363 } 364 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_model_impl.cc ('k') | chrome/browser/ui/views/omnibox/omnibox_view_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698