Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / sync / test_profile_sync_service.h
blob1c4504752b307e83ea1e1911a1e37c1cba562a1a
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/sync/glue/sync_backend_host_impl.h"
14 #include "chrome/browser/sync/profile_sync_service.h"
15 #include "components/signin/core/browser/profile_oauth2_token_service.h"
16 #include "components/sync_driver/data_type_manager_impl.h"
17 #include "components/sync_driver/sync_prefs.h"
18 #include "sync/test/engine/test_id_factory.h"
19 #include "testing/gmock/include/gmock/gmock.h"
21 class Profile;
22 class ProfileOAuth2TokenService;
23 class ProfileSyncComponentsFactoryMock;
25 ACTION(ReturnNewDataTypeManager) {
26 return new sync_driver::DataTypeManagerImpl(base::Closure(),
27 arg0,
28 arg1,
29 arg2,
30 arg3,
31 arg4);
34 namespace browser_sync {
36 class SyncBackendHostForProfileSyncTest : public SyncBackendHostImpl {
37 public:
38 SyncBackendHostForProfileSyncTest(
39 Profile* profile,
40 invalidation::InvalidationService* invalidator,
41 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs,
42 base::Closure callback);
43 ~SyncBackendHostForProfileSyncTest() override;
45 void RequestConfigureSyncer(
46 syncer::ConfigureReason reason,
47 syncer::ModelTypeSet to_download,
48 syncer::ModelTypeSet to_purge,
49 syncer::ModelTypeSet to_journal,
50 syncer::ModelTypeSet to_unapply,
51 syncer::ModelTypeSet to_ignore,
52 const syncer::ModelSafeRoutingInfo& routing_info,
53 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
54 ready_task,
55 const base::Closure& retry_callback) override;
57 protected:
58 void InitCore(scoped_ptr<DoInitializeOptions> options) override;
60 private:
61 // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop.
62 // Allows extra initialization work to be performed before the backend comes
63 // up.
64 base::Closure callback_;
67 } // namespace browser_sync
69 class TestProfileSyncService : public ProfileSyncService {
70 public:
71 // TODO(tim): Add ability to inject TokenService alongside SigninManager.
72 // TODO(rogerta): what does above comment mean?
73 TestProfileSyncService(
74 scoped_ptr<sync_driver::SyncApiComponentFactory> factory,
75 Profile* profile,
76 SigninManagerBase* signin,
77 ProfileOAuth2TokenService* oauth2_token_service,
78 browser_sync::ProfileSyncServiceStartBehavior behavior);
80 ~TestProfileSyncService() override;
82 void OnConfigureDone(
83 const sync_driver::DataTypeManager::ConfigureResult& result) override;
85 // We implement our own version to avoid some DCHECKs.
86 syncer::UserShare* GetUserShare() const override;
88 static TestProfileSyncService* BuildAutoStartAsyncInit(
89 Profile* profile, base::Closure callback);
91 ProfileSyncComponentsFactoryMock* components_factory_mock();
93 syncer::TestIdFactory* id_factory();
95 // Raise visibility to ease testing.
96 using ProfileSyncService::NotifyObservers;
98 protected:
99 static scoped_ptr<KeyedService> TestFactoryFunction(
100 content::BrowserContext* profile);
102 // Return NULL handle to use in backend initialization to avoid receiving
103 // js messages on UI loop when it's being destroyed, which are not deleted
104 // and cause memory leak in test.
105 syncer::WeakHandle<syncer::JsEventHandler> GetJsEventHandler() override;
107 bool NeedBackup() const override;
109 private:
110 syncer::TestIdFactory id_factory_;
113 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_