-
Notifications
You must be signed in to change notification settings - Fork 6k
Support right-clicking on iPadOS #27019
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,3 +18,4 @@ shoryukenn <[email protected]> | |
| SOTEC GmbH & Co. KG <[email protected]> | ||
| Hidenori Matsubayashi <[email protected]> | ||
| Sarbagya Dhaubanjar <[email protected]> | ||
| Callum Moffat <[email protected]> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright 2020 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #import <XCTest/XCTest.h> | ||
|
|
||
| static const NSInteger kSecondsToWaitForFlutterView = 30; | ||
|
|
||
| @interface iPadGestureTests : XCTestCase | ||
|
|
||
| @end | ||
|
|
||
| @implementation iPadGestureTests | ||
|
|
||
| - (void)setUp { | ||
| [super setUp]; | ||
| self.continueAfterFailure = NO; | ||
| } | ||
|
|
||
| #ifdef __IPHONE_15_0 | ||
| - (void)testPointerButtons { | ||
| if (@available(iOS 15, *)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come this is asking for iOS 15 when the implementation check is for iOS 13.4?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the pointer/trackpad features on iPad came out in iPadOS 13.4, synthesizing those events in XCTest wasn't supported until this year's new Xcode/iPadOS beta releases.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You aren't synthesizing any events here though, right? At the least please add a comment, preferably one that points to the API that is being used that requires ios 15. |
||
| XCTSkipUnless([XCUIDevice.sharedDevice supportsPointerInteraction], | ||
| "Device does not support pointer interaction"); | ||
| XCUIApplication* app = [[XCUIApplication alloc] init]; | ||
| app.launchArguments = @[ @"--pointer-events" ]; | ||
| [app launch]; | ||
|
|
||
| NSPredicate* predicateToFindFlutterView = | ||
| [NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject, | ||
| NSDictionary<NSString*, id>* _Nullable bindings) { | ||
| XCUIElement* element = evaluatedObject; | ||
| return [element.identifier hasPrefix:@"flutter_view"]; | ||
| }]; | ||
| XCUIElement* flutterView = [[app descendantsMatchingType:XCUIElementTypeAny] | ||
| elementMatchingPredicate:predicateToFindFlutterView]; | ||
| if (![flutterView waitForExistenceWithTimeout:kSecondsToWaitForFlutterView]) { | ||
| NSLog(@"%@", app.debugDescription); | ||
| XCTFail(@"Failed due to not able to find any flutterView with %@ seconds", | ||
| @(kSecondsToWaitForFlutterView)); | ||
| } | ||
|
|
||
| XCTAssertNotNil(flutterView); | ||
|
|
||
| [flutterView tap]; | ||
| // Initial add event should have buttons = 0 | ||
| XCTAssertTrue([app.textFields[@"PointerChange.add:0"] waitForExistenceWithTimeout:1], | ||
| @"PointerChange.add event did not occur"); | ||
| // Normal tap should have buttons = 0, the flutter framework will ensure it has buttons = 1 | ||
| XCTAssertTrue([app.textFields[@"PointerChange.down:0"] waitForExistenceWithTimeout:1], | ||
| @"PointerChange.down event did not occur for a normal tap"); | ||
| XCTAssertTrue([app.textFields[@"PointerChange.up:0"] waitForExistenceWithTimeout:1], | ||
| @"PointerChange.up event did not occur for a normal tap"); | ||
| [flutterView rightClick]; | ||
| // Since each touch is its own device, we can't distinguish the other add event(s) | ||
| // Right click should have buttons = 2 | ||
| XCTAssertTrue([app.textFields[@"PointerChange.down:2"] waitForExistenceWithTimeout:1], | ||
| @"PointerChange.down event did not occur for a right-click"); | ||
| XCTAssertTrue([app.textFields[@"PointerChange.up:2"] waitForExistenceWithTimeout:1], | ||
| @"PointerChange.up event did not occur for a right-click"); | ||
| NSLog(@"DebugDescriptionX: %@", app.debugDescription); | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| @end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you want conditional compilation here, you want runtime checks like you have below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this will compile on Xcode 12 without this conditional, since supportsPointerInteraction was only introduced in the Xcode 13 beta.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to do that use#if (defined (__IPHONE_15_0) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_15_0)then. We don't just care that the SDK has it, but that the target platform has it.edit: nevermind, LGTM, sdk version is the same thing as running environment for tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment wouldn't hurt, a runtime check with
respondsToSelectorwould be a bit more apparent and easier to maintain, but a comment will be good enough.