| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/test/base/module_system_test.h" | 5 #include "chrome/test/base/module_system_test.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 void RegisterModule(const std::string& name, const std::string& source) { | 114 void RegisterModule(const std::string& name, const std::string& source) { |
| 115 CHECK_EQ(0u, source_map_.count(name)) << "Module " << name << " not found"; | 115 CHECK_EQ(0u, source_map_.count(name)) << "Module " << name << " not found"; |
| 116 source_map_[name] = source; | 116 source_map_[name] = source; |
| 117 } | 117 } |
| 118 | 118 |
| 119 private: | 119 private: |
| 120 std::map<std::string, std::string> source_map_; | 120 std::map<std::string, std::string> source_map_; |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 ModuleSystemTest::ModuleSystemTest() | 123 ModuleSystemTest::ModuleSystemTest() |
| 124 : isolate_(v8::Isolate::GetCurrent()), | 124 : isolate_holder_(v8::Isolate::GetCurrent(), NULL), |
| 125 handle_scope_(isolate_), | 125 context_holder_(isolate_holder_.isolate()), |
| 126 context_( | 126 handle_scope_(isolate_holder_.isolate()), |
| 127 new extensions::ChromeV8Context( | |
| 128 v8::Context::New( | |
| 129 isolate_, | |
| 130 g_v8_extension_configurator.Get().GetConfiguration()), | |
| 131 NULL, // WebFrame | |
| 132 NULL, // Extension | |
| 133 extensions::Feature::UNSPECIFIED_CONTEXT)), | |
| 134 source_map_(new StringSourceMap()), | 127 source_map_(new StringSourceMap()), |
| 135 should_assertions_be_made_(true) { | 128 should_assertions_be_made_(true) { |
| 129 context_holder_.SetContext( |
| 130 v8::Context::New(isolate_holder_.isolate(), |
| 131 g_v8_extension_configurator.Get().GetConfiguration())); |
| 132 context_.reset(new extensions::ChromeV8Context( |
| 133 context_holder_.context(), |
| 134 NULL, // WebFrame |
| 135 NULL, // Extension |
| 136 extensions::Feature::UNSPECIFIED_CONTEXT)); |
| 136 context_->v8_context()->Enter(); | 137 context_->v8_context()->Enter(); |
| 137 assert_natives_ = new AssertNatives(context_.get()); | 138 assert_natives_ = new AssertNatives(context_.get()); |
| 138 | 139 |
| 139 { | 140 { |
| 140 scoped_ptr<ModuleSystem> module_system( | 141 scoped_ptr<ModuleSystem> module_system( |
| 141 new ModuleSystem(context_.get(), source_map_.get())); | 142 new ModuleSystem(context_.get(), source_map_.get())); |
| 142 context_->set_module_system(module_system.Pass()); | 143 context_->set_module_system(module_system.Pass()); |
| 143 } | 144 } |
| 144 ModuleSystem* module_system = context_->module_system(); | 145 ModuleSystem* module_system = context_->module_system(); |
| 145 module_system->RegisterNativeHandler("assert", scoped_ptr<NativeHandler>( | 146 module_system->RegisterNativeHandler("assert", scoped_ptr<NativeHandler>( |
| 146 assert_natives_)); | 147 assert_natives_)); |
| 147 module_system->RegisterNativeHandler("logging", scoped_ptr<NativeHandler>( | 148 module_system->RegisterNativeHandler("logging", scoped_ptr<NativeHandler>( |
| 148 new extensions::LoggingNativeHandler(context_.get()))); | 149 new extensions::LoggingNativeHandler(context_.get()))); |
| 149 module_system->RegisterNativeHandler("utils", scoped_ptr<NativeHandler>( | 150 module_system->RegisterNativeHandler( |
| 150 new extensions::UtilsNativeHandler(context_.get()))); | 151 "utils_natives", |
| 152 scoped_ptr<NativeHandler>( |
| 153 new extensions::UtilsNativeHandler(context_.get()))); |
| 151 module_system->SetExceptionHandlerForTest( | 154 module_system->SetExceptionHandlerForTest( |
| 152 scoped_ptr<ModuleSystem::ExceptionHandler>(new FailsOnException)); | 155 scoped_ptr<ModuleSystem::ExceptionHandler>(new FailsOnException)); |
| 153 } | 156 } |
| 154 | 157 |
| 155 ModuleSystemTest::~ModuleSystemTest() { | 158 ModuleSystemTest::~ModuleSystemTest() { |
| 156 context_->v8_context()->Exit(); | 159 context_->v8_context()->Exit(); |
| 157 } | 160 } |
| 158 | 161 |
| 159 void ModuleSystemTest::RegisterModule(const std::string& name, | 162 void ModuleSystemTest::RegisterModule(const std::string& name, |
| 160 const std::string& code) { | 163 const std::string& code) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 200 } |
| 198 | 201 |
| 199 v8::Handle<v8::Object> ModuleSystemTest::CreateGlobal(const std::string& name) { | 202 v8::Handle<v8::Object> ModuleSystemTest::CreateGlobal(const std::string& name) { |
| 200 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 203 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 201 v8::EscapableHandleScope handle_scope(isolate); | 204 v8::EscapableHandleScope handle_scope(isolate); |
| 202 v8::Local<v8::Object> object = v8::Object::New(isolate); | 205 v8::Local<v8::Object> object = v8::Object::New(isolate); |
| 203 isolate->GetCurrentContext()->Global()->Set( | 206 isolate->GetCurrentContext()->Global()->Set( |
| 204 v8::String::NewFromUtf8(isolate, name.c_str()), object); | 207 v8::String::NewFromUtf8(isolate, name.c_str()), object); |
| 205 return handle_scope.Escape(object); | 208 return handle_scope.Escape(object); |
| 206 } | 209 } |
| OLD | NEW |