Flutter Engine
The 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
5#include "flutter/runtime/dart_isolate.h"
6
7#include "flutter/fml/paths.h"
8#include "flutter/runtime/dart_vm.h"
9#include "flutter/runtime/dart_vm_lifecycle.h"
10#include "flutter/testing/dart_isolate_runner.h"
11#include "flutter/testing/fixture_test.h"
12#include "flutter/testing/testing.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 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
30
31 std::vector<std::string> messages;
33
34 AddNativeCallback(
35 "PassMessage",
36 CREATE_NATIVE_ENTRY(([&latch, &messages](Dart_NativeArguments args) {
39 messages.push_back(message);
40 latch.Signal();
41 })));
42
43 auto settings = CreateSettingsForFixture();
44 auto did_throw_exception = false;
45 settings.unhandled_exception_callback = [&](const std::string& error,
46 const std::string& stack_trace) {
47 did_throw_exception = true;
48 return true;
49 };
50
51 auto vm_ref = DartVMRef::Create(settings);
52 auto thread = CreateNewThread();
53 TaskRunners task_runners(GetCurrentTestName(), //
54 thread, //
55 thread, //
56 thread, //
57 thread //
58 );
59
60 auto kernel_path =
62 auto isolate = RunDartCodeInIsolate(vm_ref, settings, task_runners, "main",
63 {}, kernel_path);
64
65 ASSERT_TRUE(isolate);
66 ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
67
68 latch.Wait();
69
70 ASSERT_EQ(messages.size(), 1u);
71 ASSERT_EQ(messages[0], "main() was called");
72 ASSERT_FALSE(did_throw_exception);
73}
74
75} // namespace testing
76} // namespace flutter
77
78// 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()
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
struct _Dart_NativeArguments * Dart_NativeArguments
Definition dart_api.h:3010
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint8_t uint32_t uint32_t GError ** error
Win32Message message
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:15
TEST_F(DisplayListTest, Defaults)
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
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::shared_ptr< VolatilePathTracker > volatile_path_tracker, std::unique_ptr< PlatformConfiguration > platform_configuration)
std::string JoinPaths(std::initializer_list< std::string > components)
Definition paths.cc:14
#define CREATE_NATIVE_ENTRY(native_entry)