Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(902)

Side by Side Diff: chrome/test/base/v8_unit_test.cc

Issue 1743763004: Use v8::MicrotasksScope internally in V8RecursionScope. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@v8rs-2-endofscope
Patch Set: v8_helpers Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/child/v8_value_converter_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/v8_unit_test.h" 5 #include "chrome/test/base/v8_unit_test.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "chrome/common/chrome_paths.h" 12 #include "chrome/common/chrome_paths.h"
13 #include "third_party/WebKit/public/web/WebKit.h" 13 #include "third_party/WebKit/public/web/WebKit.h"
14 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
14 15
15 namespace { 16 namespace {
16 17
17 // |args| are passed through the various JavaScript logging functions such as 18 // |args| are passed through the various JavaScript logging functions such as
18 // console.log. Returns a string appropriate for logging with LOG(severity). 19 // console.log. Returns a string appropriate for logging with LOG(severity).
19 std::string LogArgs2String(const v8::FunctionCallbackInfo<v8::Value>& args) { 20 std::string LogArgs2String(const v8::FunctionCallbackInfo<v8::Value>& args) {
20 std::string message; 21 std::string message;
21 bool first = true; 22 bool first = true;
22 for (int i = 0; i < args.Length(); i++) { 23 for (int i = 0; i < args.Length(); i++) {
23 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 24 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 g_test_result_ok = false; 89 g_test_result_ok = false;
89 std::string test_js; 90 std::string test_js;
90 if (!ExecuteJavascriptLibraries()) 91 if (!ExecuteJavascriptLibraries())
91 return false; 92 return false;
92 93
93 v8::Isolate* isolate = blink::mainThreadIsolate(); 94 v8::Isolate* isolate = blink::mainThreadIsolate();
94 v8::HandleScope handle_scope(isolate); 95 v8::HandleScope handle_scope(isolate);
95 v8::Local<v8::Context> context = 96 v8::Local<v8::Context> context =
96 v8::Local<v8::Context>::New(isolate, context_); 97 v8::Local<v8::Context>::New(isolate, context_);
97 v8::Context::Scope context_scope(context); 98 v8::Context::Scope context_scope(context);
99 blink::WebScopedMicrotaskSuppression microtasks_scope;
98 100
99 v8::Local<v8::Value> function_property = 101 v8::Local<v8::Value> function_property =
100 context->Global()->Get(v8::String::NewFromUtf8(isolate, "runTest")); 102 context->Global()->Get(v8::String::NewFromUtf8(isolate, "runTest"));
101 EXPECT_FALSE(function_property.IsEmpty()); 103 EXPECT_FALSE(function_property.IsEmpty());
102 if (::testing::Test::HasNonfatalFailure()) 104 if (::testing::Test::HasNonfatalFailure())
103 return false; 105 return false;
104 EXPECT_TRUE(function_property->IsFunction()); 106 EXPECT_TRUE(function_property->IsFunction());
105 if (::testing::Test::HasNonfatalFailure()) 107 if (::testing::Test::HasNonfatalFailure())
106 return false; 108 return false;
107 v8::Local<v8::Function> function = 109 v8::Local<v8::Function> function =
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 isolate, value.c_str(), v8::String::kNormalString, value.length())); 204 isolate, value.c_str(), v8::String::kNormalString, value.length()));
203 } 205 }
204 206
205 void V8UnitTest::ExecuteScriptInContext(const base::StringPiece& script_source, 207 void V8UnitTest::ExecuteScriptInContext(const base::StringPiece& script_source,
206 const base::StringPiece& script_name) { 208 const base::StringPiece& script_name) {
207 v8::Isolate* isolate = blink::mainThreadIsolate(); 209 v8::Isolate* isolate = blink::mainThreadIsolate();
208 v8::HandleScope handle_scope(isolate); 210 v8::HandleScope handle_scope(isolate);
209 v8::Local<v8::Context> context = 211 v8::Local<v8::Context> context =
210 v8::Local<v8::Context>::New(isolate, context_); 212 v8::Local<v8::Context>::New(isolate, context_);
211 v8::Context::Scope context_scope(context); 213 v8::Context::Scope context_scope(context);
214 blink::WebScopedMicrotaskSuppression microtasks_scope;
212 v8::Local<v8::String> source = 215 v8::Local<v8::String> source =
213 v8::String::NewFromUtf8(isolate, 216 v8::String::NewFromUtf8(isolate,
214 script_source.data(), 217 script_source.data(),
215 v8::String::kNormalString, 218 v8::String::kNormalString,
216 script_source.size()); 219 script_source.size());
217 v8::Local<v8::String> name = 220 v8::Local<v8::String> name =
218 v8::String::NewFromUtf8(isolate, 221 v8::String::NewFromUtf8(isolate,
219 script_name.data(), 222 script_name.data(),
220 v8::String::kNormalString, 223 v8::String::kNormalString,
221 script_name.size()); 224 script_name.size());
(...skipping 28 matching lines...) Expand all
250 } 253 }
251 return str; 254 return str;
252 } 255 }
253 256
254 void V8UnitTest::TestFunction(const std::string& function_name) { 257 void V8UnitTest::TestFunction(const std::string& function_name) {
255 v8::Isolate* isolate = blink::mainThreadIsolate(); 258 v8::Isolate* isolate = blink::mainThreadIsolate();
256 v8::HandleScope handle_scope(isolate); 259 v8::HandleScope handle_scope(isolate);
257 v8::Local<v8::Context> context = 260 v8::Local<v8::Context> context =
258 v8::Local<v8::Context>::New(isolate, context_); 261 v8::Local<v8::Context>::New(isolate, context_);
259 v8::Context::Scope context_scope(context); 262 v8::Context::Scope context_scope(context);
263 blink::WebScopedMicrotaskSuppression microtasks_scope;
260 264
261 v8::Local<v8::Value> function_property = context->Global()->Get( 265 v8::Local<v8::Value> function_property = context->Global()->Get(
262 v8::String::NewFromUtf8(isolate, function_name.c_str())); 266 v8::String::NewFromUtf8(isolate, function_name.c_str()));
263 ASSERT_FALSE(function_property.IsEmpty()); 267 ASSERT_FALSE(function_property.IsEmpty());
264 ASSERT_TRUE(function_property->IsFunction()); 268 ASSERT_TRUE(function_property->IsFunction());
265 v8::Local<v8::Function> function = 269 v8::Local<v8::Function> function =
266 v8::Local<v8::Function>::Cast(function_property); 270 v8::Local<v8::Function>::Cast(function_property);
267 271
268 v8::TryCatch try_catch(isolate); 272 v8::TryCatch try_catch(isolate);
269 v8::Local<v8::Value> result = function->Call(context->Global(), 0, NULL); 273 v8::Local<v8::Value> result = function->Call(context->Global(), 0, NULL);
(...skipping 30 matching lines...) Expand all
300 v8::Local<v8::Array> test_result(args[1].As<v8::Array>()); 304 v8::Local<v8::Array> test_result(args[1].As<v8::Array>());
301 EXPECT_EQ(2U, test_result->Length()); 305 EXPECT_EQ(2U, test_result->Length());
302 if (::testing::Test::HasNonfatalFailure()) 306 if (::testing::Test::HasNonfatalFailure())
303 return; 307 return;
304 g_test_result_ok = test_result->Get(0)->BooleanValue(); 308 g_test_result_ok = test_result->Get(0)->BooleanValue();
305 if (!g_test_result_ok) { 309 if (!g_test_result_ok) {
306 v8::String::Utf8Value message(test_result->Get(1)); 310 v8::String::Utf8Value message(test_result->Get(1));
307 LOG(ERROR) << *message; 311 LOG(ERROR) << *message;
308 } 312 }
309 } 313 }
OLDNEW
« no previous file with comments | « no previous file | content/child/v8_value_converter_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698