| 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 #include "extensions/renderer/module_system_test.h" | 5 #include "extensions/renderer/module_system_test.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 void RegisterModule(const std::string& name, const std::string& source) { | 115 void RegisterModule(const std::string& name, const std::string& source) { |
| 116 CHECK_EQ(0u, source_map_.count(name)) << "Module " << name << " not found"; | 116 CHECK_EQ(0u, source_map_.count(name)) << "Module " << name << " not found"; |
| 117 source_map_[name] = source; | 117 source_map_[name] = source; |
| 118 } | 118 } |
| 119 | 119 |
| 120 private: | 120 private: |
| 121 std::map<std::string, std::string> source_map_; | 121 std::map<std::string, std::string> source_map_; |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 ModuleSystemTestEnvironment::ModuleSystemTestEnvironment( | 124 ModuleSystemTestEnvironment::ModuleSystemTestEnvironment(v8::Isolate* isolate) |
| 125 gin::IsolateHolder* isolate_holder) | 125 : isolate_(isolate), |
| 126 : isolate_holder_(isolate_holder), | 126 context_holder_(new gin::ContextHolder(isolate_)), |
| 127 context_holder_(new gin::ContextHolder(isolate_holder_->isolate())), | 127 handle_scope_(isolate_), |
| 128 handle_scope_(isolate_holder_->isolate()), | |
| 129 source_map_(new StringSourceMap()) { | 128 source_map_(new StringSourceMap()) { |
| 130 context_holder_->SetContext( | 129 context_holder_->SetContext(v8::Context::New( |
| 131 v8::Context::New(isolate_holder->isolate(), | 130 isolate, g_v8_extension_configurator.Get().GetConfiguration())); |
| 132 g_v8_extension_configurator.Get().GetConfiguration())); | |
| 133 context_.reset(new ScriptContext(context_holder_->context(), | 131 context_.reset(new ScriptContext(context_holder_->context(), |
| 134 NULL, // WebFrame | 132 NULL, // WebFrame |
| 135 NULL, // Extension | 133 NULL, // Extension |
| 136 Feature::UNSPECIFIED_CONTEXT)); | 134 Feature::UNSPECIFIED_CONTEXT)); |
| 137 context_->v8_context()->Enter(); | 135 context_->v8_context()->Enter(); |
| 138 assert_natives_ = new AssertNatives(context_.get()); | 136 assert_natives_ = new AssertNatives(context_.get()); |
| 139 | 137 |
| 140 { | 138 { |
| 141 scoped_ptr<ModuleSystem> module_system( | 139 scoped_ptr<ModuleSystem> module_system( |
| 142 new ModuleSystem(context_.get(), source_map_.get())); | 140 new ModuleSystem(context_.get(), source_map_.get())); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 context_holder_.reset(); | 193 context_holder_.reset(); |
| 196 } | 194 } |
| 197 | 195 |
| 198 void ModuleSystemTestEnvironment::ShutdownModuleSystem() { | 196 void ModuleSystemTestEnvironment::ShutdownModuleSystem() { |
| 199 context_->v8_context()->Exit(); | 197 context_->v8_context()->Exit(); |
| 200 context_.reset(); | 198 context_.reset(); |
| 201 } | 199 } |
| 202 | 200 |
| 203 v8::Handle<v8::Object> ModuleSystemTestEnvironment::CreateGlobal( | 201 v8::Handle<v8::Object> ModuleSystemTestEnvironment::CreateGlobal( |
| 204 const std::string& name) { | 202 const std::string& name) { |
| 205 v8::Isolate* isolate = isolate_holder_->isolate(); | 203 v8::EscapableHandleScope handle_scope(isolate_); |
| 206 v8::EscapableHandleScope handle_scope(isolate); | 204 v8::Local<v8::Object> object = v8::Object::New(isolate_); |
| 207 v8::Local<v8::Object> object = v8::Object::New(isolate); | 205 isolate_->GetCurrentContext()->Global()->Set( |
| 208 isolate->GetCurrentContext()->Global()->Set( | 206 v8::String::NewFromUtf8(isolate_, name.c_str()), object); |
| 209 v8::String::NewFromUtf8(isolate, name.c_str()), object); | |
| 210 return handle_scope.Escape(object); | 207 return handle_scope.Escape(object); |
| 211 } | 208 } |
| 212 | 209 |
| 213 ModuleSystemTest::ModuleSystemTest() | 210 ModuleSystemTest::ModuleSystemTest() |
| 214 : isolate_holder_(v8::Isolate::GetCurrent(), NULL), | 211 : isolate_(v8::Isolate::GetCurrent()), |
| 215 env_(CreateEnvironment()), | 212 env_(CreateEnvironment()), |
| 216 should_assertions_be_made_(true) { | 213 should_assertions_be_made_(true) { |
| 217 } | 214 } |
| 218 | 215 |
| 219 ModuleSystemTest::~ModuleSystemTest() { | 216 ModuleSystemTest::~ModuleSystemTest() { |
| 220 } | 217 } |
| 221 | 218 |
| 222 void ModuleSystemTest::TearDown() { | 219 void ModuleSystemTest::TearDown() { |
| 223 // All tests must assert at least once unless otherwise specified. | 220 // All tests must assert at least once unless otherwise specified. |
| 224 EXPECT_EQ(should_assertions_be_made_, | 221 EXPECT_EQ(should_assertions_be_made_, |
| 225 env_->assert_natives()->assertion_made()); | 222 env_->assert_natives()->assertion_made()); |
| 226 EXPECT_FALSE(env_->assert_natives()->failed()); | 223 EXPECT_FALSE(env_->assert_natives()->failed()); |
| 227 } | 224 } |
| 228 | 225 |
| 229 scoped_ptr<ModuleSystemTestEnvironment> ModuleSystemTest::CreateEnvironment() { | 226 scoped_ptr<ModuleSystemTestEnvironment> ModuleSystemTest::CreateEnvironment() { |
| 230 return make_scoped_ptr(new ModuleSystemTestEnvironment(&isolate_holder_)); | 227 return make_scoped_ptr(new ModuleSystemTestEnvironment(isolate_)); |
| 231 } | 228 } |
| 232 | 229 |
| 233 void ModuleSystemTest::ExpectNoAssertionsMade() { | 230 void ModuleSystemTest::ExpectNoAssertionsMade() { |
| 234 should_assertions_be_made_ = false; | 231 should_assertions_be_made_ = false; |
| 235 } | 232 } |
| 236 | 233 |
| 237 void ModuleSystemTest::RunResolvedPromises() { | 234 void ModuleSystemTest::RunResolvedPromises() { |
| 238 isolate_holder_.isolate()->RunMicrotasks(); | 235 isolate_->RunMicrotasks(); |
| 239 } | 236 } |
| 240 | 237 |
| 241 } // namespace extensions | 238 } // namespace extensions |
| OLD | NEW |