Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "extensions/common/mojo/keep_alive.mojom.h" | |
| 14 #include "extensions/renderer/module_system_test.h" | 15 #include "extensions/renderer/module_system_test.h" |
| 15 #include "extensions/renderer/v8_schema_registry.h" | 16 #include "extensions/renderer/v8_schema_registry.h" |
| 16 #include "gin/handle.h" | 17 #include "gin/handle.h" |
| 17 #include "gin/modules/module_registry.h" | 18 #include "gin/modules/module_registry.h" |
| 18 #include "gin/object_template_builder.h" | 19 #include "gin/object_template_builder.h" |
| 19 #include "gin/wrappable.h" | 20 #include "gin/wrappable.h" |
| 20 #include "mojo/bindings/js/handle.h" | 21 #include "mojo/bindings/js/handle.h" |
| 21 #include "mojo/public/cpp/bindings/interface_request.h" | 22 #include "mojo/public/cpp/bindings/interface_request.h" |
| 22 #include "mojo/public/cpp/system/core.h" | 23 #include "mojo/public/cpp/system/core.h" |
| 23 | 24 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 54 static void ForwardToServiceFactory( | 55 static void ForwardToServiceFactory( |
| 55 const base::Callback<void(mojo::InterfaceRequest<Interface>)> | 56 const base::Callback<void(mojo::InterfaceRequest<Interface>)> |
| 56 service_factory, | 57 service_factory, |
| 57 mojo::ScopedMessagePipeHandle handle) { | 58 mojo::ScopedMessagePipeHandle handle) { |
| 58 service_factory.Run(mojo::MakeRequest<Interface>(handle.Pass())); | 59 service_factory.Run(mojo::MakeRequest<Interface>(handle.Pass())); |
| 59 } | 60 } |
| 60 std::map<std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)> > | 61 std::map<std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)> > |
| 61 service_factories_; | 62 service_factories_; |
| 62 }; | 63 }; |
| 63 | 64 |
| 65 // A counter for the number of keep alives requested. | |
| 66 class KeepAliveCounter { | |
|
Ken Rockot(use gerrit already)
2014/10/24 18:29:54
nit: What do you think about moving KeepAliveCount
Sam McNally
2014/10/27 05:07:24
TestServiceProvider is fairly tightly coupled to A
| |
| 67 public: | |
| 68 KeepAliveCounter(); | |
| 69 | |
| 70 void CreateKeepAlive(mojo::InterfaceRequest<KeepAlive> request); | |
| 71 void WaitUntilKeepAlivesFinish(); | |
| 72 | |
| 73 int keep_alives() { return keep_alives_; } | |
| 74 int keep_alive_ends() { return keep_alive_ends_; } | |
| 75 | |
| 76 private: | |
| 77 class Instance; | |
| 78 | |
| 79 void PollKeepAlives(const base::Closure& quit_closure); | |
| 80 | |
| 81 int keep_alives_; | |
| 82 int keep_alive_ends_; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(KeepAliveCounter); | |
| 85 }; | |
| 86 | |
| 64 // A base class for unit testing apps/extensions API custom bindings implemented | 87 // A base class for unit testing apps/extensions API custom bindings implemented |
| 65 // on Mojo services. To use: | 88 // on Mojo services. To use: |
| 66 // 1. Register test Mojo service implementations on service_provider(). | 89 // 1. Register test Mojo service implementations on service_provider(). |
| 67 // 2. Write JS tests in extensions/test/data/test_file.js. | 90 // 2. Write JS tests in extensions/test/data/test_file.js. |
| 68 // 3. Write one C++ test function for each JS test containing | 91 // 3. Write one C++ test function for each JS test containing |
| 69 // RunTest("test_file.js", "testFunctionName"). | 92 // RunTest("test_file.js", "testFunctionName"). |
| 70 // See extensions/renderer/api_test_base_unittest.cc and | 93 // See extensions/renderer/api_test_base_unittest.cc and |
| 71 // extensions/test/data/api_test_base_unittest.js for sample usage. | 94 // extensions/test/data/api_test_base_unittest.js for sample usage. |
| 72 class ApiTestBase : public ModuleSystemTest { | 95 class ApiTestBase : public ModuleSystemTest { |
| 73 protected: | 96 protected: |
| 74 ApiTestBase(); | 97 ApiTestBase(); |
| 75 virtual ~ApiTestBase(); | 98 virtual ~ApiTestBase(); |
| 76 virtual void SetUp() override; | 99 virtual void SetUp() override; |
| 77 void RunTest(const std::string& file_name, const std::string& test_name); | 100 void RunTest(const std::string& file_name, const std::string& test_name); |
| 78 TestServiceProvider* service_provider() { return service_provider_; } | 101 TestServiceProvider* service_provider() { return service_provider_; } |
| 102 KeepAliveCounter& keep_alive_counter() { return keep_alive_counter_; } | |
| 79 | 103 |
| 80 private: | 104 private: |
| 81 void RegisterModules(); | 105 void RegisterModules(); |
| 82 void InitializeEnvironment(); | 106 void InitializeEnvironment(); |
| 83 void RunTestInner(const std::string& test_name, | 107 void RunTestInner(const std::string& test_name, |
| 84 const base::Closure& quit_closure); | 108 const base::Closure& quit_closure); |
| 85 void RunPromisesAgain(); | 109 void RunPromisesAgain(); |
| 86 | 110 |
| 87 base::MessageLoop message_loop_; | 111 base::MessageLoop message_loop_; |
| 88 TestServiceProvider* service_provider_; | 112 TestServiceProvider* service_provider_; |
| 89 scoped_ptr<V8SchemaRegistry> v8_schema_registry_; | 113 scoped_ptr<V8SchemaRegistry> v8_schema_registry_; |
| 114 KeepAliveCounter keep_alive_counter_; | |
| 90 }; | 115 }; |
| 91 | 116 |
| 92 } // namespace extensions | 117 } // namespace extensions |
| 93 | 118 |
| 94 #endif // EXTENSIONS_RENDERER_API_TEST_BASE_H_ | 119 #endif // EXTENSIONS_RENDERER_API_TEST_BASE_H_ |
| OLD | NEW |