| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
| 7 #include "base/optional.h" | 7 #include "base/optional.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "chrome/browser/sync/chrome_sync_client.h" | 9 #include "chrome/browser/sync/chrome_sync_client.h" |
| 10 #include "chrome/browser/sync/profile_sync_service_factory.h" | 10 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 194 |
| 195 class TwoClientUssSyncTest : public SyncTest { | 195 class TwoClientUssSyncTest : public SyncTest { |
| 196 public: | 196 public: |
| 197 TwoClientUssSyncTest() : SyncTest(TWO_CLIENT) { | 197 TwoClientUssSyncTest() : SyncTest(TWO_CLIENT) { |
| 198 DisableVerifier(); | 198 DisableVerifier(); |
| 199 sync_client_factory_ = base::Bind(&TwoClientUssSyncTest::CreateSyncClient, | 199 sync_client_factory_ = base::Bind(&TwoClientUssSyncTest::CreateSyncClient, |
| 200 base::Unretained(this)); | 200 base::Unretained(this)); |
| 201 ProfileSyncServiceFactory::SetSyncClientFactoryForTest( | 201 ProfileSyncServiceFactory::SetSyncClientFactoryForTest( |
| 202 &sync_client_factory_); | 202 &sync_client_factory_); |
| 203 ProfileSyncComponentsFactoryImpl::OverridePrefsForUssTest(true); | 203 ProfileSyncComponentsFactoryImpl::OverridePrefsForUssTest(true); |
| 204 // The test infra creates a profile before the two made for sync tests. |
| 205 number_of_clients_ignored_ = 1; |
| 206 #if defined(OS_CHROMEOS) |
| 207 // ChromeOS will force loading a signin profile, so we need to ingore one |
| 208 // more client. |
| 209 ++number_of_clients_ignored_; |
| 210 #endif |
| 204 } | 211 } |
| 205 | 212 |
| 206 ~TwoClientUssSyncTest() override { | 213 ~TwoClientUssSyncTest() override { |
| 207 ProfileSyncServiceFactory::SetSyncClientFactoryForTest(nullptr); | 214 ProfileSyncServiceFactory::SetSyncClientFactoryForTest(nullptr); |
| 208 ProfileSyncComponentsFactoryImpl::OverridePrefsForUssTest(false); | 215 ProfileSyncComponentsFactoryImpl::OverridePrefsForUssTest(false); |
| 209 } | 216 } |
| 210 | 217 |
| 211 bool TestUsesSelfNotifications() override { return false; } | 218 bool TestUsesSelfNotifications() override { return false; } |
| 212 | 219 |
| 213 TestModelTypeSyncBridge* GetModelTypeSyncBridge(int i) { | 220 TestModelTypeSyncBridge* GetModelTypeSyncBridge(int i) { |
| 214 return bridges_.at(i).get(); | 221 return bridges_.at(i).get(); |
| 215 } | 222 } |
| 216 | 223 |
| 217 protected: | 224 protected: |
| 218 std::unique_ptr<syncer::SyncClient> CreateSyncClient(Profile* profile) { | 225 std::unique_ptr<syncer::SyncClient> CreateSyncClient(Profile* profile) { |
| 219 if (!first_client_ignored_) { | 226 if (number_of_clients_ignored_ > 0) { |
| 220 // The test infra creates a profile before the two made for sync tests. | 227 --number_of_clients_ignored_; |
| 221 first_client_ignored_ = true; | |
| 222 return base::MakeUnique<ChromeSyncClient>(profile); | 228 return base::MakeUnique<ChromeSyncClient>(profile); |
| 223 } | 229 } |
| 224 auto bridge = base::MakeUnique<TestModelTypeSyncBridge>(); | 230 auto bridge = base::MakeUnique<TestModelTypeSyncBridge>(); |
| 225 auto client = base::MakeUnique<TestSyncClient>(profile, bridge.get()); | 231 auto client = base::MakeUnique<TestSyncClient>(profile, bridge.get()); |
| 226 clients_.push_back(client.get()); | 232 clients_.push_back(client.get()); |
| 227 bridges_.push_back(std::move(bridge)); | 233 bridges_.push_back(std::move(bridge)); |
| 228 return std::move(client); | 234 return std::move(client); |
| 229 } | 235 } |
| 230 | 236 |
| 231 ProfileSyncServiceFactory::SyncClientFactory sync_client_factory_; | 237 ProfileSyncServiceFactory::SyncClientFactory sync_client_factory_; |
| 232 std::vector<std::unique_ptr<TestModelTypeSyncBridge>> bridges_; | 238 std::vector<std::unique_ptr<TestModelTypeSyncBridge>> bridges_; |
| 233 std::vector<TestSyncClient*> clients_; | 239 std::vector<TestSyncClient*> clients_; |
| 234 bool first_client_ignored_ = false; | 240 size_t number_of_clients_ignored_; |
| 235 | 241 |
| 236 private: | 242 private: |
| 237 DISALLOW_COPY_AND_ASSIGN(TwoClientUssSyncTest); | 243 DISALLOW_COPY_AND_ASSIGN(TwoClientUssSyncTest); |
| 238 }; | 244 }; |
| 239 | 245 |
| 240 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, Sanity) { | 246 IN_PROC_BROWSER_TEST_F(TwoClientUssSyncTest, Sanity) { |
| 241 ASSERT_TRUE(SetupSync()); | 247 ASSERT_TRUE(SetupSync()); |
| 242 ASSERT_EQ(2U, clients_.size()); | 248 ASSERT_EQ(2U, clients_.size()); |
| 243 ASSERT_EQ(2U, bridges_.size()); | 249 ASSERT_EQ(2U, bridges_.size()); |
| 244 TestModelTypeSyncBridge* model0 = GetModelTypeSyncBridge(0); | 250 TestModelTypeSyncBridge* model0 = GetModelTypeSyncBridge(0); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 | 369 |
| 364 ASSERT_TRUE(DataChecker(model1, kKey1, kValue2).Wait()); | 370 ASSERT_TRUE(DataChecker(model1, kKey1, kValue2).Wait()); |
| 365 ASSERT_TRUE(DataChecker(model1, kKey2, kValue1).Wait()); | 371 ASSERT_TRUE(DataChecker(model1, kKey2, kValue1).Wait()); |
| 366 ASSERT_TRUE(DataChecker(model1, kKey4, kValue1).Wait()); | 372 ASSERT_TRUE(DataChecker(model1, kKey4, kValue1).Wait()); |
| 367 | 373 |
| 368 ASSERT_TRUE(DataChecker(model0, kKey1, kValue2).Wait()); | 374 ASSERT_TRUE(DataChecker(model0, kKey1, kValue2).Wait()); |
| 369 ASSERT_TRUE(DataChecker(model0, kKey3, kValue1).Wait()); | 375 ASSERT_TRUE(DataChecker(model0, kKey3, kValue1).Wait()); |
| 370 } | 376 } |
| 371 | 377 |
| 372 } // namespace | 378 } // namespace |
| OLD | NEW |