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 "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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 }, | 58 }, |
59 { | 59 { |
60 GURL("chrome-extension://monkey/balls.html"), | 60 GURL("chrome-extension://monkey/balls.html"), |
61 base::ASCIIToUTF16("chrome-extension://monkey/balls.html"), | 61 base::ASCIIToUTF16("chrome-extension://monkey/balls.html"), |
62 base::ASCIIToUTF16("chrome-extension://monkey/balls.html"), | 62 base::ASCIIToUTF16("chrome-extension://monkey/balls.html"), |
63 base::string16(), | 63 base::string16(), |
64 false, | 64 false, |
65 true | 65 true |
66 }, | 66 }, |
67 { | 67 { |
68 GURL(content::kAboutBlankURL), | 68 GURL(url::kAboutBlankURL), |
69 base::ASCIIToUTF16(content::kAboutBlankURL), | 69 base::ASCIIToUTF16(url::kAboutBlankURL), |
70 base::ASCIIToUTF16(content::kAboutBlankURL), | 70 base::ASCIIToUTF16(url::kAboutBlankURL), |
71 base::string16(), | 71 base::string16(), |
72 false, | 72 false, |
73 true | 73 true |
74 }, | 74 }, |
75 { | 75 { |
76 GURL("http://searchurl/?q=tractor+supply"), | 76 GURL("http://searchurl/?q=tractor+supply"), |
77 base::ASCIIToUTF16("searchurl/?q=tractor+supply"), | 77 base::ASCIIToUTF16("searchurl/?q=tractor+supply"), |
78 base::ASCIIToUTF16("searchurl/?q=tractor+supply"), | 78 base::ASCIIToUTF16("searchurl/?q=tractor+supply"), |
79 base::string16(), | 79 base::string16(), |
80 false, | 80 false, |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 246 } |
247 | 247 |
248 PopupToolbarModelTest::~PopupToolbarModelTest() { | 248 PopupToolbarModelTest::~PopupToolbarModelTest() { |
249 } | 249 } |
250 | 250 |
251 // Actual tests --------------------------------------------------------------- | 251 // Actual tests --------------------------------------------------------------- |
252 | 252 |
253 // Test that we only replace URLs when query extraction and URL replacement | 253 // Test that we only replace URLs when query extraction and URL replacement |
254 // are enabled. | 254 // are enabled. |
255 TEST_F(ToolbarModelTest, ShouldDisplayURL_QueryExtraction) { | 255 TEST_F(ToolbarModelTest, ShouldDisplayURL_QueryExtraction) { |
256 AddTab(browser(), GURL(content::kAboutBlankURL)); | 256 AddTab(browser(), GURL(url::kAboutBlankURL)); |
257 | 257 |
258 // Before we enable instant extended, query extraction is disabled. | 258 // Before we enable instant extended, query extraction is disabled. |
259 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()) | 259 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()) |
260 << "This test expects query extraction to be disabled."; | 260 << "This test expects query extraction to be disabled."; |
261 for (size_t i = 0; i < arraysize(test_items); ++i) { | 261 for (size_t i = 0; i < arraysize(test_items); ++i) { |
262 const TestItem& test_item = test_items[i]; | 262 const TestItem& test_item = test_items[i]; |
263 NavigateAndCheckText(test_item.url, | 263 NavigateAndCheckText(test_item.url, |
264 test_item.expected_text_url_replacement_inactive, | 264 test_item.expected_text_url_replacement_inactive, |
265 false, test_item.should_display_url); | 265 false, test_item.should_display_url); |
266 } | 266 } |
(...skipping 16 matching lines...) Expand all Loading... |
283 NavigateAndCheckText(test_item.url, | 283 NavigateAndCheckText(test_item.url, |
284 test_item.expected_text_url_replacement_inactive, | 284 test_item.expected_text_url_replacement_inactive, |
285 false, test_item.should_display_url); | 285 false, test_item.should_display_url); |
286 } | 286 } |
287 } | 287 } |
288 | 288 |
289 // Test that we remove or replace URLs appropriately when the origin chip is | 289 // Test that we remove or replace URLs appropriately when the origin chip is |
290 // enabled. | 290 // enabled. |
291 TEST_F(ToolbarModelTest, ShouldDisplayURL_OriginChip) { | 291 TEST_F(ToolbarModelTest, ShouldDisplayURL_OriginChip) { |
292 EnableOriginChipFieldTrial(); | 292 EnableOriginChipFieldTrial(); |
293 AddTab(browser(), GURL(content::kAboutBlankURL)); | 293 AddTab(browser(), GURL(url::kAboutBlankURL)); |
294 | 294 |
295 // Check each case with the origin chip enabled but query extraction disabled. | 295 // Check each case with the origin chip enabled but query extraction disabled. |
296 EXPECT_TRUE(chrome::ShouldDisplayOriginChip()); | 296 EXPECT_TRUE(chrome::ShouldDisplayOriginChip()); |
297 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()); | 297 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()); |
298 for (size_t i = 0; i < arraysize(test_items); ++i) { | 298 for (size_t i = 0; i < arraysize(test_items); ++i) { |
299 const TestItem& test_item = test_items[i]; | 299 const TestItem& test_item = test_items[i]; |
300 NavigateAndCheckText(test_item.url, base::string16(), false, | 300 NavigateAndCheckText(test_item.url, base::string16(), false, |
301 test_item.should_display_url); | 301 test_item.should_display_url); |
302 } | 302 } |
303 | 303 |
(...skipping 14 matching lines...) Expand all Loading... |
318 const TestItem& test_item = test_items[i]; | 318 const TestItem& test_item = test_items[i]; |
319 NavigateAndCheckText(test_item.url, | 319 NavigateAndCheckText(test_item.url, |
320 test_item.expected_text_url_replacement_inactive, | 320 test_item.expected_text_url_replacement_inactive, |
321 false, test_item.should_display_url); | 321 false, test_item.should_display_url); |
322 } | 322 } |
323 } | 323 } |
324 | 324 |
325 // Verify that search terms are extracted while the page is loading. | 325 // Verify that search terms are extracted while the page is loading. |
326 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) { | 326 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) { |
327 chrome::EnableQueryExtractionForTesting(); | 327 chrome::EnableQueryExtractionForTesting(); |
328 AddTab(browser(), GURL(content::kAboutBlankURL)); | 328 AddTab(browser(), GURL(url::kAboutBlankURL)); |
329 | 329 |
330 // While loading, we should be willing to extract search terms. | 330 // While loading, we should be willing to extract search terms. |
331 content::NavigationController* controller = | 331 content::NavigationController* controller = |
332 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); | 332 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); |
333 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"), | 333 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"), |
334 content::Referrer(), content::PAGE_TRANSITION_LINK, | 334 content::Referrer(), content::PAGE_TRANSITION_LINK, |
335 std::string()); | 335 std::string()); |
336 ToolbarModel* toolbar_model = browser()->toolbar_model(); | 336 ToolbarModel* toolbar_model = browser()->toolbar_model(); |
337 controller->GetVisibleEntry()->GetSSL().security_style = | 337 controller->GetVisibleEntry()->GetSSL().security_style = |
338 content::SECURITY_STYLE_UNKNOWN; | 338 content::SECURITY_STYLE_UNKNOWN; |
339 EXPECT_TRUE(toolbar_model->WouldPerformSearchTermReplacement(false)); | 339 EXPECT_TRUE(toolbar_model->WouldPerformSearchTermReplacement(false)); |
340 | 340 |
341 // When done loading, we shouldn't extract search terms if we didn't get an | 341 // When done loading, we shouldn't extract search terms if we didn't get an |
342 // authenticated connection. | 342 // authenticated connection. |
343 CommitPendingLoad(controller); | 343 CommitPendingLoad(controller); |
344 controller->GetVisibleEntry()->GetSSL().security_style = | 344 controller->GetVisibleEntry()->GetSSL().security_style = |
345 content::SECURITY_STYLE_UNKNOWN; | 345 content::SECURITY_STYLE_UNKNOWN; |
346 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); | 346 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); |
347 } | 347 } |
348 | 348 |
349 // When the Google base URL is overridden on the command line, we should extract | 349 // When the Google base URL is overridden on the command line, we should extract |
350 // search terms from URLs that start with that base URL even when they're not | 350 // search terms from URLs that start with that base URL even when they're not |
351 // secure. | 351 // secure. |
352 TEST_F(ToolbarModelTest, GoogleBaseURL) { | 352 TEST_F(ToolbarModelTest, GoogleBaseURL) { |
353 chrome::EnableQueryExtractionForTesting(); | 353 chrome::EnableQueryExtractionForTesting(); |
354 AddTab(browser(), GURL(content::kAboutBlankURL)); | 354 AddTab(browser(), GURL(url::kAboutBlankURL)); |
355 | 355 |
356 // If the Google base URL wasn't specified on the command line, then if it's | 356 // If the Google base URL wasn't specified on the command line, then if it's |
357 // HTTP, we should not extract search terms. | 357 // HTTP, we should not extract search terms. |
358 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); | 358 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); |
359 NavigateAndCheckText( | 359 NavigateAndCheckText( |
360 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), | 360 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), |
361 base::ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), false, | 361 base::ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), false, |
362 true); | 362 true); |
363 | 363 |
364 // The same URL, when specified on the command line, should allow search term | 364 // The same URL, when specified on the command line, should allow search term |
365 // extraction. | 365 // extraction. |
366 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); | 366 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); |
367 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, | 367 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, |
368 "http://www.foo.com/"); | 368 "http://www.foo.com/"); |
369 NavigateAndCheckText( | 369 NavigateAndCheckText( |
370 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), | 370 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), |
371 base::ASCIIToUTF16("tractor supply"), true, true); | 371 base::ASCIIToUTF16("tractor supply"), true, true); |
372 } | 372 } |
373 | 373 |
374 // Popup windows don't have an origin chip, so test that URL display in a popup | 374 // Popup windows don't have an origin chip, so test that URL display in a popup |
375 // ignores whether the origin chip is enabled and only respects the query | 375 // ignores whether the origin chip is enabled and only respects the query |
376 // extraction flag. | 376 // extraction flag. |
377 TEST_F(PopupToolbarModelTest, ShouldDisplayURL) { | 377 TEST_F(PopupToolbarModelTest, ShouldDisplayURL) { |
378 AddTab(browser(), GURL(content::kAboutBlankURL)); | 378 AddTab(browser(), GURL(url::kAboutBlankURL)); |
379 | 379 |
380 // Check with neither query extraction nor the origin chip enabled. | 380 // Check with neither query extraction nor the origin chip enabled. |
381 EXPECT_FALSE(chrome::ShouldDisplayOriginChip()); | 381 EXPECT_FALSE(chrome::ShouldDisplayOriginChip()); |
382 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()); | 382 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()); |
383 for (size_t i = 0; i < arraysize(test_items); ++i) { | 383 for (size_t i = 0; i < arraysize(test_items); ++i) { |
384 const TestItem& test_item = test_items[i]; | 384 const TestItem& test_item = test_items[i]; |
385 NavigateAndCheckText(test_item.url, | 385 NavigateAndCheckText(test_item.url, |
386 test_item.expected_text_url_replacement_inactive, | 386 test_item.expected_text_url_replacement_inactive, |
387 false, test_item.should_display_url); | 387 false, test_item.should_display_url); |
388 } | 388 } |
(...skipping 24 matching lines...) Expand all Loading... |
413 | 413 |
414 // Disabling URL replacement should reset to only showing URLs. | 414 // Disabling URL replacement should reset to only showing URLs. |
415 browser()->toolbar_model()->set_url_replacement_enabled(false); | 415 browser()->toolbar_model()->set_url_replacement_enabled(false); |
416 for (size_t i = 0; i < arraysize(test_items); ++i) { | 416 for (size_t i = 0; i < arraysize(test_items); ++i) { |
417 const TestItem& test_item = test_items[i]; | 417 const TestItem& test_item = test_items[i]; |
418 NavigateAndCheckText(test_item.url, | 418 NavigateAndCheckText(test_item.url, |
419 test_item.expected_text_url_replacement_inactive, | 419 test_item.expected_text_url_replacement_inactive, |
420 false, test_item.should_display_url); | 420 false, test_item.should_display_url); |
421 } | 421 } |
422 } | 422 } |
OLD | NEW |