blob: 406c9cc667af597398612b4a5bf68b4ec0919cf3 [file] [log] [blame]
[email protected]abe2c032011-03-31 18:49:341// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]72a31b42010-02-17 22:26:332// 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]32b76ef2010-07-26 23:08:247#pragma once
[email protected]72a31b42010-02-17 22:26:338
9#include <string>
10
[email protected]1b21a1d2011-05-06 00:01:2411#include "base/compiler_specific.h"
[email protected]e3b0ee52011-10-12 03:04:1312#include "base/memory/weak_ptr.h"
[email protected]7cef1c442010-07-07 17:05:2213#include "chrome/browser/sync/glue/data_type_manager_impl.h"
[email protected]420914932011-01-24 23:32:4114#include "chrome/browser/sync/profile_sync_service.h"
[email protected]1695f10f2011-09-02 22:16:3215#include "chrome/browser/sync/test/engine/test_id_factory.h"
[email protected]7bc60682011-07-29 20:55:5916#include "chrome/test/base/profile_mock.h"
[email protected]7cef1c442010-07-07 17:05:2217#include "testing/gmock/include/gmock/gmock.h"
18
[email protected]95f0fe742010-12-10 01:38:2919class Profile;
[email protected]420914932011-01-24 23:32:4120class Task;
[email protected]3fd04f52011-01-15 01:49:5421class TestProfileSyncService;
[email protected]95f0fe742010-12-10 01:38:2922
[email protected]7cef1c442010-07-07 17:05:2223ACTION(ReturnNewDataTypeManager) {
24 return new browser_sync::DataTypeManagerImpl(arg0, arg1);
25}
26
[email protected]18af9a22010-08-11 00:47:1927namespace browser_sync {
28
[email protected]fa134872011-08-02 18:39:5529class SyncBackendHostForProfileSyncTest : public SyncBackendHost {
[email protected]7cef1c442010-07-07 17:05:2230 public:
[email protected]18af9a22010-08-11 00:47:1931 // |synchronous_init| causes initialization to block until the syncapi has
32 // completed setting itself up and called us back.
[email protected]3fd04f52011-01-15 01:49:5433 SyncBackendHostForProfileSyncTest(
[email protected]7cef1c442010-07-07 17:05:2234 Profile* profile,
[email protected]e3b0ee52011-10-12 03:04:1335 const base::WeakPtr<SyncPrefs>& sync_prefs,
[email protected]18af9a22010-08-11 00:47:1936 bool set_initial_sync_ended_on_init,
[email protected]e5e6e252011-07-21 21:14:2737 bool synchronous_init,
38 bool fail_initial_download);
[email protected]28dc4212011-02-08 20:44:0039 virtual ~SyncBackendHostForProfileSyncTest();
[email protected]7cef1c442010-07-07 17:05:2240
[email protected]b38db7882011-04-05 01:39:0441 MOCK_METHOD1(RequestNudge, void(const tracked_objects::Location&));
[email protected]18af9a22010-08-11 00:47:1942
[email protected]18af9a22010-08-11 00:47:1943 // Called when a nudge comes in.
[email protected]b38db7882011-04-05 01:39:0444 void SimulateSyncCycleCompletedInitialSyncEnded(
45 const tracked_objects::Location&);
[email protected]3fd04f52011-01-15 01:49:5446
[email protected]18af9a22010-08-11 00:47:1947 virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory(
[email protected]fa134872011-08-02 18:39:5548 const scoped_refptr<net::URLRequestContextGetter>& getter) OVERRIDE;
[email protected]18af9a22010-08-11 00:47:1949
[email protected]8e1eaf92011-10-04 00:10:1950 virtual void StartConfiguration(const base::Closure& callback) OVERRIDE;
[email protected]b006a932011-04-21 05:34:2051
[email protected]420914932011-01-24 23:32:4152 static void SetDefaultExpectationsForWorkerCreation(ProfileMock* profile);
[email protected]ea74cbf2010-11-04 23:49:5453
[email protected]420914932011-01-24 23:32:4154 static void SetHistoryServiceExpectations(ProfileMock* profile);
[email protected]18af9a22010-08-11 00:47:1955
[email protected]fa134872011-08-02 18:39:5556 protected:
57 virtual void InitCore(const Core::DoInitializeOptions& options) OVERRIDE;
58
[email protected]7cef1c442010-07-07 17:05:2259 private:
[email protected]18af9a22010-08-11 00:47:1960 bool synchronous_init_;
[email protected]e5e6e252011-07-21 21:14:2761 bool fail_initial_download_;
[email protected]7cef1c442010-07-07 17:05:2262};
[email protected]72a31b42010-02-17 22:26:3363
[email protected]18af9a22010-08-11 00:47:1964} // namespace browser_sync
65
[email protected]72a31b42010-02-17 22:26:3366class TestProfileSyncService : public ProfileSyncService {
67 public:
[email protected]420914932011-01-24 23:32:4168 // |initial_condition_setup_task| can be used to populate nodes
69 // before the OnBackendInitialized callback fires.
[email protected]7cef1c442010-07-07 17:05:2270 TestProfileSyncService(ProfileSyncFactory* factory,
71 Profile* profile,
[email protected]e8234d32010-09-09 20:36:3972 const std::string& test_user,
[email protected]7cef1c442010-07-07 17:05:2273 bool synchronous_backend_initialization,
[email protected]420914932011-01-24 23:32:4174 Task* initial_condition_setup_task);
[email protected]72a31b42010-02-17 22:26:3375
[email protected]420914932011-01-24 23:32:4176 virtual ~TestProfileSyncService();
77
[email protected]e057d762011-08-23 04:39:0578 void SetInitialSyncEndedForAllTypes();
[email protected]420914932011-01-24 23:32:4179
[email protected]fa134872011-08-02 18:39:5580 virtual void OnBackendInitialized(
81 const browser_sync::WeakHandle<browser_sync::JsBackend>& backend,
82 bool success) OVERRIDE;
[email protected]72a31b42010-02-17 22:26:3383
[email protected]432115822011-07-10 15:52:2784 virtual void Observe(int type,
[email protected]420914932011-01-24 23:32:4185 const NotificationSource& source,
[email protected]fa134872011-08-02 18:39:5586 const NotificationDetails& details) OVERRIDE;
[email protected]7cef1c442010-07-07 17:05:2287
[email protected]420914932011-01-24 23:32:4188 // 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]e5e6e252011-07-21 21:14:2793 void fail_initial_download();
94
[email protected]420914932011-01-24 23:32:4195 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]fa134872011-08-02 18:39:55101 GetBackendForTest() OVERRIDE;
[email protected]3fd04f52011-01-15 01:49:54102
[email protected]1a787692011-01-19 22:19:46103 protected:
[email protected]fa134872011-08-02 18:39:55104 virtual void CreateBackend() OVERRIDE;
[email protected]1a787692011-01-19 22:19:46105
[email protected]72a31b42010-02-17 22:26:33106 private:
[email protected]420914932011-01-24 23:32:41107 browser_sync::TestIdFactory id_factory_;
[email protected]4c217582010-05-13 21:37:14108
109 bool synchronous_backend_initialization_;
[email protected]7cef1c442010-07-07 17:05:22110
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]7cef1c442010-07-07 17:05:22115
[email protected]420914932011-01-24 23:32:41116 Task* initial_condition_setup_task_;
[email protected]18af9a22010-08-11 00:47:19117 bool set_initial_sync_ended_on_init_;
[email protected]e5e6e252011-07-21 21:14:27118
119 bool fail_initial_download_;
[email protected]72a31b42010-02-17 22:26:33120};
121
[email protected]3fd04f52011-01-15 01:49:54122
123
[email protected]72a31b42010-02-17 22:26:33124#endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_