Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
dart_persistent_handle_unittest.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/testing/dart_isolate_runner.h"
6#include "flutter/testing/fixture_test.h"
7
8namespace flutter {
9namespace testing {
10
12 public:
22
24
25 [[nodiscard]] bool RunWithEntrypoint(const std::string& entrypoint) {
26 if (running_isolate_) {
27 return false;
28 }
29 auto isolate =
32 if (!isolate || isolate->get()->GetPhase() != DartIsolate::Phase::Running) {
33 return false;
34 }
35
36 running_isolate_ = std::move(isolate);
37 return true;
38 }
39
40 protected:
43 std::unique_ptr<AutoIsolateShutdown> running_isolate_;
47};
48
49TEST_F(DartPersistentHandleTest, ClearAfterShutdown) {
50 auto persistent_value = tonic::DartPersistentValue();
51
53 AddNativeCallback("GiveObjectToNative",
55 auto handle = Dart_GetNativeArgument(args, 0);
56
57 auto dart_state = tonic::DartState::Current();
58 ASSERT_TRUE(dart_state);
59 ASSERT_TRUE(tonic::DartState::Current());
60 persistent_value.Set(dart_state, handle);
61
62 event.Signal();
63 }));
64
65 ASSERT_TRUE(RunWithEntrypoint("callGiveObjectToNative"));
66 event.Wait();
67
68 running_isolate_->Shutdown();
69
71 task_runners_.GetUITaskRunner()->PostTask([&] {
72 persistent_value.Clear();
73 clear.Signal();
74 });
75 clear.Wait();
76}
77} // namespace testing
78} // namespace flutter
static sk_sp< Effect > Create()
virtual Settings CreateSettingsForFixture()
std::unique_ptr< AutoIsolateShutdown > running_isolate_
FML_DISALLOW_COPY_AND_ASSIGN(DartPersistentHandleTest)
fml::RefPtr< fml::TaskRunner > CreateNewThread(const std::string &name="")
Creates a new thread, initializes a message loop on it, and, returns its task runner to the unit-test...
static DartState * Current()
Definition dart_state.cc:56
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
struct _Dart_NativeArguments * Dart_NativeArguments
Definition dart_api.h:3010
TaskRunners task_runners_
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent * event
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)
std::string GetDefaultKernelFilePath()
Returns the default path to kernel_blob.bin. This file is within the directory returned by GetFixture...
Definition testing.cc:19
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)
#define CREATE_NATIVE_ENTRY(native_entry)