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

Side by Side Diff: chrome/browser/search_engines/template_url_service_sync_unittest.cc

Issue 263823007: Handle TemplateURLService load failure better (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/memory/scoped_vector.h" 6 #include "base/memory/scoped_vector.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // Creates a new TemplateURL copying the fields of |turl| but replacing 206 // Creates a new TemplateURL copying the fields of |turl| but replacing
207 // the |url| and |guid| and initializing the date_created and last_modified 207 // the |url| and |guid| and initializing the date_created and last_modified
208 // timestamps to a default value of 100. The caller owns the returned 208 // timestamps to a default value of 100. The caller owns the returned
209 // TemplateURL*. 209 // TemplateURL*.
210 TemplateURL* CopyTemplateURL(const TemplateURLData* turl, 210 TemplateURL* CopyTemplateURL(const TemplateURLData* turl,
211 const std::string& url, 211 const std::string& url,
212 const std::string& guid); 212 const std::string& guid);
213 213
214 protected: 214 protected:
215 // We keep two TemplateURLServices to test syncing between them. 215 // We keep two TemplateURLServices to test syncing between them.
216 // Unfortunately we can't have two separate TemplateURLServiceTestUtils, so we
217 // have to use lower-level classes for the second.
216 TemplateURLServiceTestUtil test_util_a_; 218 TemplateURLServiceTestUtil test_util_a_;
217 scoped_ptr<TestingProfile> profile_b_; 219 scoped_ptr<TestingProfile> profile_b_;
218 scoped_ptr<TemplateURLService> model_b_; 220 scoped_ptr<TemplateURLService> model_b_;
219 221
220 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. 222 // Our dummy ChangeProcessor used to inspect changes pushed to Sync.
221 scoped_ptr<TestChangeProcessor> sync_processor_; 223 scoped_ptr<TestChangeProcessor> sync_processor_;
222 scoped_ptr<syncer::SyncChangeProcessorWrapperForTest> sync_processor_wrapper_; 224 scoped_ptr<syncer::SyncChangeProcessorWrapperForTest> sync_processor_wrapper_;
223 225
224 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceSyncTest); 226 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceSyncTest);
225 }; 227 };
226 228
227 TemplateURLServiceSyncTest::TemplateURLServiceSyncTest() 229 TemplateURLServiceSyncTest::TemplateURLServiceSyncTest()
228 : sync_processor_(new TestChangeProcessor), 230 : sync_processor_(new TestChangeProcessor),
229 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest( 231 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest(
230 sync_processor_.get())) {} 232 sync_processor_.get())) {}
231 233
232 void TemplateURLServiceSyncTest::SetUp() { 234 void TemplateURLServiceSyncTest::SetUp() {
233 test_util_a_.SetUp(); 235 test_util_a_.SetUp();
234 // Use ChangeToLoadState() instead of VerifyLoad() so we don't actually pull 236 // Use ChangeToLoadState() instead of VerifyLoad() so we don't actually pull
235 // in the prepopulate data, which the sync tests don't care about (and would 237 // in the prepopulate data, which the sync tests don't care about (and would
236 // just foul them up). 238 // just foul them up).
237 test_util_a_.ChangeModelToLoadState(); 239 test_util_a_.ChangeModelToLoadState();
238 profile_b_.reset(new TestingProfile); 240 profile_b_.reset(new TestingProfile);
239 TemplateURLServiceFactory::GetInstance()-> 241 TemplateURLServiceFactory::GetInstance()->
240 RegisterUserPrefsOnBrowserContextForTest(profile_b_.get()); 242 RegisterUserPrefsOnBrowserContextForTest(profile_b_.get());
241 model_b_.reset(new TemplateURLService(profile_b_.get())); 243 model_b_.reset(new TemplateURLService(profile_b_.get()));
242 model_b_->Load(); 244 // These next three lines duplicate
245 // TemplateURLServiceTestUtil::ChangeModelToLoadState().
246 model_b_->ChangeToLoadedState();
247 model_b_->service_ = WebDataService::FromBrowserContext(profile_b_.get());
248 base::RunLoop().RunUntilIdle();
243 } 249 }
244 250
245 void TemplateURLServiceSyncTest::TearDown() { 251 void TemplateURLServiceSyncTest::TearDown() {
246 test_util_a_.TearDown(); 252 test_util_a_.TearDown();
247 } 253 }
248 254
249 scoped_ptr<syncer::SyncChangeProcessor> 255 scoped_ptr<syncer::SyncChangeProcessor>
250 TemplateURLServiceSyncTest::PassProcessor() { 256 TemplateURLServiceSyncTest::PassProcessor() {
251 return sync_processor_wrapper_.PassAs<syncer::SyncChangeProcessor>(); 257 return sync_processor_wrapper_.PassAs<syncer::SyncChangeProcessor>();
252 } 258 }
(...skipping 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after
2242 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( 2248 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing(
2243 syncer::SEARCH_ENGINES, list, PassProcessor(), 2249 syncer::SEARCH_ENGINES, list, PassProcessor(),
2244 CreateAndPassSyncErrorFactory()); 2250 CreateAndPassSyncErrorFactory());
2245 2251
2246 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default"); 2252 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default");
2247 EXPECT_TRUE(result_turl); 2253 EXPECT_TRUE(result_turl);
2248 EXPECT_EQ(default_turl->keyword(), result_turl->keyword()); 2254 EXPECT_EQ(default_turl->keyword(), result_turl->keyword());
2249 EXPECT_EQ(default_turl->short_name, result_turl->short_name()); 2255 EXPECT_EQ(default_turl->short_name, result_turl->short_name());
2250 EXPECT_EQ(default_turl->url(), result_turl->url()); 2256 EXPECT_EQ(default_turl->url(), result_turl->url());
2251 } 2257 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698