forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlatformViewGestureRecognizerTests.m
More file actions
168 lines (138 loc) · 6.81 KB
/
PlatformViewGestureRecognizerTests.m
File metadata and controls
168 lines (138 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Copyright 2013 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 kSecondsToWaitForPlatformView = 30;
@interface PlatformViewGestureRecognizerTests : XCTestCase
@end
@implementation PlatformViewGestureRecognizerTests
- (void)setUp {
self.continueAfterFailure = NO;
}
- (void)testRejectPolicyUtilTouchesEnded {
XCUIApplication* app = [[XCUIApplication alloc] init];
app.launchArguments =
@[ @"--gesture-reject-after-touches-ended", @"--enable-software-rendering" ];
[app launch];
NSPredicate* predicateToFindPlatformView =
[NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject,
NSDictionary<NSString*, id>* _Nullable bindings) {
XCUIElement* element = evaluatedObject;
return [element.identifier hasPrefix:@"platform_view"];
}];
XCUIElement* textView =
[app.otherElements elementMatchingPredicate:predicateToFindPlatformView].textViews.firstMatch;
if (![textView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
NSLog(@"%@", app.debugDescription);
XCTFail(@"Failed due to not able to find any textView with %@ seconds",
@(kSecondsToWaitForPlatformView));
}
XCTAssertNotNil(textView);
XCTAssertEqualObjects(textView.label, @"");
NSPredicate* predicate =
[NSPredicate predicateWithFormat:@"label == %@", @"-gestureTouchesBegan-gestureTouchesEnded"];
XCTNSPredicateExpectation* exception =
[[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:textView];
[textView tap];
[self waitForExpectations:@[ exception ] timeout:kSecondsToWaitForPlatformView];
XCTAssertEqualObjects(textView.label, @"-gestureTouchesBegan-gestureTouchesEnded");
}
- (void)testRejectPolicyEager {
XCUIApplication* app = [[XCUIApplication alloc] init];
app.launchArguments = @[ @"--gesture-reject-eager" ];
[app launch];
NSPredicate* predicateToFindPlatformView =
[NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject,
NSDictionary<NSString*, id>* _Nullable bindings) {
XCUIElement* element = evaluatedObject;
return [element.identifier hasPrefix:@"platform_view"];
}];
XCUIElement* textView =
[app.otherElements elementMatchingPredicate:predicateToFindPlatformView].textViews.firstMatch;
if (![textView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
NSLog(@"%@", app.debugDescription);
XCTFail(@"Failed due to not able to find any textView with %@ seconds",
@(kSecondsToWaitForPlatformView));
}
XCTAssertNotNil(textView);
XCTAssertEqualObjects(textView.label, @"");
NSPredicate* predicate =
[NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject,
NSDictionary<NSString*, id>* _Nullable bindings) {
XCUIElement* view = (XCUIElement*)evaluatedObject;
return [view.label containsString:@"-gestureTouchesBegan"];
}];
XCTNSPredicateExpectation* exception =
[[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:textView];
[textView tap];
[self waitForExpectations:@[ exception ] timeout:kSecondsToWaitForPlatformView];
XCTAssertTrue([textView.label containsString:@"-gestureTouchesBegan"]);
}
- (void)testAccept {
XCUIApplication* app = [[XCUIApplication alloc] init];
app.launchArguments = @[ @"--gesture-accept" ];
[app launch];
NSPredicate* predicateToFindPlatformView =
[NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject,
NSDictionary<NSString*, id>* _Nullable bindings) {
XCUIElement* element = evaluatedObject;
return [element.identifier hasPrefix:@"platform_view"];
}];
XCUIElement* textView =
[app.otherElements elementMatchingPredicate:predicateToFindPlatformView].textViews.firstMatch;
if (![textView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
NSLog(@"%@", app.debugDescription);
XCTFail(@"Failed due to not able to find any textView with %@ seconds",
@(kSecondsToWaitForPlatformView));
}
XCTAssertNotNil(textView);
XCTAssertEqualObjects(textView.label, @"");
NSPredicate* predicate = [NSPredicate
predicateWithFormat:@"label == %@",
@"-gestureTouchesBegan-gestureTouchesEnded-platformViewTapped"];
XCTNSPredicateExpectation* exception =
[[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:textView];
[textView tap];
[self waitForExpectations:@[ exception ] timeout:kSecondsToWaitForPlatformView];
XCTAssertEqualObjects(textView.label,
@"-gestureTouchesBegan-gestureTouchesEnded-platformViewTapped");
}
- (void)testGestureWithMaskViewBlockingPlatformView {
XCUIApplication* app = [[XCUIApplication alloc] init];
app.launchArguments = @[ @"--gesture-accept", @"--maskview-blocking" ];
[app launch];
NSPredicate* predicateToFindPlatformView =
[NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject,
NSDictionary<NSString*, id>* _Nullable bindings) {
XCUIElement* element = evaluatedObject;
return [element.identifier hasPrefix:@"platform_view"];
}];
XCUIElement* textView =
[app.otherElements elementMatchingPredicate:predicateToFindPlatformView].textViews.firstMatch;
if (![textView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
NSLog(@"%@", app.debugDescription);
XCTFail(@"Failed due to not able to find any platformView with %@ seconds",
@(kSecondsToWaitForPlatformView));
}
XCTAssertNotNil(textView);
XCTAssertEqualObjects(textView.label, @"");
NSPredicate* predicate = [NSPredicate
predicateWithFormat:@"label == %@",
@"-gestureTouchesBegan-gestureTouchesEnded-platformViewTapped"];
XCTNSPredicateExpectation* exception =
[[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:textView];
XCUICoordinate* coordinate =
[self getNormalizedCoordinate:app
point:CGVectorMake(textView.frame.origin.x + 10,
textView.frame.origin.y + 10)];
[coordinate tap];
[self waitForExpectations:@[ exception ] timeout:kSecondsToWaitForPlatformView];
XCTAssertEqualObjects(textView.label,
@"-gestureTouchesBegan-gestureTouchesEnded-platformViewTapped");
}
- (XCUICoordinate*)getNormalizedCoordinate:(XCUIApplication*)app point:(CGVector)vector {
XCUICoordinate* appZero = [app coordinateWithNormalizedOffset:CGVectorMake(0, 0)];
XCUICoordinate* coordinate = [appZero coordinateWithOffset:vector];
return coordinate;
}
@end