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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 set_profile(NULL); | 210 set_profile(NULL); |
211 | 211 |
212 // Pump messages posted by the sync core thread (which may end up | 212 // Pump messages posted by the sync core thread (which may end up |
213 // posting on the IO thread). | 213 // posting on the IO thread). |
214 MessageLoop::current()->RunAllPending(); | 214 MessageLoop::current()->RunAllPending(); |
215 io_thread_.Stop(); | 215 io_thread_.Stop(); |
216 MessageLoop::current()->RunAllPending(); | 216 MessageLoop::current()->RunAllPending(); |
217 BrowserWithTestWindowTest::TearDown(); | 217 BrowserWithTestWindowTest::TearDown(); |
218 } | 218 } |
219 | 219 |
220 bool StartSyncService(const base::Closure& callback, | 220 bool StartSyncService( |
221 bool will_fail_association) { | 221 const base::Callback<void(syncer::UserShare*)>& callback, |
| 222 bool will_fail_association) { |
222 if (sync_service_.get()) | 223 if (sync_service_.get()) |
223 return false; | 224 return false; |
224 SigninManager* signin = SigninManagerFactory::GetForProfile(profile()); | 225 SigninManager* signin = SigninManagerFactory::GetForProfile(profile()); |
225 signin->SetAuthenticatedUsername("test_user"); | 226 signin->SetAuthenticatedUsername("test_user"); |
226 ProfileSyncComponentsFactoryMock* factory = | 227 ProfileSyncComponentsFactoryMock* factory = |
227 new ProfileSyncComponentsFactoryMock(); | 228 new ProfileSyncComponentsFactoryMock(); |
228 sync_service_.reset(new TestProfileSyncService( | 229 sync_service_.reset(new TestProfileSyncService( |
229 factory, | 230 factory, |
230 profile(), | 231 profile(), |
231 signin, | 232 signin, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 public: | 276 public: |
276 explicit CreateRootHelper(ProfileSyncServiceSessionTest* test) | 277 explicit CreateRootHelper(ProfileSyncServiceSessionTest* test) |
277 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_( | 278 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_( |
278 base::Bind(&CreateRootHelper::CreateRootCallback, | 279 base::Bind(&CreateRootHelper::CreateRootCallback, |
279 base::Unretained(this), test))), | 280 base::Unretained(this), test))), |
280 success_(false) { | 281 success_(false) { |
281 } | 282 } |
282 | 283 |
283 virtual ~CreateRootHelper() {} | 284 virtual ~CreateRootHelper() {} |
284 | 285 |
285 const base::Closure& callback() const { return callback_; } | 286 const base::Callback<void(syncer::UserShare*)>& callback() const { |
286 bool success() { return success_; } | 287 return callback_; |
| 288 } |
| 289 |
| 290 bool success() { |
| 291 return success_; |
| 292 } |
287 | 293 |
288 private: | 294 private: |
289 void CreateRootCallback(ProfileSyncServiceSessionTest* test) { | 295 void CreateRootCallback(ProfileSyncServiceSessionTest* test, |
| 296 syncer::UserShare* user_share) { |
290 success_ = ProfileSyncServiceTestHelper::CreateRoot( | 297 success_ = ProfileSyncServiceTestHelper::CreateRoot( |
291 syncer::SESSIONS, test->sync_service()->GetUserShare(), test->ids()); | 298 syncer::SESSIONS, user_share, test->ids()); |
292 } | 299 } |
293 | 300 |
294 base::Closure callback_; | 301 base::Callback<void(syncer::UserShare*)> callback_; |
295 bool success_; | 302 bool success_; |
296 }; | 303 }; |
297 | 304 |
298 // Test that we can write this machine's session to a node and retrieve it. | 305 // Test that we can write this machine's session to a node and retrieve it. |
299 TEST_F(ProfileSyncServiceSessionTest, WriteSessionToNode) { | 306 TEST_F(ProfileSyncServiceSessionTest, WriteSessionToNode) { |
300 CreateRootHelper create_root(this); | 307 CreateRootHelper create_root(this); |
301 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 308 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
302 ASSERT_TRUE(create_root.success()); | 309 ASSERT_TRUE(create_root.success()); |
303 | 310 |
304 // Check that the DataTypeController associated the models. | 311 // Check that the DataTypeController associated the models. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 iter++; | 373 iter++; |
367 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); | 374 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); |
368 ASSERT_EQ(GURL("http://bar/1"), iter->second->tab()-> | 375 ASSERT_EQ(GURL("http://bar/1"), iter->second->tab()-> |
369 GetEntryAtIndex(0)->GetVirtualURL()); | 376 GetEntryAtIndex(0)->GetVirtualURL()); |
370 ASSERT_EQ(GURL("http://bar/2"), iter->second->tab()-> | 377 ASSERT_EQ(GURL("http://bar/2"), iter->second->tab()-> |
371 GetEntryAtIndex(1)->GetVirtualURL()); | 378 GetEntryAtIndex(1)->GetVirtualURL()); |
372 } | 379 } |
373 | 380 |
374 // Test that we fail on a failed model association. | 381 // Test that we fail on a failed model association. |
375 TEST_F(ProfileSyncServiceSessionTest, FailModelAssociation) { | 382 TEST_F(ProfileSyncServiceSessionTest, FailModelAssociation) { |
376 ASSERT_TRUE(StartSyncService(base::Closure(), true)); | 383 ASSERT_TRUE(StartSyncService( |
| 384 TestProfileSyncService::NullCallback(), true)); |
377 ASSERT_TRUE(sync_service_->HasUnrecoverableError()); | 385 ASSERT_TRUE(sync_service_->HasUnrecoverableError()); |
378 } | 386 } |
379 | 387 |
380 // Write a foreign session to a node, and then retrieve it. | 388 // Write a foreign session to a node, and then retrieve it. |
381 TEST_F(ProfileSyncServiceSessionTest, WriteForeignSessionToNode) { | 389 TEST_F(ProfileSyncServiceSessionTest, WriteForeignSessionToNode) { |
382 CreateRootHelper create_root(this); | 390 CreateRootHelper create_root(this); |
383 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 391 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
384 ASSERT_TRUE(create_root.success()); | 392 ASSERT_TRUE(create_root.success()); |
385 | 393 |
386 // Check that the DataTypeController associated the models. | 394 // Check that the DataTypeController associated the models. |
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 sync_pb::SessionSpecifics specifics; | 1203 sync_pb::SessionSpecifics specifics; |
1196 header.SetSessionSpecifics(specifics); | 1204 header.SetSessionSpecifics(specifics); |
1197 } | 1205 } |
1198 // Ensure we associate properly despite the pre-existing node with our local | 1206 // Ensure we associate properly despite the pre-existing node with our local |
1199 // tag. | 1207 // tag. |
1200 error = model_associator_->AssociateModels(); | 1208 error = model_associator_->AssociateModels(); |
1201 ASSERT_FALSE(error.IsSet()); | 1209 ASSERT_FALSE(error.IsSet()); |
1202 } | 1210 } |
1203 | 1211 |
1204 } // namespace browser_sync | 1212 } // namespace browser_sync |
OLD | NEW |