| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #include "extensions/renderer/api_binding_test.h" | 5 #include "extensions/renderer/api_binding_test.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "gin/array_buffer.h" | 8 #include "gin/array_buffer.h" |
| 9 #include "gin/public/context_holder.h" | 9 #include "gin/public/context_holder.h" |
| 10 #include "gin/public/isolate_holder.h" | 10 #include "gin/public/isolate_holder.h" |
| 11 #include "gin/v8_initializer.h" | 11 #include "gin/v8_initializer.h" |
| 12 | 12 |
| 13 namespace extensions { | 13 namespace extensions { |
| 14 | 14 |
| 15 APIBindingTest::APIBindingTest() {} | 15 APIBindingTest::APIBindingTest() {} |
| 16 APIBindingTest::~APIBindingTest() {} | 16 APIBindingTest::~APIBindingTest() {} |
| 17 | 17 |
| 18 v8::ExtensionConfiguration* APIBindingTest::GetV8ExtensionConfiguration() { |
| 19 return nullptr; |
| 20 } |
| 21 |
| 18 void APIBindingTest::SetUp() { | 22 void APIBindingTest::SetUp() { |
| 19 // Much of this initialization is stolen from the somewhat-similar | 23 // Much of this initialization is stolen from the somewhat-similar |
| 20 // gin::V8Test. | 24 // gin::V8Test. |
| 21 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 25 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 22 gin::V8Initializer::LoadV8Snapshot(); | 26 gin::V8Initializer::LoadV8Snapshot(); |
| 23 gin::V8Initializer::LoadV8Natives(); | 27 gin::V8Initializer::LoadV8Natives(); |
| 24 #endif | 28 #endif |
| 25 | 29 |
| 26 gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode, | 30 gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode, |
| 27 gin::IsolateHolder::kStableV8Extras, | 31 gin::IsolateHolder::kStableV8Extras, |
| 28 gin::ArrayBufferAllocator::SharedInstance()); | 32 gin::ArrayBufferAllocator::SharedInstance()); |
| 29 | 33 |
| 30 isolate_holder_ = base::MakeUnique<gin::IsolateHolder>(); | 34 isolate_holder_ = base::MakeUnique<gin::IsolateHolder>(); |
| 31 isolate()->Enter(); | 35 isolate()->Enter(); |
| 32 | 36 |
| 33 v8::HandleScope handle_scope(isolate()); | 37 v8::HandleScope handle_scope(isolate()); |
| 34 v8::Local<v8::Context> context = v8::Context::New(isolate()); | 38 v8::Local<v8::Context> context = |
| 39 v8::Context::New(isolate(), GetV8ExtensionConfiguration()); |
| 35 context->Enter(); | 40 context->Enter(); |
| 36 context_holder_ = base::MakeUnique<gin::ContextHolder>(isolate()); | 41 context_holder_ = base::MakeUnique<gin::ContextHolder>(isolate()); |
| 37 context_holder_->SetContext(context); | 42 context_holder_->SetContext(context); |
| 38 } | 43 } |
| 39 | 44 |
| 40 void APIBindingTest::TearDown() { | 45 void APIBindingTest::TearDown() { |
| 41 auto run_garbage_collection = [this]() { | 46 auto run_garbage_collection = [this]() { |
| 42 // '5' is a magic number stolen from Blink; arbitrarily large enough to | 47 // '5' is a magic number stolen from Blink; arbitrarily large enough to |
| 43 // hopefully clean up all the various paths. | 48 // hopefully clean up all the various paths. |
| 44 for (int i = 0; i < 5; ++i) { | 49 for (int i = 0; i < 5; ++i) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 87 |
| 83 void APIBindingTest::DisposeContext() { | 88 void APIBindingTest::DisposeContext() { |
| 84 context_holder_.reset(); | 89 context_holder_.reset(); |
| 85 } | 90 } |
| 86 | 91 |
| 87 v8::Isolate* APIBindingTest::isolate() { | 92 v8::Isolate* APIBindingTest::isolate() { |
| 88 return isolate_holder_->isolate(); | 93 return isolate_holder_->isolate(); |
| 89 } | 94 } |
| 90 | 95 |
| 91 } // namespace extensions | 96 } // namespace extensions |
| OLD | NEW |