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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()) | 251 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()) |
252 << "This test expects query extraction to be disabled."; | 252 << "This test expects query extraction to be disabled."; |
253 AddTab(browser(), GURL(content::kAboutBlankURL)); | 253 AddTab(browser(), GURL(content::kAboutBlankURL)); |
254 for (size_t i = 0; i < arraysize(test_items); ++i) { | 254 for (size_t i = 0; i < arraysize(test_items); ++i) { |
255 const TestItem& test_item = test_items[i]; | 255 const TestItem& test_item = test_items[i]; |
256 NavigateAndCheckText(test_item.url, test_item.expected_text, | 256 NavigateAndCheckText(test_item.url, test_item.expected_text, |
257 test_item.expected_replace_text_inactive, false, | 257 test_item.expected_replace_text_inactive, false, |
258 test_item.should_display_url); | 258 test_item.should_display_url); |
259 } | 259 } |
260 | 260 |
261 // Once we enable it, query extraction and search term replacement are | 261 chrome::EnableQueryExtractionForTesting(); |
262 // enabled by default. | |
263 chrome::EnableInstantExtendedAPIForTesting(); | |
264 EXPECT_TRUE(chrome::IsQueryExtractionEnabled()); | 262 EXPECT_TRUE(chrome::IsQueryExtractionEnabled()); |
265 EXPECT_TRUE(browser()->toolbar_model()->search_term_replacement_enabled()); | 263 EXPECT_TRUE(browser()->toolbar_model()->search_term_replacement_enabled()); |
266 for (size_t i = 0; i < arraysize(test_items); ++i) { | 264 for (size_t i = 0; i < arraysize(test_items); ++i) { |
267 const TestItem& test_item = test_items[i]; | 265 const TestItem& test_item = test_items[i]; |
268 NavigateAndCheckText(test_item.url, test_item.expected_text, | 266 NavigateAndCheckText(test_item.url, test_item.expected_text, |
269 test_item.expected_replace_text_active, | 267 test_item.expected_replace_text_active, |
270 test_item.would_perform_search_term_replacement, | 268 test_item.would_perform_search_term_replacement, |
271 test_item.should_display_url); | 269 test_item.should_display_url); |
272 } | 270 } |
273 | 271 |
274 // Disabling search term replacement should reset to only showing URLs. | 272 // Disabling search term replacement should reset to only showing URLs. |
275 browser()->toolbar_model()->set_search_term_replacement_enabled(false); | 273 browser()->toolbar_model()->set_search_term_replacement_enabled(false); |
276 for (size_t i = 0; i < arraysize(test_items); ++i) { | 274 for (size_t i = 0; i < arraysize(test_items); ++i) { |
277 const TestItem& test_item = test_items[i]; | 275 const TestItem& test_item = test_items[i]; |
278 NavigateAndCheckText(test_item.url, test_item.expected_text, | 276 NavigateAndCheckText(test_item.url, test_item.expected_text, |
279 test_item.expected_replace_text_inactive, false, | 277 test_item.expected_replace_text_inactive, false, |
280 test_item.should_display_url); | 278 test_item.should_display_url); |
281 } | 279 } |
282 } | 280 } |
283 | 281 |
284 // Verify that search terms are extracted while the page is loading. | 282 // Verify that search terms are extracted while the page is loading. |
285 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) { | 283 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) { |
286 chrome::EnableInstantExtendedAPIForTesting(); | 284 chrome::EnableQueryExtractionForTesting(); |
287 AddTab(browser(), GURL(content::kAboutBlankURL)); | 285 AddTab(browser(), GURL(content::kAboutBlankURL)); |
288 | 286 |
289 // While loading, we should be willing to extract search terms. | 287 // While loading, we should be willing to extract search terms. |
290 content::NavigationController* controller = | 288 content::NavigationController* controller = |
291 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); | 289 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); |
292 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"), |
293 content::Referrer(), content::PAGE_TRANSITION_LINK, | 291 content::Referrer(), content::PAGE_TRANSITION_LINK, |
294 std::string()); | 292 std::string()); |
295 ToolbarModel* toolbar_model = browser()->toolbar_model(); | 293 ToolbarModel* toolbar_model = browser()->toolbar_model(); |
296 controller->GetVisibleEntry()->GetSSL().security_style = | 294 controller->GetVisibleEntry()->GetSSL().security_style = |
297 content::SECURITY_STYLE_UNKNOWN; | 295 content::SECURITY_STYLE_UNKNOWN; |
298 EXPECT_TRUE(toolbar_model->WouldPerformSearchTermReplacement(false)); | 296 EXPECT_TRUE(toolbar_model->WouldPerformSearchTermReplacement(false)); |
299 | 297 |
300 // 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 |
301 // authenticated connection. | 299 // authenticated connection. |
302 CommitPendingLoad(controller); | 300 CommitPendingLoad(controller); |
303 controller->GetVisibleEntry()->GetSSL().security_style = | 301 controller->GetVisibleEntry()->GetSSL().security_style = |
304 content::SECURITY_STYLE_UNKNOWN; | 302 content::SECURITY_STYLE_UNKNOWN; |
305 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); | 303 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); |
306 } | 304 } |
307 | 305 |
308 // 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 |
309 // 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 |
310 // secure. | 308 // secure. |
311 TEST_F(ToolbarModelTest, GoogleBaseURL) { | 309 TEST_F(ToolbarModelTest, GoogleBaseURL) { |
312 chrome::EnableInstantExtendedAPIForTesting(); | 310 chrome::EnableQueryExtractionForTesting(); |
313 AddTab(browser(), GURL(content::kAboutBlankURL)); | 311 AddTab(browser(), GURL(content::kAboutBlankURL)); |
314 | 312 |
315 // 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 |
316 // HTTP, we should not extract search terms. | 314 // HTTP, we should not extract search terms. |
317 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); | 315 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); |
318 NavigateAndCheckText( | 316 NavigateAndCheckText( |
319 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), | 317 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), |
320 ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), | 318 ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), |
321 ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), false, | 319 ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), false, |
322 true); | 320 true); |
323 | 321 |
324 // The same URL, when specified on the command line, should allow search term | 322 // The same URL, when specified on the command line, should allow search term |
325 // extraction. | 323 // extraction. |
326 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); | 324 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); |
327 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, | 325 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, |
328 "http://www.foo.com/"); | 326 "http://www.foo.com/"); |
329 NavigateAndCheckText( | 327 NavigateAndCheckText( |
330 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), | 328 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), |
331 ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), | 329 ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), |
332 ASCIIToUTF16("tractor supply"), true, true); | 330 ASCIIToUTF16("tractor supply"), true, true); |
333 } | 331 } |
OLD | NEW |