Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: components/search_engines/template_url_unittest.cc

Issue 2806593006: Changed GenerateKeyword to always return keyword in lowercase (Closed)
Patch Set: Fixed after review, round 1 Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/search_engines/template_url.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/i18n/case_conversion.h"
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "components/google/core/browser/google_util.h" 14 #include "components/google/core/browser/google_util.h"
14 #include "components/metrics/proto/omnibox_event.pb.h" 15 #include "components/metrics/proto/omnibox_event.pb.h"
15 #include "components/metrics/proto/omnibox_input_type.pb.h" 16 #include "components/metrics/proto/omnibox_input_type.pb.h"
16 #include "components/search_engines/search_engines_switches.h" 17 #include "components/search_engines/search_engines_switches.h"
17 #include "components/search_engines/search_terms_data.h" 18 #include "components/search_engines/search_terms_data.h"
18 #include "components/search_engines/template_url.h" 19 #include "components/search_engines/template_url.h"
19 #include "components/search_engines/testing_search_terms_data.h" 20 #include "components/search_engines/testing_search_terms_data.h"
20 #include "net/base/url_util.h" 21 #include "net/base/url_util.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 using base::ASCIIToUTF16; 24 using base::ASCIIToUTF16;
24 25
26 namespace {
27 bool IsLowerCase(const base::string16& str) {
28 return str == base::i18n::ToLower(str);
29 }
30 }
31
25 class TemplateURLTest : public testing::Test { 32 class TemplateURLTest : public testing::Test {
26 public: 33 public:
27 TemplateURLTest() : search_terms_data_("http://www.google.com/") {} 34 TemplateURLTest() : search_terms_data_("http://www.google.com/") {}
28 void CheckSuggestBaseURL(const std::string& base_url, 35 void CheckSuggestBaseURL(const std::string& base_url,
29 const std::string& base_suggest_url) const; 36 const std::string& base_suggest_url) const;
30 37
31 static void ExpectPostParamIs( 38 static void ExpectPostParamIs(
32 const TemplateURLRef::PostParam& param, 39 const TemplateURLRef::PostParam& param,
33 const std::string& name, 40 const std::string& name,
34 const std::string& value, 41 const std::string& value,
(...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 TemplateURL::GenerateKeyword(GURL("http://www.foo"))); 1742 TemplateURL::GenerateKeyword(GURL("http://www.foo")));
1736 // Make sure we don't get a trailing '/'. 1743 // Make sure we don't get a trailing '/'.
1737 ASSERT_EQ(ASCIIToUTF16("blah"), 1744 ASSERT_EQ(ASCIIToUTF16("blah"),
1738 TemplateURL::GenerateKeyword(GURL("http://blah/"))); 1745 TemplateURL::GenerateKeyword(GURL("http://blah/")));
1739 // Don't generate the empty string. 1746 // Don't generate the empty string.
1740 ASSERT_EQ(ASCIIToUTF16("www"), 1747 ASSERT_EQ(ASCIIToUTF16("www"),
1741 TemplateURL::GenerateKeyword(GURL("http://www."))); 1748 TemplateURL::GenerateKeyword(GURL("http://www.")));
1742 ASSERT_EQ( 1749 ASSERT_EQ(
1743 base::UTF8ToUTF16("\xd0\xb0\xd0\xb1\xd0\xb2"), 1750 base::UTF8ToUTF16("\xd0\xb0\xd0\xb1\xd0\xb2"),
1744 TemplateURL::GenerateKeyword(GURL("http://xn--80acd"))); 1751 TemplateURL::GenerateKeyword(GURL("http://xn--80acd")));
1752
1753 // Generated keywords must always be in lowercase, because TemplateURLs always
1754 // converts keywords to lowercase in its constructor and TemplateURLService
1755 // stores TemplateURLs in maps using keyword as key.
1756 EXPECT_TRUE(IsLowerCase(TemplateURL::GenerateKeyword(GURL("http://BLAH/"))));
1757 EXPECT_TRUE(IsLowerCase(
1758 TemplateURL::GenerateKeyword(GURL("http://embeddedhtml.<head>/"))));
1745 } 1759 }
1746 1760
1747 TEST_F(TemplateURLTest, GenerateSearchURL) { 1761 TEST_F(TemplateURLTest, GenerateSearchURL) {
1748 struct GenerateSearchURLCase { 1762 struct GenerateSearchURLCase {
1749 const char* test_name; 1763 const char* test_name;
1750 const char* url; 1764 const char* url;
1751 const char* expected; 1765 const char* expected;
1752 } generate_url_cases[] = { 1766 } generate_url_cases[] = {
1753 { "invalid URL", "foo{searchTerms}", "" }, 1767 { "invalid URL", "foo{searchTerms}", "" },
1754 { "URL with no replacements", "http://foo/", "http://foo/" }, 1768 { "URL with no replacements", "http://foo/", "http://foo/" },
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 EXPECT_EQ(google_util::kInstantExtendedAPIParam, 1925 EXPECT_EQ(google_util::kInstantExtendedAPIParam,
1912 turl.search_terms_replacement_key()); 1926 turl.search_terms_replacement_key());
1913 // Expect that replacement of {google:instantExtendedEnabledKey} in search url 1927 // Expect that replacement of {google:instantExtendedEnabledKey} in search url
1914 // is correct. 1928 // is correct.
1915 GURL search_generated = turl.GenerateSearchURL(search_terms_data_); 1929 GURL search_generated = turl.GenerateSearchURL(search_terms_data_);
1916 EXPECT_TRUE(turl.HasSearchTermsReplacementKey(search_generated)); 1930 EXPECT_TRUE(turl.HasSearchTermsReplacementKey(search_generated));
1917 net::QueryIterator it(search_generated); 1931 net::QueryIterator it(search_generated);
1918 ASSERT_FALSE(it.IsAtEnd()); 1932 ASSERT_FALSE(it.IsAtEnd());
1919 EXPECT_EQ(google_util::kInstantExtendedAPIParam, it.GetKey()); 1933 EXPECT_EQ(google_util::kInstantExtendedAPIParam, it.GetKey());
1920 } 1934 }
OLDNEW
« no previous file with comments | « components/search_engines/template_url.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698