1212#include " gtest/gtest.h"
1313
1414using testing::_;
15+ using testing::AnyNumber;
1516using testing::Invoke;
1617using testing::Return;
1718
@@ -133,8 +134,7 @@ TEST(FlutterWindowTest, OnBitmapSurfaceUpdated) {
133134// when the DPI scale is 100% (96 DPI).
134135TEST (FlutterWindowTest, OnCursorRectUpdatedRegularDPI) {
135136 MockFlutterWindow win32window;
136- ON_CALL (win32window, GetDpiScale ()).WillByDefault (Return (1.0 ));
137- EXPECT_CALL (win32window, GetDpiScale ()).Times (1 );
137+ EXPECT_CALL (win32window, GetDpiScale ()).WillOnce (Return (1.0 ));
138138
139139 Rect cursor_rect (Point (10 , 20 ), Size (30 , 40 ));
140140 EXPECT_CALL (win32window, UpdateCursorRect (cursor_rect)).Times (1 );
@@ -147,8 +147,7 @@ TEST(FlutterWindowTest, OnCursorRectUpdatedRegularDPI) {
147147// when the DPI scale is 150% (144 DPI).
148148TEST (FlutterWindowTest, OnCursorRectUpdatedHighDPI) {
149149 MockFlutterWindow win32window;
150- ON_CALL (win32window, GetDpiScale ()).WillByDefault (Return (1.5 ));
151- EXPECT_CALL (win32window, GetDpiScale ()).Times (1 );
150+ EXPECT_CALL (win32window, GetDpiScale ()).WillOnce (Return (1.5 ));
152151
153152 Rect expected_cursor_rect (Point (15 , 30 ), Size (45 , 60 ));
154153 EXPECT_CALL (win32window, UpdateCursorRect (expected_cursor_rect)).Times (1 );
@@ -160,7 +159,9 @@ TEST(FlutterWindowTest, OnCursorRectUpdatedHighDPI) {
160159TEST (FlutterWindowTest, OnPointerStarSendsDeviceType) {
161160 FlutterWindow win32window (100 , 100 );
162161 MockWindowBindingHandlerDelegate delegate;
162+ EXPECT_CALL (delegate, OnWindowStateEvent).Times (AnyNumber ());
163163 win32window.SetView (&delegate);
164+
164165 // Move
165166 EXPECT_CALL (delegate,
166167 OnPointerMove (10.0 , 10.0 , kFlutterPointerDeviceKindMouse ,
@@ -259,6 +260,7 @@ TEST(FlutterWindowTest, OnPointerStarSendsDeviceType) {
259260TEST (FlutterWindowTest, OnScrollCallsGetScrollOffsetMultiplier) {
260261 MockFlutterWindow win32window;
261262 MockWindowBindingHandlerDelegate delegate;
263+ EXPECT_CALL (win32window, OnWindowStateEvent).Times (AnyNumber ());
262264 win32window.SetView (&delegate);
263265
264266 ON_CALL (win32window, GetScrollOffsetMultiplier ())
@@ -277,6 +279,7 @@ TEST(FlutterWindowTest, OnScrollCallsGetScrollOffsetMultiplier) {
277279TEST (FlutterWindowTest, OnWindowRepaint) {
278280 MockFlutterWindow win32window;
279281 MockWindowBindingHandlerDelegate delegate;
282+ EXPECT_CALL (win32window, OnWindowStateEvent).Times (AnyNumber ());
280283 win32window.SetView (&delegate);
281284
282285 EXPECT_CALL (delegate, OnWindowRepaint ()).Times (1 );
@@ -287,6 +290,7 @@ TEST(FlutterWindowTest, OnWindowRepaint) {
287290TEST (FlutterWindowTest, OnThemeChange) {
288291 MockFlutterWindow win32window;
289292 MockWindowBindingHandlerDelegate delegate;
293+ EXPECT_CALL (win32window, OnWindowStateEvent).Times (AnyNumber ());
290294 win32window.SetView (&delegate);
291295
292296 EXPECT_CALL (delegate, OnHighContrastChanged).Times (1 );
@@ -308,9 +312,9 @@ TEST(FlutterWindowTest, AccessibilityNodeWithoutView) {
308312TEST (FlutterWindowTest, AlertNode) {
309313 std::unique_ptr<MockFlutterWindow> win32window =
310314 std::make_unique<MockFlutterWindow>();
311- ON_CALL (*win32window, GetPlatformWindow ()). WillByDefault ( Return ( nullptr ));
312- ON_CALL (*win32window, GetAxFragmentRootDelegate ())
313- . WillByDefault ( Return ( nullptr ));
315+ EXPECT_CALL (*win32window. get (), GetAxFragmentRootDelegate ())
316+ . WillOnce ( Return ( nullptr ));
317+ EXPECT_CALL (*win32window. get (), OnWindowStateEvent). Times ( AnyNumber ( ));
314318 MockFlutterWindowsView view (std::move (win32window));
315319 std::wstring message = L" Test alert" ;
316320 EXPECT_CALL (view, NotifyWinEventWrapper (_, ax::mojom::Event::kAlert ))
@@ -337,21 +341,22 @@ TEST(FlutterWindowTest, AlertNode) {
337341
338342TEST (FlutterWindowTest, LifecycleFocusMessages) {
339343 MockFlutterWindow win32window;
340- ON_CALL (win32window, GetPlatformWindow).WillByDefault ([]() {
341- return reinterpret_cast <HWND>(1 );
342- });
344+ EXPECT_CALL (win32window, GetPlatformWindow)
345+ .WillRepeatedly (Return (reinterpret_cast <HWND>(1 )));
343346 MockWindowBindingHandlerDelegate delegate;
344- win32window.SetView (&delegate);
345347
346348 WindowStateEvent last_event;
347- ON_CALL (delegate, OnWindowStateEvent)
348- .WillByDefault ([&last_event](HWND hwnd, WindowStateEvent event) {
349+ EXPECT_CALL (delegate, OnWindowStateEvent)
350+ .WillRepeatedly ([&last_event](HWND hwnd, WindowStateEvent event) {
349351 last_event = event;
350352 });
351- ON_CALL (win32window, OnWindowStateEvent)
352- .WillByDefault ([&](WindowStateEvent event) {
353+ EXPECT_CALL (win32window, OnWindowStateEvent)
354+ .WillRepeatedly ([&](WindowStateEvent event) {
353355 win32window.FlutterWindow ::OnWindowStateEvent (event);
354356 });
357+ EXPECT_CALL (win32window, OnResize).Times (AnyNumber ());
358+
359+ win32window.SetView (&delegate);
355360
356361 win32window.InjectWindowMessage (WM_SIZE, 0 , 0 );
357362 EXPECT_EQ (last_event, WindowStateEvent::kHide );
@@ -368,13 +373,13 @@ TEST(FlutterWindowTest, LifecycleFocusMessages) {
368373
369374TEST (FlutterWindowTest, CachedLifecycleMessage) {
370375 MockFlutterWindow win32window;
371- ON_CALL (win32window, GetPlatformWindow).WillByDefault ([]() {
372- return reinterpret_cast <HWND>(1 );
373- });
374- ON_CALL (win32window, OnWindowStateEvent)
375- .WillByDefault ([&](WindowStateEvent event) {
376+ EXPECT_CALL (win32window, GetPlatformWindow)
377+ .WillRepeatedly (Return (reinterpret_cast <HWND>(1 )));
378+ EXPECT_CALL (win32window, OnWindowStateEvent)
379+ .WillRepeatedly ([&](WindowStateEvent event) {
376380 win32window.FlutterWindow ::OnWindowStateEvent (event);
377381 });
382+ EXPECT_CALL (win32window, OnResize).Times (1 );
378383
379384 // Restore
380385 win32window.InjectWindowMessage (WM_SIZE, 0 , MAKEWORD (1 , 1 ));
@@ -385,8 +390,8 @@ TEST(FlutterWindowTest, CachedLifecycleMessage) {
385390 MockWindowBindingHandlerDelegate delegate;
386391 bool focused = false ;
387392 bool restored = false ;
388- ON_CALL (delegate, OnWindowStateEvent)
389- .WillByDefault ([&](HWND hwnd, WindowStateEvent event) {
393+ EXPECT_CALL (delegate, OnWindowStateEvent)
394+ .WillRepeatedly ([&](HWND hwnd, WindowStateEvent event) {
390395 if (event == WindowStateEvent::kFocus ) {
391396 focused = true ;
392397 } else if (event == WindowStateEvent::kShow ) {
@@ -403,18 +408,19 @@ TEST(FlutterWindowTest, PosthumousWindowMessage) {
403408 MockWindowBindingHandlerDelegate delegate;
404409 int msg_count = 0 ;
405410 HWND hwnd;
406- ON_CALL (delegate, OnWindowStateEvent)
407- .WillByDefault ([&](HWND hwnd, WindowStateEvent event) { msg_count++; });
411+ EXPECT_CALL (delegate, OnWindowStateEvent)
412+ .WillRepeatedly ([&](HWND hwnd, WindowStateEvent event) { msg_count++; });
408413
409414 {
410415 MockFlutterWindow win32window (false );
411- ON_CALL (win32window, GetPlatformWindow).WillByDefault ([&]() {
416+ EXPECT_CALL (win32window, GetPlatformWindow).WillRepeatedly ([&]() {
412417 return win32window.FlutterWindow ::GetPlatformWindow ();
413418 });
414- ON_CALL (win32window, OnWindowStateEvent)
415- .WillByDefault ([&](WindowStateEvent event) {
419+ EXPECT_CALL (win32window, OnWindowStateEvent)
420+ .WillRepeatedly ([&](WindowStateEvent event) {
416421 win32window.FlutterWindow ::OnWindowStateEvent (event);
417422 });
423+ EXPECT_CALL (win32window, OnResize).Times (AnyNumber ());
418424 win32window.SetView (&delegate);
419425 win32window.InitializeChild (" Title" , 1 , 1 );
420426 hwnd = win32window.GetPlatformWindow ();
0 commit comments