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/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 16 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
17 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 17 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
18 #include "chrome/browser/bookmarks/bookmark_model.h" | 18 #include "chrome/browser/bookmarks/bookmark_model.h" |
19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
20 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 21 #include "content/public/test/test_browser_thread_bundle.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 // The bookmark corpus against which we will simulate searches. | 24 // The bookmark corpus against which we will simulate searches. |
24 struct BookmarksTestInfo { | 25 struct BookmarksTestInfo { |
25 std::string title; | 26 std::string title; |
26 std::string url; | 27 std::string url; |
27 } bookmark_provider_test_data[] = { | 28 } bookmark_provider_test_data[] = { |
28 { "abc def", "http://www.catsanddogs.com/a" }, | 29 { "abc def", "http://www.catsanddogs.com/a" }, |
29 { "abcde", "http://www.catsanddogs.com/b" }, | 30 { "abcde", "http://www.catsanddogs.com/b" }, |
30 { "abcdef", "http://www.catsanddogs.com/c" }, | 31 { "abcdef", "http://www.catsanddogs.com/c" }, |
(...skipping 24 matching lines...) Expand all Loading... |
55 public AutocompleteProviderListener { | 56 public AutocompleteProviderListener { |
56 public: | 57 public: |
57 BookmarkProviderTest() : model_(new BookmarkModel(NULL)) {} | 58 BookmarkProviderTest() : model_(new BookmarkModel(NULL)) {} |
58 | 59 |
59 // AutocompleteProviderListener: Not called. | 60 // AutocompleteProviderListener: Not called. |
60 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE {} | 61 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE {} |
61 | 62 |
62 protected: | 63 protected: |
63 virtual void SetUp() OVERRIDE; | 64 virtual void SetUp() OVERRIDE; |
64 | 65 |
| 66 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; |
65 scoped_ptr<TestingProfile> profile_; | 67 scoped_ptr<TestingProfile> profile_; |
66 scoped_ptr<BookmarkModel> model_; | 68 scoped_ptr<BookmarkModel> model_; |
67 scoped_refptr<BookmarkProvider> provider_; | 69 scoped_refptr<BookmarkProvider> provider_; |
68 | 70 |
69 private: | 71 private: |
70 DISALLOW_COPY_AND_ASSIGN(BookmarkProviderTest); | 72 DISALLOW_COPY_AND_ASSIGN(BookmarkProviderTest); |
71 }; | 73 }; |
72 | 74 |
73 void BookmarkProviderTest::SetUp() { | 75 void BookmarkProviderTest::SetUp() { |
| 76 thread_bundle_.reset(new content::TestBrowserThreadBundle()); |
74 profile_.reset(new TestingProfile()); | 77 profile_.reset(new TestingProfile()); |
75 DCHECK(profile_.get()); | 78 DCHECK(profile_.get()); |
76 provider_ = new BookmarkProvider(this, profile_.get()); | 79 provider_ = new BookmarkProvider(this, profile_.get()); |
77 DCHECK(provider_.get()); | 80 DCHECK(provider_.get()); |
78 provider_->set_bookmark_model_for_testing(model_.get()); | 81 provider_->set_bookmark_model_for_testing(model_.get()); |
79 | 82 |
80 const BookmarkNode* other_node = model_->other_node(); | 83 const BookmarkNode* other_node = model_->other_node(); |
81 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(bookmark_provider_test_data); ++i) { | 84 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(bookmark_provider_test_data); ++i) { |
82 const BookmarksTestInfo& cur(bookmark_provider_test_data[i]); | 85 const BookmarksTestInfo& cur(bookmark_provider_test_data[i]); |
83 const GURL url(cur.url); | 86 const GURL url(cur.url); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 << query_data[i].query << "'."; | 338 << query_data[i].query << "'."; |
336 if (j >= matches.size()) | 339 if (j >= matches.size()) |
337 continue; | 340 continue; |
338 EXPECT_EQ(query_data[i].matches[j], UTF16ToUTF8(matches[j].description)) | 341 EXPECT_EQ(query_data[i].matches[j], UTF16ToUTF8(matches[j].description)) |
339 << " Mismatch at [" << base::IntToString(j) << "] for query '" | 342 << " Mismatch at [" << base::IntToString(j) << "] for query '" |
340 << query_data[i].query << "'."; | 343 << query_data[i].query << "'."; |
341 EXPECT_FALSE(matches[j].allowed_to_be_default_match); | 344 EXPECT_FALSE(matches[j].allowed_to_be_default_match); |
342 } | 345 } |
343 } | 346 } |
344 } | 347 } |
OLD | NEW |