From 8998286f3bae6cb375bcd04ed1f9f75702cfcd19 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Sun, 28 Nov 2021 20:20:11 -0800 Subject: [PATCH] [Win32] Use mock macro for UpdateSemanticsEnabled Previously, we'd mocked out UpdateSemanticsEnabled using a simple lambda. Due to the embedder API's C ABI, we were unable to make use of lambda captures. This patch instead uses MOCK_ENGINE_PROC so we can make the test variable a local and rely on lambda capture. Issue: https://github.com/flutter/flutter/issues/77838 --- .../windows/flutter_windows_view_unittests.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/shell/platform/windows/flutter_windows_view_unittests.cc b/shell/platform/windows/flutter_windows_view_unittests.cc index 77343522b2363..6925f3e30189e 100644 --- a/shell/platform/windows/flutter_windows_view_unittests.cc +++ b/shell/platform/windows/flutter_windows_view_unittests.cc @@ -35,7 +35,6 @@ struct TestResponseHandle { }; static bool test_response = false; -static bool semantics_enabled = false; constexpr uint64_t kKeyEventFromChannel = 0x11; constexpr uint64_t kKeyEventFromEmbedder = 0x22; @@ -130,11 +129,15 @@ TEST(FlutterWindowsViewTest, RestartClearsKeyboardState) { TEST(FlutterWindowsViewTest, EnableSemantics) { std::unique_ptr engine = GetTestEngine(); EngineModifier modifier(engine.get()); - modifier.embedder_api().UpdateSemanticsEnabled = - [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) { + + bool semantics_enabled = false; + modifier.embedder_api().UpdateSemanticsEnabled = MOCK_ENGINE_PROC( + UpdateSemanticsEnabled, + [&semantics_enabled](FLUTTER_API_SYMBOL(FlutterEngine) engine, + bool enabled) { semantics_enabled = enabled; return kSuccess; - }; + }); auto window_binding_handler = std::make_unique<::testing::NiceMock>();