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 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 ACTION(QuitUIMessageLoop) { | 51 ACTION(QuitUIMessageLoop) { |
52 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 52 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
53 MessageLoop::current()->Quit(); | 53 MessageLoop::current()->Quit(); |
54 } | 54 } |
55 | 55 |
56 ACTION_P(InvokeTask, task) { | 56 ACTION_P(InvokeTask, task) { |
57 if (task) | 57 if (task) |
58 task->Run(); | 58 task->Run(); |
59 } | 59 } |
60 | 60 |
61 template <class ModelAssociatorImpl> | 61 class TestModelAssociatorHelper { |
62 class TestModelAssociator : public ModelAssociatorImpl { | |
63 public: | 62 public: |
64 explicit TestModelAssociator( | 63 template <class ModelAssociatorImpl> |
65 ProfileSyncService* service, | 64 bool GetSyncIdForTaggedNode(ModelAssociatorImpl* associator, |
66 browser_sync::UnrecoverableErrorHandler* error_handler) | 65 const std::string& tag, int64* sync_id) { |
67 : ModelAssociatorImpl(service, error_handler) { | |
68 } | |
69 | |
70 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { | |
71 std::wstring tag_wide; | 66 std::wstring tag_wide; |
72 if (!UTF8ToWide(tag.c_str(), tag.length(), &tag_wide)) { | 67 if (!UTF8ToWide(tag.c_str(), tag.length(), &tag_wide)) { |
73 NOTREACHED() << "Unable to convert UTF8 to wide for string: " << tag; | 68 NOTREACHED() << "Unable to convert UTF8 to wide for string: " << tag; |
74 return false; | 69 return false; |
75 } | 70 } |
76 | 71 |
77 sync_api::WriteTransaction trans( | 72 sync_api::WriteTransaction trans( |
78 ModelAssociatorImpl::sync_service()->backend()->GetUserShareHandle()); | 73 associator->sync_service()->backend()->GetUserShareHandle()); |
79 sync_api::ReadNode root(&trans); | 74 sync_api::ReadNode root(&trans); |
80 root.InitByRootLookup(); | 75 root.InitByRootLookup(); |
81 | 76 |
82 // First, try to find a node with the title among the root's children. | 77 // First, try to find a node with the title among the root's children. |
83 // This will be the case if we are testing model persistence, and | 78 // This will be the case if we are testing model persistence, and |
84 // are reloading a sync repository created earlier in the test. | 79 // are reloading a sync repository created earlier in the test. |
85 int64 last_child_id = sync_api::kInvalidId; | 80 int64 last_child_id = sync_api::kInvalidId; |
86 for (int64 id = root.GetFirstChildId(); id != sync_api::kInvalidId; /***/) { | 81 for (int64 id = root.GetFirstChildId(); id != sync_api::kInvalidId; /***/) { |
87 sync_api::ReadNode child(&trans); | 82 sync_api::ReadNode child(&trans); |
88 child.InitByIdLookup(id); | 83 child.InitByIdLookup(id); |
(...skipping 14 matching lines...) Expand all Loading... |
103 sync_api::WriteNode node(&trans); | 98 sync_api::WriteNode node(&trans); |
104 // Create new fake tagged nodes at the end of the ordering. | 99 // Create new fake tagged nodes at the end of the ordering. |
105 node.InitByCreation(ModelAssociatorImpl::model_type(), root, predecessor); | 100 node.InitByCreation(ModelAssociatorImpl::model_type(), root, predecessor); |
106 node.SetIsFolder(true); | 101 node.SetIsFolder(true); |
107 node.SetTitle(tag_wide); | 102 node.SetTitle(tag_wide); |
108 node.SetExternalId(0); | 103 node.SetExternalId(0); |
109 *sync_id = node.GetId(); | 104 *sync_id = node.GetId(); |
110 return true; | 105 return true; |
111 } | 106 } |
112 | 107 |
113 ~TestModelAssociator() {} | 108 ~TestModelAssociatorHelper() {} |
114 }; | 109 }; |
115 | 110 |
116 class ProfileSyncServiceObserverMock : public ProfileSyncServiceObserver { | 111 class ProfileSyncServiceObserverMock : public ProfileSyncServiceObserver { |
117 public: | 112 public: |
118 MOCK_METHOD0(OnStateChanged, void()); | 113 MOCK_METHOD0(OnStateChanged, void()); |
119 }; | 114 }; |
120 | 115 |
121 class ThreadNotificationService | 116 class ThreadNotificationService |
122 : public base::RefCountedThreadSafe<ThreadNotificationService> { | 117 : public base::RefCountedThreadSafe<ThreadNotificationService> { |
123 public: | 118 public: |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 const NotificationDetails& details) { | 188 const NotificationDetails& details) { |
194 NotificationService::current()->Notify(type, source, details); | 189 NotificationService::current()->Notify(type, source, details); |
195 done_event_.Signal(); | 190 done_event_.Signal(); |
196 } | 191 } |
197 | 192 |
198 base::WaitableEvent done_event_; | 193 base::WaitableEvent done_event_; |
199 base::Thread* notify_thread_; | 194 base::Thread* notify_thread_; |
200 }; | 195 }; |
201 | 196 |
202 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ | 197 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_TEST_UTIL_H_ |
OLD | NEW |