| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/dart/embedder/test/dart_test.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/files/file_path.h" | |
| 9 #include "base/path_service.h" | |
| 10 #include "base/rand_util.h" | |
| 11 #include "mojo/dart/embedder/dart_controller.h" | |
| 12 #include "mojo/public/c/system/types.h" | |
| 13 #include "mojo/public/cpp/environment/environment.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 | |
| 16 namespace mojo { | |
| 17 namespace dart { | |
| 18 | |
| 19 void DartTest::RunDartTest(const base::FilePath& path, | |
| 20 const std::vector<std::string>& script_arguments, | |
| 21 bool compile_all, | |
| 22 bool expect_unhandled_exception, | |
| 23 int expected_unclosed_handles) { | |
| 24 // Grab the C string pointer. | |
| 25 std::vector<const char*> script_arguments_c_str; | |
| 26 for (size_t i = 0; i < script_arguments.size(); i++) { | |
| 27 script_arguments_c_str.push_back(script_arguments[i].c_str()); | |
| 28 } | |
| 29 DCHECK(script_arguments.size() == script_arguments_c_str.size()); | |
| 30 | |
| 31 // Setup the package root. | |
| 32 base::FilePath package_root; | |
| 33 PathService::Get(base::DIR_EXE, &package_root); | |
| 34 package_root = package_root.AppendASCII("gen") | |
| 35 .AppendASCII("dart-pkg") | |
| 36 .AppendASCII("packages"); | |
| 37 | |
| 38 char* error = nullptr; | |
| 39 bool unhandled_exception = false; | |
| 40 int64_t closed_handles = 0; | |
| 41 DartControllerConfig config; | |
| 42 // Run with strict compilation even in Release mode so that ASAN testing gets | |
| 43 // coverage of Dart asserts, type-checking, etc. | |
| 44 config.strict_compilation = true; | |
| 45 config.compile_all = compile_all; | |
| 46 config.script_uri = path.AsUTF8Unsafe(); | |
| 47 config.package_root = package_root.AsUTF8Unsafe(); | |
| 48 config.callbacks.exception = | |
| 49 base::Bind(&ExceptionCallback, &unhandled_exception, &closed_handles); | |
| 50 config.entropy = GenerateEntropy; | |
| 51 config.error = &error; | |
| 52 | |
| 53 if (script_arguments_c_str.size() > 0) { | |
| 54 config.SetScriptFlags(script_arguments_c_str.data(), | |
| 55 script_arguments_c_str.size()); | |
| 56 } | |
| 57 | |
| 58 bool success = DartController::RunDartScript(config); | |
| 59 EXPECT_TRUE(success) << error; | |
| 60 EXPECT_EQ(expect_unhandled_exception, unhandled_exception); | |
| 61 EXPECT_EQ(expected_unclosed_handles, closed_handles); | |
| 62 } | |
| 63 | |
| 64 } // namespace dart | |
| 65 } // namespace mojo | |
| OLD | NEW |