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

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

Issue 2806593006: Changed GenerateKeyword to always return keyword in lowercase (Closed)
Patch Set: 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
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(base::string16 str) {
Peter Kasting 2017/04/18 18:46:20 Nit: const &
Alexander Yashkin 2017/04/20 07:05:53 Done.
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 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 TemplateURL::GenerateKeyword(GURL("http://www.foo"))); 1734 TemplateURL::GenerateKeyword(GURL("http://www.foo")));
1728 // Make sure we don't get a trailing '/'. 1735 // Make sure we don't get a trailing '/'.
1729 ASSERT_EQ(ASCIIToUTF16("blah"), 1736 ASSERT_EQ(ASCIIToUTF16("blah"),
1730 TemplateURL::GenerateKeyword(GURL("http://blah/"))); 1737 TemplateURL::GenerateKeyword(GURL("http://blah/")));
1731 // Don't generate the empty string. 1738 // Don't generate the empty string.
1732 ASSERT_EQ(ASCIIToUTF16("www"), 1739 ASSERT_EQ(ASCIIToUTF16("www"),
1733 TemplateURL::GenerateKeyword(GURL("http://www."))); 1740 TemplateURL::GenerateKeyword(GURL("http://www.")));
1734 ASSERT_EQ( 1741 ASSERT_EQ(
1735 base::UTF8ToUTF16("\xd0\xb0\xd0\xb1\xd0\xb2"), 1742 base::UTF8ToUTF16("\xd0\xb0\xd0\xb1\xd0\xb2"),
1736 TemplateURL::GenerateKeyword(GURL("http://xn--80acd"))); 1743 TemplateURL::GenerateKeyword(GURL("http://xn--80acd")));
1744
1745 // Generated keywords must always be in lowercase, because TemplateURLs always
1746 // converts keywords to lowercase in its constructor and TemplateURLService
1747 // stores TemplateURLs in maps using keyword as key.
1748 ASSERT_TRUE(IsLowerCase(TemplateURL::GenerateKeyword(GURL("http://BLAH/"))));
1749 ASSERT_TRUE(IsLowerCase(
Peter Kasting 2017/04/18 18:46:20 Nit: I think every ASSERT in this test could be EX
Alexander Yashkin 2017/04/20 07:05:53 Done
1750 TemplateURL::GenerateKeyword(GURL("http://embeddedhtml.<head>/"))));
1737 } 1751 }
1738 1752
1739 TEST_F(TemplateURLTest, GenerateSearchURL) { 1753 TEST_F(TemplateURLTest, GenerateSearchURL) {
1740 struct GenerateSearchURLCase { 1754 struct GenerateSearchURLCase {
1741 const char* test_name; 1755 const char* test_name;
1742 const char* url; 1756 const char* url;
1743 const char* expected; 1757 const char* expected;
1744 } generate_url_cases[] = { 1758 } generate_url_cases[] = {
1745 { "invalid URL", "foo{searchTerms}", "" }, 1759 { "invalid URL", "foo{searchTerms}", "" },
1746 { "URL with no replacements", "http://foo/", "http://foo/" }, 1760 { "URL with no replacements", "http://foo/", "http://foo/" },
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 EXPECT_EQ(google_util::kInstantExtendedAPIParam, 1917 EXPECT_EQ(google_util::kInstantExtendedAPIParam,
1904 turl.search_terms_replacement_key()); 1918 turl.search_terms_replacement_key());
1905 // Expect that replacement of {google:instantExtendedEnabledKey} in search url 1919 // Expect that replacement of {google:instantExtendedEnabledKey} in search url
1906 // is correct. 1920 // is correct.
1907 GURL search_generated = turl.GenerateSearchURL(search_terms_data_); 1921 GURL search_generated = turl.GenerateSearchURL(search_terms_data_);
1908 EXPECT_TRUE(turl.HasSearchTermsReplacementKey(search_generated)); 1922 EXPECT_TRUE(turl.HasSearchTermsReplacementKey(search_generated));
1909 net::QueryIterator it(search_generated); 1923 net::QueryIterator it(search_generated);
1910 ASSERT_FALSE(it.IsAtEnd()); 1924 ASSERT_FALSE(it.IsAtEnd());
1911 EXPECT_EQ(google_util::kInstantExtendedAPIParam, it.GetKey()); 1925 EXPECT_EQ(google_util::kInstantExtendedAPIParam, it.GetKey());
1912 } 1926 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698