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 "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" |
(...skipping 12 matching lines...) Expand all Loading... |
23 public: | 23 public: |
24 explicit TestSearchTermsData(const std::string& google_base_url); | 24 explicit TestSearchTermsData(const std::string& google_base_url); |
25 | 25 |
26 virtual std::string GoogleBaseURLValue() const OVERRIDE; | 26 virtual std::string GoogleBaseURLValue() const OVERRIDE; |
27 virtual base::string16 GetRlzParameterValue( | 27 virtual base::string16 GetRlzParameterValue( |
28 bool from_app_list) const OVERRIDE; | 28 bool from_app_list) const OVERRIDE; |
29 virtual std::string GetSearchClient() const OVERRIDE; | 29 virtual std::string GetSearchClient() const OVERRIDE; |
30 virtual std::string GoogleImageSearchSource() const OVERRIDE; | 30 virtual std::string GoogleImageSearchSource() const OVERRIDE; |
31 virtual bool EnableAnswersInSuggest() const OVERRIDE; | 31 virtual bool EnableAnswersInSuggest() const OVERRIDE; |
32 virtual bool IsShowingSearchTermsOnSearchResultsPages() const OVERRIDE; | 32 virtual bool IsShowingSearchTermsOnSearchResultsPages() const OVERRIDE; |
| 33 virtual int OmniboxStartMargin() const OVERRIDE; |
33 | 34 |
34 void set_google_base_url(const std::string& google_base_url) { | 35 void set_google_base_url(const std::string& google_base_url) { |
35 google_base_url_ = google_base_url; | 36 google_base_url_ = google_base_url; |
36 } | 37 } |
37 void set_search_client(const std::string& search_client) { | 38 void set_search_client(const std::string& search_client) { |
38 search_client_ = search_client; | 39 search_client_ = search_client; |
39 } | 40 } |
40 void set_enable_answers_in_suggest(bool enable_answers_in_suggest) { | 41 void set_enable_answers_in_suggest(bool enable_answers_in_suggest) { |
41 enable_answers_in_suggest_ = enable_answers_in_suggest; | 42 enable_answers_in_suggest_ = enable_answers_in_suggest; |
42 } | 43 } |
43 void set_is_showing_search_terms_on_search_results_pages(bool value) { | 44 void set_is_showing_search_terms_on_search_results_pages(bool value) { |
44 is_showing_search_terms_on_search_results_pages_ = value; | 45 is_showing_search_terms_on_search_results_pages_ = value; |
45 } | 46 } |
| 47 void set_omnibox_start_margin(int omnibox_start_margin) { |
| 48 omnibox_start_margin_ = omnibox_start_margin; |
| 49 } |
46 | 50 |
47 private: | 51 private: |
48 std::string google_base_url_; | 52 std::string google_base_url_; |
49 std::string search_client_; | 53 std::string search_client_; |
50 bool enable_answers_in_suggest_; | 54 bool enable_answers_in_suggest_; |
51 bool is_showing_search_terms_on_search_results_pages_; | 55 bool is_showing_search_terms_on_search_results_pages_; |
| 56 int omnibox_start_margin_; |
52 | 57 |
53 DISALLOW_COPY_AND_ASSIGN(TestSearchTermsData); | 58 DISALLOW_COPY_AND_ASSIGN(TestSearchTermsData); |
54 }; | 59 }; |
55 | 60 |
56 TestSearchTermsData::TestSearchTermsData(const std::string& google_base_url) | 61 TestSearchTermsData::TestSearchTermsData(const std::string& google_base_url) |
57 : google_base_url_(google_base_url), | 62 : google_base_url_(google_base_url), |
58 enable_answers_in_suggest_(false), | 63 enable_answers_in_suggest_(false), |
59 is_showing_search_terms_on_search_results_pages_(false) { | 64 is_showing_search_terms_on_search_results_pages_(false) { |
60 } | 65 } |
61 | 66 |
(...skipping 16 matching lines...) Expand all Loading... |
78 } | 83 } |
79 | 84 |
80 bool TestSearchTermsData::EnableAnswersInSuggest() const { | 85 bool TestSearchTermsData::EnableAnswersInSuggest() const { |
81 return enable_answers_in_suggest_; | 86 return enable_answers_in_suggest_; |
82 } | 87 } |
83 | 88 |
84 bool TestSearchTermsData::IsShowingSearchTermsOnSearchResultsPages() const { | 89 bool TestSearchTermsData::IsShowingSearchTermsOnSearchResultsPages() const { |
85 return is_showing_search_terms_on_search_results_pages_; | 90 return is_showing_search_terms_on_search_results_pages_; |
86 } | 91 } |
87 | 92 |
| 93 int TestSearchTermsData::OmniboxStartMargin() const { |
| 94 return omnibox_start_margin_; |
| 95 } |
| 96 |
88 // TemplateURLTest ------------------------------------------------------------ | 97 // TemplateURLTest ------------------------------------------------------------ |
89 | 98 |
90 class TemplateURLTest : public testing::Test { | 99 class TemplateURLTest : public testing::Test { |
91 public: | 100 public: |
92 TemplateURLTest() : search_terms_data_("http://www.google.com/") {} | 101 TemplateURLTest() : search_terms_data_("http://www.google.com/") {} |
93 void CheckSuggestBaseURL(const std::string& base_url, | 102 void CheckSuggestBaseURL(const std::string& base_url, |
94 const std::string& base_suggest_url) const; | 103 const std::string& base_suggest_url) const; |
95 | 104 |
96 TestSearchTermsData search_terms_data_; | 105 TestSearchTermsData search_terms_data_; |
97 }; | 106 }; |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_)); | 707 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_)); |
699 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term); | 708 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term); |
700 search_terms_args.current_page_url = test_data[i].current_page_url; | 709 search_terms_args.current_page_url = test_data[i].current_page_url; |
701 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args, | 710 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args, |
702 search_terms_data_)); | 711 search_terms_data_)); |
703 ASSERT_TRUE(result.is_valid()); | 712 ASSERT_TRUE(result.is_valid()); |
704 EXPECT_EQ(test_data[i].expected_result, result.spec()); | 713 EXPECT_EQ(test_data[i].expected_result, result.spec()); |
705 } | 714 } |
706 } | 715 } |
707 | 716 |
| 717 TEST_F(TemplateURLTest, OmniboxStartmargin) { |
| 718 struct TestData { |
| 719 const bool enable_omnibox_start_margin; |
| 720 const int omnibox_start_margin; |
| 721 const std::string expected_result; |
| 722 } test_data[] = { |
| 723 { false, |
| 724 0, |
| 725 "http://bar/foo?q=foobar" }, |
| 726 { true, |
| 727 0, |
| 728 "http://bar/foo?es_sm=0&q=foobar" }, |
| 729 { true, |
| 730 42, |
| 731 "http://bar/foo?es_sm=42&q=foobar" }, |
| 732 }; |
| 733 TemplateURLData data; |
| 734 data.SetURL("http://bar/foo?{google:omniboxStartMarginParameter}" |
| 735 "q={searchTerms}"); |
| 736 data.input_encodings.push_back("UTF-8"); |
| 737 TemplateURL url(data); |
| 738 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_)); |
| 739 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_)); |
| 740 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
| 741 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foobar")); |
| 742 search_terms_args.enable_omnibox_start_margin = |
| 743 test_data[i].enable_omnibox_start_margin; |
| 744 search_terms_data_.set_omnibox_start_margin( |
| 745 test_data[i].omnibox_start_margin); |
| 746 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args, |
| 747 search_terms_data_)); |
| 748 ASSERT_TRUE(result.is_valid()); |
| 749 EXPECT_EQ(test_data[i].expected_result, result.spec()); |
| 750 } |
| 751 } |
| 752 |
708 TEST_F(TemplateURLTest, Suggestions) { | 753 TEST_F(TemplateURLTest, Suggestions) { |
709 struct TestData { | 754 struct TestData { |
710 const int accepted_suggestion; | 755 const int accepted_suggestion; |
711 const base::string16 original_query_for_suggestion; | 756 const base::string16 original_query_for_suggestion; |
712 const std::string expected_result; | 757 const std::string expected_result; |
713 } test_data[] = { | 758 } test_data[] = { |
714 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, base::string16(), | 759 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, base::string16(), |
715 "http://bar/foo?q=foobar" }, | 760 "http://bar/foo?q=foobar" }, |
716 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"), | 761 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"), |
717 "http://bar/foo?q=foobar" }, | 762 "http://bar/foo?q=foobar" }, |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1530 EXPECT_EQ("http://bar/search?q=foo&pfq=full%20query%20text&qha=2338&xssi=t", | 1575 EXPECT_EQ("http://bar/search?q=foo&pfq=full%20query%20text&qha=2338&xssi=t", |
1531 result); | 1576 result); |
1532 | 1577 |
1533 TemplateURL url2(data); | 1578 TemplateURL url2(data); |
1534 search_terms_args.prefetch_query.clear(); | 1579 search_terms_args.prefetch_query.clear(); |
1535 search_terms_args.prefetch_query_type.clear(); | 1580 search_terms_args.prefetch_query_type.clear(); |
1536 result = | 1581 result = |
1537 url2.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_); | 1582 url2.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_); |
1538 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result); | 1583 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result); |
1539 } | 1584 } |
OLD | NEW |