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