@@ -640,9 +640,8 @@ TEST_F(FlutterWindowsEngineTest, AlertPlatformMessage) {
640640 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
641641 ui::AXPlatformNodeDelegateBase parent_delegate;
642642 AlertPlatformNodeDelegate delegate (parent_delegate);
643- ON_CALL (*window_binding_handler, GetAlertDelegate).WillByDefault ([&delegate] {
644- return &delegate;
645- });
643+ EXPECT_CALL (*window_binding_handler, GetAlertDelegate)
644+ .WillRepeatedly (Return (&delegate));
646645 MockFlutterWindowsView view (std::move (window_binding_handler));
647646 view.SetEngine (engine.get ());
648647
@@ -660,9 +659,9 @@ TEST_F(FlutterWindowsEngineTest, AlertPlatformMessage) {
660659 });
661660
662661 bool did_call = false ;
663- ON_CALL (view, NotifyWinEventWrapper)
664- .WillByDefault ([&did_call](ui::AXPlatformNodeWin* node,
665- ax::mojom::Event event) { did_call = true ; });
662+ EXPECT_CALL (view, NotifyWinEventWrapper)
663+ .WillOnce ([&did_call](ui::AXPlatformNodeWin* node,
664+ ax::mojom::Event event) { did_call = true ; });
666665
667666 engine->UpdateSemanticsEnabled (true );
668667 engine->Run ();
@@ -712,13 +711,13 @@ TEST_F(FlutterWindowsEngineTest, TestExit) {
712711 EngineModifier modifier (engine.get ());
713712 modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
714713 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get ());
715- ON_CALL (*handler, Quit)
716- . WillByDefault (
717- [&finished](std::optional<HWND> hwnd, std::optional<WPARAM> wparam ,
718- std::optional<LPARAM> lparam ,
719- UINT exit_code) { finished = exit_code == 0 ; });
720- ON_CALL (*handler, IsLastWindowOfProcess). WillByDefault ([]() { return true ; });
721- EXPECT_CALL (*handler, Quit). Times ( 1 );
714+ EXPECT_CALL (*handler, SetLifecycleState (AppLifecycleState:: kResumed ));
715+ EXPECT_CALL (*handler, Quit)
716+ . WillOnce ( [&finished](std::optional<HWND> hwnd,
717+ std::optional<WPARAM> wparam ,
718+ std::optional<LPARAM> lparam,
719+ UINT exit_code) { finished = exit_code == 0 ; });
720+ EXPECT_CALL (*handler, IsLastWindowOfProcess). WillRepeatedly ( Return ( true ) );
722721 modifier.SetLifecycleManager (std::move (handler));
723722
724723 engine->lifecycle_manager ()->BeginProcessingExit ();
@@ -738,7 +737,6 @@ TEST_F(FlutterWindowsEngineTest, TestExit) {
738737TEST_F (FlutterWindowsEngineTest, TestExitCancel) {
739738 FlutterWindowsEngineBuilder builder{GetContext ()};
740739 builder.SetDartEntrypoint (" exitTestCancel" );
741- bool finished = false ;
742740 bool did_call = false ;
743741
744742 auto engine = builder.Build ();
@@ -750,12 +748,8 @@ TEST_F(FlutterWindowsEngineTest, TestExitCancel) {
750748 EngineModifier modifier (engine.get ());
751749 modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
752750 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get ());
753- ON_CALL (*handler, Quit)
754- .WillByDefault ([&finished](std::optional<HWND> hwnd,
755- std::optional<WPARAM> wparam,
756- std::optional<LPARAM> lparam,
757- UINT exit_code) { finished = true ; });
758- ON_CALL (*handler, IsLastWindowOfProcess).WillByDefault ([]() { return true ; });
751+ EXPECT_CALL (*handler, SetLifecycleState (AppLifecycleState::kResumed ));
752+ EXPECT_CALL (*handler, IsLastWindowOfProcess).WillRepeatedly (Return (true ));
759753 EXPECT_CALL (*handler, Quit).Times (0 );
760754 modifier.SetLifecycleManager (std::move (handler));
761755 engine->lifecycle_manager ()->BeginProcessingExit ();
@@ -783,10 +777,11 @@ TEST_F(FlutterWindowsEngineTest, TestExitCancel) {
783777 while (!did_call) {
784778 engine->task_runner ()->ProcessTasks ();
785779 }
786-
787- EXPECT_FALSE (finished);
788780}
789781
782+ // TODO(loicsharma): This test is passing incorrectly on the first
783+ // WM_CLOSE message when instead it should pass on the second WM_CLOSE message.
784+ // https://github.com/flutter/flutter/issues/137963
790785TEST_F (FlutterWindowsEngineTest, TestExitSecondCloseMessage) {
791786 FlutterWindowsEngineBuilder builder{GetContext ()};
792787 builder.SetDartEntrypoint (" exitTestExit" );
@@ -801,18 +796,18 @@ TEST_F(FlutterWindowsEngineTest, TestExitSecondCloseMessage) {
801796 EngineModifier modifier (engine.get ());
802797 modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
803798 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get ());
804- auto & handler_obj = *handler;
805- ON_CALL (handler_obj, IsLastWindowOfProcess). WillByDefault ([]() {
806- return true ;
807- } );
808- ON_CALL (handler_obj , Quit)
809- .WillByDefault (
810- [&handler_obj]( std::optional<HWND> hwnd, std::optional<WPARAM> wparam,
799+ EXPECT_CALL ( *handler, SetLifecycleState (AppLifecycleState:: kResumed )) ;
800+ // TODO(loicsharma): These should be `EXPECT_CALL`s
801+ // https://github.com/flutter/flutter/issues/137963
802+ ON_CALL (*handler, IsLastWindowOfProcess). WillByDefault ( Return ( true ) );
803+ ON_CALL (*handler , Quit)
804+ .WillByDefault ([handler_ptr = handler. get ()](
805+ std::optional<HWND> hwnd, std::optional<WPARAM> wparam,
811806 std::optional<LPARAM> lparam, UINT exit_code) {
812- handler_obj. WindowsLifecycleManager ::Quit (hwnd, wparam, lparam,
813- exit_code);
814- });
815- ON_CALL (handler_obj , DispatchMessage)
807+ handler_ptr-> WindowsLifecycleManager ::Quit (hwnd, wparam, lparam,
808+ exit_code);
809+ });
810+ ON_CALL (*handler , DispatchMessage)
816811 .WillByDefault (
817812 [&engine](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
818813 engine->window_proc_delegate_manager ()->OnTopLevelWindowProc (
@@ -863,7 +858,8 @@ TEST_F(FlutterWindowsEngineTest, TestExitCloseMultiWindow) {
863858 EngineModifier modifier (engine.get ());
864859 modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
865860 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get ());
866- ON_CALL (*handler, IsLastWindowOfProcess).WillByDefault ([&finished]() {
861+ EXPECT_CALL (*handler, SetLifecycleState (AppLifecycleState::kResumed ));
862+ EXPECT_CALL (*handler, IsLastWindowOfProcess).WillOnce ([&finished]() {
867863 finished = true ;
868864 return false ;
869865 });
@@ -913,10 +909,7 @@ TEST_F(FlutterWindowsEngineTest, EnableApplicationLifecycle) {
913909 EngineModifier modifier (engine.get ());
914910 modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
915911 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get ());
916- ON_CALL (*handler, IsLastWindowOfProcess).WillByDefault ([]() {
917- return false ;
918- });
919- EXPECT_CALL (*handler, IsLastWindowOfProcess).Times (1 );
912+ EXPECT_CALL (*handler, IsLastWindowOfProcess).WillOnce (Return (false ));
920913 modifier.SetLifecycleManager (std::move (handler));
921914 engine->lifecycle_manager ()->BeginProcessingExit ();
922915
@@ -936,10 +929,7 @@ TEST_F(FlutterWindowsEngineTest, ApplicationLifecycleExternalWindow) {
936929 EngineModifier modifier (engine.get ());
937930 modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
938931 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get ());
939- ON_CALL (*handler, IsLastWindowOfProcess).WillByDefault ([]() {
940- return false ;
941- });
942- EXPECT_CALL (*handler, IsLastWindowOfProcess).Times (1 );
932+ EXPECT_CALL (*handler, IsLastWindowOfProcess).WillOnce (Return (false ));
943933 modifier.SetLifecycleManager (std::move (handler));
944934 engine->lifecycle_manager ()->BeginProcessingExit ();
945935
@@ -1065,8 +1055,8 @@ TEST_F(FlutterWindowsEngineTest, EnableLifecycleState) {
10651055 EngineModifier modifier (engine.get ());
10661056 modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
10671057 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get ());
1068- ON_CALL (*handler, SetLifecycleState)
1069- .WillByDefault ([handler_ptr = handler.get ()](AppLifecycleState state) {
1058+ EXPECT_CALL (*handler, SetLifecycleState)
1059+ .WillRepeatedly ([handler_ptr = handler.get ()](AppLifecycleState state) {
10701060 handler_ptr->WindowsLifecycleManager ::SetLifecycleState (state);
10711061 });
10721062 modifier.SetLifecycleManager (std::move (handler));
@@ -1118,8 +1108,8 @@ TEST_F(FlutterWindowsEngineTest, LifecycleStateToFrom) {
11181108 EngineModifier modifier (engine.get ());
11191109 modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
11201110 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get ());
1121- ON_CALL (*handler, SetLifecycleState)
1122- .WillByDefault ([handler_ptr = handler.get ()](AppLifecycleState state) {
1111+ EXPECT_CALL (*handler, SetLifecycleState)
1112+ .WillRepeatedly ([handler_ptr = handler.get ()](AppLifecycleState state) {
11231113 handler_ptr->WindowsLifecycleManager ::SetLifecycleState (state);
11241114 });
11251115 handler->begin_processing_callback = [&]() { enabled_lifecycle = true ; };
@@ -1167,6 +1157,7 @@ TEST_F(FlutterWindowsEngineTest, ChannelListenedTo) {
11671157
11681158 bool lifecycle_began = false ;
11691159 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get ());
1160+ EXPECT_CALL (*handler, SetLifecycleState).Times (1 );
11701161 handler->begin_processing_callback = [&]() { lifecycle_began = true ; };
11711162 modifier.SetLifecycleManager (std::move (handler));
11721163
0 commit comments