Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: chrome/browser/autocomplete/history_url_provider_unittest.cc

Issue 19616004: Add asserts to TestingProfile::CreateHistoryService to ensure files are deleted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Propigate CreateHistoryService return value properly Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 19 matching lines...) Expand all
190 scoped_ptr<TestingProfile> profile_; 190 scoped_ptr<TestingProfile> profile_;
191 HistoryService* history_service_; 191 HistoryService* history_service_;
192 scoped_refptr<HistoryURLProvider> autocomplete_; 192 scoped_refptr<HistoryURLProvider> autocomplete_;
193 // Should the matches be sorted and duplicates removed? 193 // Should the matches be sorted and duplicates removed?
194 bool sort_matches_; 194 bool sort_matches_;
195 }; 195 };
196 196
197 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest { 197 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest {
198 protected: 198 protected:
199 virtual void SetUp() { 199 virtual void SetUp() {
200 SetUpImpl(true); 200 ASSERT_TRUE(SetUpImpl(true));
201 } 201 }
202 }; 202 };
203 203
204 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { 204 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) {
205 if (autocomplete_->done()) 205 if (autocomplete_->done())
206 base::MessageLoop::current()->Quit(); 206 base::MessageLoop::current()->Quit();
207 } 207 }
208 208
209 void HistoryURLProviderTest::SetUpImpl(bool no_db) { 209 bool HistoryURLProviderTest::SetUpImpl(bool no_db) {
210 profile_.reset(new TestingProfile()); 210 profile_.reset(new TestingProfile());
211 profile_->CreateHistoryService(true, no_db); 211 if (!(profile_->CreateHistoryService(true, no_db)))
212 return false;
212 if (!no_db) { 213 if (!no_db) {
213 profile_->BlockUntilHistoryProcessesPendingRequests(); 214 profile_->BlockUntilHistoryProcessesPendingRequests();
214 profile_->BlockUntilHistoryIndexIsRefreshed(); 215 profile_->BlockUntilHistoryIndexIsRefreshed();
215 } 216 }
216 history_service_ = 217 history_service_ =
217 HistoryServiceFactory::GetForProfile(profile_.get(), 218 HistoryServiceFactory::GetForProfile(profile_.get(),
218 Profile::EXPLICIT_ACCESS); 219 Profile::EXPLICIT_ACCESS);
219 220
220 autocomplete_ = new HistoryURLProvider(this, profile_.get(), "en-US,en,ko"); 221 autocomplete_ = new HistoryURLProvider(this, profile_.get(), "en-US,en,ko");
221 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 222 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
222 profile_.get(), &HistoryURLProviderTest::CreateTemplateURLService); 223 profile_.get(), &HistoryURLProviderTest::CreateTemplateURLService);
223 FillData(); 224 FillData();
225 return true;
224 } 226 }
225 227
226 void HistoryURLProviderTest::TearDown() { 228 void HistoryURLProviderTest::TearDown() {
227 autocomplete_ = NULL; 229 autocomplete_ = NULL;
228 } 230 }
229 231
230 void HistoryURLProviderTest::FillData() { 232 void HistoryURLProviderTest::FillData() {
231 // All visits are a long time ago (some tests require this since we do some 233 // 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 234 // 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 235 // be more recent than the "archived history" threshold for the data to go
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 EXPECT_EQ(test_cases[i].offsets[match_index], 865 EXPECT_EQ(test_cases[i].offsets[match_index],
864 match.contents_class[match_index].offset); 866 match.contents_class[match_index].offset);
865 EXPECT_EQ(ACMatchClassification::URL | 867 EXPECT_EQ(ACMatchClassification::URL |
866 (match_index == test_cases[i].match_classification_index ? 868 (match_index == test_cases[i].match_classification_index ?
867 ACMatchClassification::MATCH : 0), 869 ACMatchClassification::MATCH : 0),
868 match.contents_class[match_index].style); 870 match.contents_class[match_index].style);
869 } 871 }
870 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]); 872 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]);
871 } 873 }
872 } 874 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698