| 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> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 toolbar_model->WouldReplaceSearchURLWithSearchTerms()); | 249 toolbar_model->WouldReplaceSearchURLWithSearchTerms()); |
| 250 } | 250 } |
| 251 | 251 |
| 252 | 252 |
| 253 // Actual tests --------------------------------------------------------------- | 253 // Actual tests --------------------------------------------------------------- |
| 254 | 254 |
| 255 // Test that we don't replace any URLs when the query extraction is disabled. | 255 // Test that we don't replace any URLs when the query extraction is disabled. |
| 256 TEST_F(ToolbarModelTest, ShouldDisplayURLQueryExtractionDisabled) { | 256 TEST_F(ToolbarModelTest, ShouldDisplayURLQueryExtractionDisabled) { |
| 257 ASSERT_FALSE(chrome::IsQueryExtractionEnabled()) | 257 ASSERT_FALSE(chrome::IsQueryExtractionEnabled()) |
| 258 << "This test expects query extraction to be disabled."; | 258 << "This test expects query extraction to be disabled."; |
| 259 ResetDefaultTemplateURL(); | |
| 260 AddTab(browser(), GURL(content::kAboutBlankURL)); | 259 AddTab(browser(), GURL(content::kAboutBlankURL)); |
| 261 for (size_t i = 0; i < arraysize(test_items); ++i) { | 260 for (size_t i = 0; i < arraysize(test_items); ++i) { |
| 262 const TestItem& test_item = test_items[i]; | 261 const TestItem& test_item = test_items[i]; |
| 263 NavigateAndCheckText(test_item.url, | 262 NavigateAndCheckText(test_item.url, test_item.expected_text, |
| 264 test_item.expected_text, | 263 test_item.expected_replace_text_inactive, false, |
| 265 test_item.expected_replace_text_inactive, | |
| 266 false, | |
| 267 test_item.should_display); | 264 test_item.should_display); |
| 268 } | 265 } |
| 269 } | 266 } |
| 270 | 267 |
| 271 // Test that we replace URLs when the query extraction API is enabled. | 268 // Test that we replace URLs when the query extraction API is enabled. |
| 272 TEST_F(ToolbarModelTest, ShouldDisplayURLQueryExtractionEnabled) { | 269 TEST_F(ToolbarModelTest, ShouldDisplayURLQueryExtractionEnabled) { |
| 273 chrome::EnableInstantExtendedAPIForTesting(); | 270 chrome::EnableInstantExtendedAPIForTesting(); |
| 274 ResetDefaultTemplateURL(); | |
| 275 AddTab(browser(), GURL(content::kAboutBlankURL)); | 271 AddTab(browser(), GURL(content::kAboutBlankURL)); |
| 276 for (size_t i = 0; i < arraysize(test_items); ++i) { | 272 for (size_t i = 0; i < arraysize(test_items); ++i) { |
| 277 const TestItem& test_item = test_items[i]; | 273 const TestItem& test_item = test_items[i]; |
| 278 NavigateAndCheckText(test_item.url, | 274 NavigateAndCheckText(test_item.url, test_item.expected_text, |
| 279 test_item.expected_text, | |
| 280 test_item.expected_replace_text_active, | 275 test_item.expected_replace_text_active, |
| 281 test_item.would_replace, | 276 test_item.would_replace, test_item.should_display); |
| 282 test_item.should_display); | |
| 283 } | 277 } |
| 284 } | 278 } |
| 285 | 279 |
| 286 // Verify that search terms are extracted while the page is loading. | 280 // Verify that search terms are extracted while the page is loading. |
| 287 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) { | 281 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) { |
| 288 chrome::EnableInstantExtendedAPIForTesting(); | 282 chrome::EnableInstantExtendedAPIForTesting(); |
| 289 ResetDefaultTemplateURL(); | 283 ResetDefaultTemplateURL(); |
| 290 AddTab(browser(), GURL(content::kAboutBlankURL)); | 284 AddTab(browser(), GURL(content::kAboutBlankURL)); |
| 291 | 285 |
| 292 // While loading, we should be willing to extract search terms. | 286 // While loading, we should be willing to extract search terms. |
| 293 content::NavigationController* controller = | 287 content::NavigationController* controller = |
| 294 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); | 288 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); |
| 295 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"), |
| 296 content::Referrer(), content::PAGE_TRANSITION_LINK, | 290 content::Referrer(), content::PAGE_TRANSITION_LINK, |
| 297 std::string()); | 291 std::string()); |
| 298 ToolbarModel* toolbar_model = browser()->toolbar_model(); | 292 ToolbarModel* toolbar_model = browser()->toolbar_model(); |
| 299 controller->GetVisibleEntry()->GetSSL().security_style = | 293 controller->GetVisibleEntry()->GetSSL().security_style = |
| 300 content::SECURITY_STYLE_UNKNOWN; | 294 content::SECURITY_STYLE_UNKNOWN; |
| 301 EXPECT_TRUE(toolbar_model->WouldReplaceSearchURLWithSearchTerms()); | 295 EXPECT_TRUE(toolbar_model->WouldReplaceSearchURLWithSearchTerms()); |
| 302 | 296 |
| 303 // When done loading, we shouldn't extract search terms if we didn't get an | 297 // When done loading, we shouldn't extract search terms if we didn't get an |
| 304 // authenticated connection. | 298 // authenticated connection. |
| 305 CommitPendingLoad(controller); | 299 CommitPendingLoad(controller); |
| 306 controller->GetVisibleEntry()->GetSSL().security_style = | 300 controller->GetVisibleEntry()->GetSSL().security_style = |
| 307 content::SECURITY_STYLE_UNKNOWN; | 301 content::SECURITY_STYLE_UNKNOWN; |
| 308 EXPECT_FALSE(toolbar_model->WouldReplaceSearchURLWithSearchTerms()); | 302 EXPECT_FALSE(toolbar_model->WouldReplaceSearchURLWithSearchTerms()); |
| 309 } | 303 } |
| OLD | NEW |