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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 bool failed_; | 94 bool failed_; |
95 }; | 95 }; |
96 | 96 |
97 // Source map that operates on std::strings. | 97 // Source map that operates on std::strings. |
98 class ModuleSystemTestEnvironment::StringSourceMap | 98 class ModuleSystemTestEnvironment::StringSourceMap |
99 : public ModuleSystem::SourceMap { | 99 : public ModuleSystem::SourceMap { |
100 public: | 100 public: |
101 StringSourceMap() {} | 101 StringSourceMap() {} |
102 ~StringSourceMap() override {} | 102 ~StringSourceMap() override {} |
103 | 103 |
104 v8::Handle<v8::Value> GetSource(v8::Isolate* isolate, | 104 v8::Local<v8::Value> GetSource(v8::Isolate* isolate, |
105 const std::string& name) override { | 105 const std::string& name) override { |
106 if (source_map_.count(name) == 0) | 106 if (source_map_.count(name) == 0) |
107 return v8::Undefined(isolate); | 107 return v8::Undefined(isolate); |
108 return v8::String::NewFromUtf8(isolate, source_map_[name].c_str()); | 108 return v8::String::NewFromUtf8(isolate, source_map_[name].c_str()); |
109 } | 109 } |
110 | 110 |
111 bool Contains(const std::string& name) override { | 111 bool Contains(const std::string& name) override { |
112 return source_map_.count(name); | 112 return source_map_.count(name); |
113 } | 113 } |
114 | 114 |
115 void RegisterModule(const std::string& name, const std::string& source) { | 115 void RegisterModule(const std::string& name, const std::string& source) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 void ModuleSystemTestEnvironment::ShutdownGin() { | 194 void ModuleSystemTestEnvironment::ShutdownGin() { |
195 context_holder_.reset(); | 195 context_holder_.reset(); |
196 } | 196 } |
197 | 197 |
198 void ModuleSystemTestEnvironment::ShutdownModuleSystem() { | 198 void ModuleSystemTestEnvironment::ShutdownModuleSystem() { |
199 CHECK(context_->is_valid()); | 199 CHECK(context_->is_valid()); |
200 context_->v8_context()->Exit(); | 200 context_->v8_context()->Exit(); |
201 context_->Invalidate(); | 201 context_->Invalidate(); |
202 } | 202 } |
203 | 203 |
204 v8::Handle<v8::Object> ModuleSystemTestEnvironment::CreateGlobal( | 204 v8::Local<v8::Object> ModuleSystemTestEnvironment::CreateGlobal( |
205 const std::string& name) { | 205 const std::string& name) { |
206 v8::EscapableHandleScope handle_scope(isolate_); | 206 v8::EscapableHandleScope handle_scope(isolate_); |
207 v8::Local<v8::Object> object = v8::Object::New(isolate_); | 207 v8::Local<v8::Object> object = v8::Object::New(isolate_); |
208 isolate_->GetCurrentContext()->Global()->Set( | 208 isolate_->GetCurrentContext()->Global()->Set( |
209 v8::String::NewFromUtf8(isolate_, name.c_str()), object); | 209 v8::String::NewFromUtf8(isolate_, name.c_str()), object); |
210 return handle_scope.Escape(object); | 210 return handle_scope.Escape(object); |
211 } | 211 } |
212 | 212 |
213 ModuleSystemTest::ModuleSystemTest() | 213 ModuleSystemTest::ModuleSystemTest() |
214 : isolate_(v8::Isolate::GetCurrent()), | 214 : isolate_(v8::Isolate::GetCurrent()), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 247 |
248 void ModuleSystemTest::ExpectNoAssertionsMade() { | 248 void ModuleSystemTest::ExpectNoAssertionsMade() { |
249 should_assertions_be_made_ = false; | 249 should_assertions_be_made_ = false; |
250 } | 250 } |
251 | 251 |
252 void ModuleSystemTest::RunResolvedPromises() { | 252 void ModuleSystemTest::RunResolvedPromises() { |
253 isolate_->RunMicrotasks(); | 253 isolate_->RunMicrotasks(); |
254 } | 254 } |
255 | 255 |
256 } // namespace extensions | 256 } // namespace extensions |
OLD | NEW |