@@ -1801,6 +1801,49 @@ - (bool)testSelectorsAreForwardedToFramework {
1801
1801
return true ;
1802
1802
}
1803
1803
1804
+ - (bool )testSelectorsNotForwardedToFrameworkIfNoClient {
1805
+ id engineMock = flutter::testing::CreateMockFlutterEngine (@" " );
1806
+ id binaryMessengerMock = OCMProtocolMock (@protocol (FlutterBinaryMessenger));
1807
+ OCMStub ( // NOLINT(google-objc-avoid-throwing-exception)
1808
+ [engineMock binaryMessenger ])
1809
+ .andReturn (binaryMessengerMock);
1810
+ // Make sure the selectors are not forwarded to the framework.
1811
+ OCMReject ([binaryMessengerMock sendOnChannel: @" flutter/textinput" message: [OCMArg any ]]);
1812
+ FlutterViewController* viewController = [[FlutterViewController alloc ] initWithEngine: engineMock
1813
+ nibName: @" "
1814
+ bundle: nil ];
1815
+
1816
+ FlutterTextInputPlugin* plugin =
1817
+ [[FlutterTextInputPlugin alloc ] initWithViewController: viewController];
1818
+
1819
+ // Can't run CFRunLoop in default mode because it causes crashes from scheduled
1820
+ // sources from other tests.
1821
+ NSString * runLoopMode = @" FlutterTestRunLoopMode" ;
1822
+ plugin.customRunLoopMode = runLoopMode;
1823
+
1824
+ // Ensure both selectors are grouped in one platform channel call.
1825
+ [plugin doCommandBySelector: @selector (moveUp: )];
1826
+ [plugin doCommandBySelector: @selector (moveRightAndModifySelection: )];
1827
+
1828
+ // Clear the client before the CFRunLoop is run.
1829
+ [plugin handleMethodCall: [FlutterMethodCall methodCallWithMethodName: @" TextInput.clearClient"
1830
+ arguments: @[]]
1831
+ result: ^(id ){
1832
+ }];
1833
+
1834
+ __block bool done = false ;
1835
+ CFRunLoopPerformBlock (CFRunLoopGetMain (), (__bridge CFStringRef )runLoopMode, ^{
1836
+ done = true ;
1837
+ });
1838
+
1839
+ while (!done) {
1840
+ // Each invocation will handle one source.
1841
+ CFRunLoopRunInMode ((__bridge CFStringRef )runLoopMode, 0 , true );
1842
+ }
1843
+ // At this point the selectors should be dropped; otherwise, OCMReject will throw.
1844
+ return true ;
1845
+ }
1846
+
1804
1847
@end
1805
1848
1806
1849
namespace flutter ::testing {
@@ -1886,7 +1929,7 @@ - (bool)testSelectorsAreForwardedToFramework {
1886
1929
ASSERT_TRUE ([[FlutterInputPluginTestObjc alloc ] testComposingWithDelta ]);
1887
1930
}
1888
1931
1889
- TEST (FlutterTextInputPluginTest, testComposingWithDeltasWhenSelectionIsActive ) {
1932
+ TEST (FlutterTextInputPluginTest, TestComposingWithDeltasWhenSelectionIsActive ) {
1890
1933
ASSERT_TRUE ([[FlutterInputPluginTestObjc alloc ] testComposingWithDeltasWhenSelectionIsActive ]);
1891
1934
}
1892
1935
@@ -1910,6 +1953,10 @@ - (bool)testSelectorsAreForwardedToFramework {
1910
1953
ASSERT_TRUE ([[FlutterInputPluginTestObjc alloc ] testSelectorsAreForwardedToFramework ]);
1911
1954
}
1912
1955
1956
+ TEST (FlutterTextInputPluginTest, TestSelectorsNotForwardedToFrameworkIfNoClient) {
1957
+ ASSERT_TRUE ([[FlutterInputPluginTestObjc alloc ] testSelectorsNotForwardedToFrameworkIfNoClient ]);
1958
+ }
1959
+
1913
1960
TEST (FlutterTextInputPluginTest, TestInsertNewLine) {
1914
1961
ASSERT_TRUE ([[FlutterInputPluginTestObjc alloc ] testInsertNewLine ]);
1915
1962
}
0 commit comments