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

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

Issue 2659353002: Fix TemplateUrl::MatchesData comparison of search_terms_replacement_key (reland) (Closed)
Patch Set: Fixed deps Created 3 years, 10 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_service.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/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "components/google/core/browser/google_util.h"
13 #include "components/metrics/proto/omnibox_event.pb.h" 14 #include "components/metrics/proto/omnibox_event.pb.h"
14 #include "components/metrics/proto/omnibox_input_type.pb.h" 15 #include "components/metrics/proto/omnibox_input_type.pb.h"
15 #include "components/search_engines/search_engines_switches.h" 16 #include "components/search_engines/search_engines_switches.h"
16 #include "components/search_engines/search_terms_data.h" 17 #include "components/search_engines/search_terms_data.h"
17 #include "components/search_engines/template_url.h" 18 #include "components/search_engines/template_url.h"
18 #include "components/search_engines/testing_search_terms_data.h" 19 #include "components/search_engines/testing_search_terms_data.h"
20 #include "net/base/url_util.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 22
21 using base::ASCIIToUTF16; 23 using base::ASCIIToUTF16;
22 24
23 class TemplateURLTest : public testing::Test { 25 class TemplateURLTest : public testing::Test {
24 public: 26 public:
25 TemplateURLTest() : search_terms_data_("http://www.google.com/") {} 27 TemplateURLTest() : search_terms_data_("http://www.google.com/") {}
26 void CheckSuggestBaseURL(const std::string& base_url, 28 void CheckSuggestBaseURL(const std::string& base_url,
27 const std::string& base_suggest_url) const; 29 const std::string& base_suggest_url) const;
28 30
(...skipping 1832 matching lines...) Expand 10 before | Expand all | Expand 10 after
1861 GURL("https://www.foo.org/search?q=Y+Z"), 1863 GURL("https://www.foo.org/search?q=Y+Z"),
1862 search_terms_data_, &search_terms)); 1864 search_terms_data_, &search_terms));
1863 EXPECT_EQ(base::ASCIIToUTF16("Y Z"), search_terms); 1865 EXPECT_EQ(base::ASCIIToUTF16("Y Z"), search_terms);
1864 EXPECT_TRUE(url.ExtractSearchTermsFromURL( 1866 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
1865 GURL("https://www.foo.org/s#q=123"), 1867 GURL("https://www.foo.org/s#q=123"),
1866 search_terms_data_, &search_terms)); 1868 search_terms_data_, &search_terms));
1867 EXPECT_EQ(base::ASCIIToUTF16("123"), search_terms); 1869 EXPECT_EQ(base::ASCIIToUTF16("123"), search_terms);
1868 1870
1869 search_terms_data_.set_google_base_url("http://www.google.com/"); 1871 search_terms_data_.set_google_base_url("http://www.google.com/");
1870 } 1872 }
1873
1874 // search_terms_replacement_key param of TemplateURLData with value of
1875 // "{google:instantExtendedEnabledKey}" is replaced inside TemplateUrl
1876 // constructor so must be handled specially inside MatchesData.
1877 // Test that TemplateURL object created with such param matches correctly its
1878 // TemplateURLData.
1879 TEST_F(TemplateURLTest, MatchesData) {
1880 TemplateURLData data;
1881 data.search_terms_replacement_key =
1882 google_util::kGoogleInstantExtendedEnabledKeyFull;
1883 TemplateURL url(data);
1884 EXPECT_NE(google_util::kGoogleInstantExtendedEnabledKeyFull,
1885 url.search_terms_replacement_key());
1886 EXPECT_TRUE(TemplateURL::MatchesData(&url, &data, search_terms_data_));
1887 }
1888
1889 // Test for correct replacement of GoogleInstantExtendedEnabledKey param.
1890 TEST_F(TemplateURLTest, GoogleInstantExtendedEnabledReplacement) {
1891 TemplateURLData data;
1892 data.SetURL(std::string("https://www.google.com?") +
1893 google_util::kGoogleInstantExtendedEnabledKeyFull +
1894 "&q={searchTerms}");
1895 data.SetShortName(ASCIIToUTF16("Google"));
1896 data.SetKeyword(ASCIIToUTF16("google.com"));
1897 data.search_terms_replacement_key =
1898 google_util::kGoogleInstantExtendedEnabledKeyFull;
1899 TemplateURL turl(data);
1900 EXPECT_TRUE(TemplateURL::MatchesData(&turl, &data, search_terms_data_));
1901 // Expect that replacement of search_terms_replacement_key in TemplateURL
1902 // constructor is correct.
1903 EXPECT_EQ(google_util::kInstantExtendedAPIParam,
1904 turl.search_terms_replacement_key());
1905 // Expect that replacement of {google:instantExtendedEnabledKey} in search url
1906 // is correct.
1907 GURL search_generated = turl.GenerateSearchURL(search_terms_data_);
1908 EXPECT_TRUE(turl.HasSearchTermsReplacementKey(search_generated));
1909 net::QueryIterator it(search_generated);
1910 ASSERT_FALSE(it.IsAtEnd());
1911 EXPECT_EQ(google_util::kInstantExtendedAPIParam, it.GetKey());
1912 }
OLDNEW
« no previous file with comments | « components/search_engines/template_url_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698