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

Commit 6b022df

Browse files
authored
Fixes crash in testTrackpadGesturesAreSentToFramework (#55990)
fixes flutter/flutter#157205 This crashed because ocmock was storing references to rvalues for its mocked arguments. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent ec6e28a commit 6b022df

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
#pragma mark - Test Helper Classes
2323

24+
static const FlutterPointerEvent kDefaultFlutterPointerEvent = {};
25+
static const FlutterKeyEvent kDefaultFlutterKeyEvent = {};
26+
2427
// A wrap to convert FlutterKeyEvent to a ObjC class.
2528
@interface KeyEventWrapper : NSObject
2629
@property(nonatomic) FlutterKeyEvent* data;
@@ -339,7 +342,7 @@ - (bool)testKeyEventsAreSentToFramework:(id)engineMock {
339342
OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
340343
[engineMock binaryMessenger])
341344
.andReturn(binaryMessengerMock);
342-
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:FlutterKeyEvent {}
345+
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:kDefaultFlutterKeyEvent
343346
callback:nil
344347
userData:nil])
345348
.andCall([FlutterViewControllerTestObjC class],
@@ -375,7 +378,7 @@ - (bool)testKeyEventsAreSentToFramework:(id)engineMock {
375378
- (bool)testCtrlTabKeyEventIsPropagated:(id)engineMock {
376379
__block bool called = false;
377380
__block FlutterKeyEvent last_event;
378-
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:FlutterKeyEvent {}
381+
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:kDefaultFlutterKeyEvent
379382
callback:nil
380383
userData:nil])
381384
.andDo((^(NSInvocation* invocation) {
@@ -419,7 +422,7 @@ - (bool)testCtrlTabKeyEventIsPropagated:(id)engineMock {
419422
- (bool)testKeyEquivalentIsPassedToTextInputPlugin:(id)engineMock {
420423
__block bool called = false;
421424
__block FlutterKeyEvent last_event;
422-
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:FlutterKeyEvent {}
425+
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:kDefaultFlutterKeyEvent
423426
callback:nil
424427
userData:nil])
425428
.andDo((^(NSInvocation* invocation) {
@@ -471,7 +474,7 @@ - (bool)testKeyEventsArePropagatedIfNotHandled:(id)engineMock {
471474
OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
472475
[engineMock binaryMessenger])
473476
.andReturn(binaryMessengerMock);
474-
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:FlutterKeyEvent {}
477+
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:kDefaultFlutterKeyEvent
475478
callback:nil
476479
userData:nil])
477480
.andCall([FlutterViewControllerTestObjC class],
@@ -545,7 +548,7 @@ - (bool)testFlagsChangedEventsArePropagatedIfNotHandled:(id)engineMock {
545548
OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
546549
[engineMock binaryMessenger])
547550
.andReturn(binaryMessengerMock);
548-
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:FlutterKeyEvent {}
551+
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:kDefaultFlutterKeyEvent
549552
callback:nil
550553
userData:nil])
551554
.andCall([FlutterViewControllerTestObjC class],
@@ -598,7 +601,7 @@ - (bool)testKeyEventsAreNotPropagatedIfHandled:(id)engineMock {
598601
OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
599602
[engineMock binaryMessenger])
600603
.andReturn(binaryMessengerMock);
601-
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:FlutterKeyEvent {}
604+
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:kDefaultFlutterKeyEvent
602605
callback:nil
603606
userData:nil])
604607
.andCall([FlutterViewControllerTestObjC class],
@@ -655,7 +658,7 @@ - (bool)testKeyboardIsRestartedOnEngineRestart:(id)engineMock {
655658
.andReturn(binaryMessengerMock);
656659
__block bool called = false;
657660
__block FlutterKeyEvent last_event;
658-
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:FlutterKeyEvent {}
661+
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:kDefaultFlutterKeyEvent
659662
callback:nil
660663
userData:nil])
661664
.andDo((^(NSInvocation* invocation) {
@@ -715,7 +718,7 @@ - (bool)testTrackpadGesturesAreSentToFramework:(id)engineMock {
715718
OCMStub([engineMock renderer]).andReturn(renderer_);
716719
__block bool called = false;
717720
__block FlutterPointerEvent last_event;
718-
OCMStub([[engineMock ignoringNonObjectArgs] sendPointerEvent:FlutterPointerEvent{}])
721+
OCMStub([[engineMock ignoringNonObjectArgs] sendPointerEvent:kDefaultFlutterPointerEvent])
719722
.andDo((^(NSInvocation* invocation) {
720723
FlutterPointerEvent* event;
721724
[invocation getArgument:&event atIndex:2];
@@ -1139,7 +1142,7 @@ - (bool)testModifierKeysAreSynthesizedOnMouseMove:(id)engineMock {
11391142

11401143
// Capture calls to sendKeyEvent
11411144
__block NSMutableArray<KeyEventWrapper*>* events = [NSMutableArray array];
1142-
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:FlutterKeyEvent {}
1145+
OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:kDefaultFlutterKeyEvent
11431146
callback:nil
11441147
userData:nil])
11451148
.andDo((^(NSInvocation* invocation) {

0 commit comments

Comments
 (0)