| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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_BINDING_TEST_H_ | |
| 6 #define EXTENSIONS_RENDERER_API_BINDING_TEST_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/test/scoped_task_environment.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 #include "v8/include/v8.h" | |
| 15 | |
| 16 namespace gin { | |
| 17 class ContextHolder; | |
| 18 class IsolateHolder; | |
| 19 } | |
| 20 | |
| 21 namespace extensions { | |
| 22 | |
| 23 // A common unit test class for testing API bindings. Creates an isolate and an | |
| 24 // initial v8 context, and checks for v8 leaks at the end of the test. | |
| 25 class APIBindingTest : public testing::Test { | |
| 26 protected: | |
| 27 APIBindingTest(); | |
| 28 ~APIBindingTest() override; | |
| 29 | |
| 30 // Returns the V8 ExtensionConfiguration to use for contexts. The default | |
| 31 // implementation returns null. | |
| 32 virtual v8::ExtensionConfiguration* GetV8ExtensionConfiguration(); | |
| 33 | |
| 34 // testing::Test: | |
| 35 void SetUp() override; | |
| 36 void TearDown() override; | |
| 37 | |
| 38 // Returns a local to the main context. | |
| 39 v8::Local<v8::Context> MainContext(); | |
| 40 | |
| 41 // Creates a new context (maintaining it with a holder in | |
| 42 // |additional_context_holders_| and returns a local. | |
| 43 v8::Local<v8::Context> AddContext(); | |
| 44 | |
| 45 // Disposes the context pointed to by |context|. | |
| 46 void DisposeContext(v8::Local<v8::Context> context); | |
| 47 | |
| 48 // Disposes all contexts and checks for leaks. | |
| 49 void DisposeAllContexts(); | |
| 50 | |
| 51 // Allows subclasses to perform context disposal cleanup. | |
| 52 virtual void OnWillDisposeContext(v8::Local<v8::Context> context) {} | |
| 53 | |
| 54 // Returns the associated isolate. Defined out-of-line to avoid the include | |
| 55 // for IsolateHolder in the header. | |
| 56 v8::Isolate* isolate(); | |
| 57 | |
| 58 private: | |
| 59 void RunGarbageCollection(); | |
| 60 | |
| 61 base::test::ScopedTaskEnvironment scoped_task_environment_; | |
| 62 | |
| 63 std::unique_ptr<gin::IsolateHolder> isolate_holder_; | |
| 64 std::unique_ptr<gin::ContextHolder> main_context_holder_; | |
| 65 std::vector<std::unique_ptr<gin::ContextHolder>> additional_context_holders_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(APIBindingTest); | |
| 68 }; | |
| 69 | |
| 70 } // namespace extensions | |
| 71 | |
| 72 #endif // EXTENSIONS_RENDERER_API_BINDING_TEST_H_ | |
| OLD | NEW |