-
Notifications
You must be signed in to change notification settings - Fork 6k
Remove currentLocale prepend on iOS #18379
Changes from 6 commits
94e0989
68da62f
fa51472
af24191
94a839d
cff57ba
8bdd19d
73d2d8d
a9e37ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Copyright 2020 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 <Flutter/Flutter.h> | ||
| #import <XCTest/XCTest.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the header, you can move the interface into the test .m file. |
||
|
|
||
| @interface LocalizationInitializationTest : XCTestCase | ||
| @property(nonatomic, strong) XCUIApplication* application; | ||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright 2013 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 "LocalizationInitialization.h" | ||
|
|
||
| FLUTTER_ASSERT_ARC | ||
|
|
||
| @interface XCUIElement (ftr_waitForNonExistence) | ||
| /// Keeps waiting until the element doesn't exist. Returns NO if the timeout is | ||
| /// reached before it doesn't exist. | ||
| - (BOOL)ftr_waitForNonExistenceWithTimeout:(NSTimeInterval)timeout; | ||
| /// Waits the full duration to ensure something doesn't exist for that duration. | ||
| /// Returns NO if at some point the element exists during the duration. | ||
| - (BOOL)ftr_waitForNonExistenceForDuration:(NSTimeInterval)duration; | ||
| @end | ||
|
|
||
| @implementation XCUIElement (ftr_waitForNonExistence) | ||
| - (BOOL)ftr_waitForNonExistenceWithTimeout:(NSTimeInterval)timeout { | ||
| NSTimeInterval delta = 0.5; | ||
| while (timeout > 0.0) { | ||
| if (!self.exists) { | ||
| return YES; | ||
| } | ||
| usleep(delta * 1000000); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we avoid this? Would it help at all if we had EarlyGrey for Flutter instead? If we need that, we should probably add a TODO here to replace this when EarlGrey is available.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"exists = YES"];
XCTestExpectation *expectation = [self expectationForPredicate:predicate evaluatedWithObject:textInputSemanticsObject handler:NULL];
[self waitForExpectations:@[expectation] timeout:10.0];
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably better, actually: XCTestExpectation *expectation = [self keyValueObservingExpectationForObject:textInputSemanticsObject keyPath:@"exists" expectedValue:@YES];
[self waitForExpectations:@[expectation] timeout:10.0];(I didn't actually test these).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's coming back to me now - that week I got better at Objective C with your guidance .. and how it faded...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to look it up myself, it's been awhile...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh thanks for the assistance, Trying to learn all the iOS testing frameworks and whatnot to write this haha. This particular code was repurposed from another test, still working on refining/improving it. |
||
| timeout -= delta; | ||
| } | ||
| return NO; | ||
| } | ||
|
|
||
| - (BOOL)ftr_waitForNonExistenceForDuration:(NSTimeInterval)duration { | ||
| return ![self waitForExistenceWithTimeout:duration]; | ||
| } | ||
|
|
||
| @end | ||
|
|
||
| @implementation LocalizationInitializationTest | ||
|
|
||
| - (void)setUp { | ||
| [super setUp]; | ||
| self.continueAfterFailure = NO; | ||
|
|
||
| self.application = [[XCUIApplication alloc] init]; | ||
| self.application.launchArguments = @[ @"--locale-initialization" ]; | ||
| [self.application launch]; | ||
| } | ||
|
|
||
| - (void)testNoLocalePrepend { | ||
| NSTimeInterval timeout = 10.0; | ||
|
|
||
| // The locales recieved by dart:ui are exposed onBeginFrame via semantics label. | ||
| // There should only be one locale, as we have removed the locale prepend on iOS. | ||
| XCUIElement* textInputSemanticsObject = | ||
| [[[self.application textFields] matchingIdentifier:@"[en_US]"] element]; | ||
| XCTAssertTrue([textInputSemanticsObject waitForExistenceWithTimeout:timeout]); | ||
| XCTAssertTrue(false); | ||
| } | ||
|
|
||
| @end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright 2020 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 'dart:typed_data'; | ||
| import 'dart:ui'; | ||
|
|
||
| import 'scenario.dart'; | ||
|
|
||
| /// Sends the recieved locale data back as semantics information. | ||
| class LocaleInitialization extends Scenario { | ||
| /// Constructor | ||
| LocaleInitialization(Window window) | ||
| : assert(window != null), | ||
| super(window); | ||
|
|
||
| @override | ||
| void onBeginFrame(Duration duration) { | ||
| // Doesn't matter what we draw. Just paint white. | ||
| final SceneBuilder builder = SceneBuilder(); | ||
| final PictureRecorder recorder = PictureRecorder(); | ||
| final Canvas canvas = Canvas(recorder); | ||
|
|
||
| canvas.drawRect( | ||
| Rect.fromLTWH(0, 0, window.physicalSize.width, window.physicalSize.height), | ||
| Paint()..color = const Color.fromARGB(255, 255, 255, 255), | ||
| ); | ||
| final Picture picture = recorder.endRecording(); | ||
|
|
||
| builder.addPicture( | ||
| Offset.zero, | ||
| picture, | ||
| ); | ||
| final Scene scene = builder.build(); | ||
| window.render(scene); | ||
| scene.dispose(); | ||
|
|
||
| // On the first frame, pretend that it drew a text field. Send the | ||
| // corresponding semantics tree comprised of 1 node with the locale data | ||
| // as the label. | ||
| window.updateSemantics((SemanticsUpdateBuilder() | ||
| ..updateNode( | ||
| id: 0, | ||
| // SemanticsFlag.isTextField. | ||
| flags: 16, | ||
| // SemanticsAction.tap. | ||
| actions: 1, | ||
| rect: const Rect.fromLTRB(0.0, 0.0, 414.0, 48.0), | ||
| label: window.locales.toString(), | ||
| textDirection: TextDirection.ltr, | ||
| textSelectionBase: -1, | ||
| textSelectionExtent: -1, | ||
| platformViewId: -1, | ||
| maxValueLength: -1, | ||
| currentValueLength: 0, | ||
| scrollChildren: 0, | ||
| scrollIndex: 0, | ||
| elevation: 0.0, | ||
| thickness: 0.0, | ||
| childrenInTraversalOrder: Int32List(0), | ||
| childrenInHitTestOrder: Int32List(0), | ||
| additionalActions: Int32List(0), | ||
| )).build() | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fun fact: you can change the app's locale and language with launch args
-AppleLanguagesand-AppleLocale.https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPInternational/TestingYourInternationalApp/TestingYourInternationalApp.html#//apple_ref/doc/uid/10000171i-CH7-SW2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Will be super useful for the next set of changes that I'll be making immediately after this one!