Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
platform_message_response_dart_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.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 nativeCallPlatformMessageResponseDart =
28 [ui_task_runner =
30 auto dart_state = std::make_shared<tonic::DartState>();
31 auto response = fml::MakeRefCounted<PlatformMessageResponseDart>(
34 ui_task_runner, "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("CallPlatformMessageResponseDart",
41 CREATE_NATIVE_ENTRY(nativeCallPlatformMessageResponseDart));
42
43 auto nativeFinishCallResponse = [message_latch,
44 &did_pass](Dart_NativeArguments args) {
45 did_pass =
47 message_latch->Signal();
48 };
49
50 AddNativeCallback("FinishCallResponse",
51 CREATE_NATIVE_ENTRY(nativeFinishCallResponse));
52
53 Settings settings = CreateSettingsForFixture();
54
55 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
56
57 ASSERT_TRUE(shell->IsSetup());
58 auto configuration = RunConfiguration::InferFromSettings(settings);
59 configuration.SetEntrypoint("platformMessageResponseTest");
60
61 shell->RunEngine(std::move(configuration), [](auto result) {
63 });
64
65 message_latch->Wait();
66
67 ASSERT_TRUE(did_pass);
68 DestroyShell(std::move(shell), task_runners);
69}
70
71} // namespace testing
72} // namespace flutter
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
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
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
GAsyncResult * result
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)