Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 758f705

Browse files
authored
iOS: Use standard Obj-C cflags for ios_test_flutter (#56384)
Previously, we had not enabled standard iOS cflags for `ios_test_flutter`, though ARC had been manually added to the cflags. This meant that the following flags were not enabled: * -Werror=overriding-method-mismatch * -Werror=undeclared-selector Both of these existed in the code within this target: * undeclared-selector: `insertionPointColor` was a non-public selector on UITextInput prior to iOS 17. * overriding-method-mismatch: `FakeFlutterUndoManagerDelegate`, which implements the `FlutterUndoManagerDelegate` protocol, declared `initWithUndoManager:activeInputView:` with a different type for `activeInputView`. This was a hack to jam in a test mock object that didn't match the required type for the property. Conveniently we have a class (`FlutterTextInputView`) that implements the required type and protocol (`UIView<UITextInput>`). Issue: flutter/flutter#137801 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent ab9b354 commit 758f705

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

shell/platform/darwin/ios/BUILD.gn

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,20 @@ platform_frameworks_path =
198198
shared_library("ios_test_flutter") {
199199
testonly = true
200200
visibility = [ "*" ]
201+
202+
# Xcode 15 beta has a bug where iOS 17 API usage is not guarded.
203+
# This bug results engine build failure since the engine treats warnings as errors.
204+
# The `-Wno-unguarded-availability-new` can be removed when the Xcode bug is fixed.
205+
# See details in https://github.com/flutter/flutter/issues/128958.
206+
cflags_objc = flutter_cflags_objc_arc
207+
cflags_objcc =
208+
flutter_cflags_objcc_arc + [ "-Wno-unguarded-availability-new" ]
201209
cflags = [
202210
"-fvisibility=default",
203211
"-F$platform_frameworks_path",
204-
"-fobjc-arc",
205212
"-mios-simulator-version-min=$ios_testing_deployment_target",
206213
]
207214

208-
# XCode 15 beta has a bug where iOS 17 API usage is not guarded.
209-
# This bug results engine build failure since the engine treats warnings as errors.
210-
# The `-Wno-unguarded-availability-new` can be removed when the XCode bug is fixed.
211-
# See details in https://github.com/flutter/flutter/issues/128958.
212-
cflags_objcc = [ "-Wno-unguarded-availability-new" ]
213215
ldflags = [
214216
"-F$platform_frameworks_path",
215217
"-Wl,-install_name,@rpath/Frameworks/libios_test_flutter.dylib",

shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,10 @@ - (void)testReplaceTestLocalAdjustSelectionAndMarkedTextRange {
834834

835835
- (void)testFlutterTextInputViewOnlyRespondsToInsertionPointColorBelowIOS17 {
836836
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];
837-
BOOL respondsToInsertionPointColor =
838-
[inputView respondsToSelector:@selector(insertionPointColor)];
837+
// [UITextInputTraits insertionPointColor] is non-public API, so @selector(insertionPointColor)
838+
// would generate a compile-time warning.
839+
SEL insertionPointColor = NSSelectorFromString(@"insertionPointColor");
840+
BOOL respondsToInsertionPointColor = [inputView respondsToSelector:insertionPointColor];
839841
if (@available(iOS 17, *)) {
840842
XCTAssertFalse(respondsToInsertionPointColor);
841843
} else {

shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPluginTest.mm

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,24 @@
88
#import <XCTest/XCTest.h>
99

1010
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
11+
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
1112

1213
FLUTTER_ASSERT_ARC
1314

14-
/// OCMock does not allow mocking both class and protocol. Use this to mock the methods used on
15-
/// `UIView<UITextInput>*` in the plugin.
16-
@interface TextInputViewTest : NSObject
17-
18-
@property(nonatomic, weak) id<UITextInputDelegate> inputDelegate;
19-
@property(nonatomic, readonly) UITextInputAssistantItem* inputAssistantItem;
20-
21-
@end
22-
23-
@implementation TextInputViewTest
24-
@end
25-
2615
@interface FakeFlutterUndoManagerDelegate : NSObject <FlutterUndoManagerDelegate>
2716

2817
@property(readonly) NSUInteger undoCount;
2918
@property(readonly) NSUInteger redoCount;
3019
@property(nonatomic, nullable) NSUndoManager* undoManager;
20+
@property(nonatomic, nullable) UIView<UITextInput>* activeTextInputView;
3121

3222
- (instancetype)initWithUndoManager:(NSUndoManager*)undoManager
33-
activeTextInputView:(TextInputViewTest*)activeTextInputView;
23+
activeTextInputView:(UIView<UITextInput>*)activeTextInputView;
3424

3525
@end
3626

3727
@implementation FakeFlutterUndoManagerDelegate
3828

39-
@synthesize undoManager = _undoManager;
40-
@synthesize activeTextInputView = _activeTextInputView;
41-
4229
- (instancetype)initWithUndoManager:(NSUndoManager*)undoManager
4330
activeTextInputView:(UIView<UITextInput>*)activeTextInputView {
4431
self = [super init];
@@ -62,7 +49,7 @@ - (void)handleUndoWithDirection:(FlutterUndoRedoDirection)direction {
6249
@interface FlutterUndoManagerPluginTest : XCTestCase
6350
@property(nonatomic) FakeFlutterUndoManagerDelegate* undoManagerDelegate;
6451
@property(nonatomic) FlutterUndoManagerPlugin* undoManagerPlugin;
65-
@property(nonatomic) TextInputViewTest* activeTextInputView;
52+
@property(nonatomic) UIView<UITextInput>* activeTextInputView;
6653
@property(nonatomic) NSUndoManager* undoManager;
6754
@end
6855

@@ -72,7 +59,7 @@ - (void)setUp {
7259
[super setUp];
7360

7461
self.undoManager = OCMClassMock([NSUndoManager class]);
75-
self.activeTextInputView = OCMClassMock([TextInputViewTest class]);
62+
self.activeTextInputView = OCMClassMock([FlutterTextInputView class]);
7663

7764
self.undoManagerDelegate =
7865
[[FakeFlutterUndoManagerDelegate alloc] initWithUndoManager:self.undoManager
@@ -170,7 +157,7 @@ - (void)testDeallocRemovesAllUndoManagerActions {
170157
// Use a real undo manager.
171158
NSUndoManager* undoManager = [[NSUndoManager alloc] init];
172159
@autoreleasepool {
173-
id activeTextInputView = OCMClassMock([TextInputViewTest class]);
160+
id activeTextInputView = OCMClassMock([FlutterTextInputView class]);
174161

175162
FakeFlutterUndoManagerDelegate* undoManagerDelegate =
176163
[[FakeFlutterUndoManagerDelegate alloc] initWithUndoManager:undoManager

0 commit comments

Comments
 (0)