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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 // join while handles are still open, until the C++ side closes them. | 265 // join while handles are still open, until the C++ side closes them. |
266 base::Thread dart_thread("dart"); | 266 base::Thread dart_thread("dart"); |
267 cpp_side->set_run_loop(&run_loop_); | 267 cpp_side->set_run_loop(&run_loop_); |
268 return RunWithDartOnThread(&dart_thread, test, cpp_side); | 268 return RunWithDartOnThread(&dart_thread, test, cpp_side); |
269 } | 269 } |
270 | 270 |
271 private: | 271 private: |
272 base::MessageLoop loop; | 272 base::MessageLoop loop; |
273 base::RunLoop run_loop_; | 273 base::RunLoop run_loop_; |
274 | 274 |
275 static void UnhandledExceptionCallback(bool* exception, Dart_Handle error) { | 275 static void UnhandledExceptionCallback(bool* exception, |
| 276 int64_t* closed_handles, |
| 277 Dart_Handle error, |
| 278 int64_t count) { |
276 *exception = true; | 279 *exception = true; |
| 280 *closed_handles = count; |
277 } | 281 } |
278 | 282 |
279 static bool GenerateEntropy(uint8_t* buffer, intptr_t length) { | 283 static bool GenerateEntropy(uint8_t* buffer, intptr_t length) { |
280 base::RandBytes(reinterpret_cast<void*>(buffer), length); | 284 base::RandBytes(reinterpret_cast<void*>(buffer), length); |
281 return true; | 285 return true; |
282 } | 286 } |
283 | 287 |
284 static void InitializeDartConfig(DartControllerConfig* config, | 288 static void InitializeDartConfig(DartControllerConfig* config, |
285 const std::string& test, | 289 const std::string& test, |
286 MojoHandle handle, | 290 MojoHandle handle, |
287 const char** arguments, | 291 const char** arguments, |
288 int arguments_count, | 292 int arguments_count, |
289 bool* unhandled_exception, | 293 bool* unhandled_exception, |
| 294 int64_t* closed_handles, |
290 char** error) { | 295 char** error) { |
291 base::FilePath path; | 296 base::FilePath path; |
292 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 297 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
293 path = path.AppendASCII("mojo") | 298 path = path.AppendASCII("mojo") |
294 .AppendASCII("dart") | 299 .AppendASCII("dart") |
295 .AppendASCII("embedder") | 300 .AppendASCII("embedder") |
296 .AppendASCII("test") | 301 .AppendASCII("test") |
297 .AppendASCII(test); | 302 .AppendASCII(test); |
298 | 303 |
299 // Setup the package root. | 304 // Setup the package root. |
300 base::FilePath package_root; | 305 base::FilePath package_root; |
301 PathService::Get(base::DIR_EXE, &package_root); | 306 PathService::Get(base::DIR_EXE, &package_root); |
302 package_root = package_root.AppendASCII("gen") | 307 package_root = package_root.AppendASCII("gen") |
303 .AppendASCII("dart-pkg") | 308 .AppendASCII("dart-pkg") |
304 .AppendASCII("packages"); | 309 .AppendASCII("packages"); |
305 | 310 |
306 | 311 |
307 config->strict_compilation = true; | 312 config->strict_compilation = true; |
308 config->script_uri = path.AsUTF8Unsafe(); | 313 config->script_uri = path.AsUTF8Unsafe(); |
309 config->package_root = package_root.AsUTF8Unsafe(); | 314 config->package_root = package_root.AsUTF8Unsafe(); |
310 config->callbacks.exception = | 315 config->callbacks.exception = base::Bind( |
311 base::Bind(&UnhandledExceptionCallback, unhandled_exception); | 316 &UnhandledExceptionCallback, unhandled_exception, closed_handles); |
312 config->entropy = GenerateEntropy; | 317 config->entropy = GenerateEntropy; |
313 config->handle = handle; | 318 config->handle = handle; |
314 config->SetVmFlags(arguments, arguments_count); | 319 config->SetVmFlags(arguments, arguments_count); |
315 config->error = error; | 320 config->error = error; |
316 } | 321 } |
317 | 322 |
318 static void RunDartSide(const DartControllerConfig& config) { | 323 static void RunDartSide(const DartControllerConfig& config) { |
319 DartController::RunSingleDartScript(config); | 324 DartController::RunSingleDartScript(config); |
320 } | 325 } |
321 | 326 |
322 bool RunWithDartOnThread(base::Thread* dart_thread, | 327 bool RunWithDartOnThread(base::Thread* dart_thread, |
323 const std::string& test, | 328 const std::string& test, |
324 CppSideConnection* cpp_side) { | 329 CppSideConnection* cpp_side) { |
325 dart_to_cpp::DartSidePtr dart_side_ptr; | 330 dart_to_cpp::DartSidePtr dart_side_ptr; |
326 auto dart_side_request = GetProxy(&dart_side_ptr); | 331 auto dart_side_request = GetProxy(&dart_side_ptr); |
327 | 332 |
328 dart_to_cpp::CppSidePtr cpp_side_ptr; | 333 dart_to_cpp::CppSidePtr cpp_side_ptr; |
329 cpp_side->Bind(GetProxy(&cpp_side_ptr)); | 334 cpp_side->Bind(GetProxy(&cpp_side_ptr)); |
330 dart_side_ptr->SetClient(cpp_side_ptr.Pass()); | 335 dart_side_ptr->SetClient(cpp_side_ptr.Pass()); |
331 | 336 |
332 dart_side_ptr.internal_state()->router_for_testing()->EnableTestingMode(); | 337 dart_side_ptr.internal_state()->router_for_testing()->EnableTestingMode(); |
333 | 338 |
334 cpp_side->set_dart_side(dart_side_ptr.get()); | 339 cpp_side->set_dart_side(dart_side_ptr.get()); |
335 | 340 |
336 DartControllerConfig config; | 341 DartControllerConfig config; |
337 char* error; | 342 char* error; |
338 bool unhandled_exception = false; | 343 bool unhandled_exception = false; |
| 344 int64_t closed_handles; |
339 InitializeDartConfig( | 345 InitializeDartConfig( |
340 &config, | 346 &config, test, dart_side_request.PassMessagePipe().release().value(), |
341 test, | 347 nullptr, 0, &unhandled_exception, &closed_handles, &error); |
342 dart_side_request.PassMessagePipe().release().value(), | |
343 nullptr, | |
344 0, | |
345 &unhandled_exception, | |
346 &error); | |
347 | 348 |
348 dart_thread->Start(); | 349 dart_thread->Start(); |
349 dart_thread->message_loop()->PostTask(FROM_HERE, | 350 dart_thread->message_loop()->PostTask(FROM_HERE, |
350 base::Bind(&RunDartSide, base::ConstRef(config))); | 351 base::Bind(&RunDartSide, base::ConstRef(config))); |
351 | 352 |
352 run_loop_.Run(); | 353 run_loop_.Run(); |
353 return unhandled_exception; | 354 return unhandled_exception; |
354 } | 355 } |
355 | 356 |
356 DISALLOW_COPY_AND_ASSIGN(DartToCppTest); | 357 DISALLOW_COPY_AND_ASSIGN(DartToCppTest); |
(...skipping 10 matching lines...) Expand all Loading... |
367 TEST_F(DartToCppTest, Echo) { | 368 TEST_F(DartToCppTest, Echo) { |
368 EchoCppSideConnection cpp_side_connection; | 369 EchoCppSideConnection cpp_side_connection; |
369 bool unhandled_exception = | 370 bool unhandled_exception = |
370 RunTest("dart_to_cpp_tests.dart", &cpp_side_connection); | 371 RunTest("dart_to_cpp_tests.dart", &cpp_side_connection); |
371 EXPECT_TRUE(cpp_side_connection.DidSucceed()); | 372 EXPECT_TRUE(cpp_side_connection.DidSucceed()); |
372 EXPECT_FALSE(unhandled_exception); | 373 EXPECT_FALSE(unhandled_exception); |
373 } | 374 } |
374 | 375 |
375 } // namespace dart | 376 } // namespace dart |
376 } // namespace mojo | 377 } // namespace mojo |
OLD | NEW |