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/history_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE; | 145 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE; |
146 | 146 |
147 protected: | 147 protected: |
148 static BrowserContextKeyedService* CreateTemplateURLService( | 148 static BrowserContextKeyedService* CreateTemplateURLService( |
149 content::BrowserContext* profile) { | 149 content::BrowserContext* profile) { |
150 return new TemplateURLService(static_cast<Profile*>(profile)); | 150 return new TemplateURLService(static_cast<Profile*>(profile)); |
151 } | 151 } |
152 | 152 |
153 // testing::Test | 153 // testing::Test |
154 virtual void SetUp() { | 154 virtual void SetUp() { |
155 SetUpImpl(false); | 155 ASSERT_TRUE(SetUpImpl(false)); |
156 } | 156 } |
157 virtual void TearDown(); | 157 virtual void TearDown(); |
158 | 158 |
159 // Does the real setup. | 159 // Does the real setup. |
160 void SetUpImpl(bool no_db); | 160 bool SetUpImpl(bool no_db) WARN_UNUSED_RESULT; |
161 | 161 |
162 // Fills test data into the history system. | 162 // Fills test data into the history system. |
163 void FillData(); | 163 void FillData(); |
164 | 164 |
165 // Runs an autocomplete query on |text| and checks to see that the returned | 165 // Runs an autocomplete query on |text| and checks to see that the returned |
166 // results' destination URLs match those provided. Also allows checking | 166 // results' destination URLs match those provided. Also allows checking |
167 // that the input type was identified correctly. | 167 // that the input type was identified correctly. |
168 void RunTest(const string16 text, | 168 void RunTest(const string16 text, |
169 const string16& desired_tld, | 169 const string16& desired_tld, |
170 bool prevent_inline_autocomplete, | 170 bool prevent_inline_autocomplete, |
(...skipping 17 matching lines...) Expand all Loading... |
188 scoped_ptr<TestingProfile> profile_; | 188 scoped_ptr<TestingProfile> profile_; |
189 HistoryService* history_service_; | 189 HistoryService* history_service_; |
190 scoped_refptr<HistoryURLProvider> autocomplete_; | 190 scoped_refptr<HistoryURLProvider> autocomplete_; |
191 // Should the matches be sorted and duplicates removed? | 191 // Should the matches be sorted and duplicates removed? |
192 bool sort_matches_; | 192 bool sort_matches_; |
193 }; | 193 }; |
194 | 194 |
195 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest { | 195 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest { |
196 protected: | 196 protected: |
197 virtual void SetUp() { | 197 virtual void SetUp() { |
198 SetUpImpl(true); | 198 ASSERT_TRUE(SetUpImpl(true)); |
199 } | 199 } |
200 }; | 200 }; |
201 | 201 |
202 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { | 202 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { |
203 if (autocomplete_->done()) | 203 if (autocomplete_->done()) |
204 base::MessageLoop::current()->Quit(); | 204 base::MessageLoop::current()->Quit(); |
205 } | 205 } |
206 | 206 |
207 void HistoryURLProviderTest::SetUpImpl(bool no_db) { | 207 bool HistoryURLProviderTest::SetUpImpl(bool no_db) { |
208 profile_.reset(new TestingProfile()); | 208 profile_.reset(new TestingProfile()); |
209 profile_->CreateHistoryService(true, no_db); | 209 if (!(profile_->CreateHistoryService(true, no_db))) |
| 210 return false; |
210 if (!no_db) { | 211 if (!no_db) { |
211 profile_->BlockUntilHistoryProcessesPendingRequests(); | 212 profile_->BlockUntilHistoryProcessesPendingRequests(); |
212 profile_->BlockUntilHistoryIndexIsRefreshed(); | 213 profile_->BlockUntilHistoryIndexIsRefreshed(); |
213 } | 214 } |
214 history_service_ = | 215 history_service_ = |
215 HistoryServiceFactory::GetForProfile(profile_.get(), | 216 HistoryServiceFactory::GetForProfile(profile_.get(), |
216 Profile::EXPLICIT_ACCESS); | 217 Profile::EXPLICIT_ACCESS); |
217 | 218 |
218 autocomplete_ = new HistoryURLProvider(this, profile_.get(), "en-US,en,ko"); | 219 autocomplete_ = new HistoryURLProvider(this, profile_.get(), "en-US,en,ko"); |
219 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 220 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
220 profile_.get(), &HistoryURLProviderTest::CreateTemplateURLService); | 221 profile_.get(), &HistoryURLProviderTest::CreateTemplateURLService); |
221 FillData(); | 222 FillData(); |
| 223 return true; |
222 } | 224 } |
223 | 225 |
224 void HistoryURLProviderTest::TearDown() { | 226 void HistoryURLProviderTest::TearDown() { |
225 autocomplete_ = NULL; | 227 autocomplete_ = NULL; |
226 } | 228 } |
227 | 229 |
228 void HistoryURLProviderTest::FillData() { | 230 void HistoryURLProviderTest::FillData() { |
229 // All visits are a long time ago (some tests require this since we do some | 231 // All visits are a long time ago (some tests require this since we do some |
230 // special logic for things visited very recently). Note that this time must | 232 // special logic for things visited very recently). Note that this time must |
231 // be more recent than the "archived history" threshold for the data to go | 233 // be more recent than the "archived history" threshold for the data to go |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 EXPECT_EQ(test_cases[i].offsets[match_index], | 846 EXPECT_EQ(test_cases[i].offsets[match_index], |
845 match.contents_class[match_index].offset); | 847 match.contents_class[match_index].offset); |
846 EXPECT_EQ(ACMatchClassification::URL | | 848 EXPECT_EQ(ACMatchClassification::URL | |
847 (match_index == test_cases[i].match_classification_index ? | 849 (match_index == test_cases[i].match_classification_index ? |
848 ACMatchClassification::MATCH : 0), | 850 ACMatchClassification::MATCH : 0), |
849 match.contents_class[match_index].style); | 851 match.contents_class[match_index].style); |
850 } | 852 } |
851 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]); | 853 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]); |
852 } | 854 } |
853 } | 855 } |
OLD | NEW |