Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
16
18
20 public:
24
25 void ExpectCompleted(std::string expected) {
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,
39 message.c_str() + message.size()),
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.
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_
void Complete(std::unique_ptr< fml::Mapping > data) override
std::unique_ptr< PlatformMessage > WithMessage(std::string channel, std::string message)
static fml::RefPtr< FakePlatformMessageResponse > Create()
static MallocMapping Copy(const T *begin, const T *end)
Definition mapping.h:162
Win32Message message
RefPtr< T > AdoptRef(T *ptr)
Definition ref_ptr.h:222
#define EXPECT_TRUE(handle)
Definition unit_test.h:685