Roll src/third_party/WebKit 8b42d1d:744641d (svn 186770:186771)
[chromium-blink-merge.git] / extensions / test / test_service_registration_manager.h
blob3bfef63b8a5020bc7fb678b947d356116c90fc95
1 // Copyright 2014 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 EXTENSIONS_TEST_TEST_SERVICE_REGISTRATION_MANAGER_H_
6 #define EXTENSIONS_TEST_TEST_SERVICE_REGISTRATION_MANAGER_H_
8 #include <map>
9 #include <string>
11 #include "extensions/browser/mojo/service_registration_manager.h"
13 namespace extensions {
15 class TestServiceRegistrationManager : public ServiceRegistrationManager {
16 public:
17 TestServiceRegistrationManager();
18 ~TestServiceRegistrationManager() override;
20 // Overrides an existing service factory with |factory| for testing. This
21 // does not alter the permission checks used to determine whether a service
22 // is available.
23 template <typename Interface>
24 void OverrideServiceFactoryForTest(
25 const base::Callback<void(mojo::InterfaceRequest<Interface>)>& factory) {
26 linked_ptr<internal::ServiceFactoryBase> service_factory(
27 new internal::ServiceFactory<Interface>(factory));
28 auto result = test_factories_.insert(
29 std::make_pair(Interface::Name_, service_factory));
30 DCHECK(result.second);
33 void AddServiceToServiceRegistry(
34 content::ServiceRegistry* service_registry,
35 internal::ServiceFactoryBase* service_factory) override;
37 private:
38 std::map<std::string, linked_ptr<internal::ServiceFactoryBase>>
39 test_factories_;
41 ServiceRegistrationManager* service_registration_manager_;
43 DISALLOW_COPY_AND_ASSIGN(TestServiceRegistrationManager);
46 } // namespace extensions
48 #endif // EXTENSIONS_TEST_TEST_SERVICE_REGISTRATION_MANAGER_H_