9 #include "flutter/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.h"
10 #include "gtest/gtest.h"
17 class TestFlutterWindowsApi :
public testing::StubFlutterWindowsApi {
22 create_called_ =
true;
26 dart_entrypoint_arguments_.clear();
28 dart_entrypoint_arguments_.push_back(
35 bool EngineRun(
const char* entry_point)
override {
41 bool EngineDestroy()
override {
42 destroy_called_ =
true;
47 uint64_t EngineProcessMessages()
override {
return 99; }
57 void EngineReloadSystemFonts()
override { reload_fonts_called_ =
true; }
65 LRESULT* result)
override {
66 last_external_message_ =
message;
70 bool create_called() {
return create_called_; }
72 bool run_called() {
return run_called_; }
74 bool destroy_called() {
return destroy_called_; }
76 bool reload_fonts_called() {
return reload_fonts_called_; }
78 const std::vector<std::string>& dart_entrypoint_arguments() {
79 return dart_entrypoint_arguments_;
82 bool has_next_frame_callback() {
return next_frame_callback_ !=
nullptr; }
83 void run_next_frame_callback() {
84 next_frame_callback_(next_frame_user_data_);
85 next_frame_callback_ =
nullptr;
88 UINT last_external_message() {
return last_external_message_; }
91 bool create_called_ =
false;
92 bool run_called_ =
false;
93 bool destroy_called_ =
false;
94 bool reload_fonts_called_ =
false;
95 std::vector<std::string> dart_entrypoint_arguments_;
97 void* next_frame_user_data_ =
nullptr;
98 UINT last_external_message_ = 0;
103 TEST(FlutterEngineTest, CreateDestroy) {
104 testing::ScopedStubFlutterWindowsApi scoped_api_stub(
105 std::make_unique<TestFlutterWindowsApi>());
106 auto test_api =
static_cast<TestFlutterWindowsApi*
>(scoped_api_stub.stub());
110 EXPECT_EQ(test_api->create_called(),
true);
111 EXPECT_EQ(test_api->run_called(),
true);
112 EXPECT_EQ(test_api->destroy_called(),
false);
115 EXPECT_EQ(test_api->destroy_called(),
true);
118 TEST(FlutterEngineTest, CreateDestroyWithCustomEntrypoint) {
119 testing::ScopedStubFlutterWindowsApi scoped_api_stub(
120 std::make_unique<TestFlutterWindowsApi>());
121 auto test_api =
static_cast<TestFlutterWindowsApi*
>(scoped_api_stub.stub());
127 EXPECT_EQ(test_api->create_called(),
true);
128 EXPECT_EQ(test_api->run_called(),
true);
129 EXPECT_EQ(test_api->destroy_called(),
false);
132 EXPECT_EQ(test_api->destroy_called(),
true);
135 TEST(FlutterEngineTest, ExplicitShutDown) {
136 testing::ScopedStubFlutterWindowsApi scoped_api_stub(
137 std::make_unique<TestFlutterWindowsApi>());
138 auto test_api =
static_cast<TestFlutterWindowsApi*
>(scoped_api_stub.stub());
142 EXPECT_EQ(test_api->create_called(),
true);
143 EXPECT_EQ(test_api->run_called(),
true);
144 EXPECT_EQ(test_api->destroy_called(),
false);
146 EXPECT_EQ(test_api->destroy_called(),
true);
149 TEST(FlutterEngineTest, ProcessMessages) {
150 testing::ScopedStubFlutterWindowsApi scoped_api_stub(
151 std::make_unique<TestFlutterWindowsApi>());
152 auto test_api =
static_cast<TestFlutterWindowsApi*
>(scoped_api_stub.stub());
158 EXPECT_EQ(next_event_time.count(), 99);
161 TEST(FlutterEngineTest, ReloadFonts) {
162 testing::ScopedStubFlutterWindowsApi scoped_api_stub(
163 std::make_unique<TestFlutterWindowsApi>());
164 auto test_api =
static_cast<TestFlutterWindowsApi*
>(scoped_api_stub.stub());
170 EXPECT_TRUE(test_api->reload_fonts_called());
173 TEST(FlutterEngineTest, GetMessenger) {
175 testing::ScopedStubFlutterWindowsApi scoped_api_stub(
176 std::make_unique<TestFlutterWindowsApi>());
177 auto test_api =
static_cast<TestFlutterWindowsApi*
>(scoped_api_stub.stub());
183 TEST(FlutterEngineTest, DartEntrypointArgs) {
184 testing::ScopedStubFlutterWindowsApi scoped_api_stub(
185 std::make_unique<TestFlutterWindowsApi>());
186 auto test_api =
static_cast<TestFlutterWindowsApi*
>(scoped_api_stub.stub());
189 std::vector<std::string> arguments = {
"one",
"two"};
193 const std::vector<std::string>& arguments_ref =
194 test_api->dart_entrypoint_arguments();
195 ASSERT_EQ(2, arguments_ref.size());
196 EXPECT_TRUE(arguments[0] == arguments_ref[0]);
197 EXPECT_TRUE(arguments[1] == arguments_ref[1]);
200 TEST(FlutterEngineTest, SetNextFrameCallback) {
202 testing::ScopedStubFlutterWindowsApi scoped_api_stub(
203 std::make_unique<TestFlutterWindowsApi>());
204 auto test_api =
static_cast<TestFlutterWindowsApi*
>(scoped_api_stub.stub());
208 bool success =
false;
211 EXPECT_TRUE(test_api->has_next_frame_callback());
213 test_api->run_next_frame_callback();
215 EXPECT_TRUE(success);
218 TEST(FlutterEngineTest, ProcessExternalWindowMessage) {
219 testing::ScopedStubFlutterWindowsApi scoped_api_stub(
220 std::make_unique<TestFlutterWindowsApi>());
221 auto test_api =
static_cast<TestFlutterWindowsApi*
>(scoped_api_stub.stub());
227 EXPECT_EQ(test_api->last_external_message(), 1234);