Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@GaryQian
Copy link
Contributor

@GaryQian GaryQian commented May 14, 2020

Partially reverts #6995

Since we handle null country codes now, this prepend should be safe to remove. [NSLocale currentLocale] is a pre-resolved locale, which can result in the first locale being one that is not preferred by the user. See flutter/flutter#49775

@GaryQian GaryQian added platform-ios Work in progress (WIP) Not ready (yet) for review! labels May 14, 2020
@auto-assign auto-assign bot requested a review from chinmaygarde May 14, 2020 10:40
@GaryQian GaryQian requested a review from cbracken May 14, 2020 10:52
@GaryQian GaryQian removed the Work in progress (WIP) Not ready (yet) for review! label May 14, 2020
Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test covering this?

@GaryQian
Copy link
Contributor Author

GaryQian commented May 15, 2020

Tests pending

@dnfield
Copy link
Contributor

dnfield commented May 15, 2020

There are a few places this should be testable, @gaaclarke and @xster have done some work recently to make it even easier from what I understand

@dnfield
Copy link
Contributor

dnfield commented May 15, 2020

If nothing else, soemthing in the scenarios app should cover this.

@xster
Copy link
Member

xster commented May 16, 2020

We also have FlutterEngine unit tests

if (!self.exists) {
return YES;
}
usleep(delta * 1000000);
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
/cc @jmagman who might know a good trick for this

Copy link
Member

Choose a reason for hiding this comment

The 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];

Copy link
Member

Choose a reason for hiding this comment

The 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).

Copy link
Contributor

Choose a reason for hiding this comment

The 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...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to look it up myself, it's been awhile...

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

#import <Flutter/Flutter.h>
#import <XCTest/XCTest.h>

NS_ASSUME_NONNULL_BEGIN
Copy link
Member

Choose a reason for hiding this comment

The 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.

// 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.
XCTAssertTrue([textInputSemanticsObject waitForExistenceWithTimeout:timeout]);
XCTAssertEqualObjects([textInputSemanticsObject valueForKey:@"hasKeyboardFocus"], @(NO));
Copy link
Member

@jmagman jmagman May 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing textInputSemanticsObject.hasKeyboardFocus isn't an exposed property?

The better typed way to do this when you really have to (ignoring StackOverflow) is to put a category at the top of your implementation file:

@interface XCUIElement (FlutterTests)
@property BOOL hasKeyboardFocus;
@end
...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then:

XCTAssertFalse(textInputSemanticsObject.hasKeyboardFocus);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will keep in mind. I will actually remove this here as it is exercised in other tests.

- (void)testNoLocalePrepend {
NSTimeInterval timeout = 10.0;

XCUIElement* textInputSemanticsObject =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the engine has variable usage of dot notation, but the "modern" syntax (like circa 2006 modern) of properties would be:

XCUIElement* textInputSemanticsObject = [self.application.textFields matchingIdentifier:@"[en]"].element;

@GaryQian GaryQian requested a review from jmagman May 19, 2020 22:36
Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Objective-C side LGTM

NSArray<NSString*>* preferredLocales = [NSLocale preferredLanguages];
NSMutableArray<NSString*>* data = [[NSMutableArray new] autorelease];

// Force prepend the [NSLocale currentLocale] to the front of the list
Copy link
Member

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 -AppleLanguages and -AppleLocale.
https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPInternational/TestingYourInternationalApp/TestingYourInternationalApp.html#//apple_ref/doc/uid/10000171i-CH7-SW2

Alternatively, add AppleLanguages and AppleLocale launch arguments using the scheme editor—for example, add -AppleLanguages "(de)" to specify the German language and -AppleLocale "fr_FR" to specify the France region.

Copy link
Contributor Author

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!

@GaryQian
Copy link
Contributor Author

Mac iOS Engine LUCI passes on rerun: https://ci.chromium.org/p/flutter/builders/try/Mac%20iOS%20Engine/2826

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks for taking the time to write a good test!

@GaryQian GaryQian merged commit 9d0ae1c into flutter:master May 20, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 21, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 21, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 22, 2020
wandyers pushed a commit to wandyers/engine that referenced this pull request May 23, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 23, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 26, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 26, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 26, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants