Flutter Engine
The Flutter Engine
shell
platform
fuchsia
flutter
tests
fakes
platform_message.h
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
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_FAKES_PLATFORM_MESSAGE_H_
6
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_FAKES_PLATFORM_MESSAGE_H_
7
8
#include <gtest/gtest.h>
9
#include <optional>
10
11
#include "flutter/lib/ui/window/platform_message.h"
12
#include "third_party/rapidjson/include/rapidjson/document.h"
13
14
using
PlatformMessageResponse
=
flutter::PlatformMessageResponse
;
15
using
PlatformMessage
=
flutter::PlatformMessage
;
16
17
namespace
flutter_runner::testing
{
18
19
class
FakePlatformMessageResponse
:
public
PlatformMessageResponse
{
20
public
:
21
static
fml::RefPtr<FakePlatformMessageResponse>
Create
() {
22
return
fml::AdoptRef
(
new
FakePlatformMessageResponse
());
23
}
24
25
void
ExpectCompleted
(std::string expected) {
26
EXPECT_TRUE
(
is_complete_
);
27
if
(
is_complete_
) {
28
EXPECT_EQ(expected, response_);
29
}
30
}
31
32
bool
IsCompleted
() {
return
is_complete_
; }
33
34
std::unique_ptr<PlatformMessage>
WithMessage
(std::string channel,
35
std::string
message
) {
36
return
std::make_unique<PlatformMessage>(
37
channel,
38
fml::MallocMapping::Copy
(
message
.c_str(),
39
message
.c_str() +
message
.size()),
40
fml::RefPtr<FakePlatformMessageResponse>
(
this
));
41
}
42
43
void
Complete
(std::unique_ptr<fml::Mapping>
data
)
override
{
44
response_ =
45
std::string(
data
->GetMapping(),
data
->GetMapping() +
data
->GetSize());
46
FinalizeComplete();
47
};
48
49
void
CompleteEmpty
()
override
{ FinalizeComplete(); };
50
51
private
:
52
// Private constructors.
53
FakePlatformMessageResponse
() {}
54
55
void
FinalizeComplete() {
56
EXPECT_FALSE(std::exchange(
is_complete_
,
true
))
57
<<
"Platform message responses can only be completed once!"
;
58
}
59
60
std::string response_;
61
};
62
63
}
// namespace flutter_runner::testing
64
65
#endif
// FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_FAKES_PLATFORM_MESSAGE_H_
flutter::PlatformMessageResponse
Definition:
platform_message_response.h:17
flutter::PlatformMessageResponse::is_complete_
bool is_complete_
Definition:
platform_message_response.h:31
flutter::PlatformMessage
Definition:
platform_message.h:17
flutter_runner::testing::FakePlatformMessageResponse
Definition:
platform_message.h:19
flutter_runner::testing::FakePlatformMessageResponse::CompleteEmpty
void CompleteEmpty() override
Definition:
platform_message.h:49
flutter_runner::testing::FakePlatformMessageResponse::Complete
void Complete(std::unique_ptr< fml::Mapping > data) override
Definition:
platform_message.h:43
flutter_runner::testing::FakePlatformMessageResponse::WithMessage
std::unique_ptr< PlatformMessage > WithMessage(std::string channel, std::string message)
Definition:
platform_message.h:34
flutter_runner::testing::FakePlatformMessageResponse::Create
static fml::RefPtr< FakePlatformMessageResponse > Create()
Definition:
platform_message.h:21
flutter_runner::testing::FakePlatformMessageResponse::IsCompleted
bool IsCompleted()
Definition:
platform_message.h:32
flutter_runner::testing::FakePlatformMessageResponse::ExpectCompleted
void ExpectCompleted(std::string expected)
Definition:
platform_message.h:25
fml::MallocMapping::Copy
static MallocMapping Copy(const T *begin, const T *end)
Definition:
mapping.h:162
fml::RefPtr
Definition:
ref_ptr.h:65
message
Win32Message message
Definition:
keyboard_unittests.cc:139
flutter_runner::testing
Definition:
engine.h:33
fml::AdoptRef
RefPtr< T > AdoptRef(T *ptr)
Definition:
ref_ptr.h:222
PlatformMessageResponse
flutter::PlatformMessageResponse PlatformMessageResponse
Definition:
platform_message.h:14
PlatformMessage
flutter::PlatformMessage PlatformMessage
Definition:
platform_message.h:15
data
std::shared_ptr< const fml::Mapping > data
Definition:
texture_gles.cc:63
EXPECT_TRUE
#define EXPECT_TRUE(handle)
Definition:
unit_test.h:678
Generated on Sun Jun 23 2024 21:55:06 for Flutter Engine by
1.9.4