[Win32, Keyboard] Unify key changes in keyboard tests (flutter/engine#31299)

This commit is contained in:
Tong Mu 2022-02-14 15:40:11 -08:00 committed by GitHub
parent 2264b26901
commit 6370d313bb
3 changed files with 357 additions and 350 deletions

View File

@ -191,25 +191,25 @@ void MockEmbedderApiForKeyboard(
modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; };
}
void MockMessageQueue::InjectMessageList(int count,
const Win32Message* messages) {
for (int i = 0; i < count; i += 1) {
_pending_messages.push_back(messages[i]);
}
while (!_pending_messages.empty()) {
Win32Message message = _pending_messages.front();
_pending_messages.pop_front();
_sent_messages.push_back(message);
LRESULT result =
Win32SendMessage(message.message, message.wParam, message.lParam);
if (message.expected_result != kWmResultDontCheck) {
EXPECT_EQ(result, message.expected_result)
<< " This is the " << _sent_messages.size()
<< ordinal(_sent_messages.size()) << " event, with\n " << std::hex
<< "Message 0x" << message.message << " LParam 0x" << message.lParam
<< " WParam 0x" << message.wParam;
}
void MockMessageQueue::PushBack(const Win32Message* message) {
_pending_messages.push_back(*message);
}
LRESULT MockMessageQueue::DispatchFront() {
assert(!_pending_messages.empty());
Win32Message message = _pending_messages.front();
_pending_messages.pop_front();
_sent_messages.push_back(message);
LRESULT result =
Win32SendMessage(message.message, message.wParam, message.lParam);
if (message.expected_result != kWmResultDontCheck) {
EXPECT_EQ(result, message.expected_result)
<< " This is the " << _sent_messages.size()
<< ordinal(_sent_messages.size()) << " event, with\n " << std::hex
<< "Message 0x" << message.message << " LParam 0x" << message.lParam
<< " WParam 0x" << message.wParam;
}
return result;
}
BOOL MockMessageQueue::Win32PeekMessage(LPMSG lpMsg,

View File

@ -110,10 +110,14 @@ void MockEmbedderApiForKeyboard(
// Subclasses must implement |Win32SendMessage| for how dispatched messages are
// processed.
class MockMessageQueue {
public:
// Push a list of messages to the message queue, then dispatch
// them with |Win32SendMessage| one by one.
void InjectMessageList(int count, const Win32Message* messages);
protected:
// Push a message to the message queue without dispatching it.
void PushBack(const Win32Message* message);
// Dispatch the first message of the message queue and return its result.
//
// This method asserts that the queue is not empty.
LRESULT DispatchFront();
// Peak the next message in the message queue.
//
@ -123,7 +127,7 @@ class MockMessageQueue {
UINT wMsgFilterMax,
UINT wRemoveMsg);
protected:
// Simulate dispatching a message to the system.
virtual LRESULT Win32SendMessage(UINT const message,
WPARAM const wparam,
LPARAM const lparam) = 0;