| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/google/google_url_tracker.h" | 7 #include "chrome/browser/google/google_url_tracker.h" |
| 8 #include "chrome/browser/google/google_util.h" | 8 #include "chrome/browser/google/google_util.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 EXPECT_TRUE(IsGoogleDomainUrl("http://test.foo.com:1234", | 369 EXPECT_TRUE(IsGoogleDomainUrl("http://test.foo.com:1234", |
| 370 google_util::DISALLOW_SUBDOMAIN, | 370 google_util::DISALLOW_SUBDOMAIN, |
| 371 google_util::DISALLOW_NON_STANDARD_PORTS)); | 371 google_util::DISALLOW_NON_STANDARD_PORTS)); |
| 372 EXPECT_FALSE(IsGoogleDomainUrl("file://test.foo.com:1234", | 372 EXPECT_FALSE(IsGoogleDomainUrl("file://test.foo.com:1234", |
| 373 google_util::DISALLOW_SUBDOMAIN, | 373 google_util::DISALLOW_SUBDOMAIN, |
| 374 google_util::DISALLOW_NON_STANDARD_PORTS)); | 374 google_util::DISALLOW_NON_STANDARD_PORTS)); |
| 375 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com", | 375 EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com", |
| 376 google_util::DISALLOW_SUBDOMAIN, | 376 google_util::DISALLOW_SUBDOMAIN, |
| 377 google_util::DISALLOW_NON_STANDARD_PORTS)); | 377 google_util::DISALLOW_NON_STANDARD_PORTS)); |
| 378 } | 378 } |
| 379 | |
| 380 TEST(GoogleUtilTest, SearchTerms) { | |
| 381 // Simple searches. | |
| 382 EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( | |
| 383 "http://google.com/search?q=tractor+supply")); | |
| 384 EXPECT_EQ(ASCIIToUTF16("tractor supply"), | |
| 385 google_util::GetSearchTermsFromGoogleSearchURL( | |
| 386 "http://google.com/search?q=tractor+supply&espv=1")); | |
| 387 // espv=1 only applies in query. | |
| 388 EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( | |
| 389 "http://google.com/search?q=potato#espv=1")); | |
| 390 | |
| 391 // Instant searches. | |
| 392 EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( | |
| 393 "http://google.com/webhp#q=tractor+supply")); | |
| 394 EXPECT_EQ(ASCIIToUTF16("tractor supply"), | |
| 395 google_util::GetSearchTermsFromGoogleSearchURL( | |
| 396 "http://google.com/webhp?espv=1#q=tractor+supply")); | |
| 397 // espv=1 only applies in query. | |
| 398 EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( | |
| 399 "http://google.com/webhp?#espv=1&q=potato")); | |
| 400 | |
| 401 // Both query and ref components have a search term. | |
| 402 EXPECT_EQ(ASCIIToUTF16("tractor supply"), | |
| 403 google_util::GetSearchTermsFromGoogleSearchURL( | |
| 404 "http://google.com/webhp?q=potato&espv=1#q=tractor+supply")); | |
| 405 | |
| 406 // Blank queries. | |
| 407 EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( | |
| 408 "http://google.com/search?q=&q=potato&espv=1")); | |
| 409 EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( | |
| 410 "http://google.com/webhp?espv=1#q=&q=tractor+supply")); | |
| 411 | |
| 412 // Multiple non-empty queries. | |
| 413 EXPECT_EQ(ASCIIToUTF16("tractor supply"), | |
| 414 google_util::GetSearchTermsFromGoogleSearchURL( | |
| 415 "http://google.com/search?q=tractor+supply&q=potato&espv=1")); | |
| 416 EXPECT_EQ(ASCIIToUTF16("tractor supply"), | |
| 417 google_util::GetSearchTermsFromGoogleSearchURL( | |
| 418 "http://google.com/webhp?espv=1#q=tractor+supply&q=potato")); | |
| 419 | |
| 420 // Blank terms in ref override non-blank terms in query. | |
| 421 EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( | |
| 422 "http://google.com/search?q=potato&espv=1#q=")); | |
| 423 | |
| 424 // Blank terms in query do not override non-blank terms in ref. | |
| 425 EXPECT_EQ(ASCIIToUTF16("tractor supply"), | |
| 426 google_util::GetSearchTermsFromGoogleSearchURL( | |
| 427 "http://google.com/search?q=&espv=1#q=tractor+supply")); | |
| 428 } | |
| OLD | NEW |