9 #include "flutter/fml/macros.h"
14 #include "flutter/shell/platform/windows/testing/engine_modifier.h"
15 #include "flutter/shell/platform/windows/testing/flutter_windows_engine_builder.h"
16 #include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h"
17 #include "flutter/shell/platform/windows/testing/test_binary_messenger.h"
18 #include "flutter/shell/platform/windows/testing/windows_test.h"
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
27 using ::testing::NotNull;
28 using ::testing::Return;
30 static constexpr
char kChannelName[] =
"flutter/mousecursor";
34 "createCustomCursor/windows";
37 "deleteCustomCursor/windows";
39 void SimulateCursorMessage(TestBinaryMessenger* messenger,
40 const std::string& method_name,
41 std::unique_ptr<EncodableValue> arguments,
42 MethodResult<EncodableValue>* result_handler) {
43 MethodCall<> call(method_name, std::move(arguments));
47 EXPECT_TRUE(messenger->SimulateEngineMessage(
49 [&result_handler](
const uint8_t* reply,
size_t reply_size) {
50 StandardMethodCodec::GetInstance().DecodeAndProcessResponseEnvelope(
51 reply, reply_size, result_handler);
65 MockWindowBindingHandler*
window() {
return window_; }
68 FlutterWindowsEngineBuilder builder{GetContext()};
70 engine_ = builder.Build();
74 FlutterWindowsEngineBuilder builder{GetContext()};
76 auto window = std::make_unique<MockWindowBindingHandler>();
77 EXPECT_CALL(*
window.get(), SetView).Times(1);
78 EXPECT_CALL(*
window.get(), GetWindowHandle).WillRepeatedly(Return(
nullptr));
81 engine_ = builder.Build();
82 view_ = std::make_unique<FlutterWindowsView>(
kImplicitViewId, engine_.get(),
85 EngineModifier modifier{engine_.get()};
86 modifier.SetImplicitView(view_.get());
90 std::unique_ptr<FlutterWindowsEngine> engine_;
91 std::unique_ptr<FlutterWindowsView> view_;
92 MockWindowBindingHandler* window_;
100 TestBinaryMessenger messenger;
103 EXPECT_CALL(*window(), UpdateFlutterCursor(
"click")).Times(1);
105 bool success =
false;
109 EXPECT_EQ(result,
nullptr);
120 EXPECT_TRUE(success);
126 TestBinaryMessenger messenger;
132 [&error](
const std::string& error_code,
const std::string& error_message,
135 EXPECT_EQ(error_message,
136 "Cursor is not available in Windows headless mode");
153 TestBinaryMessenger messenger;
157 std::vector<uint8_t> buffer(4 * 4 * 4, 0);
159 bool success =
false;
163 EXPECT_EQ(std::get<std::string>(*result),
"hello");
178 EXPECT_TRUE(success);
184 TestBinaryMessenger messenger;
188 std::vector<uint8_t> buffer(4 * 4 * 4, 0);
190 bool success =
false;
195 EXPECT_EQ(result,
nullptr);
199 EXPECT_CALL(*window(), SetFlutterCursor(NotNull())).Times(1);
210 &create_result_handler);
216 &set_result_handler);
218 EXPECT_TRUE(success);
224 TestBinaryMessenger messenger;
228 std::vector<uint8_t> buffer(4 * 4 * 4, 0);
234 [&error](
const std::string& error_code,
const std::string& error_message,
237 EXPECT_EQ(error_message,
238 "Cursor is not available in Windows headless mode");
251 &create_result_handler);
257 &set_result_handler);
265 TestBinaryMessenger messenger;
271 [&error](
const std::string& error_code,
const std::string& error_message,
276 "The custom cursor identified by the argument key cannot be found");
280 EXPECT_CALL(*window(), SetFlutterCursor).Times(0);
294 TestBinaryMessenger messenger;
298 std::vector<uint8_t> buffer(4 * 4 * 4, 0);
300 bool success =
false;
305 EXPECT_EQ(result,
nullptr);
318 &create_result_handler);
324 &delete_result_handler);
326 EXPECT_TRUE(success);
332 TestBinaryMessenger messenger;
335 bool success =
false;
339 EXPECT_EQ(result,
nullptr);
349 EXPECT_TRUE(success);