@@ -640,9 +640,8 @@ TEST_F(FlutterWindowsEngineTest, AlertPlatformMessage) {
640
640
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
641
641
ui::AXPlatformNodeDelegateBase parent_delegate;
642
642
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));
646
645
MockFlutterWindowsView view (std::move (window_binding_handler));
647
646
view.SetEngine (engine.get ());
648
647
@@ -660,9 +659,9 @@ TEST_F(FlutterWindowsEngineTest, AlertPlatformMessage) {
660
659
});
661
660
662
661
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 ; });
666
665
667
666
engine->UpdateSemanticsEnabled (true );
668
667
engine->Run ();
@@ -712,13 +711,13 @@ TEST_F(FlutterWindowsEngineTest, TestExit) {
712
711
EngineModifier modifier (engine.get ());
713
712
modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
714
713
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 ) );
722
721
modifier.SetLifecycleManager (std::move (handler));
723
722
724
723
engine->lifecycle_manager ()->BeginProcessingExit ();
@@ -738,7 +737,6 @@ TEST_F(FlutterWindowsEngineTest, TestExit) {
738
737
TEST_F (FlutterWindowsEngineTest, TestExitCancel) {
739
738
FlutterWindowsEngineBuilder builder{GetContext ()};
740
739
builder.SetDartEntrypoint (" exitTestCancel" );
741
- bool finished = false ;
742
740
bool did_call = false ;
743
741
744
742
auto engine = builder.Build ();
@@ -750,12 +748,8 @@ TEST_F(FlutterWindowsEngineTest, TestExitCancel) {
750
748
EngineModifier modifier (engine.get ());
751
749
modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
752
750
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 ));
759
753
EXPECT_CALL (*handler, Quit).Times (0 );
760
754
modifier.SetLifecycleManager (std::move (handler));
761
755
engine->lifecycle_manager ()->BeginProcessingExit ();
@@ -783,10 +777,11 @@ TEST_F(FlutterWindowsEngineTest, TestExitCancel) {
783
777
while (!did_call) {
784
778
engine->task_runner ()->ProcessTasks ();
785
779
}
786
-
787
- EXPECT_FALSE (finished);
788
780
}
789
781
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
790
785
TEST_F (FlutterWindowsEngineTest, TestExitSecondCloseMessage) {
791
786
FlutterWindowsEngineBuilder builder{GetContext ()};
792
787
builder.SetDartEntrypoint (" exitTestExit" );
@@ -801,18 +796,18 @@ TEST_F(FlutterWindowsEngineTest, TestExitSecondCloseMessage) {
801
796
EngineModifier modifier (engine.get ());
802
797
modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
803
798
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,
811
806
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)
816
811
.WillByDefault (
817
812
[&engine](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
818
813
engine->window_proc_delegate_manager ()->OnTopLevelWindowProc (
@@ -863,7 +858,8 @@ TEST_F(FlutterWindowsEngineTest, TestExitCloseMultiWindow) {
863
858
EngineModifier modifier (engine.get ());
864
859
modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
865
860
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]() {
867
863
finished = true ;
868
864
return false ;
869
865
});
@@ -913,10 +909,7 @@ TEST_F(FlutterWindowsEngineTest, EnableApplicationLifecycle) {
913
909
EngineModifier modifier (engine.get ());
914
910
modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
915
911
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 ));
920
913
modifier.SetLifecycleManager (std::move (handler));
921
914
engine->lifecycle_manager ()->BeginProcessingExit ();
922
915
@@ -936,10 +929,7 @@ TEST_F(FlutterWindowsEngineTest, ApplicationLifecycleExternalWindow) {
936
929
EngineModifier modifier (engine.get ());
937
930
modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
938
931
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 ));
943
933
modifier.SetLifecycleManager (std::move (handler));
944
934
engine->lifecycle_manager ()->BeginProcessingExit ();
945
935
@@ -1065,8 +1055,8 @@ TEST_F(FlutterWindowsEngineTest, EnableLifecycleState) {
1065
1055
EngineModifier modifier (engine.get ());
1066
1056
modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
1067
1057
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) {
1070
1060
handler_ptr->WindowsLifecycleManager ::SetLifecycleState (state);
1071
1061
});
1072
1062
modifier.SetLifecycleManager (std::move (handler));
@@ -1118,8 +1108,8 @@ TEST_F(FlutterWindowsEngineTest, LifecycleStateToFrom) {
1118
1108
EngineModifier modifier (engine.get ());
1119
1109
modifier.embedder_api ().RunsAOTCompiledDartCode = []() { return false ; };
1120
1110
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) {
1123
1113
handler_ptr->WindowsLifecycleManager ::SetLifecycleState (state);
1124
1114
});
1125
1115
handler->begin_processing_callback = [&]() { enabled_lifecycle = true ; };
@@ -1167,6 +1157,7 @@ TEST_F(FlutterWindowsEngineTest, ChannelListenedTo) {
1167
1157
1168
1158
bool lifecycle_began = false ;
1169
1159
auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get ());
1160
+ EXPECT_CALL (*handler, SetLifecycleState).Times (1 );
1170
1161
handler->begin_processing_callback = [&]() { lifecycle_began = true ; };
1171
1162
modifier.SetLifecycleManager (std::move (handler));
1172
1163
0 commit comments