Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 033514b

Browse files
authored
[Windows] Remove dead code from FlutterWindow tests (#39216)
1 parent 5011144 commit 033514b

File tree

1 file changed

+5
-136
lines changed

1 file changed

+5
-136
lines changed

shell/platform/windows/flutter_window_unittests.cc

Lines changed: 5 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,14 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "flutter/shell/platform/common/json_message_codec.h"
6-
#include "flutter/shell/platform/embedder/embedder.h"
7-
#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
8-
#include "flutter/shell/platform/windows/flutter_windows_engine.h"
9-
#include "flutter/shell/platform/windows/keyboard_key_channel_handler.h"
10-
#include "flutter/shell/platform/windows/keyboard_key_handler.h"
11-
#include "flutter/shell/platform/windows/testing/engine_modifier.h"
125
#include "flutter/shell/platform/windows/testing/flutter_window_test.h"
136
#include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h"
147
#include "flutter/shell/platform/windows/testing/mock_window_binding_handler_delegate.h"
15-
#include "flutter/shell/platform/windows/testing/test_keyboard.h"
16-
#include "flutter/shell/platform/windows/text_input_plugin.h"
17-
#include "flutter/shell/platform/windows/text_input_plugin_delegate.h"
8+
#include "flutter/shell/platform/windows/testing/wm_builders.h"
189

1910
#include "gmock/gmock.h"
2011
#include "gtest/gtest.h"
2112

22-
#include <rapidjson/document.h>
23-
2413
using testing::_;
2514
using testing::Invoke;
2615
using testing::Return;
@@ -31,74 +20,6 @@ namespace testing {
3120
namespace {
3221
static constexpr int32_t kDefaultPointerDeviceId = 0;
3322

34-
// A key event handler that can be spied on while it forwards calls to the real
35-
// key event handler.
36-
class SpyKeyboardKeyHandler : public KeyboardHandlerBase {
37-
public:
38-
SpyKeyboardKeyHandler(flutter::BinaryMessenger* messenger) {
39-
real_implementation_ = std::make_unique<KeyboardKeyHandler>();
40-
real_implementation_->AddDelegate(
41-
std::make_unique<KeyboardKeyChannelHandler>(messenger));
42-
ON_CALL(*this, KeyboardHook(_, _, _, _, _, _, _))
43-
.WillByDefault(Invoke(real_implementation_.get(),
44-
&KeyboardKeyHandler::KeyboardHook));
45-
ON_CALL(*this, SyncModifiersIfNeeded(_))
46-
.WillByDefault(Invoke(real_implementation_.get(),
47-
&KeyboardKeyHandler::SyncModifiersIfNeeded));
48-
}
49-
50-
MOCK_METHOD7(KeyboardHook,
51-
void(int key,
52-
int scancode,
53-
int action,
54-
char32_t character,
55-
bool extended,
56-
bool was_down,
57-
KeyEventCallback callback));
58-
59-
MOCK_METHOD1(SyncModifiersIfNeeded, void(int modifiers_state));
60-
61-
private:
62-
std::unique_ptr<KeyboardKeyHandler> real_implementation_;
63-
};
64-
65-
// A text input plugin that can be spied on while it forwards calls to the real
66-
// text input plugin.
67-
class SpyTextInputPlugin : public TextInputPlugin,
68-
public TextInputPluginDelegate {
69-
public:
70-
SpyTextInputPlugin(flutter::BinaryMessenger* messenger)
71-
: TextInputPlugin(messenger, this) {
72-
real_implementation_ = std::make_unique<TextInputPlugin>(messenger, this);
73-
ON_CALL(*this, KeyboardHook(_, _, _, _, _, _))
74-
.WillByDefault(
75-
Invoke(real_implementation_.get(), &TextInputPlugin::KeyboardHook));
76-
ON_CALL(*this, TextHook(_))
77-
.WillByDefault(
78-
Invoke(real_implementation_.get(), &TextInputPlugin::TextHook));
79-
}
80-
81-
MOCK_METHOD6(KeyboardHook,
82-
void(int key,
83-
int scancode,
84-
int action,
85-
char32_t character,
86-
bool extended,
87-
bool was_down));
88-
MOCK_METHOD1(TextHook, void(const std::u16string& text));
89-
MOCK_METHOD0(ComposeBeginHook, void());
90-
MOCK_METHOD0(ComposeCommitHook, void());
91-
MOCK_METHOD0(ComposeEndHook, void());
92-
MOCK_METHOD2(ComposeChangeHook,
93-
void(const std::u16string& text, int cursor_pos));
94-
95-
virtual void OnCursorRectUpdated(const Rect& rect) {}
96-
virtual void OnResetImeComposing() {}
97-
98-
private:
99-
std::unique_ptr<TextInputPlugin> real_implementation_;
100-
};
101-
10223
class MockFlutterWindow : public FlutterWindow {
10324
public:
10425
MockFlutterWindow() : FlutterWindow(800, 600) {
@@ -154,68 +75,16 @@ class MockFlutterWindow : public FlutterWindow {
15475
}
15576
};
15677

157-
// A FlutterWindowsView that overrides the RegisterKeyboardHandlers function
158-
// to register the keyboard hook handlers that can be spied upon.
159-
class TestFlutterWindowsView : public FlutterWindowsView {
78+
class MockFlutterWindowsView : public FlutterWindowsView {
16079
public:
161-
TestFlutterWindowsView(std::unique_ptr<WindowBindingHandler> window_binding)
80+
MockFlutterWindowsView(std::unique_ptr<WindowBindingHandler> window_binding)
16281
: FlutterWindowsView(std::move(window_binding)) {}
163-
~TestFlutterWindowsView() {}
164-
165-
SpyKeyboardKeyHandler* key_event_handler;
166-
SpyTextInputPlugin* text_input_plugin;
82+
~MockFlutterWindowsView() {}
16783

16884
MOCK_METHOD2(NotifyWinEventWrapper,
16985
void(ui::AXPlatformNodeWin*, ax::mojom::Event));
170-
171-
protected:
172-
std::unique_ptr<KeyboardHandlerBase> CreateKeyboardKeyHandler(
173-
flutter::BinaryMessenger* messenger,
174-
flutter::KeyboardKeyEmbedderHandler::GetKeyStateHandler get_key_state,
175-
KeyboardKeyEmbedderHandler::MapVirtualKeyToScanCode map_vk_to_scan)
176-
override {
177-
auto spy_key_event_handler =
178-
std::make_unique<SpyKeyboardKeyHandler>(messenger);
179-
key_event_handler = spy_key_event_handler.get();
180-
return spy_key_event_handler;
181-
}
182-
183-
std::unique_ptr<TextInputPlugin> CreateTextInputPlugin(
184-
flutter::BinaryMessenger* messenger) override {
185-
auto spy_key_event_handler =
186-
std::make_unique<SpyTextInputPlugin>(messenger);
187-
text_input_plugin = spy_key_event_handler.get();
188-
return spy_key_event_handler;
189-
}
19086
};
19187

192-
// The static value to return as the "handled" value from the framework for key
193-
// events. Individual tests set this to change the framework response that the
194-
// test engine simulates.
195-
static bool test_response = false;
196-
197-
// Returns an engine instance configured with dummy project path values, and
198-
// overridden methods for sending platform messages, so that the engine can
199-
// respond as if the framework were connected.
200-
std::unique_ptr<FlutterWindowsEngine> GetTestEngine() {
201-
FlutterDesktopEngineProperties properties = {};
202-
properties.assets_path = L"C:\\foo\\flutter_assets";
203-
properties.icu_data_path = L"C:\\foo\\icudtl.dat";
204-
properties.aot_library_path = L"C:\\foo\\aot.so";
205-
FlutterProjectBundle project(properties);
206-
auto engine = std::make_unique<FlutterWindowsEngine>(project);
207-
208-
EngineModifier modifier(engine.get());
209-
auto key_response_controller = std::make_shared<MockKeyResponseController>();
210-
key_response_controller->SetChannelResponse(
211-
[](MockKeyResponseController::ResponseCallback callback) {
212-
callback(test_response);
213-
});
214-
MockEmbedderApiForKeyboard(modifier, key_response_controller);
215-
216-
return engine;
217-
}
218-
21988
} // namespace
22089

22190
TEST(FlutterWindowTest, CreateDestroy) {
@@ -419,7 +288,7 @@ TEST(FlutterWindowTest, AlertNode) {
419288
ON_CALL(*win32window, GetPlatformWindow()).WillByDefault(Return(nullptr));
420289
ON_CALL(*win32window, GetAxFragmentRootDelegate())
421290
.WillByDefault(Return(nullptr));
422-
TestFlutterWindowsView view(std::move(win32window));
291+
MockFlutterWindowsView view(std::move(win32window));
423292
std::wstring message = L"Test alert";
424293
EXPECT_CALL(view, NotifyWinEventWrapper(_, ax::mojom::Event::kAlert))
425294
.Times(1);

0 commit comments

Comments
 (0)