From 2a6f1b734246a9734aa11fa61818712d7c683a50 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 14 Aug 2019 23:01:17 -0700 Subject: [PATCH] Fix up iOS Add to App tests (#38603) --- .cirrus.yml | 2 + .../ios_add2app/build_and_test.sh | 13 +++++- .../ios_add2app.xcodeproj/project.pbxproj | 16 ++++++- .../ios_add2app/ios_add2app/AppDelegate.h | 1 - .../ios_add2app/ios_add2app/AppDelegate.m | 2 +- .../ios_add2app/HybridViewController.m | 2 +- .../FlutterViewControllerTests.m | 2 +- .../ios_add2appTests/IntegrationTests.m | 44 +++++-------------- 8 files changed, 42 insertions(+), 40 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index d19c275dd4..958113b357 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -534,6 +534,8 @@ task: - name: add2app-macos env: SHARD: add2app_test + setup_xcpretty_script: + - sudo gem install xcpretty test_all_script: - ulimit -S -n 2048 # https://github.com/flutter/flutter/issues/2976 - dart --enable-asserts dev/bots/test.dart diff --git a/dev/integration_tests/ios_add2app/build_and_test.sh b/dev/integration_tests/ios_add2app/build_and_test.sh index 4c08afdbe7..1681699de2 100755 --- a/dev/integration_tests/ios_add2app/build_and_test.sh +++ b/dev/integration_tests/ios_add2app/build_and_test.sh @@ -10,4 +10,15 @@ popd pod install os_version=$(xcrun --show-sdk-version --sdk iphonesimulator) -xcodebuild -workspace ios_add2app.xcworkspace -scheme ios_add2appTests -sdk "iphonesimulator$os_version" -destination "OS=$os_version,name=iPhone X" test \ No newline at end of file + +PRETTY="cat" +if which xcpretty; then + PRETTY="xcpretty" +fi + +set -o pipefail && xcodebuild \ + -workspace ios_add2app.xcworkspace \ + -scheme ios_add2appTests \ + -sdk "iphonesimulator$os_version" \ + -destination "OS=$os_version,name=iPhone X" test | $PRETTY + diff --git a/dev/integration_tests/ios_add2app/ios_add2app.xcodeproj/project.pbxproj b/dev/integration_tests/ios_add2app/ios_add2app.xcodeproj/project.pbxproj index 40bddef14b..2b1925d70c 100644 --- a/dev/integration_tests/ios_add2app/ios_add2app.xcodeproj/project.pbxproj +++ b/dev/integration_tests/ios_add2app/ios_add2app.xcodeproj/project.pbxproj @@ -338,7 +338,7 @@ name = "[CP-User] Run Flutter Build Script"; runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "set -e\nset -u\nsource \"${SRCROOT}/flutterapp/.ios/Flutter/flutter_export_environment.sh\"\n\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/xcode_backend.sh build\n"; + shellScript = "set -e\nset -u\nsource \"${SRCROOT}/flutterapp/.ios/Flutter/flutter_export_environment.sh\"\n\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/xcode_backend.sh build"; }; DE5CDCD8B3565EAB9F38F455 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; @@ -502,8 +502,10 @@ "DEBUG=1", "$(inherited)", ); + GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_PEDANTIC = YES; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; @@ -513,6 +515,11 @@ MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; + WARNING_CFLAGS = "-Wno-gnu"; + WARNING_LDFLAGS = ( + "-Wall", + "-Werror", + ); }; name = Debug; }; @@ -556,8 +563,10 @@ ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_PEDANTIC = YES; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; @@ -567,6 +576,11 @@ MTL_FAST_MATH = YES; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; + WARNING_CFLAGS = "-Wno-gnu"; + WARNING_LDFLAGS = ( + "-Wall", + "-Werror", + ); }; name = Release; }; diff --git a/dev/integration_tests/ios_add2app/ios_add2app/AppDelegate.h b/dev/integration_tests/ios_add2app/ios_add2app/AppDelegate.h index 816e424a55..43a7e63129 100644 --- a/dev/integration_tests/ios_add2app/ios_add2app/AppDelegate.h +++ b/dev/integration_tests/ios_add2app/ios_add2app/AppDelegate.h @@ -8,7 +8,6 @@ @interface AppDelegate : FlutterAppDelegate @property(nonatomic, strong) FlutterEngine* engine; -@property(nonatomic, strong) UIWindow* window; @property(nonatomic, strong) FlutterBasicMessageChannel* reloadMessageChannel; @end diff --git a/dev/integration_tests/ios_add2app/ios_add2app/AppDelegate.m b/dev/integration_tests/ios_add2app/ios_add2app/AppDelegate.m index b69c346846..6d5a00f15f 100644 --- a/dev/integration_tests/ios_add2app/ios_add2app/AppDelegate.m +++ b/dev/integration_tests/ios_add2app/ios_add2app/AppDelegate.m @@ -41,7 +41,7 @@ static NSString *_kReloadChannelName = @"reload"; _reloadMessageChannel = [[FlutterBasicMessageChannel alloc] initWithName:_kReloadChannelName - binaryMessenger:_engine + binaryMessenger:_engine.binaryMessenger codec:[FlutterStringCodec sharedInstance]]; self.window.rootViewController = _navigationController; diff --git a/dev/integration_tests/ios_add2app/ios_add2app/HybridViewController.m b/dev/integration_tests/ios_add2app/ios_add2app/HybridViewController.m index af584139ea..df6b254b45 100644 --- a/dev/integration_tests/ios_add2app/ios_add2app/HybridViewController.m +++ b/dev/integration_tests/ios_add2app/ios_add2app/HybridViewController.m @@ -56,7 +56,7 @@ static NSString *_kPing = @"ping"; _messageChannel = [[FlutterBasicMessageChannel alloc] initWithName:_kChannel - binaryMessenger:_flutterViewController + binaryMessenger:_flutterViewController.binaryMessenger codec:[FlutterStringCodec sharedInstance]]; [self addChildViewController:_flutterViewController]; [stackView addArrangedSubview:_flutterViewController.view]; diff --git a/dev/integration_tests/ios_add2app/ios_add2appTests/FlutterViewControllerTests.m b/dev/integration_tests/ios_add2app/ios_add2appTests/FlutterViewControllerTests.m index 6aee224d0f..46cf50e48c 100644 --- a/dev/integration_tests/ios_add2app/ios_add2appTests/FlutterViewControllerTests.m +++ b/dev/integration_tests/ios_add2app/ios_add2appTests/FlutterViewControllerTests.m @@ -21,7 +21,7 @@ [viewController viewWillAppear:NO]; [viewController viewDidDisappear:NO]; } - XCTAssertNil(weakEngine); + XCTAssertNil(weakEngine, @"Engine failed to release."); } @end diff --git a/dev/integration_tests/ios_add2app/ios_add2appTests/IntegrationTests.m b/dev/integration_tests/ios_add2app/ios_add2appTests/IntegrationTests.m index 6c6b36ec5e..c92e1b10bd 100644 --- a/dev/integration_tests/ios_add2app/ios_add2appTests/IntegrationTests.m +++ b/dev/integration_tests/ios_add2app/ios_add2appTests/IntegrationTests.m @@ -11,36 +11,6 @@ #import "../ios_add2app/MainViewController.h" #import "../ios_add2app/HybridViewController.h" -static void waitForFlutterSemanticsTree(FlutterViewController *viewController) { - int tries = 10; - double delay = 1.0; - - // ensureSemanticsEnabled is a synchronous call, but only ensures that the - // semantics tree will be built on a subsequent frame (as opposed to being - // available at time it returns). - // To actually get the tree, we have to wait for the FlutterSemanticsUpdate - // notification, which lets us know that a semantics tree has been built; - // but we cannot block the main thread while waiting (so we use - // CFRunLoopRunInMode). - - __block BOOL semanticsAvailable = NO; - __block id observer = [[NSNotificationCenter defaultCenter] - addObserverForName:@"FlutterSemanticsUpdate" - object:viewController - queue:nil - usingBlock:^(NSNotification *notification) { - semanticsAvailable = YES; - [[NSNotificationCenter defaultCenter] removeObserver:observer]; - }]; - [viewController.engine ensureSemanticsEnabled]; - while (semanticsAvailable == NO && tries != 0) { - CFRunLoopRunInMode(kCFRunLoopDefaultMode, delay, false); - tries--; - [viewController.engine ensureSemanticsEnabled]; - } - GREYAssertTrue(semanticsAvailable, @"Semantics Tree did not build!"); -} - @interface FlutterTests : XCTestCase @end @@ -58,6 +28,12 @@ static void waitForFlutterSemanticsTree(FlutterViewController *viewController) { return self; } +- (void)expectSemanticsNotification:(FlutterViewController*)viewController { + [self expectationForNotification:FlutterSemanticsUpdateNotification object:viewController handler:nil]; + [viewController.engine ensureSemanticsEnabled]; + [self waitForExpectationsWithTimeout:30.0 handler:nil]; +} + - (void)testFullScreenCanPop { [[EarlGrey selectElementWithMatcher:grey_keyWindow()] assertWithMatcher:grey_sufficientlyVisible()]; @@ -74,7 +50,7 @@ static void waitForFlutterSemanticsTree(FlutterViewController *viewController) { .window.rootViewController; weakViewController = (FullScreenViewController *)navController.visibleViewController; - waitForFlutterSemanticsTree(weakViewController); + [self expectSemanticsNotification:weakViewController]; GREYAssertNotNil(weakViewController, @"Expected non-nil FullScreenViewController."); } @@ -112,8 +88,8 @@ static void waitForFlutterSemanticsTree(FlutterViewController *viewController) { (DualFlutterViewController *)navController.visibleViewController; GREYAssertNotNil(viewController, @"Expected non-nil DualFlutterViewController."); - waitForFlutterSemanticsTree(viewController.topFlutterViewController); - waitForFlutterSemanticsTree(viewController.bottomFlutterViewController); + [self expectSemanticsNotification:viewController.topFlutterViewController]; + [self expectSemanticsNotification:viewController.bottomFlutterViewController]; } // Verify that there are two Flutter views with the expected marquee text. @@ -148,7 +124,7 @@ static void waitForFlutterSemanticsTree(FlutterViewController *viewController) { (HybridViewController *)navController.visibleViewController; GREYAssertNotNil(viewController.flutterViewController, @"Expected non-nil FlutterViewController."); - waitForFlutterSemanticsTree(viewController.flutterViewController); + [self expectSemanticsNotification:viewController.flutterViewController]; } [self validateCountsFlutter:@"Platform" count:0];