OLD | NEW |
---|---|
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" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 using base::ASCIIToUTF16; | 22 using base::ASCIIToUTF16; |
22 | 23 |
(...skipping 1838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1861 GURL("https://www.foo.org/search?q=Y+Z"), | 1862 GURL("https://www.foo.org/search?q=Y+Z"), |
1862 search_terms_data_, &search_terms)); | 1863 search_terms_data_, &search_terms)); |
1863 EXPECT_EQ(base::ASCIIToUTF16("Y Z"), search_terms); | 1864 EXPECT_EQ(base::ASCIIToUTF16("Y Z"), search_terms); |
1864 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | 1865 EXPECT_TRUE(url.ExtractSearchTermsFromURL( |
1865 GURL("https://www.foo.org/s#q=123"), | 1866 GURL("https://www.foo.org/s#q=123"), |
1866 search_terms_data_, &search_terms)); | 1867 search_terms_data_, &search_terms)); |
1867 EXPECT_EQ(base::ASCIIToUTF16("123"), search_terms); | 1868 EXPECT_EQ(base::ASCIIToUTF16("123"), search_terms); |
1868 | 1869 |
1869 search_terms_data_.set_google_base_url("http://www.google.com/"); | 1870 search_terms_data_.set_google_base_url("http://www.google.com/"); |
1870 } | 1871 } |
1872 | |
1873 // search_terms_replacement_key param of TemplateURLData with value of | |
1874 // "{google:instantExtendedEnabledKey}" is replaced inside TemplateUrl | |
1875 // constructor so must be handled specially inside MatchesData. | |
1876 // Test that TemplateURL object created with such param matches correctly its | |
1877 // TemplateURLData. | |
1878 TEST_F(TemplateURLTest, MatchesData) { | |
1879 TemplateURLData data; | |
1880 data.search_terms_replacement_key = | |
1881 google_util::kGoogleInstantExtendedEnabledKeyFull; | |
1882 TemplateURL url(data); | |
1883 EXPECT_NE(google_util::kGoogleInstantExtendedEnabledKeyFull, | |
1884 url.search_terms_replacement_key()); | |
1885 EXPECT_TRUE(TemplateURL::MatchesData(&url, &data, search_terms_data_)); | |
1886 } | |
1887 | |
1888 // Test for correct replacement of GoogleInstantExtendedEnabledKey param. | |
1889 TEST_F(TemplateURLTest, GoogleInstantExtendedEnabledReplacement) { | |
1890 TemplateURLData data; | |
1891 data.SetURL( | |
1892 "{google:baseURL}search/" | |
1893 "?{google:instantExtendedEnabledKey}&q={searchTerms}"); | |
Peter Kasting
2017/02/15 02:09:57
Nit: I would trim the google:baseURL bit out of th
Alexander Yashkin
2017/02/15 12:46:10
Done
Peter Kasting
2017/02/16 00:12:10
Looks like google:baseURL is still around and coul
Alexander Yashkin
2017/02/16 07:26:30
Sorry, missed that, replaced with google.com.
| |
1894 data.SetShortName(ASCIIToUTF16("Google")); | |
1895 data.SetKeyword(ASCIIToUTF16("google.com")); | |
1896 data.search_terms_replacement_key = | |
1897 google_util::kGoogleInstantExtendedEnabledKeyFull; | |
1898 TemplateURL turl(data); | |
1899 EXPECT_TRUE(TemplateURL::MatchesData(&turl, &data, search_terms_data_)); | |
1900 // Expect that replacement of search_terms_replacement_key in TemplateURL | |
1901 // constructor is correct. | |
1902 EXPECT_EQ(google_util::kInstantExtendedAPIParam, | |
1903 turl.search_terms_replacement_key()); | |
1904 // Expect that replacement of {google:instantExtendedEnabledKey} in search url | |
1905 // is correct. | |
1906 GURL search_generated = turl.GenerateSearchURL(search_terms_data_); | |
1907 EXPECT_EQ("http://www.google.com/search/?espv&q=blah.blah.blah.blah.blah", | |
1908 search_generated.spec()); | |
Peter Kasting
2017/02/15 02:09:57
Rather than string-match the spec, What about usin
Alexander Yashkin
2017/02/15 12:46:10
Done
| |
1909 EXPECT_TRUE(turl.HasSearchTermsReplacementKey(search_generated)); | |
1910 } | |
OLD | NEW |