OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <stack> | 5 #include <stack> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
17 #include "chrome/browser/chrome_thread.h" | 17 #include "chrome/browser/chrome_thread.h" |
| 18 #include "chrome/browser/net/gaia/token_service.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
20 #include "chrome/browser/sync/engine/syncapi.h" | 21 #include "chrome/browser/sync/engine/syncapi.h" |
21 #include "chrome/browser/sync/glue/change_processor.h" | 22 #include "chrome/browser/sync/glue/change_processor.h" |
22 #include "chrome/browser/sync/glue/bookmark_change_processor.h" | 23 #include "chrome/browser/sync/glue/bookmark_change_processor.h" |
23 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" | 24 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" |
24 #include "chrome/browser/sync/glue/bookmark_model_associator.h" | 25 #include "chrome/browser/sync/glue/bookmark_model_associator.h" |
25 #include "chrome/browser/sync/glue/data_type_controller.h" | 26 #include "chrome/browser/sync/glue/data_type_controller.h" |
26 #include "chrome/browser/sync/glue/model_associator.h" | 27 #include "chrome/browser/sync/glue/model_associator.h" |
27 #include "chrome/browser/sync/glue/sync_backend_host.h" | 28 #include "chrome/browser/sync/glue/sync_backend_host.h" |
28 #include "chrome/browser/sync/glue/sync_backend_host_mock.h" | 29 #include "chrome/browser/sync/glue/sync_backend_host_mock.h" |
29 #include "chrome/browser/sync/notification_method.h" | 30 #include "chrome/browser/sync/notification_method.h" |
30 #include "chrome/browser/sync/profile_sync_factory.h" | 31 #include "chrome/browser/sync/profile_sync_factory.h" |
31 #include "chrome/browser/sync/profile_sync_factory_mock.h" | 32 #include "chrome/browser/sync/profile_sync_factory_mock.h" |
32 #include "chrome/browser/sync/test_profile_sync_service.h" | 33 #include "chrome/browser/sync/test_profile_sync_service.h" |
33 #include "chrome/browser/sync/profile_sync_test_util.h" | 34 #include "chrome/browser/sync/profile_sync_test_util.h" |
34 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
| 36 #include "chrome/common/net/gaia/gaia_constants.h" |
35 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
36 #include "chrome/test/testing_profile.h" | 38 #include "chrome/test/testing_profile.h" |
37 #include "testing/gmock/include/gmock/gmock.h" | 39 #include "testing/gmock/include/gmock/gmock.h" |
38 | 40 |
39 using std::vector; | 41 using std::vector; |
40 using browser_sync::AssociatorInterface; | 42 using browser_sync::AssociatorInterface; |
41 using browser_sync::BookmarkChangeProcessor; | 43 using browser_sync::BookmarkChangeProcessor; |
42 using browser_sync::BookmarkModelAssociator; | 44 using browser_sync::BookmarkModelAssociator; |
43 using browser_sync::ChangeProcessor; | 45 using browser_sync::ChangeProcessor; |
44 using browser_sync::DataTypeController; | 46 using browser_sync::DataTypeController; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 241 |
240 BookmarkChangeProcessor* change_processor() { | 242 BookmarkChangeProcessor* change_processor() { |
241 return change_processor_; | 243 return change_processor_; |
242 } | 244 } |
243 | 245 |
244 void StartSyncService() { | 246 void StartSyncService() { |
245 StartSyncServiceAndSetInitialSyncEnded(true); | 247 StartSyncServiceAndSetInitialSyncEnded(true); |
246 } | 248 } |
247 void StartSyncServiceAndSetInitialSyncEnded(bool set_initial_sync_ended) { | 249 void StartSyncServiceAndSetInitialSyncEnded(bool set_initial_sync_ended) { |
248 if (!service_.get()) { | 250 if (!service_.get()) { |
| 251 // Set bootstrap to true and it will provide a logged in user for test |
249 service_.reset(new TestProfileSyncService(&factory_, | 252 service_.reset(new TestProfileSyncService(&factory_, |
250 profile_.get(), | 253 profile_.get(), |
251 false, false, NULL)); | 254 "test", false, NULL)); |
252 if (!set_initial_sync_ended) | 255 if (!set_initial_sync_ended) |
253 service_->dont_set_initial_sync_ended_on_init(); | 256 service_->dont_set_initial_sync_ended_on_init(); |
254 | 257 |
255 // Register the bookmark data type. | 258 // Register the bookmark data type. |
256 model_associator_ = new TestBookmarkModelAssociator(service_.get(), | 259 model_associator_ = new TestBookmarkModelAssociator(service_.get(), |
257 service_.get()); | 260 service_.get()); |
258 change_processor_ = new BookmarkChangeProcessor(model_associator_, | 261 change_processor_ = new BookmarkChangeProcessor(model_associator_, |
259 service_.get()); | 262 service_.get()); |
260 EXPECT_CALL(factory_, CreateBookmarkSyncComponents(_, _)). | 263 EXPECT_CALL(factory_, CreateBookmarkSyncComponents(_, _)). |
261 WillOnce(Return(ProfileSyncFactory::SyncComponents( | 264 WillOnce(Return(ProfileSyncFactory::SyncComponents( |
262 model_associator_, change_processor_))); | 265 model_associator_, change_processor_))); |
263 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). | 266 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). |
264 WillOnce(ReturnNewDataTypeManager()); | 267 WillOnce(ReturnNewDataTypeManager()); |
265 | 268 |
266 service_->RegisterDataTypeController( | 269 service_->RegisterDataTypeController( |
267 new browser_sync::BookmarkDataTypeController(&factory_, | 270 new browser_sync::BookmarkDataTypeController(&factory_, |
268 profile_.get(), | 271 profile_.get(), |
269 service_.get())); | 272 service_.get())); |
| 273 |
| 274 profile_->GetTokenService()->IssueAuthTokenForTest( |
| 275 GaiaConstants::kSyncService, "token"); |
270 service_->Initialize(); | 276 service_->Initialize(); |
271 MessageLoop::current()->Run(); | 277 MessageLoop::current()->Run(); |
272 } | 278 } |
273 } | 279 } |
274 | 280 |
275 void StopSyncService(SaveOption save) { | 281 void StopSyncService(SaveOption save) { |
276 if (save == DONT_SAVE_TO_STORAGE) | 282 if (save == DONT_SAVE_TO_STORAGE) |
277 service_->DisableForUser(); | 283 service_->DisableForUser(); |
278 service_.reset(); | 284 service_.reset(); |
279 } | 285 } |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 ProfileSyncService::kDevServerUrl); | 466 ProfileSyncService::kDevServerUrl); |
461 | 467 |
462 EXPECT_TRUE(other_bookmarks_id()); | 468 EXPECT_TRUE(other_bookmarks_id()); |
463 EXPECT_TRUE(bookmark_bar_id()); | 469 EXPECT_TRUE(bookmark_bar_id()); |
464 | 470 |
465 ExpectModelMatch(); | 471 ExpectModelMatch(); |
466 } | 472 } |
467 | 473 |
468 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { | 474 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { |
469 service_.reset(new TestProfileSyncService(&factory_, profile_.get(), | 475 service_.reset(new TestProfileSyncService(&factory_, profile_.get(), |
470 false, true, NULL)); | 476 "test", true, NULL)); |
471 service_->set_num_expected_resumes(0); | 477 service_->set_num_expected_resumes(0); |
472 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). | 478 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)).Times(0); |
473 WillOnce(ReturnNewDataTypeManager()); | |
474 EXPECT_CALL(factory_, CreateBookmarkSyncComponents(_, _)).Times(0); | 479 EXPECT_CALL(factory_, CreateBookmarkSyncComponents(_, _)).Times(0); |
475 service_->RegisterDataTypeController( | 480 service_->RegisterDataTypeController( |
476 new browser_sync::BookmarkDataTypeController(&factory_, | 481 new browser_sync::BookmarkDataTypeController(&factory_, |
477 profile_.get(), | 482 profile_.get(), |
478 service_.get())); | 483 service_.get())); |
| 484 |
479 service_->Initialize(); | 485 service_->Initialize(); |
480 service_.reset(); | 486 service_.reset(); |
481 } | 487 } |
482 | 488 |
483 TEST_F(ProfileSyncServiceTest, BookmarkModelOperations) { | 489 TEST_F(ProfileSyncServiceTest, BookmarkModelOperations) { |
484 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 490 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
485 StartSyncService(); | 491 StartSyncService(); |
486 | 492 |
487 // Test addition. | 493 // Test addition. |
488 const BookmarkNode* folder = | 494 const BookmarkNode* folder = |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1342 FilePath sync_file3 = temp_directory.AppendASCII("nonsense_file"); | 1348 FilePath sync_file3 = temp_directory.AppendASCII("nonsense_file"); |
1343 file_util::CreateDirectory(temp_directory); | 1349 file_util::CreateDirectory(temp_directory); |
1344 file_util::WriteFile(sync_file1, nonsense1, strlen(nonsense1)); | 1350 file_util::WriteFile(sync_file1, nonsense1, strlen(nonsense1)); |
1345 file_util::WriteFile(sync_file2, nonsense2, strlen(nonsense2)); | 1351 file_util::WriteFile(sync_file2, nonsense2, strlen(nonsense2)); |
1346 file_util::WriteFile(sync_file3, nonsense3, strlen(nonsense3)); | 1352 file_util::WriteFile(sync_file3, nonsense3, strlen(nonsense3)); |
1347 | 1353 |
1348 LoadBookmarkModel(LOAD_FROM_STORAGE, SAVE_TO_STORAGE); | 1354 LoadBookmarkModel(LOAD_FROM_STORAGE, SAVE_TO_STORAGE); |
1349 if (!service_.get()) { | 1355 if (!service_.get()) { |
1350 service_.reset( | 1356 service_.reset( |
1351 new TestProfileSyncService(&factory_, profile_.get(), | 1357 new TestProfileSyncService(&factory_, profile_.get(), |
1352 false, true, NULL)); | 1358 "test", true, NULL)); |
1353 | |
1354 service_->dont_set_initial_sync_ended_on_init(); | 1359 service_->dont_set_initial_sync_ended_on_init(); |
| 1360 service_->set_synchronous_sync_configuration(); |
1355 profile_->GetPrefs()->SetBoolean(prefs::kSyncHasSetupCompleted, false); | 1361 profile_->GetPrefs()->SetBoolean(prefs::kSyncHasSetupCompleted, false); |
1356 | 1362 |
1357 model_associator_ = new TestBookmarkModelAssociator(service_.get(), | 1363 model_associator_ = new TestBookmarkModelAssociator(service_.get(), |
1358 service_.get()); | 1364 service_.get()); |
1359 change_processor_ = new BookmarkChangeProcessor(model_associator_, | 1365 change_processor_ = new BookmarkChangeProcessor(model_associator_, |
1360 service_.get()); | 1366 service_.get()); |
1361 EXPECT_CALL(factory_, CreateBookmarkSyncComponents(_, _)). | 1367 EXPECT_CALL(factory_, CreateBookmarkSyncComponents(_, _)). |
1362 WillOnce(Return(ProfileSyncFactory::SyncComponents( | 1368 WillOnce(Return(ProfileSyncFactory::SyncComponents( |
1363 model_associator_, change_processor_))); | 1369 model_associator_, change_processor_))); |
1364 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). | 1370 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). |
1365 WillOnce(ReturnNewDataTypeManager()); | 1371 WillOnce(ReturnNewDataTypeManager()); |
1366 | 1372 |
1367 service_->RegisterDataTypeController( | 1373 service_->RegisterDataTypeController( |
1368 new browser_sync::BookmarkDataTypeController(&factory_, | 1374 new browser_sync::BookmarkDataTypeController(&factory_, |
1369 profile_.get(), | 1375 profile_.get(), |
1370 service_.get())); | 1376 service_.get())); |
1371 | 1377 |
1372 service_->Initialize(); // will call disableForUser because sync setup | 1378 service_->Initialize(); // will call disableForUser because sync setup |
1373 // hasn't been completed. | 1379 // hasn't been completed. |
1374 } | 1380 } |
1375 | 1381 |
1376 ASSERT_FALSE(service_->backend()); | 1382 ASSERT_FALSE(service_->backend()); |
1377 ASSERT_FALSE(service_->HasSyncSetupCompleted()); | 1383 ASSERT_FALSE(service_->HasSyncSetupCompleted()); |
1378 | 1384 |
1379 // This will actually start up the sync service. | 1385 // Create some tokens in the token service; the service will startup when |
1380 service_->EnableForUser(NULL); | 1386 // it is notified that tokens are available. |
| 1387 profile_->GetTokenService()->IssueAuthTokenForTest( |
| 1388 GaiaConstants::kSyncService, "sync_token"); |
| 1389 |
1381 syncable::ModelTypeSet set; | 1390 syncable::ModelTypeSet set; |
1382 set.insert(syncable::BOOKMARKS); | 1391 set.insert(syncable::BOOKMARKS); |
1383 service_->OnUserChoseDatatypes(false, set); | 1392 service_->OnUserChoseDatatypes(false, set); |
1384 | 1393 |
1385 MessageLoop::current()->Run(); | 1394 MessageLoop::current()->RunAllPending(); |
1386 | 1395 |
1387 // Stop the service so we can read the new Sync Data files that were created. | 1396 // Stop the service so we can read the new Sync Data files that were created. |
1388 service_.reset(); | 1397 service_.reset(); |
1389 | 1398 |
1390 // This file should have been deleted when the whole directory was nuked. | 1399 // This file should have been deleted when the whole directory was nuked. |
1391 ASSERT_FALSE(file_util::PathExists(sync_file3)); | 1400 ASSERT_FALSE(file_util::PathExists(sync_file3)); |
| 1401 ASSERT_FALSE(file_util::PathExists(sync_file1)); |
1392 | 1402 |
1393 // These two will still exist, but their texts should have changed. | 1403 // This will still exist, but the text should have changed. |
1394 ASSERT_TRUE(file_util::PathExists(sync_file1)); | |
1395 std::string file1text; | |
1396 file_util::ReadFileToString(sync_file1, &file1text); | |
1397 ASSERT_FALSE(file1text.compare(nonsense1) == 0); | |
1398 | |
1399 ASSERT_TRUE(file_util::PathExists(sync_file2)); | 1404 ASSERT_TRUE(file_util::PathExists(sync_file2)); |
1400 std::string file2text; | 1405 std::string file2text; |
1401 file_util::ReadFileToString(sync_file2, &file2text); | 1406 file_util::ReadFileToString(sync_file2, &file2text); |
1402 ASSERT_FALSE(file2text.compare(nonsense2) == 0); | 1407 ASSERT_FALSE(file2text.compare(nonsense2) == 0); |
1403 } | 1408 } |
OLD | NEW |