OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 using std::vector; | 35 using std::vector; |
36 using browser_sync::AssociatorInterface; | 36 using browser_sync::AssociatorInterface; |
37 using browser_sync::BookmarkChangeProcessor; | 37 using browser_sync::BookmarkChangeProcessor; |
38 using browser_sync::BookmarkModelAssociator; | 38 using browser_sync::BookmarkModelAssociator; |
39 using browser_sync::ChangeProcessor; | 39 using browser_sync::ChangeProcessor; |
40 using browser_sync::DataTypeController; | 40 using browser_sync::DataTypeController; |
41 using browser_sync::ModelAssociator; | 41 using browser_sync::ModelAssociator; |
42 using browser_sync::SyncBackendHost; | 42 using browser_sync::SyncBackendHost; |
43 using browser_sync::SyncBackendHostMock; | 43 using browser_sync::SyncBackendHostMock; |
| 44 using browser_sync::UnrecoverableErrorHandler; |
44 using testing::_; | 45 using testing::_; |
45 using testing::Return; | 46 using testing::Return; |
46 | 47 |
47 class TestBookmarkModelAssociator : | 48 class TestBookmarkModelAssociator : public BookmarkModelAssociator { |
48 public TestModelAssociator<BookmarkModelAssociator> { | |
49 public: | 49 public: |
50 explicit TestBookmarkModelAssociator(ProfileSyncService* service) | 50 TestBookmarkModelAssociator(ProfileSyncService* service, |
51 : TestModelAssociator<BookmarkModelAssociator>(service, service) { | 51 UnrecoverableErrorHandler* persist_ids_error_handler) |
| 52 : BookmarkModelAssociator(service, persist_ids_error_handler), |
| 53 helper_(new TestModelAssociatorHelper()) { |
52 } | 54 } |
| 55 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { |
| 56 return helper_->GetSyncIdForTaggedNode(this, tag, sync_id); |
| 57 } |
| 58 private: |
| 59 scoped_ptr<TestModelAssociatorHelper> helper_; |
53 }; | 60 }; |
54 | 61 |
55 // FakeServerChange constructs a list of sync_api::ChangeRecords while modifying | 62 // FakeServerChange constructs a list of sync_api::ChangeRecords while modifying |
56 // the sync model, and can pass the ChangeRecord list to a | 63 // the sync model, and can pass the ChangeRecord list to a |
57 // sync_api::SyncObserver (i.e., the ProfileSyncService) to test the client | 64 // sync_api::SyncObserver (i.e., the ProfileSyncService) to test the client |
58 // change-application behavior. | 65 // change-application behavior. |
59 // Tests using FakeServerChange should be careful to avoid back-references, | 66 // Tests using FakeServerChange should be careful to avoid back-references, |
60 // since FakeServerChange will send the edits in the order specified. | 67 // since FakeServerChange will send the edits in the order specified. |
61 class FakeServerChange { | 68 class FakeServerChange { |
62 public: | 69 public: |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 return change_processor_; | 235 return change_processor_; |
229 } | 236 } |
230 | 237 |
231 void StartSyncService() { | 238 void StartSyncService() { |
232 if (!service_.get()) { | 239 if (!service_.get()) { |
233 service_.reset(new TestProfileSyncService(&factory_, | 240 service_.reset(new TestProfileSyncService(&factory_, |
234 profile_.get(), | 241 profile_.get(), |
235 false, true)); | 242 false, true)); |
236 | 243 |
237 // Register the bookmark data type. | 244 // Register the bookmark data type. |
238 model_associator_ = new TestBookmarkModelAssociator(service_.get()); | 245 model_associator_ = new TestBookmarkModelAssociator(service_.get(), |
| 246 service_.get()); |
239 change_processor_ = new BookmarkChangeProcessor(model_associator_, | 247 change_processor_ = new BookmarkChangeProcessor(model_associator_, |
240 service_.get()); | 248 service_.get()); |
241 EXPECT_CALL(factory_, CreateBookmarkSyncComponents(_, _)). | 249 EXPECT_CALL(factory_, CreateBookmarkSyncComponents(_, _)). |
242 WillOnce(Return(ProfileSyncFactory::SyncComponents( | 250 WillOnce(Return(ProfileSyncFactory::SyncComponents( |
243 model_associator_, change_processor_))); | 251 model_associator_, change_processor_))); |
244 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). | 252 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). |
245 WillOnce(MakeDataTypeManager(&backend_mock_)); | 253 WillOnce(MakeDataTypeManager(&backend_mock_)); |
246 | 254 |
247 service_->RegisterDataTypeController( | 255 service_->RegisterDataTypeController( |
248 new browser_sync::BookmarkDataTypeController(&factory_, | 256 new browser_sync::BookmarkDataTypeController(&factory_, |
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 file_util::WriteFile(sync_file2, nonsense2, strlen(nonsense2)); | 1338 file_util::WriteFile(sync_file2, nonsense2, strlen(nonsense2)); |
1331 file_util::WriteFile(sync_file3, nonsense3, strlen(nonsense3)); | 1339 file_util::WriteFile(sync_file3, nonsense3, strlen(nonsense3)); |
1332 | 1340 |
1333 LoadBookmarkModel(LOAD_FROM_STORAGE, SAVE_TO_STORAGE); | 1341 LoadBookmarkModel(LOAD_FROM_STORAGE, SAVE_TO_STORAGE); |
1334 if (!service_.get()) { | 1342 if (!service_.get()) { |
1335 service_.reset( | 1343 service_.reset( |
1336 new TestProfileSyncService(&factory_, profile_.get(), | 1344 new TestProfileSyncService(&factory_, profile_.get(), |
1337 false, true)); | 1345 false, true)); |
1338 profile_->GetPrefs()->SetBoolean(prefs::kSyncHasSetupCompleted, false); | 1346 profile_->GetPrefs()->SetBoolean(prefs::kSyncHasSetupCompleted, false); |
1339 | 1347 |
1340 model_associator_ = new TestBookmarkModelAssociator(service_.get()); | 1348 model_associator_ = new TestBookmarkModelAssociator(service_.get(), |
| 1349 service_.get()); |
1341 change_processor_ = new BookmarkChangeProcessor(model_associator_, | 1350 change_processor_ = new BookmarkChangeProcessor(model_associator_, |
1342 service_.get()); | 1351 service_.get()); |
1343 EXPECT_CALL(factory_, CreateBookmarkSyncComponents(_, _)). | 1352 EXPECT_CALL(factory_, CreateBookmarkSyncComponents(_, _)). |
1344 WillOnce(Return(ProfileSyncFactory::SyncComponents( | 1353 WillOnce(Return(ProfileSyncFactory::SyncComponents( |
1345 model_associator_, change_processor_))); | 1354 model_associator_, change_processor_))); |
1346 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). | 1355 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). |
1347 WillOnce(MakeDataTypeManager(&backend_mock_)); | 1356 WillOnce(MakeDataTypeManager(&backend_mock_)); |
1348 | 1357 |
1349 service_->RegisterDataTypeController( | 1358 service_->RegisterDataTypeController( |
1350 new browser_sync::BookmarkDataTypeController(&factory_, | 1359 new browser_sync::BookmarkDataTypeController(&factory_, |
(...skipping 20 matching lines...) Expand all Loading... |
1371 ASSERT_TRUE(file_util::PathExists(sync_file1)); | 1380 ASSERT_TRUE(file_util::PathExists(sync_file1)); |
1372 std::string file1text; | 1381 std::string file1text; |
1373 file_util::ReadFileToString(sync_file1, &file1text); | 1382 file_util::ReadFileToString(sync_file1, &file1text); |
1374 ASSERT_FALSE(file1text.compare(nonsense1) == 0); | 1383 ASSERT_FALSE(file1text.compare(nonsense1) == 0); |
1375 | 1384 |
1376 ASSERT_TRUE(file_util::PathExists(sync_file2)); | 1385 ASSERT_TRUE(file_util::PathExists(sync_file2)); |
1377 std::string file2text; | 1386 std::string file2text; |
1378 file_util::ReadFileToString(sync_file2, &file2text); | 1387 file_util::ReadFileToString(sync_file2, &file2text); |
1379 ASSERT_FALSE(file2text.compare(nonsense2) == 0); | 1388 ASSERT_FALSE(file2text.compare(nonsense2) == 0); |
1380 } | 1389 } |
OLD | NEW |