Flutter Engine
The Flutter Engine
PlatformViewGestureRecognizerTests.m
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import <XCTest/XCTest.h>
6
7static const NSInteger kSecondsToWaitForPlatformView = 30;
8
9@interface PlatformViewGestureRecognizerTests : XCTestCase
10
11@end
12
14
15- (void)setUp {
16 self.continueAfterFailure = NO;
17}
18
20 XCUIApplication* app = [[XCUIApplication alloc] init];
21 app.launchArguments = @[ @"--gesture-reject-after-touches-ended" ];
22 [app launch];
23
24 NSPredicate* predicateToFindPlatformView =
25 [NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject,
26 NSDictionary<NSString*, id>* _Nullable bindings) {
27 XCUIElement* element = evaluatedObject;
28 return [element.identifier hasPrefix:@"platform_view"];
29 }];
30 XCUIElement* textView =
31 [app.otherElements elementMatchingPredicate:predicateToFindPlatformView].textViews.firstMatch;
32 if (![textView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
33 NSLog(@"%@", app.debugDescription);
34 XCTFail(@"Failed due to not able to find any textView with %@ seconds",
36 }
37
38 XCTAssertNotNil(textView);
39 XCTAssertEqualObjects(textView.label, @"");
40
41 NSPredicate* predicate =
42 [NSPredicate predicateWithFormat:@"label == %@", @"-gestureTouchesBegan-gestureTouchesEnded"];
43 XCTNSPredicateExpectation* exception =
44 [[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:textView];
45
46 [textView tap];
47 [self waitForExpectations:@[ exception ] timeout:kSecondsToWaitForPlatformView];
48 XCTAssertEqualObjects(textView.label, @"-gestureTouchesBegan-gestureTouchesEnded");
49}
50
52 XCUIApplication* app = [[XCUIApplication alloc] init];
53 app.launchArguments = @[ @"--gesture-reject-eager" ];
54 [app launch];
55
56 NSPredicate* predicateToFindPlatformView =
57 [NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject,
58 NSDictionary<NSString*, id>* _Nullable bindings) {
59 XCUIElement* element = evaluatedObject;
60 return [element.identifier hasPrefix:@"platform_view"];
61 }];
62 XCUIElement* textView =
63 [app.otherElements elementMatchingPredicate:predicateToFindPlatformView].textViews.firstMatch;
64 if (![textView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
65 NSLog(@"%@", app.debugDescription);
66 XCTFail(@"Failed due to not able to find any textView with %@ seconds",
68 }
69
70 XCTAssertNotNil(textView);
71 XCTAssertEqualObjects(textView.label, @"");
72
73 NSPredicate* predicate =
74 [NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject,
75 NSDictionary<NSString*, id>* _Nullable bindings) {
76 XCUIElement* view = (XCUIElement*)evaluatedObject;
77 return [view.label containsString:@"-gestureTouchesBegan"];
78 }];
79 XCTNSPredicateExpectation* exception =
80 [[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:textView];
81
82 [textView tap];
83 [self waitForExpectations:@[ exception ] timeout:kSecondsToWaitForPlatformView];
84 XCTAssertTrue([textView.label containsString:@"-gestureTouchesBegan"]);
85}
86
87- (void)testAccept {
88 XCUIApplication* app = [[XCUIApplication alloc] init];
89 app.launchArguments = @[ @"--gesture-accept" ];
90 [app launch];
91
92 NSPredicate* predicateToFindPlatformView =
93 [NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject,
94 NSDictionary<NSString*, id>* _Nullable bindings) {
95 XCUIElement* element = evaluatedObject;
96 return [element.identifier hasPrefix:@"platform_view"];
97 }];
98 XCUIElement* textView =
99 [app.otherElements elementMatchingPredicate:predicateToFindPlatformView].textViews.firstMatch;
100 if (![textView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
101 NSLog(@"%@", app.debugDescription);
102 XCTFail(@"Failed due to not able to find any textView with %@ seconds",
104 }
105
106 XCTAssertNotNil(textView);
107 XCTAssertEqualObjects(textView.label, @"");
108
109 NSPredicate* predicate = [NSPredicate
110 predicateWithFormat:@"label == %@",
111 @"-gestureTouchesBegan-gestureTouchesEnded-platformViewTapped"];
112 XCTNSPredicateExpectation* exception =
113 [[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:textView];
114
115 [textView tap];
116
117 [self waitForExpectations:@[ exception ] timeout:kSecondsToWaitForPlatformView];
118 XCTAssertEqualObjects(textView.label,
119 @"-gestureTouchesBegan-gestureTouchesEnded-platformViewTapped");
120}
121
123 XCUIApplication* app = [[XCUIApplication alloc] init];
124 app.launchArguments = @[ @"--gesture-accept", @"--maskview-blocking" ];
125 [app launch];
126
127 NSPredicate* predicateToFindPlatformView =
128 [NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject,
129 NSDictionary<NSString*, id>* _Nullable bindings) {
130 XCUIElement* element = evaluatedObject;
131 return [element.identifier hasPrefix:@"platform_view"];
132 }];
133 XCUIElement* textView =
134 [app.otherElements elementMatchingPredicate:predicateToFindPlatformView].textViews.firstMatch;
135 if (![textView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
136 NSLog(@"%@", app.debugDescription);
137 XCTFail(@"Failed due to not able to find any platformView with %@ seconds",
139 }
140
141 XCTAssertNotNil(textView);
142 XCTAssertEqualObjects(textView.label, @"");
143
144 NSPredicate* predicate = [NSPredicate
145 predicateWithFormat:@"label == %@",
146 @"-gestureTouchesBegan-gestureTouchesEnded-platformViewTapped"];
147 XCTNSPredicateExpectation* exception =
148 [[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:textView];
149
150 XCUICoordinate* coordinate =
152 point:CGVectorMake(textView.frame.origin.x + 10,
153 textView.frame.origin.y + 10)];
154 [coordinate tap];
155
156 [self waitForExpectations:@[ exception ] timeout:kSecondsToWaitForPlatformView];
157 XCTAssertEqualObjects(textView.label,
158 @"-gestureTouchesBegan-gestureTouchesEnded-platformViewTapped");
159}
160
161- (XCUICoordinate*)getNormalizedCoordinate:(XCUIApplication*)app point:(CGVector)vector {
162 XCUICoordinate* appZero = [app coordinateWithNormalizedOffset:CGVectorMake(0, 0)];
163 XCUICoordinate* coordinate = [appZero coordinateWithOffset:vector];
164 return coordinate;
165}
166
168 XCUIApplication* app = [[XCUIApplication alloc] init];
169 app.launchArguments = @[ @"--gesture-accept-with-overlapping-platform-views" ];
170 [app launch];
171
172 XCUIElement* foreground = app.otherElements[@"platform_view[0]"];
173 XCTAssertEqual(foreground.frame.origin.x, 50);
174 XCTAssertEqual(foreground.frame.origin.y, 50);
175 XCTAssertEqual(foreground.frame.size.width, 50);
176 XCTAssertEqual(foreground.frame.size.height, 50);
177 XCTAssertTrue([foreground waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]);
178
179 XCUIElement* background = app.otherElements[@"platform_view[1]"];
180 XCTAssertEqual(background.frame.origin.x, 0);
181 XCTAssertEqual(background.frame.origin.y, 0);
182 XCTAssertEqual(background.frame.size.width, 150);
183 XCTAssertEqual(background.frame.size.height, 150);
184 XCTAssertTrue([background waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]);
185
186 XCUIElement* textView = foreground.textViews.firstMatch;
187 XCTAssertTrue(textView.exists);
188
189 XCTAssertTrue(foreground.isHittable);
190 [foreground tap];
191
192 XCTAssertEqualObjects(textView.label,
193 @"-gestureTouchesBegan-gestureTouchesEnded-platformViewTapped");
194}
195@end
static const NSInteger kSecondsToWaitForPlatformView
XCUICoordinate * getNormalizedCoordinate:point:(XCUIApplication *app, [point] CGVector vector)