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 ASSERT_TRUE(SetUpImpl(false)); | 155 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 bool SetUpImpl(bool no_db) WARN_UNUSED_RESULT; | 160 void SetUpImpl(bool no_db); |
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 ASSERT_TRUE(SetUpImpl(true)); | 198 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 bool HistoryURLProviderTest::SetUpImpl(bool no_db) { | 207 void HistoryURLProviderTest::SetUpImpl(bool no_db) { |
208 profile_.reset(new TestingProfile()); | 208 profile_.reset(new TestingProfile()); |
209 if (!(profile_->CreateHistoryService(true, no_db))) | 209 profile_->CreateHistoryService(true, no_db); |
210 return false; | |
211 if (!no_db) { | 210 if (!no_db) { |
212 profile_->BlockUntilHistoryProcessesPendingRequests(); | 211 profile_->BlockUntilHistoryProcessesPendingRequests(); |
213 profile_->BlockUntilHistoryIndexIsRefreshed(); | 212 profile_->BlockUntilHistoryIndexIsRefreshed(); |
214 } | 213 } |
215 history_service_ = | 214 history_service_ = |
216 HistoryServiceFactory::GetForProfile(profile_.get(), | 215 HistoryServiceFactory::GetForProfile(profile_.get(), |
217 Profile::EXPLICIT_ACCESS); | 216 Profile::EXPLICIT_ACCESS); |
218 | 217 |
219 autocomplete_ = new HistoryURLProvider(this, profile_.get(), "en-US,en,ko"); | 218 autocomplete_ = new HistoryURLProvider(this, profile_.get(), "en-US,en,ko"); |
220 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 219 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
221 profile_.get(), &HistoryURLProviderTest::CreateTemplateURLService); | 220 profile_.get(), &HistoryURLProviderTest::CreateTemplateURLService); |
222 FillData(); | 221 FillData(); |
223 return true; | |
224 } | 222 } |
225 | 223 |
226 void HistoryURLProviderTest::TearDown() { | 224 void HistoryURLProviderTest::TearDown() { |
227 autocomplete_ = NULL; | 225 autocomplete_ = NULL; |
228 } | 226 } |
229 | 227 |
230 void HistoryURLProviderTest::FillData() { | 228 void HistoryURLProviderTest::FillData() { |
231 // All visits are a long time ago (some tests require this since we do some | 229 // All visits are a long time ago (some tests require this since we do some |
232 // special logic for things visited very recently). Note that this time must | 230 // special logic for things visited very recently). Note that this time must |
233 // be more recent than the "archived history" threshold for the data to go | 231 // 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... |
846 EXPECT_EQ(test_cases[i].offsets[match_index], | 844 EXPECT_EQ(test_cases[i].offsets[match_index], |
847 match.contents_class[match_index].offset); | 845 match.contents_class[match_index].offset); |
848 EXPECT_EQ(ACMatchClassification::URL | | 846 EXPECT_EQ(ACMatchClassification::URL | |
849 (match_index == test_cases[i].match_classification_index ? | 847 (match_index == test_cases[i].match_classification_index ? |
850 ACMatchClassification::MATCH : 0), | 848 ACMatchClassification::MATCH : 0), |
851 match.contents_class[match_index].style); | 849 match.contents_class[match_index].style); |
852 } | 850 } |
853 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]); | 851 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]); |
854 } | 852 } |
855 } | 853 } |
OLD | NEW |