OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 COMPONENTS_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_ | 5 #ifndef COMPONENTS_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_ |
6 #define COMPONENTS_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_ | 6 #define COMPONENTS_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/test/test_message_loop.h" | 16 #include "base/test/test_message_loop.h" |
17 #include "components/browser_sync/profile_sync_test_util.h" | 17 #include "components/browser_sync/profile_sync_test_util.h" |
18 #include "components/sync/base/model_type.h" | 18 #include "components/sync/base/model_type.h" |
19 #include "components/sync/core/change_record.h" | 19 #include "components/sync/core/change_record.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
22 class TestProfileSyncService; | |
23 | |
24 namespace syncer { | 22 namespace syncer { |
25 struct UserShare; | 23 struct UserShare; |
26 } // namespace syncer | 24 } // namespace syncer |
27 | 25 |
| 26 namespace browser_sync { |
| 27 |
| 28 class TestProfileSyncService; |
| 29 |
28 class ProfileSyncServiceTestHelper { | 30 class ProfileSyncServiceTestHelper { |
29 public: | 31 public: |
30 static syncer::ImmutableChangeRecordList MakeSingletonChangeRecordList( | 32 static syncer::ImmutableChangeRecordList MakeSingletonChangeRecordList( |
31 int64_t node_id, | 33 int64_t node_id, |
32 syncer::ChangeRecord::Action action); | 34 syncer::ChangeRecord::Action action); |
33 | 35 |
34 // Deletions must provide an EntitySpecifics for the deleted data. | 36 // Deletions must provide an EntitySpecifics for the deleted data. |
35 static syncer::ImmutableChangeRecordList | 37 static syncer::ImmutableChangeRecordList |
36 MakeSingletonDeletionChangeRecordList( | 38 MakeSingletonDeletionChangeRecordList( |
37 int64_t node_id, | 39 int64_t node_id, |
38 const sync_pb::EntitySpecifics& specifics); | 40 const sync_pb::EntitySpecifics& specifics); |
39 | 41 |
40 private: | 42 private: |
41 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceTestHelper); | 43 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceTestHelper); |
42 }; | 44 }; |
43 | 45 |
44 class AbstractProfileSyncServiceTest : public testing::Test { | 46 class AbstractProfileSyncServiceTest : public testing::Test { |
45 public: | 47 public: |
46 AbstractProfileSyncServiceTest(); | 48 AbstractProfileSyncServiceTest(); |
47 ~AbstractProfileSyncServiceTest() override; | 49 ~AbstractProfileSyncServiceTest() override; |
48 | 50 |
49 bool CreateRoot(syncer::ModelType model_type); | 51 bool CreateRoot(syncer::ModelType model_type); |
50 | 52 |
51 protected: | 53 protected: |
52 // Creates a TestProfileSyncService instance based on | 54 // Creates a TestProfileSyncService instance based on |
53 // |profile_sync_service_bundle_|, with start behavior | 55 // |profile_sync_service_bundle_|, with start behavior AUTO_START. Passes |
54 // browser_sync::AUTO_START. Passes |callback| down to | 56 // |callback| down to SyncManagerForProfileSyncTest to be used by |
55 // SyncManagerForProfileSyncTest to be used by NotifyInitializationSuccess. | 57 // NotifyInitializationSuccess. |sync_client| is passed to the service. The |
56 // |sync_client| is passed to the service. The created service is stored in | 58 // created service is stored in |sync_service_|. |
57 // |sync_service_|. | |
58 void CreateSyncService(std::unique_ptr<sync_driver::SyncClient> sync_client, | 59 void CreateSyncService(std::unique_ptr<sync_driver::SyncClient> sync_client, |
59 const base::Closure& initialization_success_callback); | 60 const base::Closure& initialization_success_callback); |
60 | 61 |
61 base::Thread* data_type_thread() { return &data_type_thread_; } | 62 base::Thread* data_type_thread() { return &data_type_thread_; } |
62 | 63 |
63 TestProfileSyncService* sync_service() { return sync_service_.get(); } | 64 TestProfileSyncService* sync_service() { return sync_service_.get(); } |
64 | 65 |
65 // Returns the callback for the FakeSyncClient builder. It is not possible to | 66 // Returns the callback for the FakeSyncClient builder. It is not possible to |
66 // just Bind() sync_service(), because of Callback not understanding the | 67 // just Bind() sync_service(), because of Callback not understanding the |
67 // inheritance of its template arguments. | 68 // inheritance of its template arguments. |
68 base::Callback<sync_driver::SyncService*(void)> GetSyncServiceCallback(); | 69 base::Callback<sync_driver::SyncService*(void)> GetSyncServiceCallback(); |
69 | 70 |
70 browser_sync::ProfileSyncServiceBundle* profile_sync_service_bundle() { | 71 ProfileSyncServiceBundle* profile_sync_service_bundle() { |
71 return &profile_sync_service_bundle_; | 72 return &profile_sync_service_bundle_; |
72 } | 73 } |
73 | 74 |
74 private: | 75 private: |
75 // Use |data_type_thread_| for code disallowed on the UI thread. | 76 // Use |data_type_thread_| for code disallowed on the UI thread. |
76 base::Thread data_type_thread_; | 77 base::Thread data_type_thread_; |
77 | 78 |
78 base::TestMessageLoop message_loop_; | 79 base::TestMessageLoop message_loop_; |
79 browser_sync::ProfileSyncServiceBundle profile_sync_service_bundle_; | 80 ProfileSyncServiceBundle profile_sync_service_bundle_; |
80 std::unique_ptr<TestProfileSyncService> sync_service_; | 81 std::unique_ptr<TestProfileSyncService> sync_service_; |
81 | 82 |
82 base::ScopedTempDir temp_dir_; // To pass to the backend host. | 83 base::ScopedTempDir temp_dir_; // To pass to the backend host. |
83 | 84 |
84 DISALLOW_COPY_AND_ASSIGN(AbstractProfileSyncServiceTest); | 85 DISALLOW_COPY_AND_ASSIGN(AbstractProfileSyncServiceTest); |
85 }; | 86 }; |
86 | 87 |
87 class CreateRootHelper { | 88 class CreateRootHelper { |
88 public: | 89 public: |
89 CreateRootHelper(AbstractProfileSyncServiceTest* test, | 90 CreateRootHelper(AbstractProfileSyncServiceTest* test, |
90 syncer::ModelType model_type); | 91 syncer::ModelType model_type); |
91 virtual ~CreateRootHelper(); | 92 virtual ~CreateRootHelper(); |
92 | 93 |
93 const base::Closure& callback() const; | 94 const base::Closure& callback() const; |
94 bool success(); | 95 bool success(); |
95 | 96 |
96 private: | 97 private: |
97 void CreateRootCallback(); | 98 void CreateRootCallback(); |
98 | 99 |
99 base::Closure callback_; | 100 base::Closure callback_; |
100 AbstractProfileSyncServiceTest* test_; | 101 AbstractProfileSyncServiceTest* test_; |
101 syncer::ModelType model_type_; | 102 syncer::ModelType model_type_; |
102 bool success_; | 103 bool success_; |
103 | 104 |
104 DISALLOW_COPY_AND_ASSIGN(CreateRootHelper); | 105 DISALLOW_COPY_AND_ASSIGN(CreateRootHelper); |
105 }; | 106 }; |
106 | 107 |
| 108 } // namespace browser_sync |
| 109 |
107 #endif // COMPONENTS_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_ | 110 #endif // COMPONENTS_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_ |
OLD | NEW |