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" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
18 #include "extensions/common/extension_paths.h" | 18 #include "extensions/common/extension_paths.h" |
19 #include "extensions/renderer/logging_native_handler.h" | 19 #include "extensions/renderer/logging_native_handler.h" |
20 #include "extensions/renderer/object_backed_native_handler.h" | 20 #include "extensions/renderer/object_backed_native_handler.h" |
21 #include "extensions/renderer/safe_builtins.h" | 21 #include "extensions/renderer/safe_builtins.h" |
22 #include "extensions/renderer/utils_native_handler.h" | 22 #include "extensions/renderer/utils_native_handler.h" |
23 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
24 | 24 |
25 namespace extensions { | 25 namespace extensions { |
26 namespace { | 26 namespace { |
27 | 27 |
28 class FailsOnException : public ModuleSystem::ExceptionHandler { | 28 class FailsOnException : public ModuleSystem::ExceptionHandler { |
29 public: | 29 public: |
30 virtual void HandleUncaughtException(const v8::TryCatch& try_catch) OVERRIDE { | 30 virtual void HandleUncaughtException(const v8::TryCatch& try_catch) override { |
31 FAIL() << "Uncaught exception: " << CreateExceptionString(try_catch); | 31 FAIL() << "Uncaught exception: " << CreateExceptionString(try_catch); |
32 } | 32 } |
33 }; | 33 }; |
34 | 34 |
35 class V8ExtensionConfigurator { | 35 class V8ExtensionConfigurator { |
36 public: | 36 public: |
37 V8ExtensionConfigurator() | 37 V8ExtensionConfigurator() |
38 : safe_builtins_(SafeBuiltins::CreateV8Extension()), | 38 : safe_builtins_(SafeBuiltins::CreateV8Extension()), |
39 names_(1, safe_builtins_->name()), | 39 names_(1, safe_builtins_->name()), |
40 configuration_( | 40 configuration_( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 virtual ~StringSourceMap() {} | 102 virtual ~StringSourceMap() {} |
103 | 103 |
104 virtual v8::Handle<v8::Value> GetSource(v8::Isolate* isolate, | 104 virtual v8::Handle<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 virtual bool Contains(const std::string& name) OVERRIDE { | 111 virtual 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) { |
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_; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 246 |
247 void ModuleSystemTest::ExpectNoAssertionsMade() { | 247 void ModuleSystemTest::ExpectNoAssertionsMade() { |
248 should_assertions_be_made_ = false; | 248 should_assertions_be_made_ = false; |
249 } | 249 } |
250 | 250 |
251 void ModuleSystemTest::RunResolvedPromises() { | 251 void ModuleSystemTest::RunResolvedPromises() { |
252 isolate_->RunMicrotasks(); | 252 isolate_->RunMicrotasks(); |
253 } | 253 } |
254 | 254 |
255 } // namespace extensions | 255 } // namespace extensions |
OLD | NEW |