[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 5 | #include "extensions/renderer/module_system_test.h" |
| 6 | |
avi | 2d124c0 | 2015-12-23 06:36:42 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 9 | #include <map> |
dcheng | f6f8066 | 2016-04-20 20:26:04 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 11 | #include <string> |
dcheng | e59eca160 | 2015-12-18 17:48:00 | [diff] [blame] | 12 | #include <utility> |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 13 | |
| 14 | #include "base/callback.h" |
rdevlin.cronin | 585b125 | 2016-04-19 23:29:26 | [diff] [blame] | 15 | #include "base/command_line.h" |
[email protected] | f8d87d3 | 2013-06-06 02:51:29 | [diff] [blame] | 16 | #include "base/files/file_path.h" |
thestig | 9471270 | 2014-09-10 07:46:59 | [diff] [blame] | 17 | #include "base/files/file_util.h" |
[email protected] | 295890bd | 2013-06-15 10:52:45 | [diff] [blame] | 18 | #include "base/lazy_instance.h" |
dcheng | f6f8066 | 2016-04-20 20:26:04 | [diff] [blame] | 19 | #include "base/memory/ptr_util.h" |
[email protected] | f8d87d3 | 2013-06-06 02:51:29 | [diff] [blame] | 20 | #include "base/path_service.h" |
[email protected] | 4570a25 | 2013-03-31 00:35:43 | [diff] [blame] | 21 | #include "base/strings/string_piece.h" |
Devlin Cronin | 2db58e3 | 2017-08-15 21:29:29 | [diff] [blame^] | 22 | #include "extensions/common/extension_builder.h" |
[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 23 | #include "extensions/common/extension_paths.h" |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 24 | #include "extensions/common/feature_switch.h" |
Devlin Cronin | 2db58e3 | 2017-08-15 21:29:29 | [diff] [blame^] | 25 | #include "extensions/common/value_builder.h" |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 26 | #include "extensions/renderer/ipc_message_sender.h" |
[email protected] | 701a94e | 2014-04-17 04:37:37 | [diff] [blame] | 27 | #include "extensions/renderer/logging_native_handler.h" |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 28 | #include "extensions/renderer/native_extension_bindings_system.h" |
[email protected] | f55c90ee6 | 2014-04-12 00:50:03 | [diff] [blame] | 29 | #include "extensions/renderer/object_backed_native_handler.h" |
kalman | 33076cb | 2015-08-11 19:12:07 | [diff] [blame] | 30 | #include "extensions/renderer/safe_builtins.h" |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 31 | #include "extensions/renderer/script_context_set.h" |
rdevlin.cronin | 892cc67 | 2016-12-19 20:00:18 | [diff] [blame] | 32 | #include "extensions/renderer/string_source_map.h" |
| 33 | #include "extensions/renderer/test_v8_extension_configuration.h" |
[email protected] | 701a94e | 2014-04-17 04:37:37 | [diff] [blame] | 34 | #include "extensions/renderer/utils_native_handler.h" |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 35 | #include "gin/converter.h" |
[email protected] | 11844fa | 2012-05-10 00:35:59 | [diff] [blame] | 36 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 37 | |
[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 38 | namespace extensions { |
[email protected] | 295890bd | 2013-06-15 10:52:45 | [diff] [blame] | 39 | namespace { |
| 40 | |
| 41 | class FailsOnException : public ModuleSystem::ExceptionHandler { |
| 42 | public: |
bashi | 6a4854f | 2015-06-19 00:51:51 | [diff] [blame] | 43 | FailsOnException() : ModuleSystem::ExceptionHandler(nullptr) {} |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 44 | void HandleUncaughtException(const v8::TryCatch& try_catch) override { |
[email protected] | 295890bd | 2013-06-15 10:52:45 | [diff] [blame] | 45 | FAIL() << "Uncaught exception: " << CreateExceptionString(try_catch); |
| 46 | } |
| 47 | }; |
| 48 | |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 49 | class GetAPINatives : public ObjectBackedNativeHandler { |
| 50 | public: |
| 51 | GetAPINatives(ScriptContext* context, |
| 52 | NativeExtensionBindingsSystem* bindings_system) |
| 53 | : ObjectBackedNativeHandler(context) { |
| 54 | DCHECK_EQ(FeatureSwitch::native_crx_bindings()->IsEnabled(), |
| 55 | !!bindings_system); |
| 56 | |
| 57 | auto get_api = [](ScriptContext* context, |
| 58 | NativeExtensionBindingsSystem* bindings_system, |
| 59 | const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 60 | CHECK_EQ(1, args.Length()); |
| 61 | CHECK(args[0]->IsString()); |
| 62 | std::string api_name = gin::V8ToString(args[0]); |
| 63 | v8::Local<v8::Object> api; |
| 64 | if (bindings_system) { |
| 65 | api = bindings_system->GetAPIObjectForTesting(context, api_name); |
| 66 | } else { |
| 67 | v8::Local<v8::Object> full_binding; |
| 68 | CHECK( |
| 69 | context->module_system()->Require(api_name).ToLocal(&full_binding)) |
| 70 | << "Failed to get: " << api_name; |
| 71 | v8::Local<v8::Value> api_value; |
| 72 | CHECK(full_binding |
| 73 | ->Get(context->v8_context(), |
| 74 | gin::StringToSymbol(context->isolate(), "binding")) |
| 75 | .ToLocal(&api_value)) |
| 76 | << "Failed to get: " << api_name; |
| 77 | CHECK(api_value->IsObject()) << "Failed to get: " << api_name; |
| 78 | api = api_value.As<v8::Object>(); |
| 79 | } |
| 80 | args.GetReturnValue().Set(api); |
| 81 | }; |
| 82 | |
| 83 | RouteFunction("get", base::Bind(get_api, context, bindings_system)); |
| 84 | } |
| 85 | }; |
| 86 | |
[email protected] | 295890bd | 2013-06-15 10:52:45 | [diff] [blame] | 87 | } // namespace |
| 88 | |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 89 | // Native JS functions for doing asserts. |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 90 | class ModuleSystemTestEnvironment::AssertNatives |
| 91 | : public ObjectBackedNativeHandler { |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 92 | public: |
[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 93 | explicit AssertNatives(ScriptContext* context) |
[email protected] | 4f1633f | 2013-03-09 14:26:24 | [diff] [blame] | 94 | : ObjectBackedNativeHandler(context), |
[email protected] | 2e0e0bc | 2013-02-04 10:30:34 | [diff] [blame] | 95 | assertion_made_(false), |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 96 | failed_(false) { |
[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 97 | RouteFunction( |
| 98 | "AssertTrue", |
| 99 | base::Bind(&AssertNatives::AssertTrue, base::Unretained(this))); |
| 100 | RouteFunction( |
| 101 | "AssertFalse", |
| 102 | base::Bind(&AssertNatives::AssertFalse, base::Unretained(this))); |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | bool assertion_made() { return assertion_made_; } |
| 106 | bool failed() { return failed_; } |
| 107 | |
[email protected] | d8c5fbb | 2013-06-14 11:35:25 | [diff] [blame] | 108 | void AssertTrue(const v8::FunctionCallbackInfo<v8::Value>& args) { |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 109 | CHECK_EQ(1, args.Length()); |
| 110 | assertion_made_ = true; |
dcarney | 04cd964 | 2014-11-21 13:58:11 | [diff] [blame] | 111 | failed_ = failed_ || !args[0]->ToBoolean(args.GetIsolate())->Value(); |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 112 | } |
| 113 | |
[email protected] | d8c5fbb | 2013-06-14 11:35:25 | [diff] [blame] | 114 | void AssertFalse(const v8::FunctionCallbackInfo<v8::Value>& args) { |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 115 | CHECK_EQ(1, args.Length()); |
| 116 | assertion_made_ = true; |
dcarney | 04cd964 | 2014-11-21 13:58:11 | [diff] [blame] | 117 | failed_ = failed_ || args[0]->ToBoolean(args.GetIsolate())->Value(); |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | private: |
| 121 | bool assertion_made_; |
| 122 | bool failed_; |
| 123 | }; |
| 124 | |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 125 | ModuleSystemTestEnvironment::ModuleSystemTestEnvironment( |
| 126 | v8::Isolate* isolate, |
Devlin Cronin | 2db58e3 | 2017-08-15 21:29:29 | [diff] [blame^] | 127 | ScriptContextSet* context_set, |
| 128 | scoped_refptr<const Extension> extension) |
[email protected] | 99ea16b | 2014-07-17 22:15:56 | [diff] [blame] | 129 | : isolate_(isolate), |
| 130 | context_holder_(new gin::ContextHolder(isolate_)), |
| 131 | handle_scope_(isolate_), |
Devlin Cronin | 2db58e3 | 2017-08-15 21:29:29 | [diff] [blame^] | 132 | extension_(extension), |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 133 | context_set_(context_set), |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 134 | source_map_(new StringSourceMap()) { |
kalman | 33076cb | 2015-08-11 19:12:07 | [diff] [blame] | 135 | context_holder_->SetContext(v8::Context::New( |
rdevlin.cronin | 892cc67 | 2016-12-19 20:00:18 | [diff] [blame] | 136 | isolate, TestV8ExtensionConfiguration::GetConfiguration())); |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 137 | |
| 138 | { |
Devlin Cronin | 2db58e3 | 2017-08-15 21:29:29 | [diff] [blame^] | 139 | auto context = base::MakeUnique<ScriptContext>( |
| 140 | context_holder_->context(), |
| 141 | nullptr, // WebFrame |
| 142 | extension_.get(), Feature::BLESSED_EXTENSION_CONTEXT, extension_.get(), |
| 143 | Feature::BLESSED_EXTENSION_CONTEXT); |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 144 | context_ = context.get(); |
| 145 | context_set_->AddForTesting(std::move(context)); |
| 146 | } |
| 147 | |
[email protected] | 9a59844 | 2013-06-04 16:39:12 | [diff] [blame] | 148 | context_->v8_context()->Enter(); |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 149 | assert_natives_ = new AssertNatives(context_); |
| 150 | |
| 151 | if (FeatureSwitch::native_crx_bindings()->IsEnabled()) |
| 152 | bindings_system_ = base::MakeUnique<NativeExtensionBindingsSystem>(nullptr); |
[email protected] | 2a35687 | 2014-02-21 23:18:52 | [diff] [blame] | 153 | |
| 154 | { |
dcheng | f6f8066 | 2016-04-20 20:26:04 | [diff] [blame] | 155 | std::unique_ptr<ModuleSystem> module_system( |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 156 | new ModuleSystem(context_, source_map_.get())); |
dcheng | e59eca160 | 2015-12-18 17:48:00 | [diff] [blame] | 157 | context_->set_module_system(std::move(module_system)); |
[email protected] | 2a35687 | 2014-02-21 23:18:52 | [diff] [blame] | 158 | } |
| 159 | ModuleSystem* module_system = context_->module_system(); |
[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 160 | module_system->RegisterNativeHandler( |
dcheng | f6f8066 | 2016-04-20 20:26:04 | [diff] [blame] | 161 | "assert", std::unique_ptr<NativeHandler>(assert_natives_)); |
[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 162 | module_system->RegisterNativeHandler( |
| 163 | "logging", |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 164 | std::unique_ptr<NativeHandler>(new LoggingNativeHandler(context_))); |
[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 165 | module_system->RegisterNativeHandler( |
| 166 | "utils", |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 167 | std::unique_ptr<NativeHandler>(new UtilsNativeHandler(context_))); |
| 168 | module_system->RegisterNativeHandler( |
| 169 | "apiGetter", |
| 170 | base::MakeUnique<GetAPINatives>(context_, bindings_system_.get())); |
[email protected] | 2a35687 | 2014-02-21 23:18:52 | [diff] [blame] | 171 | module_system->SetExceptionHandlerForTest( |
dcheng | f6f8066 | 2016-04-20 20:26:04 | [diff] [blame] | 172 | std::unique_ptr<ModuleSystem::ExceptionHandler>(new FailsOnException)); |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 173 | |
| 174 | if (bindings_system_) { |
| 175 | bindings_system_->DidCreateScriptContext(context_); |
| 176 | bindings_system_->UpdateBindingsForContext(context_); |
| 177 | } |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 178 | } |
| 179 | |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 180 | ModuleSystemTestEnvironment::~ModuleSystemTestEnvironment() { |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 181 | if (context_) |
kalman | b0c1c50 | 2015-04-15 00:25:06 | [diff] [blame] | 182 | ShutdownModuleSystem(); |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 183 | } |
| 184 | |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 185 | void ModuleSystemTestEnvironment::RegisterModule(const std::string& name, |
| 186 | const std::string& code) { |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 187 | source_map_->RegisterModule(name, code); |
| 188 | } |
| 189 | |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 190 | void ModuleSystemTestEnvironment::RegisterModule(const std::string& name, |
| 191 | int resource_id) { |
[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 192 | const std::string& code = ResourceBundle::GetSharedInstance() |
| 193 | .GetRawDataResource(resource_id) |
| 194 | .as_string(); |
[email protected] | 11844fa | 2012-05-10 00:35:59 | [diff] [blame] | 195 | source_map_->RegisterModule(name, code); |
| 196 | } |
| 197 | |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 198 | void ModuleSystemTestEnvironment::OverrideNativeHandler( |
| 199 | const std::string& name, |
| 200 | const std::string& code) { |
[email protected] | 11844fa | 2012-05-10 00:35:59 | [diff] [blame] | 201 | RegisterModule(name, code); |
[email protected] | 2a35687 | 2014-02-21 23:18:52 | [diff] [blame] | 202 | context_->module_system()->OverrideNativeHandlerForTest(name); |
[email protected] | 11844fa | 2012-05-10 00:35:59 | [diff] [blame] | 203 | } |
| 204 | |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 205 | void ModuleSystemTestEnvironment::RegisterTestFile( |
| 206 | const std::string& module_name, |
| 207 | const std::string& file_name) { |
[email protected] | f8d87d3 | 2013-06-06 02:51:29 | [diff] [blame] | 208 | base::FilePath test_js_file_path; |
[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 209 | ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_js_file_path)); |
| 210 | test_js_file_path = test_js_file_path.AppendASCII(file_name); |
[email protected] | f8d87d3 | 2013-06-06 02:51:29 | [diff] [blame] | 211 | std::string test_js; |
[email protected] | 82f84b9 | 2013-08-30 18:23:50 | [diff] [blame] | 212 | ASSERT_TRUE(base::ReadFileToString(test_js_file_path, &test_js)); |
[email protected] | f8d87d3 | 2013-06-06 02:51:29 | [diff] [blame] | 213 | source_map_->RegisterModule(module_name, test_js); |
| 214 | } |
| 215 | |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 216 | void ModuleSystemTestEnvironment::ShutdownGin() { |
| 217 | context_holder_.reset(); |
| 218 | } |
| 219 | |
| 220 | void ModuleSystemTestEnvironment::ShutdownModuleSystem() { |
kalman | b0c1c50 | 2015-04-15 00:25:06 | [diff] [blame] | 221 | CHECK(context_->is_valid()); |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 222 | context_->v8_context()->Exit(); |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 223 | context_set_->Remove(context_); |
| 224 | base::RunLoop().RunUntilIdle(); |
| 225 | context_ = nullptr; |
| 226 | assert_natives_ = nullptr; |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 227 | } |
| 228 | |
tfarina | f85316f | 2015-04-29 17:03:40 | [diff] [blame] | 229 | v8::Local<v8::Object> ModuleSystemTestEnvironment::CreateGlobal( |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 230 | const std::string& name) { |
[email protected] | 99ea16b | 2014-07-17 22:15:56 | [diff] [blame] | 231 | v8::EscapableHandleScope handle_scope(isolate_); |
| 232 | v8::Local<v8::Object> object = v8::Object::New(isolate_); |
| 233 | isolate_->GetCurrentContext()->Global()->Set( |
| 234 | v8::String::NewFromUtf8(isolate_, name.c_str()), object); |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 235 | return handle_scope.Escape(object); |
| 236 | } |
| 237 | |
| 238 | ModuleSystemTest::ModuleSystemTest() |
[email protected] | 99ea16b | 2014-07-17 22:15:56 | [diff] [blame] | 239 | : isolate_(v8::Isolate::GetCurrent()), |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 240 | context_set_(&extension_ids_), |
| 241 | should_assertions_be_made_(true) {} |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 242 | |
| 243 | ModuleSystemTest::~ModuleSystemTest() { |
| 244 | } |
| 245 | |
sammc | 32a6fc7d | 2014-09-15 02:47:31 | [diff] [blame] | 246 | void ModuleSystemTest::SetUp() { |
Devlin Cronin | 2db58e3 | 2017-08-15 21:29:29 | [diff] [blame^] | 247 | extension_ = CreateExtension(); |
sammc | 32a6fc7d | 2014-09-15 02:47:31 | [diff] [blame] | 248 | env_ = CreateEnvironment(); |
rdevlin.cronin | 585b125 | 2016-04-19 23:29:26 | [diff] [blame] | 249 | base::CommandLine::ForCurrentProcess()->AppendSwitch("test-type"); |
sammc | 32a6fc7d | 2014-09-15 02:47:31 | [diff] [blame] | 250 | } |
| 251 | |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 252 | void ModuleSystemTest::TearDown() { |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 253 | // All tests must assert at least once unless otherwise specified. |
Devlin Cronin | 8cade48 | 2017-07-20 03:09:31 | [diff] [blame] | 254 | if (env_->assert_natives()) { // The context may have already been shutdown. |
| 255 | EXPECT_EQ(should_assertions_be_made_, |
| 256 | env_->assert_natives()->assertion_made()); |
| 257 | EXPECT_FALSE(env_->assert_natives()->failed()); |
| 258 | } else { |
| 259 | EXPECT_FALSE(should_assertions_be_made_); |
| 260 | } |
sammc | 32a6fc7d | 2014-09-15 02:47:31 | [diff] [blame] | 261 | env_.reset(); |
| 262 | v8::HeapStatistics stats; |
| 263 | isolate_->GetHeapStatistics(&stats); |
| 264 | size_t old_heap_size = 0; |
| 265 | // Run the GC until the heap size reaches a steady state to ensure that |
| 266 | // all the garbage is collected. |
| 267 | while (stats.used_heap_size() != old_heap_size) { |
| 268 | old_heap_size = stats.used_heap_size(); |
| 269 | isolate_->RequestGarbageCollectionForTesting( |
| 270 | v8::Isolate::kFullGarbageCollection); |
| 271 | isolate_->GetHeapStatistics(&stats); |
| 272 | } |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 273 | } |
| 274 | |
Devlin Cronin | 2db58e3 | 2017-08-15 21:29:29 | [diff] [blame^] | 275 | scoped_refptr<const Extension> ModuleSystemTest::CreateExtension() { |
| 276 | std::unique_ptr<base::DictionaryValue> manifest = |
| 277 | DictionaryBuilder() |
| 278 | .Set("name", "test") |
| 279 | .Set("version", "1.0") |
| 280 | .Set("manifest_version", 2) |
| 281 | .Build(); |
| 282 | return ExtensionBuilder().SetManifest(std::move(manifest)).Build(); |
| 283 | } |
| 284 | |
dcheng | f6f8066 | 2016-04-20 20:26:04 | [diff] [blame] | 285 | std::unique_ptr<ModuleSystemTestEnvironment> |
| 286 | ModuleSystemTest::CreateEnvironment() { |
Devlin Cronin | 2db58e3 | 2017-08-15 21:29:29 | [diff] [blame^] | 287 | return base::MakeUnique<ModuleSystemTestEnvironment>(isolate_, &context_set_, |
| 288 | extension_); |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | void ModuleSystemTest::ExpectNoAssertionsMade() { |
| 292 | should_assertions_be_made_ = false; |
| 293 | } |
| 294 | |
[email protected] | d9f51dad | 2014-07-09 05:39:38 | [diff] [blame] | 295 | void ModuleSystemTest::RunResolvedPromises() { |
dgozman | fdfd5d1 | 2016-03-11 07:50:47 | [diff] [blame] | 296 | v8::MicrotasksScope::PerformCheckpoint(isolate_); |
[email protected] | 1164b86 | 2012-05-09 22:38:37 | [diff] [blame] | 297 | } |
[email protected] | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 298 | |
| 299 | } // namespace extensions |