OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/autocomplete/autocomplete_result.h" | 5 #include "chrome/browser/autocomplete/autocomplete_result.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/autocomplete/autocomplete_input.h" | 10 #include "chrome/browser/autocomplete/autocomplete_input.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 EXPECT_EQ(expected_match.relevance, match.relevance) << i; | 108 EXPECT_EQ(expected_match.relevance, match.relevance) << i; |
109 EXPECT_EQ(expected_match.destination_url.spec(), | 109 EXPECT_EQ(expected_match.destination_url.spec(), |
110 match.destination_url.spec()) << i; | 110 match.destination_url.spec()) << i; |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 void AutocompleteResultTest::RunCopyOldMatchesTest( | 114 void AutocompleteResultTest::RunCopyOldMatchesTest( |
115 const TestData* last, size_t last_size, | 115 const TestData* last, size_t last_size, |
116 const TestData* current, size_t current_size, | 116 const TestData* current, size_t current_size, |
117 const TestData* expected, size_t expected_size) { | 117 const TestData* expected, size_t expected_size) { |
118 AutocompleteInput input(ASCIIToUTF16("a"), string16::npos, string16(), false, | 118 AutocompleteInput input(ASCIIToUTF16("a"), string16::npos, string16(), GURL(), |
119 false, false, AutocompleteInput::ALL_MATCHES); | 119 false, false, false, AutocompleteInput::ALL_MATCHES); |
120 | 120 |
121 ACMatches last_matches; | 121 ACMatches last_matches; |
122 PopulateAutocompleteMatches(last, last_size, &last_matches); | 122 PopulateAutocompleteMatches(last, last_size, &last_matches); |
123 AutocompleteResult last_result; | 123 AutocompleteResult last_result; |
124 last_result.AppendMatches(last_matches); | 124 last_result.AppendMatches(last_matches); |
125 last_result.SortAndCull(input, test_util_.profile()); | 125 last_result.SortAndCull(input, test_util_.profile()); |
126 | 126 |
127 ACMatches current_matches; | 127 ACMatches current_matches; |
128 PopulateAutocompleteMatches(current, current_size, ¤t_matches); | 128 PopulateAutocompleteMatches(current, current_size, ¤t_matches); |
129 AutocompleteResult current_result; | 129 AutocompleteResult current_result; |
(...skipping 10 matching lines...) Expand all Loading... |
140 AutocompleteResult r2; | 140 AutocompleteResult r2; |
141 | 141 |
142 // Swap with empty shouldn't do anything interesting. | 142 // Swap with empty shouldn't do anything interesting. |
143 r1.Swap(&r2); | 143 r1.Swap(&r2); |
144 EXPECT_EQ(r1.end(), r1.default_match()); | 144 EXPECT_EQ(r1.end(), r1.default_match()); |
145 EXPECT_EQ(r2.end(), r2.default_match()); | 145 EXPECT_EQ(r2.end(), r2.default_match()); |
146 | 146 |
147 // Swap with a single match. | 147 // Swap with a single match. |
148 ACMatches matches; | 148 ACMatches matches; |
149 AutocompleteMatch match; | 149 AutocompleteMatch match; |
150 AutocompleteInput input(ASCIIToUTF16("a"), string16::npos, string16(), false, | 150 AutocompleteInput input(ASCIIToUTF16("a"), string16::npos, string16(), GURL(), |
151 false, false, AutocompleteInput::ALL_MATCHES); | 151 false, false, false, AutocompleteInput::ALL_MATCHES); |
152 matches.push_back(match); | 152 matches.push_back(match); |
153 r1.AppendMatches(matches); | 153 r1.AppendMatches(matches); |
154 r1.SortAndCull(input, test_util_.profile()); | 154 r1.SortAndCull(input, test_util_.profile()); |
155 EXPECT_EQ(r1.begin(), r1.default_match()); | 155 EXPECT_EQ(r1.begin(), r1.default_match()); |
156 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); | 156 EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); |
157 r1.Swap(&r2); | 157 r1.Swap(&r2); |
158 EXPECT_TRUE(r1.empty()); | 158 EXPECT_TRUE(r1.empty()); |
159 EXPECT_EQ(r1.end(), r1.default_match()); | 159 EXPECT_EQ(r1.end(), r1.default_match()); |
160 EXPECT_TRUE(r1.alternate_nav_url().is_empty()); | 160 EXPECT_TRUE(r1.alternate_nav_url().is_empty()); |
161 ASSERT_FALSE(r2.empty()); | 161 ASSERT_FALSE(r2.empty()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 }; | 221 }; |
222 | 222 |
223 ACMatches matches; | 223 ACMatches matches; |
224 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 224 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
225 matches[1].destination_url = GURL(); | 225 matches[1].destination_url = GURL(); |
226 matches[3].destination_url = GURL(); | 226 matches[3].destination_url = GURL(); |
227 matches[4].destination_url = GURL(); | 227 matches[4].destination_url = GURL(); |
228 | 228 |
229 AutocompleteResult result; | 229 AutocompleteResult result; |
230 result.AppendMatches(matches); | 230 result.AppendMatches(matches); |
231 AutocompleteInput input(string16(), string16::npos, string16(), false, false, | 231 AutocompleteInput input(string16(), string16::npos, string16(), GURL(), false, |
232 false, AutocompleteInput::ALL_MATCHES); | 232 false, false, AutocompleteInput::ALL_MATCHES); |
233 result.SortAndCull(input, test_util_.profile()); | 233 result.SortAndCull(input, test_util_.profile()); |
234 | 234 |
235 // Of the two results with the same non-empty destination URL, the | 235 // Of the two results with the same non-empty destination URL, the |
236 // lower-relevance one should be dropped. All of the results with empty URLs | 236 // lower-relevance one should be dropped. All of the results with empty URLs |
237 // should be kept. | 237 // should be kept. |
238 ASSERT_EQ(4U, result.size()); | 238 ASSERT_EQ(4U, result.size()); |
239 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); | 239 EXPECT_TRUE(result.match_at(0)->destination_url.is_empty()); |
240 EXPECT_EQ(1300, result.match_at(0)->relevance); | 240 EXPECT_EQ(1300, result.match_at(0)->relevance); |
241 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty()); | 241 EXPECT_TRUE(result.match_at(1)->destination_url.is_empty()); |
242 EXPECT_EQ(1200, result.match_at(1)->relevance); | 242 EXPECT_EQ(1200, result.match_at(1)->relevance); |
(...skipping 22 matching lines...) Expand all Loading... |
265 ACMatches matches; | 265 ACMatches matches; |
266 PopulateAutocompleteMatches(data, arraysize(data), &matches); | 266 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
267 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); | 267 matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); |
268 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); | 268 matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); |
269 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); | 269 matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); |
270 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); | 270 matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); |
271 matches[4].destination_url = GURL("http://www.foo.com/"); | 271 matches[4].destination_url = GURL("http://www.foo.com/"); |
272 | 272 |
273 AutocompleteResult result; | 273 AutocompleteResult result; |
274 result.AppendMatches(matches); | 274 result.AppendMatches(matches); |
275 AutocompleteInput input(string16(), string16::npos, string16(), false, false, | 275 AutocompleteInput input(string16(), string16::npos, string16(), GURL(), false, |
276 false, AutocompleteInput::ALL_MATCHES); | 276 false, false, AutocompleteInput::ALL_MATCHES); |
277 result.SortAndCull(input, test_util_.profile()); | 277 result.SortAndCull(input, test_util_.profile()); |
278 | 278 |
279 // We expect the 3rd and 4th results to be removed. | 279 // We expect the 3rd and 4th results to be removed. |
280 ASSERT_EQ(3U, result.size()); | 280 ASSERT_EQ(3U, result.size()); |
281 EXPECT_EQ("http://www.foo.com/s?q=foo", | 281 EXPECT_EQ("http://www.foo.com/s?q=foo", |
282 result.match_at(0)->destination_url.spec()); | 282 result.match_at(0)->destination_url.spec()); |
283 EXPECT_EQ(1300, result.match_at(0)->relevance); | 283 EXPECT_EQ(1300, result.match_at(0)->relevance); |
284 EXPECT_EQ("http://www.foo.com/s?q=foo2", | 284 EXPECT_EQ("http://www.foo.com/s?q=foo2", |
285 result.match_at(1)->destination_url.spec()); | 285 result.match_at(1)->destination_url.spec()); |
286 EXPECT_EQ(1200, result.match_at(1)->relevance); | 286 EXPECT_EQ(1200, result.match_at(1)->relevance); |
287 EXPECT_EQ("http://www.foo.com/", | 287 EXPECT_EQ("http://www.foo.com/", |
288 result.match_at(2)->destination_url.spec()); | 288 result.match_at(2)->destination_url.spec()); |
289 EXPECT_EQ(900, result.match_at(2)->relevance); | 289 EXPECT_EQ(900, result.match_at(2)->relevance); |
290 } | 290 } |
OLD | NEW |