OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/browser/autocomplete/autocomplete.h" | 8 #include "chrome/browser/autocomplete/autocomplete.h" |
9 #include "chrome/browser/autocomplete/history_contents_provider.h" | 9 #include "chrome/browser/autocomplete/history_contents_provider.h" |
| 10 #include "chrome/browser/chrome_thread.h" |
10 #include "chrome/browser/history/history.h" | 11 #include "chrome/browser/history/history.h" |
11 #include "chrome/test/testing_profile.h" | 12 #include "chrome/test/testing_profile.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 using base::Time; | 15 using base::Time; |
15 using base::TimeDelta; | 16 using base::TimeDelta; |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 struct TestEntry { | 20 struct TestEntry { |
20 const char* url; | 21 const char* url; |
21 const wchar_t* title; | 22 const wchar_t* title; |
22 const wchar_t* body; | 23 const wchar_t* body; |
23 } test_entries[] = { | 24 } test_entries[] = { |
24 {"http://www.google.com/1", L"PAGEONE 1", L"FOO some body text"}, | 25 {"http://www.google.com/1", L"PAGEONE 1", L"FOO some body text"}, |
25 {"http://www.google.com/2", L"PAGEONE 2", L"FOO some more blah blah"}, | 26 {"http://www.google.com/2", L"PAGEONE 2", L"FOO some more blah blah"}, |
26 {"http://www.google.com/3", L"PAGETHREE 3", L"BAR some hello world for you"}, | 27 {"http://www.google.com/3", L"PAGETHREE 3", L"BAR some hello world for you"}, |
27 }; | 28 }; |
28 | 29 |
29 class HistoryContentsProviderTest : public testing::Test, | 30 class HistoryContentsProviderTest : public testing::Test, |
30 public ACProviderListener { | 31 public ACProviderListener { |
31 public: | 32 public: |
| 33 HistoryContentsProviderTest() |
| 34 : ui_thread_(ChromeThread::UI, &message_loop_), |
| 35 file_thread_(ChromeThread::FILE, &message_loop_) {} |
32 | 36 |
33 void RunQuery(const AutocompleteInput& input, | 37 void RunQuery(const AutocompleteInput& input, |
34 bool minimal_changes) { | 38 bool minimal_changes) { |
35 provider_->Start(input, minimal_changes); | 39 provider_->Start(input, minimal_changes); |
36 | 40 |
37 // When we're waiting for asynchronous messages, we have to spin the message | 41 // When we're waiting for asynchronous messages, we have to spin the message |
38 // loop. This will be exited in the OnProviderUpdate function when complete. | 42 // loop. This will be exited in the OnProviderUpdate function when complete. |
39 if (!input.synchronous_only()) | 43 if (!input.synchronous_only()) |
40 MessageLoop::current()->Run(); | 44 MessageLoop::current()->Run(); |
41 } | 45 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 profile_.reset(NULL); | 84 profile_.reset(NULL); |
81 } | 85 } |
82 | 86 |
83 // ACProviderListener | 87 // ACProviderListener |
84 virtual void OnProviderUpdate(bool updated_matches) { | 88 virtual void OnProviderUpdate(bool updated_matches) { |
85 // When we quit, the test will get back control. | 89 // When we quit, the test will get back control. |
86 MessageLoop::current()->Quit(); | 90 MessageLoop::current()->Quit(); |
87 } | 91 } |
88 | 92 |
89 MessageLoopForUI message_loop_; | 93 MessageLoopForUI message_loop_; |
| 94 ChromeThread ui_thread_; |
| 95 ChromeThread file_thread_; |
90 | 96 |
91 std::wstring history_dir_; | 97 std::wstring history_dir_; |
92 | 98 |
93 scoped_ptr<TestingProfile> profile_; | 99 scoped_ptr<TestingProfile> profile_; |
94 scoped_refptr<HistoryContentsProvider> provider_; | 100 scoped_refptr<HistoryContentsProvider> provider_; |
95 }; | 101 }; |
96 | 102 |
97 TEST_F(HistoryContentsProviderTest, Body) { | 103 TEST_F(HistoryContentsProviderTest, Body) { |
98 AutocompleteInput input(L"FOO", std::wstring(), true, false, false); | 104 AutocompleteInput input(L"FOO", std::wstring(), true, false, false); |
99 RunQuery(input, false); | 105 RunQuery(input, false); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 ASSERT_EQ(2U, m3.size()); | 181 ASSERT_EQ(2U, m3.size()); |
176 if (bookmark_url == m3[0].destination_url) { | 182 if (bookmark_url == m3[0].destination_url) { |
177 EXPECT_EQ("http://www.google.com/3", m3[1].destination_url.spec()); | 183 EXPECT_EQ("http://www.google.com/3", m3[1].destination_url.spec()); |
178 } else { | 184 } else { |
179 EXPECT_EQ(bookmark_url, m3[1].destination_url); | 185 EXPECT_EQ(bookmark_url, m3[1].destination_url); |
180 EXPECT_EQ("http://www.google.com/3", m3[0].destination_url.spec()); | 186 EXPECT_EQ("http://www.google.com/3", m3[0].destination_url.spec()); |
181 } | 187 } |
182 } | 188 } |
183 | 189 |
184 } // namespace | 190 } // namespace |
OLD | NEW |