Flutter Engine
The Flutter Engine
platform_message_response_dart_port_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/common/task_runners.h"
6#include "flutter/fml/mapping.h"
7#include "flutter/fml/synchronization/waitable_event.h"
8#include "flutter/lib/ui/window/platform_message_response_dart_port.h"
9#include "flutter/runtime/dart_vm.h"
10#include "flutter/shell/common/shell_test.h"
11#include "flutter/shell/common/thread_host.h"
12#include "flutter/testing/testing.h"
13
14namespace flutter {
15namespace testing {
16
18 bool did_pass = false;
19 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
20 TaskRunners task_runners("test", // label
21 GetCurrentTaskRunner(), // platform
22 CreateNewThread(), // raster
23 CreateNewThread(), // ui
24 CreateNewThread() // io
25 );
26
27 auto nativeCallPlatformMessageResponseDartPort =
28 [ui_task_runner =
30 auto dart_state = std::make_shared<tonic::DartState>();
31 auto response = fml::MakeRefCounted<PlatformMessageResponseDartPort>(
34 123, "foobar");
35 uint8_t* data = static_cast<uint8_t*>(malloc(100));
36 auto mapping = std::make_unique<fml::MallocMapping>(data, 100);
37 response->Complete(std::move(mapping));
38 };
39
40 AddNativeCallback(
41 "CallPlatformMessageResponseDartPort",
42 CREATE_NATIVE_ENTRY(nativeCallPlatformMessageResponseDartPort));
43
44 auto nativeFinishCallResponse = [message_latch,
45 &did_pass](Dart_NativeArguments args) {
46 did_pass =
48 message_latch->Signal();
49 };
50
51 AddNativeCallback("FinishCallResponse",
52 CREATE_NATIVE_ENTRY(nativeFinishCallResponse));
53
54 Settings settings = CreateSettingsForFixture();
55
56 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
57
58 ASSERT_TRUE(shell->IsSetup());
60 configuration.SetEntrypoint("platformMessagePortResponseTest");
61
62 shell->RunEngine(std::move(configuration), [](auto result) {
64 });
65
66 message_latch->Wait();
67
68 ASSERT_TRUE(did_pass);
69 DestroyShell(std::move(shell), task_runners);
70}
71
72} // namespace testing
73} // namespace flutter
A PlatformMessageResponse that will respond over a Dart port.
static RunConfiguration InferFromSettings(const Settings &settings, const fml::RefPtr< fml::TaskRunner > &io_worker=nullptr, IsolateLaunchType launch_type=IsolateLaunchType::kNewGroup)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
fml::RefPtr< fml::TaskRunner > GetUITaskRunner() const
Definition: task_runners.cc:34
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
struct _Dart_NativeArguments * Dart_NativeArguments
Definition: dart_api.h:3019
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
GAsyncResult * result
fml::RefPtr< fml::TaskRunner > CreateNewThread(const std::string &name)
fml::RefPtr< fml::TaskRunner > GetCurrentTaskRunner()
void * malloc(size_t size)
Definition: allocation.cc:19
TEST_F(DisplayListTest, Defaults)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition: switches.h:41
#define CREATE_NATIVE_ENTRY(native_entry)