| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef EXTENSIONS_RENDERER_API_TEST_BASE_H_ | 5 #ifndef EXTENSIONS_RENDERER_API_TEST_BASE_H_ |
| 6 #define EXTENSIONS_RENDERER_API_TEST_BASE_H_ | 6 #define EXTENSIONS_RENDERER_API_TEST_BASE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 v8::Isolate* isolate) override; | 36 v8::Isolate* isolate) override; |
| 37 | 37 |
| 38 template <typename Interface> | 38 template <typename Interface> |
| 39 void AddService(const base::Callback<void(mojo::InterfaceRequest<Interface>)> | 39 void AddService(const base::Callback<void(mojo::InterfaceRequest<Interface>)> |
| 40 service_factory) { | 40 service_factory) { |
| 41 service_factories_.insert(std::make_pair( | 41 service_factories_.insert(std::make_pair( |
| 42 Interface::Name_, | 42 Interface::Name_, |
| 43 base::Bind(ForwardToServiceFactory<Interface>, service_factory))); | 43 base::Bind(ForwardToServiceFactory<Interface>, service_factory))); |
| 44 } | 44 } |
| 45 | 45 |
| 46 // Ignore requests for the Interface service. |
| 47 template <typename Interface> |
| 48 void IgnoreServiceRequests() { |
| 49 service_factories_.insert(std::make_pair( |
| 50 Interface::Name_, base::Bind(&TestServiceProvider::IgnoreHandle))); |
| 51 } |
| 52 |
| 46 static gin::WrapperInfo kWrapperInfo; | 53 static gin::WrapperInfo kWrapperInfo; |
| 47 | 54 |
| 48 private: | 55 private: |
| 49 TestServiceProvider(); | 56 TestServiceProvider(); |
| 50 | 57 |
| 51 mojo::Handle ConnectToService(const std::string& service_name); | 58 mojo::Handle ConnectToService(const std::string& service_name); |
| 52 | 59 |
| 53 template <typename Interface> | 60 template <typename Interface> |
| 54 static void ForwardToServiceFactory( | 61 static void ForwardToServiceFactory( |
| 55 const base::Callback<void(mojo::InterfaceRequest<Interface>)> | 62 const base::Callback<void(mojo::InterfaceRequest<Interface>)> |
| 56 service_factory, | 63 service_factory, |
| 57 mojo::ScopedMessagePipeHandle handle) { | 64 mojo::ScopedMessagePipeHandle handle) { |
| 58 service_factory.Run(mojo::MakeRequest<Interface>(handle.Pass())); | 65 service_factory.Run(mojo::MakeRequest<Interface>(handle.Pass())); |
| 59 } | 66 } |
| 67 |
| 68 static void IgnoreHandle(mojo::ScopedMessagePipeHandle handle); |
| 69 |
| 60 std::map<std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)> > | 70 std::map<std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)> > |
| 61 service_factories_; | 71 service_factories_; |
| 62 }; | 72 }; |
| 63 | 73 |
| 64 // A base class for unit testing apps/extensions API custom bindings implemented | 74 // A base class for unit testing apps/extensions API custom bindings implemented |
| 65 // on Mojo services. To use: | 75 // on Mojo services. To use: |
| 66 // 1. Register test Mojo service implementations on service_provider(). | 76 // 1. Register test Mojo service implementations on service_provider(). |
| 67 // 2. Write JS tests in extensions/test/data/test_file.js. | 77 // 2. Write JS tests in extensions/test/data/test_file.js. |
| 68 // 3. Write one C++ test function for each JS test containing | 78 // 3. Write one C++ test function for each JS test containing |
| 69 // RunTest("test_file.js", "testFunctionName"). | 79 // RunTest("test_file.js", "testFunctionName"). |
| (...skipping 15 matching lines...) Expand all Loading... |
| 85 void RunPromisesAgain(); | 95 void RunPromisesAgain(); |
| 86 | 96 |
| 87 base::MessageLoop message_loop_; | 97 base::MessageLoop message_loop_; |
| 88 TestServiceProvider* service_provider_; | 98 TestServiceProvider* service_provider_; |
| 89 scoped_ptr<V8SchemaRegistry> v8_schema_registry_; | 99 scoped_ptr<V8SchemaRegistry> v8_schema_registry_; |
| 90 }; | 100 }; |
| 91 | 101 |
| 92 } // namespace extensions | 102 } // namespace extensions |
| 93 | 103 |
| 94 #endif // EXTENSIONS_RENDERER_API_TEST_BASE_H_ | 104 #endif // EXTENSIONS_RENDERER_API_TEST_BASE_H_ |
| OLD | NEW |