From 7428ab66b4e79b695ffc03a6e15a2d18b019aa7f Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Fri, 14 Jan 2022 15:25:13 -0800 Subject: [PATCH] Add debug informations on ios_module_test (#96622) --- .../FlutterUITests/FlutterUITests.m | 12 ++++--- .../ios_host_app/Host/MainViewController.m | 33 ++++++++++++++++--- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/dev/integration_tests/ios_host_app/FlutterUITests/FlutterUITests.m b/dev/integration_tests/ios_host_app/FlutterUITests/FlutterUITests.m index ab7a6af990..ef27427a59 100644 --- a/dev/integration_tests/ios_host_app/FlutterUITests/FlutterUITests.m +++ b/dev/integration_tests/ios_host_app/FlutterUITests/FlutterUITests.m @@ -3,6 +3,7 @@ // found in the LICENSE file. @import XCTest; +@import os.log; static const CGFloat kStandardTimeOut = 60.0; @@ -61,10 +62,13 @@ static const CGFloat kStandardTimeOut = 60.0; [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]; + // 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); diff --git a/dev/integration_tests/ios_host_app/Host/MainViewController.m b/dev/integration_tests/ios_host_app/Host/MainViewController.m index 3f0a809dd1..f2c1c66096 100644 --- a/dev/integration_tests/ios_host_app/Host/MainViewController.m +++ b/dev/integration_tests/ios_host_app/Host/MainViewController.m @@ -12,6 +12,8 @@ @interface MainViewController () +@property (weak, nonatomic) UIButton* flutterViewWarmButton; + @end @@ -39,7 +41,7 @@ [self addButton:@"Native iOS View" action:@selector(showNative)]; [self addButton:@"Full Screen (Cold)" action:@selector(showFullScreenCold)]; [self addButton:@"Full Screen (Warm)" action:@selector(showFullScreenWarm)]; - [self addButton:@"Flutter View (Warm)" action:@selector(showFlutterViewWarm)]; + self.flutterViewWarmButton = [self addButton:@"Flutter View (Warm)" action:@selector(showFlutterViewWarm)]; [self addButton:@"Hybrid View (Warm)" action:@selector(showHybridView)]; [self addButton:@"Dual Flutter View (Cold)" action:@selector(showDualView)]; } @@ -99,26 +101,47 @@ } - (void)showFlutterViewWarm { - [[self engine].navigationChannel invokeMethod:@"setInitialRoute" + self.flutterViewWarmButton.backgroundColor = UIColor.redColor; + FlutterEngine *engine = [self engine]; + FlutterBasicMessageChannel* messageChannel = [self reloadMessageChannel]; + NSAssert(engine != nil, @"Engine is not nil."); + NSAssert(engine.navigationChannel != nil, @"Engine.navigationChannel is not nil."); + NSAssert(messageChannel != nil, @"messageChannel is not nil."); + + [engine.navigationChannel invokeMethod:@"setInitialRoute" arguments:@"/"]; - [[self reloadMessageChannel] sendMessage:@"/"]; + [messageChannel sendMessage:@"/"]; FlutterViewController *flutterViewController = [[FlutterViewController alloc] initWithEngine:[self engine] nibName:nil bundle:nil]; + flutterViewController.view.accessibilityLabel = @"flutter view"; + NSAssert(self.navigationController != nil, @"self.navigationController is not nil."); [self.navigationController pushViewController:flutterViewController - animated:YES]; + animated:NO]; + + if (self.navigationController.topViewController != flutterViewController) { + // For debugging: + // Some unknown issue happened caused `flutterViewController` not being pushed. + // We try to push an basic UIViewController to see if it would work. + UIViewController *viewController = [[UIViewController alloc] init]; + viewController.view.backgroundColor = UIColor.blueColor; + [self.navigationController pushViewController:viewController + animated:NO]; + NSAssert(self.navigationController.topViewController == viewController, @"self.navigationController.topViewController should be the basic view controller"); + } } -- (void)addButton:(NSString *)title action:(SEL)action { +- (UIButton *)addButton:(NSString *)title action:(SEL)action { UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; [button setTitle:title forState:UIControlStateNormal]; [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside]; [_stackView addArrangedSubview:button]; + return button; } @end