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