| 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 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 17 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 18 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 18 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
| 19 #include "chrome/browser/bookmarks/bookmark_model.h" | 19 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 20 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 20 #include "chrome/browser/bookmarks/test_bookmark_client.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 22 #include "components/bookmarks/core/browser/bookmark_match.h" | 22 #include "components/bookmarks/core/browser/bookmark_match.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 // The bookmark corpus against which we will simulate searches. | 25 // The bookmark corpus against which we will simulate searches. |
| 26 struct BookmarksTestInfo { | 26 struct BookmarksTestInfo { |
| 27 std::string title; | 27 std::string title; |
| 28 std::string url; | 28 std::string url; |
| 29 } bookmark_provider_test_data[] = { | 29 } bookmark_provider_test_data[] = { |
| 30 { "abc def", "http://www.catsanddogs.com/a" }, | 30 { "abc def", "http://www.catsanddogs.com/a" }, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 public AutocompleteProviderListener { | 65 public AutocompleteProviderListener { |
| 66 public: | 66 public: |
| 67 BookmarkProviderTest(); | 67 BookmarkProviderTest(); |
| 68 | 68 |
| 69 // AutocompleteProviderListener: Not called. | 69 // AutocompleteProviderListener: Not called. |
| 70 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE {} | 70 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE {} |
| 71 | 71 |
| 72 protected: | 72 protected: |
| 73 virtual void SetUp() OVERRIDE; | 73 virtual void SetUp() OVERRIDE; |
| 74 | 74 |
| 75 test::TestBookmarkClient client_; |
| 75 scoped_ptr<TestingProfile> profile_; | 76 scoped_ptr<TestingProfile> profile_; |
| 76 scoped_ptr<BookmarkModel> model_; | 77 scoped_ptr<BookmarkModel> model_; |
| 77 scoped_refptr<BookmarkProvider> provider_; | 78 scoped_refptr<BookmarkProvider> provider_; |
| 78 | 79 |
| 79 private: | 80 private: |
| 80 DISALLOW_COPY_AND_ASSIGN(BookmarkProviderTest); | 81 DISALLOW_COPY_AND_ASSIGN(BookmarkProviderTest); |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 BookmarkProviderTest::BookmarkProviderTest() { | 84 BookmarkProviderTest::BookmarkProviderTest() { |
| 84 model_.reset(new BookmarkModel(NULL, false)); | 85 model_ = client_.CreateModel(false); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void BookmarkProviderTest::SetUp() { | 88 void BookmarkProviderTest::SetUp() { |
| 88 profile_.reset(new TestingProfile()); | 89 profile_.reset(new TestingProfile()); |
| 89 DCHECK(profile_.get()); | 90 DCHECK(profile_.get()); |
| 90 provider_ = new BookmarkProvider(this, profile_.get()); | 91 provider_ = new BookmarkProvider(this, profile_.get()); |
| 91 DCHECK(provider_.get()); | 92 DCHECK(provider_.get()); |
| 92 provider_->set_bookmark_model_for_testing(model_.get()); | 93 provider_->set_bookmark_model_for_testing(model_.get()); |
| 93 | 94 |
| 94 const BookmarkNode* other_node = model_->other_node(); | 95 const BookmarkNode* other_node = model_->other_node(); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 { "blah", "blah.com", "0:3,4:1" }, | 424 { "blah", "blah.com", "0:3,4:1" }, |
| 424 { "http blah", "http://blah.com", "0:3,4:1,7:3,11:1" }, | 425 { "http blah", "http://blah.com", "0:3,4:1,7:3,11:1" }, |
| 425 { "dom", "www.domain.com/http/", "0:1,4:3,7:1" }, | 426 { "dom", "www.domain.com/http/", "0:1,4:3,7:1" }, |
| 426 { "dom http", "http://www.domain.com/http/", | 427 { "dom http", "http://www.domain.com/http/", |
| 427 "0:3,4:1,11:3,14:1,22:3,26:1" }, | 428 "0:3,4:1,11:3,14:1,22:3,26:1" }, |
| 428 { "rep", "www.repeat.com/1/repeat/2/", "0:1,4:3,7:1,17:3,20:1" }, | 429 { "rep", "www.repeat.com/1/repeat/2/", "0:1,4:3,7:1,17:3,20:1" }, |
| 429 { "versi", "chrome://version", "0:1,9:3,14:1" } | 430 { "versi", "chrome://version", "0:1,9:3,14:1" } |
| 430 }; | 431 }; |
| 431 | 432 |
| 432 // Reload the bookmarks index with |index_urls| == true. | 433 // Reload the bookmarks index with |index_urls| == true. |
| 433 model_.reset(new BookmarkModel(NULL, true)); | 434 model_ = client_.CreateModel(true); |
| 434 SetUp(); | 435 SetUp(); |
| 435 | 436 |
| 436 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { | 437 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { |
| 437 std::string description = "for query=" + query_data[i].query; | 438 std::string description = "for query=" + query_data[i].query; |
| 438 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 439 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
| 439 base::string16::npos, base::string16(), GURL(), | 440 base::string16::npos, base::string16(), GURL(), |
| 440 AutocompleteInput::INVALID_SPEC, false, false, | 441 AutocompleteInput::INVALID_SPEC, false, false, |
| 441 false, true); | 442 false, true); |
| 442 provider_->Start(input, false); | 443 provider_->Start(input, false); |
| 443 const ACMatches& matches(provider_->matches()); | 444 const ACMatches& matches(provider_->matches()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 456 ASSERT_EQ(2U, chunks.size()) << description; | 457 ASSERT_EQ(2U, chunks.size()) << description; |
| 457 size_t offset; | 458 size_t offset; |
| 458 EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description; | 459 EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description; |
| 459 EXPECT_EQ(offset, match.contents_class[i].offset) << description; | 460 EXPECT_EQ(offset, match.contents_class[i].offset) << description; |
| 460 int style; | 461 int style; |
| 461 EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description; | 462 EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description; |
| 462 EXPECT_EQ(style, match.contents_class[i].style) << description; | 463 EXPECT_EQ(style, match.contents_class[i].style) << description; |
| 463 } | 464 } |
| 464 } | 465 } |
| 465 } | 466 } |
| OLD | NEW |