Please sign in to comment.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…language-fr.html is a flaky failure https://bugs.webkit.org/show_bug.cgi?id=240104 <rdar://problem/92765233> Reviewed by Per Arne Vollan and Myles Maxfield. The test was flaky and navigator.language would sometimes return "fr" and sometimes "fr-FR". The reason for this is that Cocoa ports used 2 separate mechanisms to override the system language: 1. The override languages were used to set the AppleLanguages NSUserDefaults, causing APIs such as CFLocaleCopyPreferredLanguages() to return the overriden languages. 2. During process initialization we would also call WTF::overrideUserPreferredLanguages() which would add the override languages to an override Vector in WTF. The test was setting the override language to "fr". When method 2 would succeed, navigator.language would return "fr", from preferredLanguagesOverride(). However, Internals::resetToConsistentState() would reset WTF::preferredLanguagesOverride() shortly after the test starts running. As a result, the override Vector in WTF would often end up being empty and we would end up calling CFLocaleCopyPreferredLanguages(). However, CFLocaleCopyPreferredLanguages() return "fr-FR", which is equivalent but not exactly the same. To address the issue, I made the following changes: a. Use a single method for overriding languages for Cocoa ports. We are now using the AppleLanguages user default exclusively and not the WTF::preferredLanguagesOverride() Vector. b. We now call Internals::resetToConsistentState() only after running the test in WebKitTestRunner, not at the beginning of the test. This is consistent to what we were already doing in DumpRenderTree. Because Internals::resetToConsistentState() resets the languages, we don't want it to run at the beginning of the test. This is because some tests specify their languages in their header and WKTR ends up setting those languages via TestOptions, before actually running the test. We don't want those to get cleared. * Tools/WebKitTestRunner/TestController.cpp: (WTR::TestController::resetStateToConsistentValues): Only ask the injected bundle to reset after running the test and not before. This is consistent with what DumpRenderTree was already doing. The injected bundle would call Internals::resetToConsistentState() when receiving this reset message. * Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm: (WebKit::setAppleLanguagesPreference): Move the logic to set the AppleLanguages user default from the WebKit2 layer to WTF, inside LanguageCocoa.mm and use it inside WTF::overrideUserPreferredLanguages(). * Source/WTF/wtf/Language.cpp: (WTF::overrideUserPreferredLanguages): * Source/WTF/wtf/cocoa/LanguageCocoa.mm: (WTF::overrideUserPreferredLanguages): Stop using the WTF::preferredLanguagesOverride() Vector on Cocoa and set the AppleLanguages user default instead. WebKit2 was using both AppleLanguages and this Vector, which would give inconsistent results, especially when resetting the Vector but not the user default. Using the user default is also more realistic then the fake override Vector as we end up calling into the usual CF APIs to retrieve the languages. * Source/WebCore/platform/graphics/FontDescription.cpp: (WebCore::computeSpecializedChineseLocale): * Source/WebCore/platform/graphics/FontGenericFamilies.cpp: (WebCore::computeUserPrefersSimplified): Add some FIXME comments. These functions do locale matching but use minimized locales which may cause the matching to fail. This is causing fast/text/international/generic-font-family-language-traditional.html to fail. We didn't notice before because our test infrastructure storing language overrides in a vector in WTF, which doesn't get minimized, unlike locales we get from the system. * Source/WebCore/testing/Internals.cpp: (WebCore::Internals::userPreferredLanguages const): Stop minimizing the locales returned by internals.userPreferredLanguages(). It used to not matter because locales set by the test would be set in the WTF::overrideUserPreferredLanguages() Vector and locales from that vector would get returned un-minimized, even when requesting minimized locales. However, now that we are no longer using this vector and using the regular code path instead, locales would get minimized and this would cause a test to fail. The test was checking that the values returned by internals.userPreferredLanguages() are exactly the same as the ones set via internals.setUserPreferredLanguages(). * LayoutTests/fast/harness/user-preferred-language.html: Tweak test to use call internals.setUserPreferredLanguages() with proper locales instead of using non-locales. This used to not matter because we were storing them in the WTF::overrideUserPreferredLanguages() Vector and internals.userPreferredLanguages() would return then as-is from the vector. However, now that we actually set the AppleLanguages user default and actually call the CF APIs to retrieve the locales, having properly formatted locales is required. * LayoutTests/platform/gtk/fast/text/international/system-language/navigator-language/navigator-language-en-expected.txt: Added. We used to clear the language override shortly after starting the test so the test was actually getting the system language instead of "en" which is the override that the test sets. * LayoutTests/platform/ios/TestExpectations: * LayoutTests/platform/mac/TestExpectations: Mark fast/text/international/generic-font-family-language-traditional.html as failing since language minimization is causing it to fail. This is not a regression from this patch. This is an issue in shipping code that is now exposed because our test infrastructure for locale overriding is now closer to real life. Canonical link: https://commits.webkit.org/250473@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing with 53 additions and 35 deletions.
- +4 −7 JSTests/stress/intl-default-locale.js
- +2 −2 LayoutTests/fast/harness/user-preferred-language.html
- +6 −0 ...gtk/fast/text/international/system-language/navigator-language/navigator-language-en-expected.txt
- +2 −2 LayoutTests/platform/ios/TestExpectations
- +2 −0 LayoutTests/platform/mac/TestExpectations
- +10 −10 Source/WTF/wtf/Language.cpp
- +11 −0 Source/WTF/wtf/cocoa/LanguageCocoa.mm
- +2 −0 Source/WebCore/platform/graphics/FontDescription.cpp
- +3 −2 Source/WebCore/platform/graphics/FontGenericFamilies.cpp
- +1 −1 Source/WebCore/testing/Internals.cpp
- +8 −10 Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm
- +2 −1 Tools/WebKitTestRunner/TestController.cpp