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

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

Issue 492963005: Stop using UIThreadSearchTermsData for search_engines related tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use make_scoped_ptr Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « components/search_engines.gypi ('k') | components/search_engines/testing_search_terms_data.h » ('j') | 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 "base/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/metrics/proto/omnibox_event.pb.h" 10 #include "components/metrics/proto/omnibox_event.pb.h"
11 #include "components/metrics/proto/omnibox_input_type.pb.h" 11 #include "components/metrics/proto/omnibox_input_type.pb.h"
12 #include "components/search_engines/search_engines_switches.h" 12 #include "components/search_engines/search_engines_switches.h"
13 #include "components/search_engines/search_terms_data.h" 13 #include "components/search_engines/search_terms_data.h"
14 #include "components/search_engines/template_url.h" 14 #include "components/search_engines/template_url.h"
15 #include "components/search_engines/testing_search_terms_data.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 using base::ASCIIToUTF16; 18 using base::ASCIIToUTF16;
18 19
19 // TestSearchTermsData --------------------------------------------------------
20
21 // Simple implementation of SearchTermsData.
22 class TestSearchTermsData : public SearchTermsData {
23 public:
24 explicit TestSearchTermsData(const std::string& google_base_url);
25
26 virtual std::string GoogleBaseURLValue() const OVERRIDE;
27 virtual base::string16 GetRlzParameterValue(
28 bool from_app_list) const OVERRIDE;
29 virtual std::string GetSearchClient() const OVERRIDE;
30 virtual std::string GoogleImageSearchSource() const OVERRIDE;
31 virtual bool EnableAnswersInSuggest() const OVERRIDE;
32 virtual bool IsShowingSearchTermsOnSearchResultsPages() const OVERRIDE;
33 virtual int OmniboxStartMargin() const OVERRIDE;
34
35 void set_google_base_url(const std::string& google_base_url) {
36 google_base_url_ = google_base_url;
37 }
38 void set_search_client(const std::string& search_client) {
39 search_client_ = search_client;
40 }
41 void set_enable_answers_in_suggest(bool enable_answers_in_suggest) {
42 enable_answers_in_suggest_ = enable_answers_in_suggest;
43 }
44 void set_is_showing_search_terms_on_search_results_pages(bool value) {
45 is_showing_search_terms_on_search_results_pages_ = value;
46 }
47 void set_omnibox_start_margin(int omnibox_start_margin) {
48 omnibox_start_margin_ = omnibox_start_margin;
49 }
50
51 private:
52 std::string google_base_url_;
53 std::string search_client_;
54 bool enable_answers_in_suggest_;
55 bool is_showing_search_terms_on_search_results_pages_;
56 int omnibox_start_margin_;
57
58 DISALLOW_COPY_AND_ASSIGN(TestSearchTermsData);
59 };
60
61 TestSearchTermsData::TestSearchTermsData(const std::string& google_base_url)
62 : google_base_url_(google_base_url),
63 enable_answers_in_suggest_(false),
64 is_showing_search_terms_on_search_results_pages_(false) {
65 }
66
67 std::string TestSearchTermsData::GoogleBaseURLValue() const {
68 return google_base_url_;
69 }
70
71 base::string16 TestSearchTermsData::GetRlzParameterValue(
72 bool from_app_list) const {
73 return ASCIIToUTF16(
74 from_app_list ? "rlz_parameter_from_app_list" : "rlz_parameter");
75 }
76
77 std::string TestSearchTermsData::GetSearchClient() const {
78 return search_client_;
79 }
80
81 std::string TestSearchTermsData::GoogleImageSearchSource() const {
82 return "google_image_search_source";
83 }
84
85 bool TestSearchTermsData::EnableAnswersInSuggest() const {
86 return enable_answers_in_suggest_;
87 }
88
89 bool TestSearchTermsData::IsShowingSearchTermsOnSearchResultsPages() const {
90 return is_showing_search_terms_on_search_results_pages_;
91 }
92
93 int TestSearchTermsData::OmniboxStartMargin() const {
94 return omnibox_start_margin_;
95 }
96
97 // TemplateURLTest ------------------------------------------------------------
98
99 class TemplateURLTest : public testing::Test { 20 class TemplateURLTest : public testing::Test {
100 public: 21 public:
101 TemplateURLTest() : search_terms_data_("http://www.google.com/") {} 22 TemplateURLTest() : search_terms_data_("http://www.google.com/") {}
102 void CheckSuggestBaseURL(const std::string& base_url, 23 void CheckSuggestBaseURL(const std::string& base_url,
103 const std::string& base_suggest_url) const; 24 const std::string& base_suggest_url) const;
104 25
105 TestSearchTermsData search_terms_data_; 26 TestingSearchTermsData search_terms_data_;
106 }; 27 };
107 28
108 void TemplateURLTest::CheckSuggestBaseURL( 29 void TemplateURLTest::CheckSuggestBaseURL(
109 const std::string& base_url, 30 const std::string& base_url,
110 const std::string& base_suggest_url) const { 31 const std::string& base_suggest_url) const {
111 TestSearchTermsData search_terms_data(base_url); 32 TestingSearchTermsData search_terms_data(base_url);
112 EXPECT_EQ(base_suggest_url, search_terms_data.GoogleBaseSuggestURLValue()); 33 EXPECT_EQ(base_suggest_url, search_terms_data.GoogleBaseSuggestURLValue());
113 } 34 }
114 35
115
116 // Actual tests ---------------------------------------------------------------
117
118 TEST_F(TemplateURLTest, Defaults) { 36 TEST_F(TemplateURLTest, Defaults) {
119 TemplateURLData data; 37 TemplateURLData data;
120 EXPECT_FALSE(data.show_in_default_list); 38 EXPECT_FALSE(data.show_in_default_list);
121 EXPECT_FALSE(data.safe_for_autoreplace); 39 EXPECT_FALSE(data.safe_for_autoreplace);
122 EXPECT_EQ(0, data.prepopulate_id); 40 EXPECT_EQ(0, data.prepopulate_id);
123 } 41 }
124 42
125 TEST_F(TemplateURLTest, TestValidWithComplete) { 43 TEST_F(TemplateURLTest, TestValidWithComplete) {
126 TemplateURLData data; 44 TemplateURLData data;
127 data.SetURL("{searchTerms}"); 45 data.SetURL("{searchTerms}");
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 ASSERT_TRUE(url.image_url_ref().IsValid(search_terms_data_)); 169 ASSERT_TRUE(url.image_url_ref().IsValid(search_terms_data_));
252 ASSERT_FALSE(url.image_url_ref().SupportsReplacement(search_terms_data_)); 170 ASSERT_FALSE(url.image_url_ref().SupportsReplacement(search_terms_data_));
253 171
254 // Check term replacement. 172 // Check term replacement.
255 TemplateURLRef::SearchTermsArgs search_args(ASCIIToUTF16("X")); 173 TemplateURLRef::SearchTermsArgs search_args(ASCIIToUTF16("X"));
256 search_args.image_thumbnail_content = "dummy-image-thumbnail"; 174 search_args.image_thumbnail_content = "dummy-image-thumbnail";
257 search_args.image_url = GURL("http://dummyimage.com/dummy.jpg"); 175 search_args.image_url = GURL("http://dummyimage.com/dummy.jpg");
258 search_args.image_original_size = gfx::Size(10, 10); 176 search_args.image_original_size = gfx::Size(10, 10);
259 // Replacement operation with no post_data buffer should still return 177 // Replacement operation with no post_data buffer should still return
260 // the parsed URL. 178 // the parsed URL.
261 TestSearchTermsData search_terms_data("http://X"); 179 TestingSearchTermsData search_terms_data("http://X");
262 GURL result(url.image_url_ref().ReplaceSearchTerms( 180 GURL result(url.image_url_ref().ReplaceSearchTerms(
263 search_args, search_terms_data)); 181 search_args, search_terms_data));
264 ASSERT_TRUE(result.is_valid()); 182 ASSERT_TRUE(result.is_valid());
265 EXPECT_EQ(KImageSearchURL, result.spec()); 183 EXPECT_EQ(KImageSearchURL, result.spec());
266 TemplateURLRef::PostContent post_content; 184 TemplateURLRef::PostContent post_content;
267 result = GURL(url.image_url_ref().ReplaceSearchTerms( 185 result = GURL(url.image_url_ref().ReplaceSearchTerms(
268 search_args, search_terms_data, &post_content)); 186 search_args, search_terms_data, &post_content));
269 ASSERT_TRUE(result.is_valid()); 187 ASSERT_TRUE(result.is_valid());
270 EXPECT_EQ(KImageSearchURL, result.spec()); 188 EXPECT_EQ(KImageSearchURL, result.spec());
271 ASSERT_FALSE(post_content.first.empty()); 189 ASSERT_FALSE(post_content.first.empty());
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 const char* url; 294 const char* url;
377 const base::string16 terms; 295 const base::string16 terms;
378 const char* output; 296 const char* output;
379 } search_term_cases[] = { 297 } search_term_cases[] = {
380 { "{google:baseURL}{language}{searchTerms}", base::string16(), 298 { "{google:baseURL}{language}{searchTerms}", base::string16(),
381 "http://example.com/e/en" }, 299 "http://example.com/e/en" },
382 { "{google:baseSuggestURL}{searchTerms}", base::string16(), 300 { "{google:baseSuggestURL}{searchTerms}", base::string16(),
383 "http://example.com/complete/" } 301 "http://example.com/complete/" }
384 }; 302 };
385 303
386 TestSearchTermsData search_terms_data("http://example.com/e/"); 304 TestingSearchTermsData search_terms_data("http://example.com/e/");
387 TemplateURLData data; 305 TemplateURLData data;
388 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) { 306 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) {
389 const SearchTermsCase& value = search_term_cases[i]; 307 const SearchTermsCase& value = search_term_cases[i];
390 data.SetURL(value.url); 308 data.SetURL(value.url);
391 TemplateURL url(data); 309 TemplateURL url(data);
392 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data)); 310 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data));
393 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data)); 311 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data));
394 GURL result(url.url_ref().ReplaceSearchTerms( 312 GURL result(url.url_ref().ReplaceSearchTerms(
395 TemplateURLRef::SearchTermsArgs(value.terms), search_terms_data, NULL)); 313 TemplateURLRef::SearchTermsArgs(value.terms), search_terms_data, NULL));
396 ASSERT_TRUE(result.is_valid()); 314 ASSERT_TRUE(result.is_valid());
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 EXPECT_EQ("http://bar/search?q=foo&pfq=full%20query%20text&qha=2338&xssi=t", 1495 EXPECT_EQ("http://bar/search?q=foo&pfq=full%20query%20text&qha=2338&xssi=t",
1578 result); 1496 result);
1579 1497
1580 TemplateURL url2(data); 1498 TemplateURL url2(data);
1581 search_terms_args.prefetch_query.clear(); 1499 search_terms_args.prefetch_query.clear();
1582 search_terms_args.prefetch_query_type.clear(); 1500 search_terms_args.prefetch_query_type.clear();
1583 result = 1501 result =
1584 url2.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_); 1502 url2.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_);
1585 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result); 1503 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result);
1586 } 1504 }
OLDNEW
« no previous file with comments | « components/search_engines.gypi ('k') | components/search_engines/testing_search_terms_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698