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

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 after review round 3 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
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"
(...skipping 1850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1861 GURL("https://www.foo.org/search?q=Y+Z"), 1861 GURL("https://www.foo.org/search?q=Y+Z"),
1862 search_terms_data_, &search_terms)); 1862 search_terms_data_, &search_terms));
1863 EXPECT_EQ(base::ASCIIToUTF16("Y Z"), search_terms); 1863 EXPECT_EQ(base::ASCIIToUTF16("Y Z"), search_terms);
1864 EXPECT_TRUE(url.ExtractSearchTermsFromURL( 1864 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
1865 GURL("https://www.foo.org/s#q=123"), 1865 GURL("https://www.foo.org/s#q=123"),
1866 search_terms_data_, &search_terms)); 1866 search_terms_data_, &search_terms));
1867 EXPECT_EQ(base::ASCIIToUTF16("123"), search_terms); 1867 EXPECT_EQ(base::ASCIIToUTF16("123"), search_terms);
1868 1868
1869 search_terms_data_.set_google_base_url("http://www.google.com/"); 1869 search_terms_data_.set_google_base_url("http://www.google.com/");
1870 } 1870 }
1871
1872 // Test that TemplateURL object created with settings for google engine
1873 // matches its TemplateURLData.
1874 TEST_F(TemplateURLTest, MatchesData) {
1875 TemplateURLData data;
1876 data.SetURL("{google:baseURL}search?q={searchTerms}");
1877 data.SetShortName(ASCIIToUTF16("Google"));
1878 data.SetKeyword(ASCIIToUTF16("google.com"));
1879 data.suggestions_url = "{google:baseSuggestURL}search?q={searchTerms}";
1880 data.instant_url = "{google:baseURL}webhp";
1881 data.image_url = "{google:baseURL}searchbyimage/upload";
1882 data.new_tab_url = "{google:baseURL}_/chrome/newtab";
1883 data.contextual_search_url = "{google:baseURL}_/contextualsearch";
1884 data.image_url_post_params = "encoded_image={google:imageThumbnail}";
1885 data.alternate_urls.push_back("{google:baseURL}s#q={searchTerms}");
1886 // search_terms_replacement_key with value of
1887 // "{google:instantExtendedEnabledKey}" is replaced inside TemplateUrl
1888 // constructor so must be handled specially inside MatchesData.
Peter Kasting 2017/02/13 22:24:57 Nit: If this is the specific bit you want to test,
Alexander Yashkin 2017/02/14 12:04:43 ???? Are this digits relevant to your comment?
Peter Kasting 2017/02/15 02:09:57 Sorry, that's how I mark out 80 columns so I can e
1889 data.search_terms_replacement_key = "{google:instantExtendedEnabledKey}";
1890 TemplateURL url(data);
1891 EXPECT_TRUE(TemplateURL::MatchesData(&url, &data, search_terms_data_));
1892 }
1893
1894 // Test for correct replacement of GoogleInstantExtendedEnabledKey param.
1895 TEST_F(TemplateURLTest, GoogleInstantExtendedEnabledReplacement) {
Peter Kasting 2017/02/13 22:24:57 This test feels like a change-detector test: it wi
Alexander Yashkin 2017/02/14 12:04:43 I have added it after your comment in https://code
Peter Kasting 2017/02/15 02:09:57 Fair enough.
1896 TemplateURLData data;
1897 data.SetURL(
1898 "{google:baseURL}search/"
1899 "?{google:instantExtendedEnabledKey}&q={searchTerms}");
1900 data.SetShortName(ASCIIToUTF16("Google"));
1901 data.SetKeyword(ASCIIToUTF16("google.com"));
1902 data.search_terms_replacement_key = "{google:instantExtendedEnabledKey}";
1903 TemplateURL turl(data);
1904 EXPECT_TRUE(TemplateURL::MatchesData(&turl, &data, search_terms_data_));
1905 // Expect that replacement of search_terms_replacement_key in TemplateURL
1906 // constructor is correct.
1907 EXPECT_EQ("espv", turl.search_terms_replacement_key());
1908 // Expect that replacement of {google:instantExtendedEnabledKey} in search url
1909 // is correct.
1910 GURL search_generated = turl.GenerateSearchURL(search_terms_data_);
1911 EXPECT_EQ("http://www.google.com/search/?espv&q=blah.blah.blah.blah.blah",
1912 search_generated.spec());
1913 EXPECT_TRUE(turl.HasSearchTermsReplacementKey(search_generated));
1914 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698