Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Unified Diff: ios/public/test/test_keyed_service_provider.cc

Issue 1158223003: [iOS] Add FakeSyncService and factory for testing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/public/test/test_keyed_service_provider.cc
diff --git a/ios/public/test/test_keyed_service_provider.cc b/ios/public/test/test_keyed_service_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..978398c790ed03e2f22643f2f2936172b8c14ed7
--- /dev/null
+++ b/ios/public/test/test_keyed_service_provider.cc
@@ -0,0 +1,67 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/public/test/test_keyed_service_provider.h"
+
+#include "base/memory/singleton.h"
+#include "components/keyed_service/ios/browser_state_dependency_manager.h"
+#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
+#include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
+#include "ios/public/test/fake_sync_service.h"
+
+namespace {
+
+class FakeSyncServiceFactory : public BrowserStateKeyedServiceFactory {
sdefresne 2015/06/08 16:24:17 nit: move this to fake_sync_service_factory.{h,cc}
+ public:
+ // Returns the singleton FakeSyncServiceFactory instance.
+ static FakeSyncServiceFactory* GetInstance() {
+ return Singleton<FakeSyncServiceFactory>::get();
+ }
+
+ // Returns the FakeSyncServiceFactory associated to |browser_state|.
+ static FakeSyncService* GetForBrowserState(web::BrowserState* browser_state) {
sdefresne 2015/06/08 16:24:17 nit: s/FakeSyncService*/sync_driver::SyncService*/
+ return static_cast<FakeSyncService*>(
+ FakeSyncServiceFactory::GetInstance()->GetServiceForBrowserState(
+ browser_state, true));
+ }
+
+ private:
+ friend struct DefaultSingletonTraits<FakeSyncServiceFactory>;
+
+ // BrowserStateKeyedServiceFactory implementation:
+ KeyedService* BuildServiceInstanceFor(
+ web::BrowserState* context) const override {
+ return new FakeSyncService;
+ }
+
+ FakeSyncServiceFactory()
+ : BrowserStateKeyedServiceFactory(
+ "FakeSyncService",
+ BrowserStateDependencyManager::GetInstance()) {}
+ ~FakeSyncServiceFactory() override {}
+
+ DISALLOW_COPY_AND_ASSIGN(FakeSyncServiceFactory);
+};
+
+} // namespace
+
+namespace ios {
+
+TestKeyedServiceProvider::TestKeyedServiceProvider() {
+}
+
+TestKeyedServiceProvider::~TestKeyedServiceProvider() {
+}
+
+KeyedServiceBaseFactory* TestKeyedServiceProvider::GetSyncServiceFactory() {
+ return FakeSyncServiceFactory::GetInstance();
+}
+
+sync_driver::SyncService*
+TestKeyedServiceProvider::GetSyncServiceForBrowserState(
+ ChromeBrowserState* browser_state) {
+ return FakeSyncServiceFactory::GetForBrowserState(browser_state);
+}
+
+} // namespace ios
« ios/public/test/fake_sync_service.h ('K') | « ios/public/test/test_keyed_service_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698