diff options
author | dominich@chromium.org <dominich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-28 23:15:16 +0000 |
---|---|---|
committer | dominich@chromium.org <dominich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-28 23:15:16 +0000 |
commit | fdb6a864c836d7fb4cdd7af49af91e0620fc658b (patch) | |
tree | aa4a88905d79145c7163a2be160dc8f146f567dd /chrome/browser/google/google_util_unittest.cc | |
parent | 22d1968749e74b0e46bae393ad8812251b28c9a9 (diff) | |
download | chromium_src-fdb6a864c836d7fb4cdd7af49af91e0620fc658b.zip chromium_src-fdb6a864c836d7fb4cdd7af49af91e0620fc658b.tar.gz chromium_src-fdb6a864c836d7fb4cdd7af49af91e0620fc658b.tar.bz2 |
Add support for Google Instant search URL search term extraction.
Also add some unit tests.
BUG=135106
R=sreeram@chromium.org,isherman@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10883068
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153773 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/google/google_util_unittest.cc')
-rw-r--r-- | chrome/browser/google/google_util_unittest.cc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/chrome/browser/google/google_util_unittest.cc b/chrome/browser/google/google_util_unittest.cc index aab1c6e..d0d5280 100644 --- a/chrome/browser/google/google_util_unittest.cc +++ b/chrome/browser/google/google_util_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/utf_string_conversions.h" #include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/google/google_util.h" #include "testing/gtest/include/gtest/gtest.h" @@ -320,3 +321,53 @@ TEST(GoogleUtilTest, GoogleDomains) { EXPECT_FALSE(IsGoogleDomainUrl("doesnotexist://www.google.com", google_util::DISALLOW_SUBDOMAIN)); } + +TEST(GoogleUtilTest, SearchTerms) { + // Simple searches. + EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( + "http://google.com/search?q=tractor+supply")); + EXPECT_EQ(ASCIIToUTF16("tractor supply"), + google_util::GetSearchTermsFromGoogleSearchURL( + "http://google.com/search?q=tractor+supply&espv=1")); + // espv=1 only applies in query. + EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( + "http://google.com/search?q=potato#espv=1")); + + // Instant searches. + EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( + "http://google.com/webhp#q=tractor+supply")); + EXPECT_EQ(ASCIIToUTF16("tractor supply"), + google_util::GetSearchTermsFromGoogleSearchURL( + "http://google.com/webhp?espv=1#q=tractor+supply")); + // espv=1 only applies in query. + EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( + "http://google.com/webhp?#espv=1&q=potato")); + + // Both query and ref components have a search term. + EXPECT_EQ(ASCIIToUTF16("tractor supply"), + google_util::GetSearchTermsFromGoogleSearchURL( + "http://google.com/webhp?q=potato&espv=1#q=tractor+supply")); + + // Blank queries. + EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( + "http://google.com/search?q=&q=potato&espv=1")); + EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( + "http://google.com/webhp?espv=1#q=&q=tractor+supply")); + + // Multiple non-empty queries. + EXPECT_EQ(ASCIIToUTF16("tractor supply"), + google_util::GetSearchTermsFromGoogleSearchURL( + "http://google.com/search?q=tractor+supply&q=potato&espv=1")); + EXPECT_EQ(ASCIIToUTF16("tractor supply"), + google_util::GetSearchTermsFromGoogleSearchURL( + "http://google.com/webhp?espv=1#q=tractor+supply&q=potato")); + + // Blank terms in ref override non-blank terms in query. + EXPECT_EQ(string16(), google_util::GetSearchTermsFromGoogleSearchURL( + "http://google.com/search?q=potato&espv=1#q=")); + + // Blank terms in query do not override non-blank terms in ref. + EXPECT_EQ(ASCIIToUTF16("tractor supply"), + google_util::GetSearchTermsFromGoogleSearchURL( + "http://google.com/search?q=&espv=1#q=tractor+supply")); +} |