[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] | 1b21a1d | 2011-05-06 00:01:24 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
[email protected] | e3b0ee5 | 2011-10-12 03:04:13 | [diff] [blame] | 12 | #include "base/memory/weak_ptr.h" |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 13 | #include "chrome/browser/sync/glue/data_type_manager_impl.h" |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 14 | #include "chrome/browser/sync/profile_sync_service.h" |
[email protected] | 1695f10f | 2011-09-02 22:16:32 | [diff] [blame] | 15 | #include "chrome/browser/sync/test/engine/test_id_factory.h" |
[email protected] | 7bc6068 | 2011-07-29 20:55:59 | [diff] [blame] | 16 | #include "chrome/test/base/profile_mock.h" |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 17 | #include "testing/gmock/include/gmock/gmock.h" |
| 18 | |
[email protected] | 95f0fe74 | 2010-12-10 01:38:29 | [diff] [blame] | 19 | class Profile; |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 20 | class Task; |
[email protected] | 3fd04f5 | 2011-01-15 01:49:54 | [diff] [blame] | 21 | class TestProfileSyncService; |
[email protected] | 95f0fe74 | 2010-12-10 01:38:29 | [diff] [blame] | 22 | |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 23 | ACTION(ReturnNewDataTypeManager) { |
| 24 | return new browser_sync::DataTypeManagerImpl(arg0, arg1); |
| 25 | } |
| 26 | |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 27 | namespace browser_sync { |
| 28 | |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 29 | class SyncBackendHostForProfileSyncTest : public SyncBackendHost { |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 30 | public: |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 31 | // |synchronous_init| causes initialization to block until the syncapi has |
| 32 | // completed setting itself up and called us back. |
[email protected] | 3fd04f5 | 2011-01-15 01:49:54 | [diff] [blame] | 33 | SyncBackendHostForProfileSyncTest( |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 34 | Profile* profile, |
[email protected] | e3b0ee5 | 2011-10-12 03:04:13 | [diff] [blame] | 35 | const base::WeakPtr<SyncPrefs>& sync_prefs, |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 36 | bool set_initial_sync_ended_on_init, |
[email protected] | e5e6e25 | 2011-07-21 21:14:27 | [diff] [blame] | 37 | bool synchronous_init, |
| 38 | bool fail_initial_download); |
[email protected] | 28dc421 | 2011-02-08 20:44:00 | [diff] [blame] | 39 | virtual ~SyncBackendHostForProfileSyncTest(); |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 40 | |
[email protected] | b38db788 | 2011-04-05 01:39:04 | [diff] [blame] | 41 | MOCK_METHOD1(RequestNudge, void(const tracked_objects::Location&)); |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 42 | |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 43 | // Called when a nudge comes in. |
[email protected] | b38db788 | 2011-04-05 01:39:04 | [diff] [blame] | 44 | void SimulateSyncCycleCompletedInitialSyncEnded( |
| 45 | const tracked_objects::Location&); |
[email protected] | 3fd04f5 | 2011-01-15 01:49:54 | [diff] [blame] | 46 | |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 47 | virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 48 | const scoped_refptr<net::URLRequestContextGetter>& getter) OVERRIDE; |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 49 | |
[email protected] | 8e1eaf9 | 2011-10-04 00:10:19 | [diff] [blame] | 50 | virtual void StartConfiguration(const base::Closure& callback) OVERRIDE; |
[email protected] | b006a93 | 2011-04-21 05:34:20 | [diff] [blame] | 51 | |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 52 | static void SetDefaultExpectationsForWorkerCreation(ProfileMock* profile); |
[email protected] | ea74cbf | 2010-11-04 23:49:54 | [diff] [blame] | 53 | |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 54 | static void SetHistoryServiceExpectations(ProfileMock* profile); |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 55 | |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 56 | protected: |
| 57 | virtual void InitCore(const Core::DoInitializeOptions& options) OVERRIDE; |
| 58 | |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 59 | private: |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 60 | bool synchronous_init_; |
[email protected] | e5e6e25 | 2011-07-21 21:14:27 | [diff] [blame] | 61 | bool fail_initial_download_; |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 62 | }; |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 63 | |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 64 | } // namespace browser_sync |
| 65 | |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 66 | class TestProfileSyncService : public ProfileSyncService { |
| 67 | public: |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 68 | // |initial_condition_setup_task| can be used to populate nodes |
| 69 | // before the OnBackendInitialized callback fires. |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 70 | TestProfileSyncService(ProfileSyncFactory* factory, |
| 71 | Profile* profile, |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 72 | const std::string& test_user, |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 73 | bool synchronous_backend_initialization, |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 74 | Task* initial_condition_setup_task); |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 75 | |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 76 | virtual ~TestProfileSyncService(); |
| 77 | |
[email protected] | e057d76 | 2011-08-23 04:39:05 | [diff] [blame] | 78 | void SetInitialSyncEndedForAllTypes(); |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 79 | |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 80 | virtual void OnBackendInitialized( |
| 81 | const browser_sync::WeakHandle<browser_sync::JsBackend>& backend, |
| 82 | bool success) OVERRIDE; |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 83 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 84 | virtual void Observe(int type, |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 85 | const NotificationSource& source, |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 86 | const NotificationDetails& details) OVERRIDE; |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 87 | |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 88 | // If this is called, configuring data types will require a syncer |
| 89 | // nudge. |
| 90 | void dont_set_initial_sync_ended_on_init(); |
| 91 | void set_synchronous_sync_configuration(); |
| 92 | |
[email protected] | e5e6e25 | 2011-07-21 21:14:27 | [diff] [blame] | 93 | void fail_initial_download(); |
| 94 | |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 95 | browser_sync::TestIdFactory* id_factory(); |
| 96 | |
| 97 | // Override of ProfileSyncService::GetBackendForTest() with a more |
| 98 | // specific return type (since C++ supports covariant return types) |
| 99 | // that is made public. |
| 100 | virtual browser_sync::SyncBackendHostForProfileSyncTest* |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 101 | GetBackendForTest() OVERRIDE; |
[email protected] | 3fd04f5 | 2011-01-15 01:49:54 | [diff] [blame] | 102 | |
[email protected] | 1a78769 | 2011-01-19 22:19:46 | [diff] [blame] | 103 | protected: |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 104 | virtual void CreateBackend() OVERRIDE; |
[email protected] | 1a78769 | 2011-01-19 22:19:46 | [diff] [blame] | 105 | |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 106 | private: |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 107 | browser_sync::TestIdFactory id_factory_; |
[email protected] | 4c21758 | 2010-05-13 21:37:14 | [diff] [blame] | 108 | |
| 109 | bool synchronous_backend_initialization_; |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 110 | |
| 111 | // Set to true when a mock data type manager is being used and the configure |
| 112 | // step is performed synchronously. |
| 113 | bool synchronous_sync_configuration_; |
| 114 | bool set_expect_resume_expectations_; |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 115 | |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 116 | Task* initial_condition_setup_task_; |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 117 | bool set_initial_sync_ended_on_init_; |
[email protected] | e5e6e25 | 2011-07-21 21:14:27 | [diff] [blame] | 118 | |
| 119 | bool fail_initial_download_; |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 120 | }; |
| 121 | |
[email protected] | 3fd04f5 | 2011-01-15 01:49:54 | [diff] [blame] | 122 | |
| 123 | |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 124 | #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ |