Flutter Engine
 
Loading...
Searching...
No Matches
no_dart_plugin_registrant_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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
6
7#include "flutter/fml/paths.h"
13
14// CREATE_NATIVE_ENTRY is leaky by design
15// NOLINTBEGIN(clang-analyzer-core.StackAddressEscape)
16
17namespace flutter {
18namespace testing {
19
20const std::string kKernelFileName = "no_plugin_registrant_kernel_blob.bin";
21const std::string kElfFileName = "no_plugin_registrant_app_elf_snapshot.so";
22
23class DartIsolateTest : public FixtureTest {
24 public:
26};
27
28TEST_F(DartIsolateTest, DartPluginRegistrantIsNotPresent) {
29#if defined(OS_FUCHSIA) && (FLUTTER_RUNTIME_MODE != FLUTTER_RUNTIME_MODE_DEBUG)
30 GTEST_SKIP() << "Dart_LoadELF is not implemented on Fuchsia.";
31#else
32 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
33
34 std::vector<std::string> messages;
36
37 AddNativeCallback(
38 "PassMessage",
39 CREATE_NATIVE_ENTRY(([&latch, &messages](Dart_NativeArguments args) {
41 Dart_GetNativeArgument(args, 0));
42 messages.push_back(message);
43 latch.Signal();
44 })));
45
46 auto settings = CreateSettingsForFixture();
47 auto did_throw_exception = false;
48 settings.unhandled_exception_callback = [&](const std::string& error,
49 const std::string& stack_trace) {
50 did_throw_exception = true;
51 return true;
52 };
53
54 auto vm_ref = DartVMRef::Create(settings);
55 auto thread = CreateNewThread();
56 TaskRunners task_runners(GetCurrentTestName(), //
57 thread, //
58 thread, //
59 thread, //
60 thread //
61 );
62
63 auto kernel_path =
65 auto isolate = RunDartCodeInIsolate(vm_ref, settings, task_runners, "main",
66 {}, kernel_path);
67
68 ASSERT_TRUE(isolate);
69 ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
70
71 latch.Wait();
72
73 ASSERT_EQ(messages.size(), 1u);
74 ASSERT_EQ(messages[0], "main() was called");
75 ASSERT_FALSE(did_throw_exception);
76#endif
77}
78
79} // namespace testing
80} // namespace flutter
81
82// NOLINTEND(clang-analyzer-core.StackAddressEscape)
static DartVMRef Create(const Settings &settings, fml::RefPtr< const DartSnapshot > vm_snapshot=nullptr, fml::RefPtr< const DartSnapshot > isolate_snapshot=nullptr)
static bool IsInstanceRunning()
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_BEGIN_DECLS GBytes * message
const uint8_t uint32_t uint32_t GError ** error
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition testing.cc:14
TEST_F(DisplayListTest, Defaults)
std::unique_ptr< AutoIsolateShutdown > RunDartCodeInIsolate(DartVMRef &vm_ref, const Settings &settings, const TaskRunners &task_runners, std::string entrypoint, const std::vector< std::string > &args, const std::string &kernel_file_path, fml::WeakPtr< IOManager > io_manager, std::unique_ptr< PlatformConfiguration > platform_configuration)
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
std::string JoinPaths(std::initializer_list< std::string > components)
Definition paths.cc:14
#define CREATE_NATIVE_ENTRY(native_entry)