| 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 "chrome/browser/ui/app_list/search/omnibox_result.h" | 5 #include "chrome/browser/ui/app_list/search/omnibox_result.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/macros.h" | 9 #include "base/macros.h" |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/app_list/app_list_test_util.h" | 11 #include "chrome/browser/ui/app_list/app_list_test_util.h" |
| 11 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" | 12 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 13 #include "components/omnibox/browser/autocomplete_match.h" | 14 #include "components/omnibox/browser/autocomplete_match.h" |
| 14 #include "components/omnibox/browser/autocomplete_match_type.h" | 15 #include "components/omnibox/browser/autocomplete_match_type.h" |
| 15 #include "components/search_engines/template_url.h" | 16 #include "components/search_engines/template_url.h" |
| 16 | 17 |
| 17 namespace app_list { | 18 namespace app_list { |
| 18 namespace test { | 19 namespace test { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 45 ~OmniboxResultTest() override {} | 46 ~OmniboxResultTest() override {} |
| 46 | 47 |
| 47 // AppListTestBase overrides: | 48 // AppListTestBase overrides: |
| 48 void SetUp() override { | 49 void SetUp() override { |
| 49 AppListTestBase::SetUp(); | 50 AppListTestBase::SetUp(); |
| 50 | 51 |
| 51 app_list_controller_delegate_.reset( | 52 app_list_controller_delegate_.reset( |
| 52 new ::test::TestAppListControllerDelegate); | 53 new ::test::TestAppListControllerDelegate); |
| 53 } | 54 } |
| 54 | 55 |
| 55 scoped_ptr<OmniboxResult> CreateOmniboxResult( | 56 std::unique_ptr<OmniboxResult> CreateOmniboxResult( |
| 56 const std::string& original_query, | 57 const std::string& original_query, |
| 57 int relevance, | 58 int relevance, |
| 58 const std::string& destination_url, | 59 const std::string& destination_url, |
| 59 const std::string& contents, | 60 const std::string& contents, |
| 60 const std::string& description, | 61 const std::string& description, |
| 61 AutocompleteMatchType::Type type, | 62 AutocompleteMatchType::Type type, |
| 62 const std::string& keyword, | 63 const std::string& keyword, |
| 63 bool is_voice_query) { | 64 bool is_voice_query) { |
| 64 AutocompleteMatch match; | 65 AutocompleteMatch match; |
| 65 match.search_terms_args.reset( | 66 match.search_terms_args.reset( |
| 66 new TemplateURLRef::SearchTermsArgs(base::UTF8ToUTF16(original_query))); | 67 new TemplateURLRef::SearchTermsArgs(base::UTF8ToUTF16(original_query))); |
| 67 match.search_terms_args->original_query = base::UTF8ToUTF16(original_query); | 68 match.search_terms_args->original_query = base::UTF8ToUTF16(original_query); |
| 68 match.relevance = relevance; | 69 match.relevance = relevance; |
| 69 match.destination_url = GURL(destination_url); | 70 match.destination_url = GURL(destination_url); |
| 70 match.contents = base::UTF8ToUTF16(contents); | 71 match.contents = base::UTF8ToUTF16(contents); |
| 71 match.description = base::UTF8ToUTF16(description); | 72 match.description = base::UTF8ToUTF16(description); |
| 72 match.type = type; | 73 match.type = type; |
| 73 match.keyword = base::UTF8ToUTF16(keyword); | 74 match.keyword = base::UTF8ToUTF16(keyword); |
| 74 | 75 |
| 75 return scoped_ptr<OmniboxResult>( | 76 return std::unique_ptr<OmniboxResult>( |
| 76 new OmniboxResult(profile_.get(), app_list_controller_delegate_.get(), | 77 new OmniboxResult(profile_.get(), app_list_controller_delegate_.get(), |
| 77 nullptr, is_voice_query, match)); | 78 nullptr, is_voice_query, match)); |
| 78 } | 79 } |
| 79 | 80 |
| 80 const GURL& GetLastOpenedUrl() const { | 81 const GURL& GetLastOpenedUrl() const { |
| 81 return app_list_controller_delegate_->last_opened_url(); | 82 return app_list_controller_delegate_->last_opened_url(); |
| 82 } | 83 } |
| 83 | 84 |
| 84 private: | 85 private: |
| 85 scoped_ptr<::test::TestAppListControllerDelegate> | 86 std::unique_ptr<::test::TestAppListControllerDelegate> |
| 86 app_list_controller_delegate_; | 87 app_list_controller_delegate_; |
| 87 | 88 |
| 88 DISALLOW_COPY_AND_ASSIGN(OmniboxResultTest); | 89 DISALLOW_COPY_AND_ASSIGN(OmniboxResultTest); |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 TEST_F(OmniboxResultTest, Basic) { | 92 TEST_F(OmniboxResultTest, Basic) { |
| 92 scoped_ptr<OmniboxResult> result = CreateOmniboxResult( | 93 std::unique_ptr<OmniboxResult> result = CreateOmniboxResult( |
| 93 kFullQuery, kRelevance, kExampleUrl, kFullQuery, kExampleDescription, | 94 kFullQuery, kRelevance, kExampleUrl, kFullQuery, kExampleDescription, |
| 94 AutocompleteMatchType::HISTORY_URL, kExampleKeyword, false); | 95 AutocompleteMatchType::HISTORY_URL, kExampleKeyword, false); |
| 95 | 96 |
| 96 EXPECT_EQ(base::ASCIIToUTF16(kFullQuery), result->title()); | 97 EXPECT_EQ(base::ASCIIToUTF16(kFullQuery), result->title()); |
| 97 EXPECT_EQ(base::ASCIIToUTF16(kExampleDescription), result->details()); | 98 EXPECT_EQ(base::ASCIIToUTF16(kExampleDescription), result->details()); |
| 98 EXPECT_EQ(kAppListRelevance, result->relevance()); | 99 EXPECT_EQ(kAppListRelevance, result->relevance()); |
| 99 EXPECT_FALSE(result->voice_result()); | 100 EXPECT_FALSE(result->voice_result()); |
| 100 | 101 |
| 101 result->Open(0); | 102 result->Open(0); |
| 102 EXPECT_EQ(kExampleUrl, GetLastOpenedUrl().spec()); | 103 EXPECT_EQ(kExampleUrl, GetLastOpenedUrl().spec()); |
| 103 } | 104 } |
| 104 | 105 |
| 105 TEST_F(OmniboxResultTest, VoiceResult) { | 106 TEST_F(OmniboxResultTest, VoiceResult) { |
| 106 // Searching for part of a word, and getting a HISTORY_URL result with that | 107 // Searching for part of a word, and getting a HISTORY_URL result with that |
| 107 // exact string in the title. Should not be automatically launchable as a | 108 // exact string in the title. Should not be automatically launchable as a |
| 108 // voice result (because it is not a web search type result). | 109 // voice result (because it is not a web search type result). |
| 109 { | 110 { |
| 110 scoped_ptr<OmniboxResult> result = CreateOmniboxResult( | 111 std::unique_ptr<OmniboxResult> result = CreateOmniboxResult( |
| 111 kPartialQuery, kRelevance, kExampleUrl, kPartialQuery, | 112 kPartialQuery, kRelevance, kExampleUrl, kPartialQuery, |
| 112 kExampleDescription, AutocompleteMatchType::HISTORY_URL, | 113 kExampleDescription, AutocompleteMatchType::HISTORY_URL, |
| 113 kExampleKeyword, false); | 114 kExampleKeyword, false); |
| 114 EXPECT_FALSE(result->voice_result()); | 115 EXPECT_FALSE(result->voice_result()); |
| 115 } | 116 } |
| 116 | 117 |
| 117 // Searching for part of a word, and getting a SEARCH_WHAT_YOU_TYPED result. | 118 // Searching for part of a word, and getting a SEARCH_WHAT_YOU_TYPED result. |
| 118 // Such a result should be promoted as a voice result. | 119 // Such a result should be promoted as a voice result. |
| 119 { | 120 { |
| 120 scoped_ptr<OmniboxResult> result = CreateOmniboxResult( | 121 std::unique_ptr<OmniboxResult> result = CreateOmniboxResult( |
| 121 kPartialQuery, kRelevance, kExampleUrl, kPartialQuery, | 122 kPartialQuery, kRelevance, kExampleUrl, kPartialQuery, |
| 122 kExampleDescription, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 123 kExampleDescription, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
| 123 kExampleKeyword, false); | 124 kExampleKeyword, false); |
| 124 EXPECT_TRUE(result->voice_result()); | 125 EXPECT_TRUE(result->voice_result()); |
| 125 } | 126 } |
| 126 | 127 |
| 127 // Searching for part of a word, and getting a SEARCH_HISTORY result for that | 128 // Searching for part of a word, and getting a SEARCH_HISTORY result for that |
| 128 // exact string. Such a result should be promoted as a voice result. | 129 // exact string. Such a result should be promoted as a voice result. |
| 129 { | 130 { |
| 130 scoped_ptr<OmniboxResult> result = CreateOmniboxResult( | 131 std::unique_ptr<OmniboxResult> result = CreateOmniboxResult( |
| 131 kPartialQuery, kRelevance, kExampleUrl, kPartialQuery, | 132 kPartialQuery, kRelevance, kExampleUrl, kPartialQuery, |
| 132 kExampleDescription, AutocompleteMatchType::SEARCH_HISTORY, | 133 kExampleDescription, AutocompleteMatchType::SEARCH_HISTORY, |
| 133 kExampleKeyword, false); | 134 kExampleKeyword, false); |
| 134 EXPECT_TRUE(result->voice_result()); | 135 EXPECT_TRUE(result->voice_result()); |
| 135 } | 136 } |
| 136 | 137 |
| 137 // Searching for part of a word, and getting a SEARCH_HISTORY result for a | 138 // Searching for part of a word, and getting a SEARCH_HISTORY result for a |
| 138 // different string. Should not be automatically launchable as a voice result | 139 // different string. Should not be automatically launchable as a voice result |
| 139 // (because it does not exactly match what you typed). | 140 // (because it does not exactly match what you typed). |
| 140 { | 141 { |
| 141 scoped_ptr<OmniboxResult> result = CreateOmniboxResult( | 142 std::unique_ptr<OmniboxResult> result = CreateOmniboxResult( |
| 142 kPartialQuery, kRelevance, kExampleUrl, kFullQuery, kExampleDescription, | 143 kPartialQuery, kRelevance, kExampleUrl, kFullQuery, kExampleDescription, |
| 143 AutocompleteMatchType::SEARCH_HISTORY, kExampleKeyword, false); | 144 AutocompleteMatchType::SEARCH_HISTORY, kExampleKeyword, false); |
| 144 EXPECT_FALSE(result->voice_result()); | 145 EXPECT_FALSE(result->voice_result()); |
| 145 } | 146 } |
| 146 } | 147 } |
| 147 | 148 |
| 148 TEST_F(OmniboxResultTest, VoiceQuery) { | 149 TEST_F(OmniboxResultTest, VoiceQuery) { |
| 149 // A voice query to a random domain. URL should not change. | 150 // A voice query to a random domain. URL should not change. |
| 150 { | 151 { |
| 151 scoped_ptr<OmniboxResult> result = CreateOmniboxResult( | 152 std::unique_ptr<OmniboxResult> result = CreateOmniboxResult( |
| 152 kWeatherQuery, kRelevance, kExampleWeatherUrl, kWeatherQuery, | 153 kWeatherQuery, kRelevance, kExampleWeatherUrl, kWeatherQuery, |
| 153 kExampleDescription, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 154 kExampleDescription, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
| 154 kExampleKeyword, true); | 155 kExampleKeyword, true); |
| 155 result->Open(0); | 156 result->Open(0); |
| 156 EXPECT_EQ(kExampleWeatherUrl, GetLastOpenedUrl().spec()); | 157 EXPECT_EQ(kExampleWeatherUrl, GetLastOpenedUrl().spec()); |
| 157 } | 158 } |
| 158 | 159 |
| 159 // A voice query to a Google domain. URL should have magic "speak back" query | 160 // A voice query to a Google domain. URL should have magic "speak back" query |
| 160 // parameter appended. | 161 // parameter appended. |
| 161 { | 162 { |
| 162 scoped_ptr<OmniboxResult> result = CreateOmniboxResult( | 163 std::unique_ptr<OmniboxResult> result = CreateOmniboxResult( |
| 163 kWeatherQuery, kRelevance, kGoogleWeatherUrl, kWeatherQuery, | 164 kWeatherQuery, kRelevance, kGoogleWeatherUrl, kWeatherQuery, |
| 164 kGoogleDescription, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 165 kGoogleDescription, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
| 165 kGoogleKeyword, true); | 166 kGoogleKeyword, true); |
| 166 result->Open(0); | 167 result->Open(0); |
| 167 EXPECT_EQ("http://google.com/search?q=weather&gs_ivs=1", | 168 EXPECT_EQ("http://google.com/search?q=weather&gs_ivs=1", |
| 168 GetLastOpenedUrl().spec()); | 169 GetLastOpenedUrl().spec()); |
| 169 } | 170 } |
| 170 | 171 |
| 171 // A voice query to a Google international domain. URL should have magic | 172 // A voice query to a Google international domain. URL should have magic |
| 172 // "speak back" query parameter appended. | 173 // "speak back" query parameter appended. |
| 173 { | 174 { |
| 174 scoped_ptr<OmniboxResult> result = CreateOmniboxResult( | 175 std::unique_ptr<OmniboxResult> result = CreateOmniboxResult( |
| 175 kWeatherQuery, kRelevance, kGoogleInternationalWeatherUrl, | 176 kWeatherQuery, kRelevance, kGoogleInternationalWeatherUrl, |
| 176 kWeatherQuery, kGoogleDescription, | 177 kWeatherQuery, kGoogleDescription, |
| 177 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, kGoogleKeyword, true); | 178 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, kGoogleKeyword, true); |
| 178 result->Open(0); | 179 result->Open(0); |
| 179 EXPECT_EQ("http://google.com.au/search?q=weather&gs_ivs=1", | 180 EXPECT_EQ("http://google.com.au/search?q=weather&gs_ivs=1", |
| 180 GetLastOpenedUrl().spec()); | 181 GetLastOpenedUrl().spec()); |
| 181 } | 182 } |
| 182 | 183 |
| 183 // A non-voice query to a Google domain. URL should not change. | 184 // A non-voice query to a Google domain. URL should not change. |
| 184 { | 185 { |
| 185 scoped_ptr<OmniboxResult> result = CreateOmniboxResult( | 186 std::unique_ptr<OmniboxResult> result = CreateOmniboxResult( |
| 186 kWeatherQuery, kRelevance, kGoogleWeatherUrl, kWeatherQuery, | 187 kWeatherQuery, kRelevance, kGoogleWeatherUrl, kWeatherQuery, |
| 187 kGoogleDescription, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 188 kGoogleDescription, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
| 188 kGoogleKeyword, false); | 189 kGoogleKeyword, false); |
| 189 result->Open(0); | 190 result->Open(0); |
| 190 EXPECT_EQ(kGoogleWeatherUrl, GetLastOpenedUrl().spec()); | 191 EXPECT_EQ(kGoogleWeatherUrl, GetLastOpenedUrl().spec()); |
| 191 } | 192 } |
| 192 } | 193 } |
| 193 | 194 |
| 194 } // namespace test | 195 } // namespace test |
| 195 } // namespace app_list | 196 } // namespace app_list |
| OLD | NEW |