mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This is a reland of https://github.com/flutter/flutter/pull/177410 The previous pr was hitting deadlocks with tests that use screenshots. This reland fixes it by submitting frames asynchronously instead of synchronously. This PR fixes https://github.com/flutter/flutter/issues/169147 This is the iOS implementation of https://github.com/flutter/flutter/issues/149033 In Add-to-App scenarios, a common desired use case is to have the embedded FlutterView be able to size itself based on it's content. Up till now, the size had to be manually specified, which can be tedious and inaccurate. This PR adds a new flag, `isAutoResizable`, which enables the ability for the embedded flutter view to dynamically set it's own size based off it's content. Note that this feature will *NOT* work if the the embedded app is wrapped in flexible or unsized widgets, such as Scaffold. The FlutterView will just not display at all. To use the new flag, just set it like ``` flutterViewController.autoResizable = true; ``` or in Swift ``` flutterViewController.isAutoResizable = true ``` ## 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], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
161 lines
6.7 KiB
Objective-C
161 lines
6.7 KiB
Objective-C
// Copyright 2014 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;
|
|
@import os.log;
|
|
|
|
static const CGFloat kStandardTimeOut = 60.0;
|
|
|
|
@interface FlutterUITests : XCTestCase
|
|
@property (strong) XCUIApplication *app;
|
|
@end
|
|
|
|
@implementation FlutterUITests
|
|
|
|
- (void)setUp {
|
|
[super setUp];
|
|
self.continueAfterFailure = NO;
|
|
|
|
XCUIApplication *app = [[XCUIApplication alloc] init];
|
|
[app launch];
|
|
self.app = app;
|
|
}
|
|
|
|
- (void)testFullScreenColdPop {
|
|
XCUIApplication *app = self.app;
|
|
[self waitForAndTapElement:app.buttons[@"Full Screen (Cold)"]];
|
|
XCTAssertTrue([app.staticTexts[@"Button tapped 0 times."] waitForExistenceWithTimeout:kStandardTimeOut]);
|
|
|
|
[self waitForAndTapElement:app.otherElements[@"Increment via Flutter"]];
|
|
XCTAssertTrue([app.staticTexts[@"Button tapped 1 time."] waitForExistenceWithTimeout:kStandardTimeOut]);
|
|
|
|
// Back navigation.
|
|
[app.buttons[@"POP"] tap];
|
|
XCTAssertTrue([app.navigationBars[@"Flutter iOS Demos Home"] waitForExistenceWithTimeout:kStandardTimeOut]);
|
|
}
|
|
|
|
- (void)testFullScreenWarm {
|
|
XCUIApplication *app = self.app;
|
|
|
|
[self waitForAndTapElement:app.buttons[@"Full Screen (Warm)"]];
|
|
BOOL newPageAppeared = [app.staticTexts[@"Button tapped 0 times."] waitForExistenceWithTimeout:kStandardTimeOut];
|
|
if (!newPageAppeared) {
|
|
// Sometimes, the element doesn't respond to the tap, it seems an XCUITest race condition where the tap happened
|
|
// too soon. Trying to tap the element again.
|
|
[self waitForAndTapElement:app.buttons[@"Full Screen (Warm)"]];
|
|
newPageAppeared = [app.staticTexts[@"Button tapped 0 times."] waitForExistenceWithTimeout:kStandardTimeOut];
|
|
}
|
|
XCTAssertTrue(newPageAppeared);
|
|
|
|
[self waitForAndTapElement:app.otherElements[@"Increment via Flutter"]];
|
|
XCTAssertTrue([app.staticTexts[@"Button tapped 1 time."] waitForExistenceWithTimeout:kStandardTimeOut]);
|
|
|
|
// Back navigation.
|
|
[app.buttons[@"POP"] tap];
|
|
XCTAssertTrue([app.navigationBars[@"Flutter iOS Demos Home"] waitForExistenceWithTimeout:kStandardTimeOut]);
|
|
}
|
|
|
|
- (void)testFlutterViewWarm {
|
|
XCUIApplication *app = self.app;
|
|
|
|
[self waitForAndTapElement:app.buttons[@"Flutter View (Warm)"]];
|
|
BOOL newPageAppeared = [app.staticTexts[@"Button tapped 0 times."] waitForExistenceWithTimeout:kStandardTimeOut];
|
|
if (!newPageAppeared) {
|
|
// Sometimes, the element doesn't respond to the tap, it seems an XCUITest race condition where the tap happened
|
|
// too soon. Trying to tap the element again.
|
|
[self waitForAndTapElement:app.buttons[@"Flutter View (Warm)"]];
|
|
newPageAppeared = [app.staticTexts[@"Button tapped 0 times."] waitForExistenceWithTimeout:kStandardTimeOut];
|
|
if (!newPageAppeared) {
|
|
os_log(OS_LOG_DEFAULT, "%@", app.debugDescription);
|
|
}
|
|
}
|
|
XCTAssertTrue(newPageAppeared);
|
|
|
|
[self waitForAndTapElement:app.otherElements[@"Increment via Flutter"]];
|
|
BOOL countIncremented = [app.staticTexts[@"Button tapped 1 time."] waitForExistenceWithTimeout:kStandardTimeOut];
|
|
if (!countIncremented) {
|
|
// Sometimes, the element doesn't respond to the tap, it seems to be an iOS 17 Simulator issue where the
|
|
// simulator reboots. Try to tap the element again.
|
|
[self waitForAndTapElement:app.otherElements[@"Increment via Flutter"]];
|
|
countIncremented = [app.staticTexts[@"Button tapped 1 time."] waitForExistenceWithTimeout:kStandardTimeOut];
|
|
if (!countIncremented) {
|
|
os_log(OS_LOG_DEFAULT, "%@", app.debugDescription);
|
|
}
|
|
}
|
|
XCTAssertTrue(countIncremented);
|
|
|
|
// Back navigation.
|
|
[app.buttons[@"POP"] tap];
|
|
XCTAssertTrue([app.navigationBars[@"Flutter iOS Demos Home"] waitForExistenceWithTimeout:kStandardTimeOut]);
|
|
}
|
|
|
|
- (void)testHybridViewWarm {
|
|
XCUIApplication *app = self.app;
|
|
|
|
[self waitForAndTapElement:app.buttons[@"Hybrid View (Warm)"]];
|
|
|
|
XCTAssertTrue([app.staticTexts[@"Flutter button tapped 0 times."] waitForExistenceWithTimeout:kStandardTimeOut]);
|
|
XCTAssertTrue(app.staticTexts[@"Platform button tapped 0 times."].exists);
|
|
|
|
[self waitForAndTapElement:app.otherElements[@"Increment via Flutter"]];
|
|
XCTAssertTrue([app.staticTexts[@"Flutter button tapped 1 time."] waitForExistenceWithTimeout:kStandardTimeOut]);
|
|
XCTAssertTrue(app.staticTexts[@"Platform button tapped 0 times."].exists);
|
|
|
|
[app.buttons[@"Increment via iOS"] tap];
|
|
XCTAssertTrue([app.staticTexts[@"Flutter button tapped 1 time."] waitForExistenceWithTimeout:kStandardTimeOut]);
|
|
XCTAssertTrue(app.staticTexts[@"Platform button tapped 1 time."].exists);
|
|
|
|
// Back navigation.
|
|
[app.navigationBars[@"Hybrid Flutter/Native"].buttons[@"Flutter iOS Demos Home"] tap];
|
|
XCTAssertTrue([app.navigationBars[@"Flutter iOS Demos Home"] waitForExistenceWithTimeout:kStandardTimeOut]);
|
|
}
|
|
|
|
- (void)testDualCold {
|
|
XCUIApplication *app = self.app;
|
|
|
|
[self waitForAndTapElement:app.buttons[@"Dual Flutter View (Cold)"]];
|
|
|
|
// There are two marquees.
|
|
XCUIElementQuery *marqueeQuery = [app.staticTexts matchingIdentifier:@"This is Marquee"];
|
|
[self expectationForPredicate:[NSPredicate predicateWithFormat:@"count = 2"] evaluatedWithObject:marqueeQuery handler:nil];
|
|
[self waitForExpectationsWithTimeout:30.0 handler:nil];
|
|
|
|
// Back navigation.
|
|
[app.navigationBars[@"Dual Flutter Views"].buttons[@"Flutter iOS Demos Home"] tap];
|
|
XCTAssertTrue([app.navigationBars[@"Flutter iOS Demos Home"] waitForExistenceWithTimeout:kStandardTimeOut]);
|
|
}
|
|
|
|
- (void)testResize {
|
|
XCUIApplication *app = self.app;
|
|
|
|
[self waitForAndTapElement:app.buttons[@"Dynamic Content Resizing"]];
|
|
XCUIElement *flutterView = app.otherElements[@"flutter_view"];
|
|
|
|
CGRect flutterViewFrame = flutterView.frame;
|
|
CGSize flutterViewSize = flutterViewFrame.size;
|
|
|
|
XCTAssertTrue(flutterViewSize.height == 100);
|
|
|
|
[self waitForAndTapElement: app.otherElements[@"flutter_view"]];
|
|
|
|
XCUIElement *flutterViewPostClick = app.otherElements[@"flutter_view"];
|
|
CGRect flutterViewFramePostClick = flutterViewPostClick.frame;
|
|
CGSize flutterViewSizePostClick = flutterViewFramePostClick.size;
|
|
|
|
XCTAssertTrue(flutterViewSizePostClick.height == 200);
|
|
|
|
// Back navigation.
|
|
[app.navigationBars[@"Dynamic Content Resizing"].buttons[@"Flutter iOS Demos Home"] tap];
|
|
XCTAssertTrue([app.navigationBars[@"Flutter iOS Demos Home"] waitForExistenceWithTimeout:kStandardTimeOut]);
|
|
}
|
|
|
|
- (void)waitForAndTapElement:(XCUIElement *)element {
|
|
NSPredicate *hittable = [NSPredicate predicateWithFormat:@"exists == YES AND hittable == YES"];
|
|
[self expectationForPredicate:hittable evaluatedWithObject:element handler:nil];
|
|
[self waitForExpectationsWithTimeout:30.0 handler:nil];
|
|
[element tap];
|
|
}
|
|
|
|
@end
|