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