OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef EXTENSIONS_RENDERER_API_TEST_BASE_H_ | |
6 #define EXTENSIONS_RENDERER_API_TEST_BASE_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/message_loop/message_loop.h" | |
12 #include "base/run_loop.h" | |
13 #include "extensions/renderer/module_system_test.h" | |
14 #include "extensions/renderer/v8_schema_registry.h" | |
15 #include "gin/handle.h" | |
16 #include "gin/modules/module_registry.h" | |
17 #include "gin/object_template_builder.h" | |
18 #include "gin/wrappable.h" | |
19 #include "mojo/bindings/js/handle.h" | |
20 #include "mojo/public/cpp/bindings/interface_request.h" | |
21 #include "mojo/public/cpp/system/core.h" | |
22 | |
23 namespace extensions { | |
24 | |
25 class V8SchemaRegistry; | |
26 | |
27 class TestServiceProvider : public gin::Wrappable<TestServiceProvider> { | |
28 public: | |
29 static gin::Handle<TestServiceProvider> Create(v8::Isolate* isolate); | |
30 virtual ~TestServiceProvider(); | |
31 | |
32 virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | |
33 v8::Isolate* isolate) OVERRIDE; | |
34 | |
35 template <typename Interface> | |
36 void AddService(const base::Callback<void(mojo::InterfaceRequest<Interface>)> | |
37 service_factory) { | |
38 service_factories_.insert(std::make_pair( | |
39 Interface::Name_, | |
40 base::Bind(ForwardToServiceFactory<Interface>, service_factory))); | |
41 } | |
42 | |
43 mojo::Handle ConnectToService(const std::string& service_name); | |
44 | |
45 static gin::WrapperInfo kWrapperInfo; | |
46 | |
47 private: | |
48 TestServiceProvider(); | |
49 template <typename Interface> | |
50 static void ForwardToServiceFactory( | |
51 const base::Callback<void(mojo::InterfaceRequest<Interface>)> | |
52 service_factory, | |
53 mojo::ScopedMessagePipeHandle handle) { | |
54 service_factory.Run(mojo::MakeRequest<Interface>(handle.Pass())); | |
55 } | |
56 std::map<std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)> > | |
57 service_factories_; | |
58 }; | |
59 | |
not at google - send to devlin
2014/07/18 15:09:14
comment?
Sam McNally
2014/07/21 03:56:27
Done.
| |
60 class ApiTestBase : public ModuleSystemTest { | |
61 protected: | |
62 ApiTestBase(); | |
63 virtual ~ApiTestBase(); | |
64 virtual void SetUp() OVERRIDE; | |
65 void RunTest(const std::string& file_name, const std::string& test_name); | |
66 TestServiceProvider* service_provider() { return service_provider_.get(); } | |
67 | |
68 private: | |
69 void RegisterModules(); | |
70 void InitializeEnvironment(); | |
71 void RunTestInner(const std::string& test_name); | |
72 void RunPromisesAgain(); | |
73 | |
74 base::MessageLoop message_loop_; | |
75 gin::Handle<TestServiceProvider> service_provider_; | |
76 scoped_ptr<V8SchemaRegistry> v8_schema_registry_; | |
77 base::RunLoop run_loop_; | |
not at google - send to devlin
2014/07/18 15:09:14
I don't think this class is meant to be used as a
Sam McNally
2014/07/21 03:56:27
Done.
| |
78 }; | |
79 | |
80 } // namespace extensions | |
81 | |
82 #endif // EXTENSIONS_RENDERER_API_TEST_BASE_H_ | |
OLD | NEW |