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/bookmark_provider.h" | 5 #include "chrome/browser/autocomplete/bookmark_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 using bookmarks::BookmarkMatch; | 26 using bookmarks::BookmarkMatch; |
27 | 27 |
28 // The bookmark corpus against which we will simulate searches. | 28 // The bookmark corpus against which we will simulate searches. |
29 struct BookmarksTestInfo { | 29 struct BookmarksTestInfo { |
30 std::string title; | 30 std::string title; |
31 std::string url; | 31 std::string url; |
32 } bookmark_provider_test_data[] = { | 32 } bookmark_provider_test_data[] = { |
33 { "abc def", "http://www.catsanddogs.com/a" }, | 33 { "abc def", "http://www.catsanddogs.com/a" }, |
34 { "abcde", "http://www.catsanddogs.com/b" }, | 34 { "abcde", "http://www.catsanddogs.com/b" }, |
35 { "abcdef", "http://www.catsanddogs.com/c" }, | 35 { "abcdef", "http://www.catsanddogs.com/c" }, |
36 { "a definition", "http://www.catsanddogs.com/d" }, | 36 { "carry carbon carefully", "http://www.catsanddogs.com/d" }, |
37 { "carry carbon carefully", "http://www.catsanddogs.com/e" }, | 37 { "a definition", "http://www.catsanddogs.com/e" }, |
38 { "ghi jkl", "http://www.catsanddogs.com/f" }, | 38 { "ghi jkl", "http://www.catsanddogs.com/f" }, |
39 { "jkl ghi", "http://www.catsanddogs.com/g" }, | 39 { "jkl ghi", "http://www.catsanddogs.com/g" }, |
40 { "frankly frankly frank", "http://www.catsanddogs.com/h" }, | 40 { "frankly frankly frank", "http://www.catsanddogs.com/h" }, |
41 { "foobar foobar", "http://www.foobar.com/" }, | 41 { "foobar foobar", "http://www.foobar.com/" }, |
42 { "domain", "http://www.domain.com/http/" }, | 42 { "domain", "http://www.domain.com/http/" }, |
43 { "repeat", "http://www.repeat.com/1/repeat/2/" }, | 43 { "repeat", "http://www.repeat.com/1/repeat/2/" }, |
44 // For testing inline_autocompletion. | 44 // For testing inline_autocompletion. |
45 { "http://blah.com/", "http://blah.com/" }, | 45 { "http://blah.com/", "http://blah.com/" }, |
46 { "http://fiddle.com/", "http://fiddle.com/" }, | 46 { "http://fiddle.com/", "http://fiddle.com/" }, |
47 { "http://www.www.com/", "http://www.www.com/" }, | 47 { "http://www.www.com/", "http://www.www.com/" }, |
48 { "chrome://version", "chrome://version" }, | 48 { "chrome://version", "chrome://version" }, |
49 { "chrome://omnibox", "chrome://omnibox" }, | 49 { "chrome://omnibox", "chrome://omnibox" }, |
50 // For testing ranking with different URLs. | 50 // For testing ranking with different URLs. |
51 {"achlorhydric featherheads resuscitates mockingbirds", | 51 {"achlorhydric featherheads resuscitates mockingbirds", |
52 "http://www.featherheads.com/a" }, | 52 "http://www.manylongwords.com/1a" }, |
53 {"achlorhydric mockingbirds resuscitates featherhead", | 53 {"achlorhydric mockingbirds resuscitates featherhead", |
54 "http://www.featherheads.com/b" }, | 54 "http://www.manylongwords.com/2b" }, |
55 {"featherhead resuscitates achlorhydric mockingbirds", | 55 {"featherhead resuscitates achlorhydric mockingbirds", |
56 "http://www.featherheads.com/c" }, | 56 "http://www.manylongwords.com/3c" }, |
57 {"mockingbirds resuscitates featherheads achlorhydric", | 57 {"mockingbirds resuscitates featherheads achlorhydric", |
58 "http://www.featherheads.com/d" }, | 58 "http://www.manylongwords.com/4d" }, |
59 // For testing URL boosting. | 59 // For testing URL boosting. (URLs referenced multiple times are boosted.) |
60 {"burning worms #1", "http://www.burned.com/" }, | 60 {"burning worms #1", "http://www.burns.com/" }, |
61 {"burning worms #2", "http://www.worms.com/" }, | 61 {"burning worms #2", "http://www.worms.com/" }, |
62 {"worming burns #10", "http://www.burned.com/" }, | 62 {"worming burns #10", "http://www.burns.com/" }, |
63 {"worming burns #20", "http://www.worms.com/" }, | |
64 {"jive music", "http://www.worms.com/" }, | |
65 }; | 63 }; |
66 | 64 |
67 class BookmarkProviderTest : public testing::Test { | 65 class BookmarkProviderTest : public testing::Test { |
68 public: | 66 public: |
69 BookmarkProviderTest(); | 67 BookmarkProviderTest(); |
70 | 68 |
71 protected: | 69 protected: |
72 virtual void SetUp() OVERRIDE; | 70 virtual void SetUp() OVERRIDE; |
73 | 71 |
74 test::TestBookmarkClient client_; | 72 test::TestBookmarkClient client_; |
75 scoped_ptr<TestingProfile> profile_; | 73 scoped_ptr<TestingProfile> profile_; |
76 scoped_ptr<BookmarkModel> model_; | 74 scoped_ptr<BookmarkModel> model_; |
77 scoped_refptr<BookmarkProvider> provider_; | 75 scoped_refptr<BookmarkProvider> provider_; |
78 | 76 |
79 private: | 77 private: |
80 DISALLOW_COPY_AND_ASSIGN(BookmarkProviderTest); | 78 DISALLOW_COPY_AND_ASSIGN(BookmarkProviderTest); |
81 }; | 79 }; |
82 | 80 |
83 BookmarkProviderTest::BookmarkProviderTest() { | 81 BookmarkProviderTest::BookmarkProviderTest() { |
84 model_ = client_.CreateModel(false); | 82 model_ = client_.CreateModel(); |
85 } | 83 } |
86 | 84 |
87 void BookmarkProviderTest::SetUp() { | 85 void BookmarkProviderTest::SetUp() { |
88 profile_.reset(new TestingProfile()); | 86 profile_.reset(new TestingProfile()); |
89 DCHECK(profile_.get()); | 87 DCHECK(profile_.get()); |
90 provider_ = new BookmarkProvider(profile_.get()); | 88 provider_ = new BookmarkProvider(profile_.get()); |
91 DCHECK(provider_.get()); | 89 DCHECK(provider_.get()); |
92 provider_->set_bookmark_model_for_testing(model_.get()); | 90 provider_->set_bookmark_model_for_testing(model_.get()); |
93 | 91 |
94 const BookmarkNode* other_node = model_->other_node(); | 92 const BookmarkNode* other_node = model_->other_node(); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 {{0, 3}, {0, 0}}, | 224 {{0, 3}, {0, 0}}, |
227 {{0, 3}, {0, 0}}}}, | 225 {{0, 3}, {0, 0}}}}, |
228 {"abcde", 2, {{{0, 5}, {0, 0}}, | 226 {"abcde", 2, {{{0, 5}, {0, 0}}, |
229 {{0, 5}, {0, 0}}}}, | 227 {{0, 5}, {0, 0}}}}, |
230 {"foo bar", 0, {{{0, 0}}}}, | 228 {"foo bar", 0, {{{0, 0}}}}, |
231 {"fooey bark", 0, {{{0, 0}}}}, | 229 {"fooey bark", 0, {{{0, 0}}}}, |
232 {"def", 2, {{{2, 5}, {0, 0}}, | 230 {"def", 2, {{{2, 5}, {0, 0}}, |
233 {{4, 7}, {0, 0}}}}, | 231 {{4, 7}, {0, 0}}}}, |
234 {"ghi jkl", 2, {{{0, 3}, {4, 7}, {0, 0}}, | 232 {"ghi jkl", 2, {{{0, 3}, {4, 7}, {0, 0}}, |
235 {{0, 3}, {4, 7}, {0, 0}}}}, | 233 {{0, 3}, {4, 7}, {0, 0}}}}, |
236 // NB: GetBookmarksWithTitlesMatching(...) uses exact match for "a". | 234 // NB: GetBookmarksMatching(...) uses exact match for "a" in title or URL. |
237 {"a", 1, {{{0, 1}, {0, 0}}}}, | 235 {"a", 2, {{{0, 1}, {0, 0}}, |
| 236 {{0, 0}}}}, |
238 {"a d", 0, {{{0, 0}}}}, | 237 {"a d", 0, {{{0, 0}}}}, |
239 {"carry carbon", 1, {{{0, 5}, {6, 12}, {0, 0}}}}, | 238 {"carry carbon", 1, {{{0, 5}, {6, 12}, {0, 0}}}}, |
240 // NB: GetBookmarksWithTitlesMatching(...) sorts the match positions. | 239 // NB: GetBookmarksMatching(...) sorts the match positions. |
241 {"carbon carry", 1, {{{0, 5}, {6, 12}, {0, 0}}}}, | 240 {"carbon carry", 1, {{{0, 5}, {6, 12}, {0, 0}}}}, |
242 {"arbon", 0, {{{0, 0}}}}, | 241 {"arbon", 0, {{{0, 0}}}}, |
243 {"ar", 0, {{{0, 0}}}}, | 242 {"ar", 0, {{{0, 0}}}}, |
244 {"arry", 0, {{{0, 0}}}}, | 243 {"arry", 0, {{{0, 0}}}}, |
245 // Quoted terms are single terms. | 244 // Quoted terms are single terms. |
246 {"\"carry carbon\"", 1, {{{0, 12}, {0, 0}}}}, | 245 {"\"carry carbon\"", 1, {{{0, 12}, {0, 0}}}}, |
247 {"\"carry carbon\" care", 1, {{{0, 12}, {13, 17}, {0, 0}}}}, | 246 {"\"carry carbon\" care", 1, {{{0, 12}, {13, 17}, {0, 0}}}}, |
248 // Quoted terms require complete word matches. | 247 // Quoted terms require complete word matches. |
249 {"\"carry carbo\"", 0, {{{0, 0}}}}, | 248 {"\"carry carbo\"", 0, {{{0, 0}}}}, |
250 // This set uses duplicated and/or overlaps search terms in the title. | 249 // This set uses duplicated and/or overlaps search terms in the title. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 "achlorhydric featherheads resuscitates mockingbirds", | 314 "achlorhydric featherheads resuscitates mockingbirds", |
316 "featherhead resuscitates achlorhydric mockingbirds"}}, | 315 "featherhead resuscitates achlorhydric mockingbirds"}}, |
317 {"achlorhydric featherheads", | 316 {"achlorhydric featherheads", |
318 2, {"achlorhydric featherheads resuscitates mockingbirds", | 317 2, {"achlorhydric featherheads resuscitates mockingbirds", |
319 "mockingbirds resuscitates featherheads achlorhydric", | 318 "mockingbirds resuscitates featherheads achlorhydric", |
320 ""}}, | 319 ""}}, |
321 {"mockingbirds resuscitates", | 320 {"mockingbirds resuscitates", |
322 3, {"mockingbirds resuscitates featherheads achlorhydric", | 321 3, {"mockingbirds resuscitates featherheads achlorhydric", |
323 "achlorhydric mockingbirds resuscitates featherhead", | 322 "achlorhydric mockingbirds resuscitates featherhead", |
324 "featherhead resuscitates achlorhydric mockingbirds"}}, | 323 "featherhead resuscitates achlorhydric mockingbirds"}}, |
325 // Ranking of exact-word matches with URL boost. | 324 // Ranking of exact-word matches with URL boosts. |
326 {"worms", 2, {"burning worms #2", // boosted | 325 {"worms", 2, {"burning worms #1", // boosted |
327 "burning worms #1", // not boosted | 326 "burning worms #2", // not boosted |
328 ""}}, | 327 ""}}, |
329 // Ranking of prefix matches with URL boost. Note that a query of | 328 // Ranking of prefix matches with URL boost. |
330 // "worm burn" will have the same results. | 329 {"burn worm", 3, {"burning worms #1", // boosted |
331 {"burn worm", 3, {"burning worms #2", // boosted | 330 "worming burns #10", // boosted but longer title |
332 "worming burns #20", // boosted | 331 "burning worms #2"}}, // not boosted |
333 "burning worms #1"}}, // not boosted but shorter | 332 // A query of "worm burn" will have the same results. |
| 333 {"worm burn", 3, {"burning worms #1", // boosted |
| 334 "worming burns #10", // boosted but longer title |
| 335 "burning worms #2"}}, // not boosted |
334 }; | 336 }; |
335 | 337 |
336 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { | 338 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { |
337 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 339 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
338 base::string16::npos, base::string16(), GURL(), | 340 base::string16::npos, base::string16(), GURL(), |
339 metrics::OmniboxEventProto::INVALID_SPEC, false, | 341 metrics::OmniboxEventProto::INVALID_SPEC, false, |
340 false, false, true, | 342 false, false, true, |
341 ChromeAutocompleteSchemeClassifier(profile_.get())); | 343 ChromeAutocompleteSchemeClassifier(profile_.get())); |
342 provider_->Start(input, false); | 344 provider_->Start(input, false); |
343 const ACMatches& matches(provider_->matches()); | 345 const ACMatches& matches(provider_->matches()); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 { "foo http", "http://www.foobar.com", "0:3,4:1,11:3,14:1" }, | 427 { "foo http", "http://www.foobar.com", "0:3,4:1,11:3,14:1" }, |
426 { "blah", "blah.com", "0:3,4:1" }, | 428 { "blah", "blah.com", "0:3,4:1" }, |
427 { "http blah", "http://blah.com", "0:3,4:1,7:3,11:1" }, | 429 { "http blah", "http://blah.com", "0:3,4:1,7:3,11:1" }, |
428 { "dom", "www.domain.com/http/", "0:1,4:3,7:1" }, | 430 { "dom", "www.domain.com/http/", "0:1,4:3,7:1" }, |
429 { "dom http", "http://www.domain.com/http/", | 431 { "dom http", "http://www.domain.com/http/", |
430 "0:3,4:1,11:3,14:1,22:3,26:1" }, | 432 "0:3,4:1,11:3,14:1,22:3,26:1" }, |
431 { "rep", "www.repeat.com/1/repeat/2/", "0:1,4:3,7:1,17:3,20:1" }, | 433 { "rep", "www.repeat.com/1/repeat/2/", "0:1,4:3,7:1,17:3,20:1" }, |
432 { "versi", "chrome://version", "0:1,9:3,14:1" } | 434 { "versi", "chrome://version", "0:1,9:3,14:1" } |
433 }; | 435 }; |
434 | 436 |
435 // Reload the bookmarks index with |index_urls| == true. | |
436 model_ = client_.CreateModel(true); | |
437 SetUp(); | |
438 | |
439 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { | 437 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { |
440 std::string description = "for query=" + query_data[i].query; | 438 std::string description = "for query=" + query_data[i].query; |
441 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 439 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
442 base::string16::npos, base::string16(), GURL(), | 440 base::string16::npos, base::string16(), GURL(), |
443 metrics::OmniboxEventProto::INVALID_SPEC, false, | 441 metrics::OmniboxEventProto::INVALID_SPEC, false, |
444 false, false, true, | 442 false, false, true, |
445 ChromeAutocompleteSchemeClassifier(profile_.get())); | 443 ChromeAutocompleteSchemeClassifier(profile_.get())); |
446 provider_->Start(input, false); | 444 provider_->Start(input, false); |
447 const ACMatches& matches(provider_->matches()); | 445 const ACMatches& matches(provider_->matches()); |
448 ASSERT_EQ(1U, matches.size()) << description; | 446 ASSERT_EQ(1U, matches.size()) << description; |
(...skipping 11 matching lines...) Expand all Loading... |
460 ASSERT_EQ(2U, chunks.size()) << description; | 458 ASSERT_EQ(2U, chunks.size()) << description; |
461 size_t offset; | 459 size_t offset; |
462 EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description; | 460 EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description; |
463 EXPECT_EQ(offset, match.contents_class[i].offset) << description; | 461 EXPECT_EQ(offset, match.contents_class[i].offset) << description; |
464 int style; | 462 int style; |
465 EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description; | 463 EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description; |
466 EXPECT_EQ(style, match.contents_class[i].style) << description; | 464 EXPECT_EQ(style, match.contents_class[i].style) << description; |
467 } | 465 } |
468 } | 466 } |
469 } | 467 } |
OLD | NEW |