12
12
#include " gtest/gtest.h"
13
13
14
14
using testing::_;
15
+ using testing::AnyNumber;
15
16
using testing::Invoke;
16
17
using testing::Return;
17
18
@@ -133,8 +134,7 @@ TEST(FlutterWindowTest, OnBitmapSurfaceUpdated) {
133
134
// when the DPI scale is 100% (96 DPI).
134
135
TEST (FlutterWindowTest, OnCursorRectUpdatedRegularDPI) {
135
136
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 ));
138
138
139
139
Rect cursor_rect (Point (10 , 20 ), Size (30 , 40 ));
140
140
EXPECT_CALL (win32window, UpdateCursorRect (cursor_rect)).Times (1 );
@@ -147,8 +147,7 @@ TEST(FlutterWindowTest, OnCursorRectUpdatedRegularDPI) {
147
147
// when the DPI scale is 150% (144 DPI).
148
148
TEST (FlutterWindowTest, OnCursorRectUpdatedHighDPI) {
149
149
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 ));
152
151
153
152
Rect expected_cursor_rect (Point (15 , 30 ), Size (45 , 60 ));
154
153
EXPECT_CALL (win32window, UpdateCursorRect (expected_cursor_rect)).Times (1 );
@@ -160,7 +159,9 @@ TEST(FlutterWindowTest, OnCursorRectUpdatedHighDPI) {
160
159
TEST (FlutterWindowTest, OnPointerStarSendsDeviceType) {
161
160
FlutterWindow win32window (100 , 100 );
162
161
MockWindowBindingHandlerDelegate delegate;
162
+ EXPECT_CALL (delegate, OnWindowStateEvent).Times (AnyNumber ());
163
163
win32window.SetView (&delegate);
164
+
164
165
// Move
165
166
EXPECT_CALL (delegate,
166
167
OnPointerMove (10.0 , 10.0 , kFlutterPointerDeviceKindMouse ,
@@ -259,6 +260,7 @@ TEST(FlutterWindowTest, OnPointerStarSendsDeviceType) {
259
260
TEST (FlutterWindowTest, OnScrollCallsGetScrollOffsetMultiplier) {
260
261
MockFlutterWindow win32window;
261
262
MockWindowBindingHandlerDelegate delegate;
263
+ EXPECT_CALL (win32window, OnWindowStateEvent).Times (AnyNumber ());
262
264
win32window.SetView (&delegate);
263
265
264
266
ON_CALL (win32window, GetScrollOffsetMultiplier ())
@@ -277,6 +279,7 @@ TEST(FlutterWindowTest, OnScrollCallsGetScrollOffsetMultiplier) {
277
279
TEST (FlutterWindowTest, OnWindowRepaint) {
278
280
MockFlutterWindow win32window;
279
281
MockWindowBindingHandlerDelegate delegate;
282
+ EXPECT_CALL (win32window, OnWindowStateEvent).Times (AnyNumber ());
280
283
win32window.SetView (&delegate);
281
284
282
285
EXPECT_CALL (delegate, OnWindowRepaint ()).Times (1 );
@@ -287,6 +290,7 @@ TEST(FlutterWindowTest, OnWindowRepaint) {
287
290
TEST (FlutterWindowTest, OnThemeChange) {
288
291
MockFlutterWindow win32window;
289
292
MockWindowBindingHandlerDelegate delegate;
293
+ EXPECT_CALL (win32window, OnWindowStateEvent).Times (AnyNumber ());
290
294
win32window.SetView (&delegate);
291
295
292
296
EXPECT_CALL (delegate, OnHighContrastChanged).Times (1 );
@@ -308,9 +312,9 @@ TEST(FlutterWindowTest, AccessibilityNodeWithoutView) {
308
312
TEST (FlutterWindowTest, AlertNode) {
309
313
std::unique_ptr<MockFlutterWindow> win32window =
310
314
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 ( ));
314
318
MockFlutterWindowsView view (std::move (win32window));
315
319
std::wstring message = L" Test alert" ;
316
320
EXPECT_CALL (view, NotifyWinEventWrapper (_, ax::mojom::Event::kAlert ))
@@ -337,21 +341,22 @@ TEST(FlutterWindowTest, AlertNode) {
337
341
338
342
TEST (FlutterWindowTest, LifecycleFocusMessages) {
339
343
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 )));
343
346
MockWindowBindingHandlerDelegate delegate;
344
- win32window.SetView (&delegate);
345
347
346
348
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) {
349
351
last_event = event;
350
352
});
351
- ON_CALL (win32window, OnWindowStateEvent)
352
- .WillByDefault ([&](WindowStateEvent event) {
353
+ EXPECT_CALL (win32window, OnWindowStateEvent)
354
+ .WillRepeatedly ([&](WindowStateEvent event) {
353
355
win32window.FlutterWindow ::OnWindowStateEvent (event);
354
356
});
357
+ EXPECT_CALL (win32window, OnResize).Times (AnyNumber ());
358
+
359
+ win32window.SetView (&delegate);
355
360
356
361
win32window.InjectWindowMessage (WM_SIZE, 0 , 0 );
357
362
EXPECT_EQ (last_event, WindowStateEvent::kHide );
@@ -368,13 +373,13 @@ TEST(FlutterWindowTest, LifecycleFocusMessages) {
368
373
369
374
TEST (FlutterWindowTest, CachedLifecycleMessage) {
370
375
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) {
376
380
win32window.FlutterWindow ::OnWindowStateEvent (event);
377
381
});
382
+ EXPECT_CALL (win32window, OnResize).Times (1 );
378
383
379
384
// Restore
380
385
win32window.InjectWindowMessage (WM_SIZE, 0 , MAKEWORD (1 , 1 ));
@@ -385,8 +390,8 @@ TEST(FlutterWindowTest, CachedLifecycleMessage) {
385
390
MockWindowBindingHandlerDelegate delegate;
386
391
bool focused = false ;
387
392
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) {
390
395
if (event == WindowStateEvent::kFocus ) {
391
396
focused = true ;
392
397
} else if (event == WindowStateEvent::kShow ) {
@@ -403,18 +408,19 @@ TEST(FlutterWindowTest, PosthumousWindowMessage) {
403
408
MockWindowBindingHandlerDelegate delegate;
404
409
int msg_count = 0 ;
405
410
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++; });
408
413
409
414
{
410
415
MockFlutterWindow win32window (false );
411
- ON_CALL (win32window, GetPlatformWindow).WillByDefault ([&]() {
416
+ EXPECT_CALL (win32window, GetPlatformWindow).WillRepeatedly ([&]() {
412
417
return win32window.FlutterWindow ::GetPlatformWindow ();
413
418
});
414
- ON_CALL (win32window, OnWindowStateEvent)
415
- .WillByDefault ([&](WindowStateEvent event) {
419
+ EXPECT_CALL (win32window, OnWindowStateEvent)
420
+ .WillRepeatedly ([&](WindowStateEvent event) {
416
421
win32window.FlutterWindow ::OnWindowStateEvent (event);
417
422
});
423
+ EXPECT_CALL (win32window, OnResize).Times (AnyNumber ());
418
424
win32window.SetView (&delegate);
419
425
win32window.InitializeChild (" Title" , 1 , 1 );
420
426
hwnd = win32window.GetPlatformWindow ();
0 commit comments