Flutter Engine
UnobstructedPlatformViewTests.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 
7 @interface UnobstructedPlatformViewTests : XCTestCase
8 
9 @end
10 
11 @implementation UnobstructedPlatformViewTests
12 
13 - (void)setUp {
14  self.continueAfterFailure = NO;
15 }
16 
17 // A is the layer, which z index is higher than the platform view.
18 // +--------+
19 // | PV | +---+
20 // +--------+ | A |
21 // +---+
22 - (void)testNoOverlay {
23  XCUIApplication* app = [[XCUIApplication alloc] init];
24  app.launchArguments =
25  @[ @"--platform-view-no-overlay-intersection", @"--enable-software-rendering" ];
26  [app launch];
27 
28  XCUIElement* platform_view = app.textViews[@"platform_view[0]"];
29  XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]);
30  XCTAssertEqual(platform_view.frame.origin.x, 25);
31  XCTAssertEqual(platform_view.frame.origin.y, 25);
32  XCTAssertEqual(platform_view.frame.size.width, 250);
33  XCTAssertEqual(platform_view.frame.size.height, 250);
34 
35  XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"];
36  XCTAssertFalse(overlay.exists);
37 }
38 
39 // A is the layer above the platform view.
40 // +-----------------+
41 // | PV +---+ |
42 // | | A | |
43 // | +---+ |
44 // +-----------------+
45 - (void)testOneOverlay {
46  XCUIApplication* app = [[XCUIApplication alloc] init];
47  app.launchArguments = @[ @"--platform-view" ];
48  [app launch];
49 
50  XCUIElement* platform_view = app.textViews[@"platform_view[0]"];
51  XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]);
52  XCTAssertEqual(platform_view.frame.origin.x, 25);
53  XCTAssertEqual(platform_view.frame.origin.y, 25);
54  XCTAssertEqual(platform_view.frame.size.width, 250);
55  XCTAssertEqual(platform_view.frame.size.height, 250);
56 
57  XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"];
58  XCTAssertTrue(overlay.exists);
59  XCTAssertEqual(overlay.frame.origin.x, 150);
60  XCTAssertEqual(overlay.frame.origin.y, 150);
61  XCTAssertEqual(overlay.frame.size.width, 50);
62  XCTAssertEqual(overlay.frame.size.height, 50);
63 }
64 
65 // A is the layer above the platform view.
66 // +-----------------+
67 // | PV +---+ |
68 // +-----------| A |-+
69 // +---+
70 - (void)testOneOverlayPartialIntersection {
71  XCUIApplication* app = [[XCUIApplication alloc] init];
72  app.launchArguments = @[ @"--platform-view-partial-intersection" ];
73  [app launch];
74 
75  XCUIElement* platform_view = app.textViews[@"platform_view[0]"];
76  XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]);
77  XCTAssertEqual(platform_view.frame.origin.x, 25);
78  XCTAssertEqual(platform_view.frame.origin.y, 25);
79  XCTAssertEqual(platform_view.frame.size.width, 250);
80  XCTAssertEqual(platform_view.frame.size.height, 250);
81 
82  XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"];
83  XCTAssertTrue(overlay.exists);
84  XCTAssertEqual(overlay.frame.origin.x, 200);
85  XCTAssertEqual(overlay.frame.origin.y, 250);
86  XCTAssertEqual(overlay.frame.size.width, 50);
87  // Half the height of the overlay.
88  XCTAssertEqual(overlay.frame.size.height, 25);
89 }
90 
91 // A and B are the layers above the platform view.
92 // +--------------------+
93 // | PV +------------+ |
94 // | | B +-----+ | |
95 // | +---| A |-+ |
96 // +----------| |---+
97 // +-----+
98 - (void)testTwoIntersectingOverlays {
99  XCUIApplication* app = [[XCUIApplication alloc] init];
100  app.launchArguments = @[ @"--platform-view-two-intersecting-overlays" ];
101  [app launch];
102 
103  XCUIElement* platform_view = app.textViews[@"platform_view[0]"];
104  XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]);
105  XCTAssertEqual(platform_view.frame.origin.x, 25);
106  XCTAssertEqual(platform_view.frame.origin.y, 25);
107  XCTAssertEqual(platform_view.frame.size.width, 250);
108  XCTAssertEqual(platform_view.frame.size.height, 250);
109 
110  XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"];
111  XCTAssertTrue(overlay.exists);
112  XCTAssertEqual(overlay.frame.origin.x, 150);
113  XCTAssertEqual(overlay.frame.origin.y, 150);
114  XCTAssertEqual(overlay.frame.size.width, 75);
115  XCTAssertEqual(overlay.frame.size.height, 75);
116 
117  XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[1]"].exists);
118 }
119 
120 // A, B, and C are the layers above the platform view.
121 // +-------------------------+
122 // | PV +-----------+ |
123 // | +---+ | B +-----+ | |
124 // | | C | +---| A |-+ |
125 // | +---+ +-----+ |
126 // +-------------------------+
127 - (void)testOneOverlayAndTwoIntersectingOverlays {
128  XCUIApplication* app = [[XCUIApplication alloc] init];
129  app.launchArguments = @[ @"--platform-view-one-overlay-two-intersecting-overlays" ];
130  [app launch];
131 
132  XCUIElement* platform_view = app.textViews[@"platform_view[0]"];
133  XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]);
134  XCTAssertEqual(platform_view.frame.origin.x, 25);
135  XCTAssertEqual(platform_view.frame.origin.y, 25);
136  XCTAssertEqual(platform_view.frame.size.width, 250);
137  XCTAssertEqual(platform_view.frame.size.height, 250);
138 
139  XCUIElement* overlay1 = app.otherElements[@"platform_view[0].overlay[0]"];
140  XCTAssertTrue(overlay1.exists);
141  XCTAssertEqual(overlay1.frame.origin.x, 150);
142  XCTAssertEqual(overlay1.frame.origin.y, 150);
143  XCTAssertEqual(overlay1.frame.size.width, 75);
144  XCTAssertEqual(overlay1.frame.size.height, 75);
145 
146  XCUIElement* overlay2 = app.otherElements[@"platform_view[0].overlay[1]"];
147  XCTAssertTrue(overlay2.exists);
148  XCTAssertEqual(overlay2.frame.origin.x, 75);
149  XCTAssertEqual(overlay2.frame.origin.y, 225);
150  XCTAssertEqual(overlay2.frame.size.width, 50);
151  XCTAssertEqual(overlay2.frame.size.height, 50);
152 }
153 
154 // A is the layer, which z index is higher than the platform view.
155 // +--------+
156 // | PV | +---+
157 // +--------+ | A |
158 // +--------+ +---+
159 // | PV |
160 // +--------+
161 - (void)testMultiplePlatformViewsWithoutOverlays {
162  XCUIApplication* app = [[XCUIApplication alloc] init];
163  app.launchArguments = @[ @"--platform-view-multiple-without-overlays" ];
164  [app launch];
165 
166  XCUIElement* platform_view1 = app.textViews[@"platform_view[0]"];
167  XCTAssertTrue([platform_view1 waitForExistenceWithTimeout:1.0]);
168  XCTAssertEqual(platform_view1.frame.origin.x, 25);
169  XCTAssertEqual(platform_view1.frame.origin.y, 325);
170  XCTAssertEqual(platform_view1.frame.size.width, 250);
171  XCTAssertEqual(platform_view1.frame.size.height, 250);
172 
173  XCUIElement* platform_view2 = app.textViews[@"platform_view[1]"];
174  XCTAssertTrue(platform_view2.exists);
175  XCTAssertEqual(platform_view2.frame.origin.x, 25);
176  XCTAssertEqual(platform_view2.frame.origin.y, 25);
177  XCTAssertEqual(platform_view2.frame.size.width, 250);
178  XCTAssertEqual(platform_view2.frame.size.height, 250);
179 
180  XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[0]"].exists);
181  XCTAssertFalse(app.otherElements[@"platform_view[1].overlay[0]"].exists);
182 }
183 
184 // A is the layer above both platform view.
185 // +------------+
186 // | PV +----+ |
187 // +-----| A |-+
188 // +-----| |-+
189 // | PV +----+ |
190 // +------------+
191 - (void)testMultiplePlatformViewsWithOverlays {
192  XCUIApplication* app = [[XCUIApplication alloc] init];
193  app.launchArguments = @[ @"--platform-view-multiple-background-foreground" ];
194  [app launch];
195 
196  XCUIElement* platform_view1 = app.textViews[@"platform_view[0]"];
197  XCTAssertTrue([platform_view1 waitForExistenceWithTimeout:1.0]);
198  XCTAssertEqual(platform_view1.frame.origin.x, 25);
199  XCTAssertEqual(platform_view1.frame.origin.y, 325);
200  XCTAssertEqual(platform_view1.frame.size.width, 250);
201  XCTAssertEqual(platform_view1.frame.size.height, 250);
202 
203  XCUIElement* platform_view2 = app.textViews[@"platform_view[1]"];
204  XCTAssertTrue(platform_view2.exists);
205  XCTAssertEqual(platform_view2.frame.origin.x, 25);
206  XCTAssertEqual(platform_view2.frame.origin.y, 25);
207  XCTAssertEqual(platform_view2.frame.size.width, 250);
208  XCTAssertEqual(platform_view2.frame.size.height, 250);
209 
210  XCUIElement* overlay1 = app.otherElements[@"platform_view[0].overlay[0]"];
211  XCTAssertTrue(overlay1.exists);
212  XCTAssertEqual(overlay1.frame.origin.x, 25);
213  XCTAssertEqual(overlay1.frame.origin.y, 325);
214  XCTAssertEqual(overlay1.frame.size.width, 225);
215  XCTAssertEqual(overlay1.frame.size.height, 175);
216 
217  XCUIElement* overlay2 = app.otherElements[@"platform_view[1].overlay[0]"];
218  XCTAssertTrue(overlay2.exists);
219  XCTAssertEqual(overlay2.frame.origin.x, 25);
220  XCTAssertEqual(overlay2.frame.origin.y, 25);
221  XCTAssertEqual(overlay2.frame.size.width, 225);
222  XCTAssertEqual(overlay2.frame.size.height, 250);
223 }
224 
225 // More then two overlays are merged into a single layer.
226 // +---------------------+
227 // | +---+ +---+ +---+ |
228 // | | A | | B | | C | |
229 // | +---+ +---+ +---+ |
230 // | +-------+ |
231 // +-| D |-----------+
232 // +-------+
233 - (void)testPlatformViewsMaxOverlays {
234  XCUIApplication* app = [[XCUIApplication alloc] init];
235  app.launchArguments = @[ @"--platform-view-max-overlays" ];
236  [app launch];
237 
238  XCUIElement* platform_view = app.textViews[@"platform_view[0]"];
239  XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]);
240  XCTAssertEqual(platform_view.frame.origin.x, 25);
241  XCTAssertEqual(platform_view.frame.origin.y, 25);
242  XCTAssertEqual(platform_view.frame.size.width, 250);
243  XCTAssertEqual(platform_view.frame.size.height, 250);
244 
245  XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"];
246  XCTAssertTrue(overlay.exists);
247  XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[1]"].exists);
248  XCTAssertTrue(CGRectContainsRect(platform_view.frame, overlay.frame));
249 }
250 
251 @end