blob: 1af5d852ee51555f35de018ac41075f4780b4b1f [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]7cef1c442010-07-07 17:05:2211#include "chrome/browser/sync/glue/data_type_manager_impl.h"
[email protected]f92351d2011-02-01 07:42:1212#include "chrome/browser/sync/js_backend.h"
[email protected]420914932011-01-24 23:32:4113#include "chrome/browser/sync/profile_sync_service.h"
[email protected]18af9a22010-08-11 00:47:1914#include "chrome/test/profile_mock.h"
[email protected]3fd04f52011-01-15 01:49:5415#include "chrome/test/sync/engine/test_id_factory.h"
[email protected]7cef1c442010-07-07 17:05:2216#include "testing/gmock/include/gmock/gmock.h"
17
[email protected]95f0fe742010-12-10 01:38:2918class Profile;
[email protected]420914932011-01-24 23:32:4119class Task;
[email protected]3fd04f52011-01-15 01:49:5420class TestProfileSyncService;
[email protected]95f0fe742010-12-10 01:38:2921
[email protected]7cef1c442010-07-07 17:05:2222ACTION(ReturnNewDataTypeManager) {
23 return new browser_sync::DataTypeManagerImpl(arg0, arg1);
24}
25
[email protected]18af9a22010-08-11 00:47:1926namespace browser_sync {
27
[email protected]7cef1c442010-07-07 17:05:2228// 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]f92351d2011-02-01 07:42:1232class SyncBackendHostForProfileSyncTest
33 : public SyncBackendHost, public JsBackend {
[email protected]7cef1c442010-07-07 17:05:2234 public:
[email protected]18af9a22010-08-11 00:47:1935 // |synchronous_init| causes initialization to block until the syncapi has
36 // completed setting itself up and called us back.
[email protected]3fd04f52011-01-15 01:49:5437 SyncBackendHostForProfileSyncTest(
[email protected]7cef1c442010-07-07 17:05:2238 Profile* profile,
[email protected]18af9a22010-08-11 00:47:1939 bool set_initial_sync_ended_on_init,
[email protected]3fd04f52011-01-15 01:49:5440 bool synchronous_init);
[email protected]28dc4212011-02-08 20:44:0041 virtual ~SyncBackendHostForProfileSyncTest();
[email protected]7cef1c442010-07-07 17:05:2242
43 MOCK_METHOD0(RequestPause, bool());
44 MOCK_METHOD0(RequestResume, bool());
[email protected]18af9a22010-08-11 00:47:1945 MOCK_METHOD0(RequestNudge, void());
46
[email protected]1a787692011-01-19 22:19:4647 virtual void ConfigureDataTypes(
48 const DataTypeController::TypeMap& data_type_controllers,
49 const syncable::ModelTypeSet& types,
[email protected]420914932011-01-24 23:32:4150 CancelableTask* ready_task);
[email protected]269bb3a692011-01-05 02:54:4151
[email protected]18af9a22010-08-11 00:47:1952 // Called when a nudge comes in.
[email protected]420914932011-01-24 23:32:4153 void SimulateSyncCycleCompletedInitialSyncEnded();
[email protected]3fd04f52011-01-15 01:49:5454
[email protected]18af9a22010-08-11 00:47:1955 virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory(
[email protected]abe2c032011-03-31 18:49:3456 net::URLRequestContextGetter* getter);
[email protected]18af9a22010-08-11 00:47:1957
[email protected]420914932011-01-24 23:32:4158 virtual void InitCore(const Core::DoInitializeOptions& options);
[email protected]18af9a22010-08-11 00:47:1959
[email protected]f92351d2011-02-01 07:42:1260 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]420914932011-01-24 23:32:4172 static void SetDefaultExpectationsForWorkerCreation(ProfileMock* profile);
[email protected]ea74cbf2010-11-04 23:49:5473
[email protected]420914932011-01-24 23:32:4174 static void SetHistoryServiceExpectations(ProfileMock* profile);
[email protected]18af9a22010-08-11 00:47:1975
[email protected]7cef1c442010-07-07 17:05:2276 private:
[email protected]18af9a22010-08-11 00:47:1977 bool synchronous_init_;
[email protected]7cef1c442010-07-07 17:05:2278};
[email protected]72a31b42010-02-17 22:26:3379
[email protected]18af9a22010-08-11 00:47:1980} // namespace browser_sync
81
[email protected]72a31b42010-02-17 22:26:3382class TestProfileSyncService : public ProfileSyncService {
83 public:
[email protected]420914932011-01-24 23:32:4184 // |initial_condition_setup_task| can be used to populate nodes
85 // before the OnBackendInitialized callback fires.
[email protected]7cef1c442010-07-07 17:05:2286 TestProfileSyncService(ProfileSyncFactory* factory,
87 Profile* profile,
[email protected]e8234d32010-09-09 20:36:3988 const std::string& test_user,
[email protected]7cef1c442010-07-07 17:05:2289 bool synchronous_backend_initialization,
[email protected]420914932011-01-24 23:32:4190 Task* initial_condition_setup_task);
[email protected]72a31b42010-02-17 22:26:3391
[email protected]420914932011-01-24 23:32:4192 virtual ~TestProfileSyncService();
93
94 void SetInitialSyncEndedForEnabledTypes();
95
96 virtual void OnBackendInitialized();
[email protected]72a31b42010-02-17 22:26:3397
[email protected]7cef1c442010-07-07 17:05:2298 virtual void Observe(NotificationType type,
[email protected]420914932011-01-24 23:32:4199 const NotificationSource& source,
100 const NotificationDetails& details);
[email protected]7cef1c442010-07-07 17:05:22101
[email protected]420914932011-01-24 23:32:41102 // 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]3fd04f52011-01-15 01:49:54114
[email protected]1a787692011-01-19 22:19:46115 protected:
116 virtual void CreateBackend();
117
[email protected]72a31b42010-02-17 22:26:33118 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]420914932011-01-24 23:32:41121 virtual std::string GetLsidForAuthBootstraping();
122
123 browser_sync::TestIdFactory id_factory_;
[email protected]4c217582010-05-13 21:37:14124
125 bool synchronous_backend_initialization_;
[email protected]7cef1c442010-07-07 17:05:22126
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]7cef1c442010-07-07 17:05:22131
[email protected]420914932011-01-24 23:32:41132 Task* initial_condition_setup_task_;
[email protected]18af9a22010-08-11 00:47:19133 bool set_initial_sync_ended_on_init_;
[email protected]72a31b42010-02-17 22:26:33134};
135
[email protected]3fd04f52011-01-15 01:49:54136
137
[email protected]72a31b42010-02-17 22:26:33138#endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_