| 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 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ | 5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ |
| 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ | 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
| 14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
| 15 #include "base/task.h" | 15 #include "base/task.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "chrome/browser/browser_thread.h" | 19 #include "chrome/browser/browser_thread.h" |
| 20 #include "chrome/browser/webdata/web_database.h" | 20 #include "chrome/browser/webdata/web_database.h" |
| 21 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" |
| 21 #include "chrome/browser/sync/glue/bookmark_change_processor.h" | 22 #include "chrome/browser/sync/glue/bookmark_change_processor.h" |
| 22 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" | 23 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" |
| 23 #include "chrome/browser/sync/glue/bookmark_model_associator.h" | 24 #include "chrome/browser/sync/glue/bookmark_model_associator.h" |
| 24 #include "chrome/browser/sync/glue/change_processor.h" | 25 #include "chrome/browser/sync/glue/change_processor.h" |
| 25 #include "chrome/browser/sync/glue/data_type_manager_impl.h" | 26 #include "chrome/browser/sync/glue/data_type_manager_impl.h" |
| 27 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 26 #include "chrome/browser/sync/profile_sync_factory.h" | 28 #include "chrome/browser/sync/profile_sync_factory.h" |
| 27 #include "chrome/browser/sync/profile_sync_service.h" | 29 #include "chrome/browser/sync/profile_sync_service.h" |
| 28 #include "chrome/browser/sync/unrecoverable_error_handler.h" | 30 #include "chrome/browser/sync/unrecoverable_error_handler.h" |
| 29 #include "chrome/common/notification_details.h" | 31 #include "chrome/common/notification_details.h" |
| 30 #include "chrome/common/notification_service.h" | 32 #include "chrome/common/notification_service.h" |
| 31 #include "chrome/common/notification_source.h" | 33 #include "chrome/common/notification_source.h" |
| 32 #include "chrome/common/notification_type.h" | 34 #include "chrome/common/notification_type.h" |
| 33 #include "chrome/test/sync/test_http_bridge_factory.h" | 35 #include "chrome/test/sync/test_http_bridge_factory.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
| 35 | 37 |
| 36 ACTION_P(Notify, type) { | 38 ACTION_P(Notify, type) { |
| 37 NotificationService::current()->Notify(type, | 39 NotificationService::current()->Notify(type, |
| 38 NotificationService::AllSources(), | 40 NotificationService::AllSources(), |
| 39 NotificationService::NoDetails()); | 41 NotificationService::NoDetails()); |
| 40 } | 42 } |
| 41 | 43 |
| 42 ACTION(QuitUIMessageLoop) { | 44 ACTION(QuitUIMessageLoop) { |
| 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 44 MessageLoop::current()->Quit(); | 46 MessageLoop::current()->Quit(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 ACTION_P(InvokeTask, task) { | 49 ACTION_P(InvokeTask, task) { |
| 48 if (task) | 50 if (task) |
| 49 task->Run(); | 51 task->Run(); |
| 50 } | 52 } |
| 51 | 53 |
| 52 class TestModelAssociatorHelper { | 54 class TestModelAssociatorHelper { |
| 53 public: | 55 public: |
| 56 TestModelAssociatorHelper(browser_sync::TestIdFactory* id_factory) |
| 57 : id_factory_(id_factory) { |
| 58 } |
| 59 |
| 54 template <class ModelAssociatorImpl> | 60 template <class ModelAssociatorImpl> |
| 55 bool GetSyncIdForTaggedNode(ModelAssociatorImpl* associator, | 61 bool GetSyncIdForTaggedNode(ModelAssociatorImpl* associator, |
| 56 const std::string& tag, int64* sync_id) { | 62 const std::string& tag, int64* sync_id) { |
| 57 std::wstring tag_wide; | 63 std::wstring tag_wide; |
| 58 if (!UTF8ToWide(tag.c_str(), tag.length(), &tag_wide)) { | 64 if (!UTF8ToWide(tag.c_str(), tag.length(), &tag_wide)) { |
| 59 NOTREACHED() << "Unable to convert UTF8 to wide for string: " << tag; | 65 NOTREACHED() << "Unable to convert UTF8 to wide for string: " << tag; |
| 60 return false; | 66 return false; |
| 61 } | 67 } |
| 62 | 68 |
| 63 sync_api::WriteTransaction trans( | 69 browser_sync::SyncBackendHost::UserShareHandle share( |
| 64 associator->sync_service()->backend()->GetUserShareHandle()); | 70 associator->sync_service()->backend()->GetUserShareHandle()); |
| 71 bool root_exists = false; |
| 72 ModelType type = ModelAssociatorImpl::model_type(); |
| 73 { |
| 74 sync_api::WriteTransaction trans(share); |
| 75 sync_api::ReadNode uber_root(&trans); |
| 76 uber_root.InitByRootLookup(); |
| 77 |
| 78 sync_api::ReadNode root(&trans); |
| 79 root_exists = root.InitByTagLookup( |
| 80 ProfileSyncServiceTestHelper::GetTagForType(type)); |
| 81 } |
| 82 |
| 83 if (!root_exists) { |
| 84 bool created = ProfileSyncServiceTestHelper::CreateRoot( |
| 85 type, |
| 86 associator->sync_service(), |
| 87 id_factory_); |
| 88 if (!created) |
| 89 return false; |
| 90 } |
| 91 |
| 92 sync_api::WriteTransaction trans(share); |
| 65 sync_api::ReadNode root(&trans); | 93 sync_api::ReadNode root(&trans); |
| 66 root.InitByRootLookup(); | 94 EXPECT_TRUE(root.InitByTagLookup( |
| 95 ProfileSyncServiceTestHelper::GetTagForType(type))); |
| 67 | 96 |
| 68 // First, try to find a node with the title among the root's children. | 97 // First, try to find a node with the title among the root's children. |
| 69 // This will be the case if we are testing model persistence, and | 98 // This will be the case if we are testing model persistence, and |
| 70 // are reloading a sync repository created earlier in the test. | 99 // are reloading a sync repository created earlier in the test. |
| 71 int64 last_child_id = sync_api::kInvalidId; | 100 int64 last_child_id = sync_api::kInvalidId; |
| 72 for (int64 id = root.GetFirstChildId(); id != sync_api::kInvalidId; /***/) { | 101 for (int64 id = root.GetFirstChildId(); id != sync_api::kInvalidId; /***/) { |
| 73 sync_api::ReadNode child(&trans); | 102 sync_api::ReadNode child(&trans); |
| 74 child.InitByIdLookup(id); | 103 child.InitByIdLookup(id); |
| 75 last_child_id = id; | 104 last_child_id = id; |
| 76 if (tag_wide == child.GetTitle()) { | 105 if (tag_wide == child.GetTitle()) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 90 // Create new fake tagged nodes at the end of the ordering. | 119 // Create new fake tagged nodes at the end of the ordering. |
| 91 node.InitByCreation(ModelAssociatorImpl::model_type(), root, predecessor); | 120 node.InitByCreation(ModelAssociatorImpl::model_type(), root, predecessor); |
| 92 node.SetIsFolder(true); | 121 node.SetIsFolder(true); |
| 93 node.SetTitle(tag_wide); | 122 node.SetTitle(tag_wide); |
| 94 node.SetExternalId(0); | 123 node.SetExternalId(0); |
| 95 *sync_id = node.GetId(); | 124 *sync_id = node.GetId(); |
| 96 return true; | 125 return true; |
| 97 } | 126 } |
| 98 | 127 |
| 99 ~TestModelAssociatorHelper() {} | 128 ~TestModelAssociatorHelper() {} |
| 129 private: |
| 130 browser_sync::TestIdFactory* id_factory_; |
| 100 }; | 131 }; |
| 101 | 132 |
| 102 class ProfileSyncServiceObserverMock : public ProfileSyncServiceObserver { | 133 class ProfileSyncServiceObserverMock : public ProfileSyncServiceObserver { |
| 103 public: | 134 public: |
| 104 MOCK_METHOD0(OnStateChanged, void()); | 135 MOCK_METHOD0(OnStateChanged, void()); |
| 105 }; | 136 }; |
| 106 | 137 |
| 107 class ThreadNotificationService | 138 class ThreadNotificationService |
| 108 : public base::RefCountedThreadSafe<ThreadNotificationService> { | 139 : public base::RefCountedThreadSafe<ThreadNotificationService> { |
| 109 public: | 140 public: |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 const NotificationDetails& details) { | 210 const NotificationDetails& details) { |
| 180 NotificationService::current()->Notify(type, source, details); | 211 NotificationService::current()->Notify(type, source, details); |
| 181 done_event_.Signal(); | 212 done_event_.Signal(); |
| 182 } | 213 } |
| 183 | 214 |
| 184 base::WaitableEvent done_event_; | 215 base::WaitableEvent done_event_; |
| 185 base::Thread* notify_thread_; | 216 base::Thread* notify_thread_; |
| 186 }; | 217 }; |
| 187 | 218 |
| 188 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ | 219 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ |
| OLD | NEW |