OLD | NEW |
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/memory/ptr_util.h" |
| 10 #include "base/message_loop/message_loop.h" |
9 #include "base/path_service.h" | 11 #include "base/path_service.h" |
10 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
11 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
12 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
13 #include "third_party/WebKit/public/web/WebKit.h" | 15 #include "third_party/WebKit/public/web/WebKit.h" |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 // |args| are passed through the various JavaScript logging functions such as | 19 // |args| are passed through the various JavaScript logging functions such as |
18 // console.log. Returns a string appropriate for logging with LOG(severity). | 20 // console.log. Returns a string appropriate for logging with LOG(severity). |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 global->Set(v8::String::NewFromUtf8(isolate, "console"), console); | 187 global->Set(v8::String::NewFromUtf8(isolate, "console"), console); |
186 console->Set(log_string, log_function); | 188 console->Set(log_string, log_function); |
187 console->Set(v8::String::NewFromUtf8(isolate, "info"), log_function); | 189 console->Set(v8::String::NewFromUtf8(isolate, "info"), log_function); |
188 console->Set(v8::String::NewFromUtf8(isolate, "warn"), log_function); | 190 console->Set(v8::String::NewFromUtf8(isolate, "warn"), log_function); |
189 v8::Local<v8::FunctionTemplate> error_function = | 191 v8::Local<v8::FunctionTemplate> error_function = |
190 v8::FunctionTemplate::New(isolate, &V8UnitTest::Error); | 192 v8::FunctionTemplate::New(isolate, &V8UnitTest::Error); |
191 error_function->RemovePrototype(); | 193 error_function->RemovePrototype(); |
192 console->Set(v8::String::NewFromUtf8(isolate, "error"), error_function); | 194 console->Set(v8::String::NewFromUtf8(isolate, "error"), error_function); |
193 | 195 |
194 context_.Reset(isolate, v8::Context::New(isolate, NULL, global)); | 196 context_.Reset(isolate, v8::Context::New(isolate, NULL, global)); |
| 197 |
| 198 loop_ = base::MakeUnique<base::MessageLoop>(); |
195 } | 199 } |
196 | 200 |
197 void V8UnitTest::SetGlobalStringVar(const std::string& var_name, | 201 void V8UnitTest::SetGlobalStringVar(const std::string& var_name, |
198 const std::string& value) { | 202 const std::string& value) { |
199 v8::Isolate* isolate = blink::mainThreadIsolate(); | 203 v8::Isolate* isolate = blink::mainThreadIsolate(); |
200 v8::Local<v8::Context> context = | 204 v8::Local<v8::Context> context = |
201 v8::Local<v8::Context>::New(isolate, context_); | 205 v8::Local<v8::Context>::New(isolate, context_); |
202 v8::Context::Scope context_scope(context); | 206 v8::Context::Scope context_scope(context); |
203 context->Global()->Set( | 207 context->Global()->Set( |
204 v8::String::NewFromUtf8(isolate, | 208 v8::String::NewFromUtf8(isolate, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 v8::Local<v8::Array> test_result(args[1].As<v8::Array>()); | 315 v8::Local<v8::Array> test_result(args[1].As<v8::Array>()); |
312 EXPECT_EQ(2U, test_result->Length()); | 316 EXPECT_EQ(2U, test_result->Length()); |
313 if (::testing::Test::HasNonfatalFailure()) | 317 if (::testing::Test::HasNonfatalFailure()) |
314 return; | 318 return; |
315 g_test_result_ok = test_result->Get(0)->BooleanValue(); | 319 g_test_result_ok = test_result->Get(0)->BooleanValue(); |
316 if (!g_test_result_ok) { | 320 if (!g_test_result_ok) { |
317 v8::String::Utf8Value message(test_result->Get(1)); | 321 v8::String::Utf8Value message(test_result->Get(1)); |
318 LOG(ERROR) << *message; | 322 LOG(ERROR) << *message; |
319 } | 323 } |
320 } | 324 } |
OLD | NEW |