From a10154617906845604cc6b7d1543185591400283 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 5 Sep 2023 15:45:22 -0700 Subject: [PATCH] [iOS ] Fix errors in unittest and scenario tests running against iOS 17 simulators (details in the description) (flutter/engine#45391) 1. New Mac version seems to have updated the locale data, to match the mac change, we can dynamically read the data when testing instead of hard coding. 2. "we are sending a UIImage type as parameter to `XCTAttachment attachmentWithScreenshot:`, which takes a `XCUIScreenshot` as parameter, this is not supposed to pass in old iOS versions." In this PR we updated the parameter to use the `XCUIScreenshot` type. Fixes https://github.com/flutter/flutter/issues/133783 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../Scenarios/ScenariosUITests/GoldenTestManager.m | 2 +- .../LocalizationInitializationTest.m | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenTestManager.m b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenTestManager.m index 96f65fe760..76c95a0650 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenTestManager.m +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenTestManager.m @@ -76,7 +76,7 @@ NSDictionary* launchArgsMap; - (void)checkGoldenForTest:(XCTestCase*)test { XCUIScreenshot* screenshot = [[XCUIScreen mainScreen] screenshot]; if (!_goldenImage.image) { - XCTAttachment* attachment = [XCTAttachment attachmentWithScreenshot:screenshot.image]; + XCTAttachment* attachment = [XCTAttachment attachmentWithScreenshot:screenshot]; attachment.name = [_goldenImage.goldenName stringByAppendingString:@"_new.png"]; attachment.lifetime = XCTAttachmentLifetimeKeepAlways; [test addAttachment:attachment]; diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/LocalizationInitializationTest.m b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/LocalizationInitializationTest.m index 9b0f699eeb..a0196b9b3b 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/LocalizationInitializationTest.m +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/LocalizationInitializationTest.m @@ -26,10 +26,17 @@ FLUTTER_ASSERT_ARC NSTimeInterval timeout = 10.0; // The locales received by dart:ui are exposed onBeginFrame via semantics label. - // There should only be one locale, since the default iOS app only has en_US as - // the locale. The list should consist of just the en locale. + // There should only be one locale. The list should consist of the default + // locale provided by the iOS app. + NSArray* preferredLocales = [NSLocale preferredLanguages]; + XCTAssertEqual(preferredLocales.count, 1); + // Dart connects the locale parts with `_` while iOS connects them with `-`. + // Converts to dart format before comparing. + NSString* localeDart = [preferredLocales.firstObject stringByReplacingOccurrencesOfString:@"-" + withString:@"_"]; + NSString* expectedIdentifier = [NSString stringWithFormat:@"[%@]", localeDart]; XCUIElement* textInputSemanticsObject = - [self.application.textFields matchingIdentifier:@"[en]"].element; + [self.application.textFields matchingIdentifier:expectedIdentifier].element; XCTAssertTrue([textInputSemanticsObject waitForExistenceWithTimeout:timeout]); [textInputSemanticsObject tap];