[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame^] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |
| 6 | #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 8 | |
| 9 | #include <string> |
| 10 | |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 11 | #include "chrome/browser/sync/glue/data_type_manager_impl.h" |
[email protected] | f92351d | 2011-02-01 07:42:12 | [diff] [blame] | 12 | #include "chrome/browser/sync/js_backend.h" |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 13 | #include "chrome/browser/sync/profile_sync_service.h" |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 14 | #include "chrome/test/profile_mock.h" |
[email protected] | 3fd04f5 | 2011-01-15 01:49:54 | [diff] [blame] | 15 | #include "chrome/test/sync/engine/test_id_factory.h" |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 16 | #include "testing/gmock/include/gmock/gmock.h" |
| 17 | |
[email protected] | 95f0fe74 | 2010-12-10 01:38:29 | [diff] [blame] | 18 | class Profile; |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 19 | class Task; |
[email protected] | 3fd04f5 | 2011-01-15 01:49:54 | [diff] [blame] | 20 | class TestProfileSyncService; |
[email protected] | 95f0fe74 | 2010-12-10 01:38:29 | [diff] [blame] | 21 | |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 22 | ACTION(ReturnNewDataTypeManager) { |
| 23 | return new browser_sync::DataTypeManagerImpl(arg0, arg1); |
| 24 | } |
| 25 | |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 26 | namespace browser_sync { |
| 27 | |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 28 | // Mocks out the SyncerThread operations (Pause/Resume) since no thread is |
| 29 | // running in these tests, and allows tests to provide a task on construction |
| 30 | // to set up initial nodes to mock out an actual server initial sync |
| 31 | // download. |
[email protected] | f92351d | 2011-02-01 07:42:12 | [diff] [blame] | 32 | class SyncBackendHostForProfileSyncTest |
| 33 | : public SyncBackendHost, public JsBackend { |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 34 | public: |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 35 | // |synchronous_init| causes initialization to block until the syncapi has |
| 36 | // completed setting itself up and called us back. |
[email protected] | 3fd04f5 | 2011-01-15 01:49:54 | [diff] [blame] | 37 | SyncBackendHostForProfileSyncTest( |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 38 | Profile* profile, |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 39 | bool set_initial_sync_ended_on_init, |
[email protected] | 3fd04f5 | 2011-01-15 01:49:54 | [diff] [blame] | 40 | bool synchronous_init); |
[email protected] | 28dc421 | 2011-02-08 20:44:00 | [diff] [blame] | 41 | virtual ~SyncBackendHostForProfileSyncTest(); |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 42 | |
| 43 | MOCK_METHOD0(RequestPause, bool()); |
| 44 | MOCK_METHOD0(RequestResume, bool()); |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 45 | MOCK_METHOD0(RequestNudge, void()); |
| 46 | |
[email protected] | 1a78769 | 2011-01-19 22:19:46 | [diff] [blame] | 47 | virtual void ConfigureDataTypes( |
| 48 | const DataTypeController::TypeMap& data_type_controllers, |
| 49 | const syncable::ModelTypeSet& types, |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 50 | CancelableTask* ready_task); |
[email protected] | 269bb3a69 | 2011-01-05 02:54:41 | [diff] [blame] | 51 | |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 52 | // Called when a nudge comes in. |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 53 | void SimulateSyncCycleCompletedInitialSyncEnded(); |
[email protected] | 3fd04f5 | 2011-01-15 01:49:54 | [diff] [blame] | 54 | |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 55 | virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame^] | 56 | net::URLRequestContextGetter* getter); |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 57 | |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 58 | virtual void InitCore(const Core::DoInitializeOptions& options); |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 59 | |
[email protected] | f92351d | 2011-02-01 07:42:12 | [diff] [blame] | 60 | virtual JsBackend* GetJsBackend(); |
| 61 | |
| 62 | // JsBackend implementation. |
| 63 | virtual void SetParentJsEventRouter(JsEventRouter* router); |
| 64 | virtual void RemoveParentJsEventRouter(); |
| 65 | virtual const JsEventRouter* GetParentJsEventRouter() const; |
| 66 | // Fires an event identical to the message unless the message has |
| 67 | // "delay" as a prefix, in which case a task to fire the identical |
| 68 | // event is posted instead. |
| 69 | virtual void ProcessMessage(const std::string& name, const JsArgList& args, |
| 70 | const JsEventHandler* sender); |
| 71 | |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 72 | static void SetDefaultExpectationsForWorkerCreation(ProfileMock* profile); |
[email protected] | ea74cbf | 2010-11-04 23:49:54 | [diff] [blame] | 73 | |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 74 | static void SetHistoryServiceExpectations(ProfileMock* profile); |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 75 | |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 76 | private: |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 77 | bool synchronous_init_; |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 78 | }; |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 79 | |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 80 | } // namespace browser_sync |
| 81 | |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 82 | class TestProfileSyncService : public ProfileSyncService { |
| 83 | public: |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 84 | // |initial_condition_setup_task| can be used to populate nodes |
| 85 | // before the OnBackendInitialized callback fires. |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 86 | TestProfileSyncService(ProfileSyncFactory* factory, |
| 87 | Profile* profile, |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 88 | const std::string& test_user, |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 89 | bool synchronous_backend_initialization, |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 90 | Task* initial_condition_setup_task); |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 91 | |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 92 | virtual ~TestProfileSyncService(); |
| 93 | |
| 94 | void SetInitialSyncEndedForEnabledTypes(); |
| 95 | |
| 96 | virtual void OnBackendInitialized(); |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 97 | |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 98 | virtual void Observe(NotificationType type, |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 99 | const NotificationSource& source, |
| 100 | const NotificationDetails& details); |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 101 | |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 102 | // If this is called, configuring data types will require a syncer |
| 103 | // nudge. |
| 104 | void dont_set_initial_sync_ended_on_init(); |
| 105 | void set_synchronous_sync_configuration(); |
| 106 | |
| 107 | browser_sync::TestIdFactory* id_factory(); |
| 108 | |
| 109 | // Override of ProfileSyncService::GetBackendForTest() with a more |
| 110 | // specific return type (since C++ supports covariant return types) |
| 111 | // that is made public. |
| 112 | virtual browser_sync::SyncBackendHostForProfileSyncTest* |
| 113 | GetBackendForTest(); |
[email protected] | 3fd04f5 | 2011-01-15 01:49:54 | [diff] [blame] | 114 | |
[email protected] | 1a78769 | 2011-01-19 22:19:46 | [diff] [blame] | 115 | protected: |
| 116 | virtual void CreateBackend(); |
| 117 | |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 118 | private: |
| 119 | // When testing under ChromiumOS, this method must not return an empty |
| 120 | // value value in order for the profile sync service to start. |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 121 | virtual std::string GetLsidForAuthBootstraping(); |
| 122 | |
| 123 | browser_sync::TestIdFactory id_factory_; |
[email protected] | 4c21758 | 2010-05-13 21:37:14 | [diff] [blame] | 124 | |
| 125 | bool synchronous_backend_initialization_; |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 126 | |
| 127 | // Set to true when a mock data type manager is being used and the configure |
| 128 | // step is performed synchronously. |
| 129 | bool synchronous_sync_configuration_; |
| 130 | bool set_expect_resume_expectations_; |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 131 | |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 132 | Task* initial_condition_setup_task_; |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 133 | bool set_initial_sync_ended_on_init_; |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 134 | }; |
| 135 | |
[email protected] | 3fd04f5 | 2011-01-15 01:49:54 | [diff] [blame] | 136 | |
| 137 | |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 138 | #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |