Chromium Code Reviews| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/search_engines/template_url.h" | 9 #include "chrome/browser/search_engines/template_url.h" |
| 10 #include "chrome/browser/search_engines/template_url_service.h" | 10 #include "chrome/browser/search_engines/template_url_service.h" |
| 11 #include "chrome/browser/search_engines/template_url_service_factory.h" | 11 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 12 #include "chrome/browser/webdata/web_data_service_factory.h" | |
| 12 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/test/base/testing_pref_service.h" | 15 #include "chrome/test/base/testing_pref_service.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 17 #include "sync/protocol/search_engine_specifics.pb.h" | 18 #include "sync/protocol/search_engine_specifics.pb.h" |
| 18 #include "sync/protocol/sync.pb.h" | 19 #include "sync/protocol/sync.pb.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 using base::Time; | 22 using base::Time; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 public: | 154 public: |
| 154 typedef TemplateURLService::SyncDataMap SyncDataMap; | 155 typedef TemplateURLService::SyncDataMap SyncDataMap; |
| 155 | 156 |
| 156 TemplateURLServiceSyncTest() | 157 TemplateURLServiceSyncTest() |
| 157 : sync_processor_(new TestChangeProcessor), | 158 : sync_processor_(new TestChangeProcessor), |
| 158 sync_processor_delegate_(new SyncChangeProcessorDelegate( | 159 sync_processor_delegate_(new SyncChangeProcessorDelegate( |
| 159 sync_processor_.get())) {} | 160 sync_processor_.get())) {} |
| 160 | 161 |
| 161 virtual void SetUp() { | 162 virtual void SetUp() { |
| 162 profile_a_.reset(new TestingProfile); | 163 profile_a_.reset(new TestingProfile); |
| 164 WebDataServiceFactory::GetInstance()->SetTestingFactory( | |
| 165 profile_a_.get(), TemplateURLServiceSyncTest::BuildNull); | |
| 163 TemplateURLServiceFactory::GetInstance()->RegisterUserPrefsOnProfile( | 166 TemplateURLServiceFactory::GetInstance()->RegisterUserPrefsOnProfile( |
| 164 profile_a_.get()); | 167 profile_a_.get()); |
| 165 model_a_.reset(new TemplateURLService(profile_a_.get())); | 168 model_a_.reset(new TemplateURLService(profile_a_.get())); |
| 166 model_a_->Load(); | 169 model_a_->Load(); |
| 167 profile_b_.reset(new TestingProfile); | 170 profile_b_.reset(new TestingProfile); |
| 171 WebDataServiceFactory::GetInstance()->SetTestingFactory( | |
| 172 profile_b_.get(), TemplateURLServiceSyncTest::BuildNull); | |
| 168 TemplateURLServiceFactory::GetInstance()->RegisterUserPrefsOnProfile( | 173 TemplateURLServiceFactory::GetInstance()->RegisterUserPrefsOnProfile( |
| 169 profile_b_.get()); | 174 profile_b_.get()); |
| 170 model_b_.reset(new TemplateURLService(profile_b_.get())); | 175 model_b_.reset(new TemplateURLService(profile_b_.get())); |
| 171 model_b_->Load(); | 176 model_b_->Load(); |
| 172 } | 177 } |
| 173 | 178 |
| 174 virtual void TearDown() { } | 179 virtual void TearDown() { } |
| 175 | 180 |
| 176 TemplateURLService* model() { return model_a_.get(); } | 181 TemplateURLService* model() { return model_a_.get(); } |
| 177 // For readability, we redefine an accessor for Model A for use in tests that | 182 // For readability, we redefine an accessor for Model A for use in tests that |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | 293 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
| 289 | 294 |
| 290 return list; | 295 return list; |
| 291 } | 296 } |
| 292 | 297 |
| 293 // Syntactic sugar. | 298 // Syntactic sugar. |
| 294 TemplateURL* Deserialize(const SyncData& sync_data) { | 299 TemplateURL* Deserialize(const SyncData& sync_data) { |
| 295 return TemplateURLService::CreateTemplateURLFromSyncData(sync_data); | 300 return TemplateURLService::CreateTemplateURLFromSyncData(sync_data); |
| 296 } | 301 } |
| 297 | 302 |
| 303 // Build no service. | |
| 304 static scoped_refptr<RefcountedProfileKeyedService> BuildNull( | |
|
Peter Kasting
2012/03/27 18:18:25
Nit: It seems like this is something that should o
GeorgeY
2012/03/30 19:20:12
Done - removed
| |
| 305 Profile* profile) { | |
| 306 return NULL; | |
| 307 } | |
| 308 | |
| 298 protected: | 309 protected: |
| 299 // We keep two TemplateURLServices to test syncing between them. | 310 // We keep two TemplateURLServices to test syncing between them. |
| 300 scoped_ptr<TestingProfile> profile_a_; | 311 scoped_ptr<TestingProfile> profile_a_; |
| 301 scoped_ptr<TemplateURLService> model_a_; | 312 scoped_ptr<TemplateURLService> model_a_; |
| 302 scoped_ptr<TestingProfile> profile_b_; | 313 scoped_ptr<TestingProfile> profile_b_; |
| 303 scoped_ptr<TemplateURLService> model_b_; | 314 scoped_ptr<TemplateURLService> model_b_; |
| 304 | 315 |
| 305 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. | 316 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. |
| 306 scoped_ptr<TestChangeProcessor> sync_processor_; | 317 scoped_ptr<TestChangeProcessor> sync_processor_; |
| 307 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; | 318 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; |
| (...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1248 | 1259 |
| 1249 // The key1 entry should be a duplicate of the default. | 1260 // The key1 entry should be a duplicate of the default. |
| 1250 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1261 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1251 CreateInitialSyncData(), PassProcessor()); | 1262 CreateInitialSyncData(), PassProcessor()); |
| 1252 | 1263 |
| 1253 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1264 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1254 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); | 1265 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); |
| 1255 EXPECT_EQ(model()->GetDefaultSearchProvider(), | 1266 EXPECT_EQ(model()->GetDefaultSearchProvider(), |
| 1256 model()->GetTemplateURLForGUID("key1")); | 1267 model()->GetTemplateURLForGUID("key1")); |
| 1257 } | 1268 } |
| OLD | NEW |