<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[185816] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/185816">185816</a></dd>
<dt>Author</dt> <dd>ap@apple.com</dd>
<dt>Date</dt> <dd>2015-06-21 21:25:18 -0700 (Sun, 21 Jun 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>REGRESSION (<a href="http://trac.webkit.org/projects/webkit/changeset/172975">r172975</a>): navigator.language unable to tell region for Traditional Chinese users
https://bugs.webkit.org/show_bug.cgi?id=146121
rdar://problem/21395180

Reviewed by Darin Adler.

Source/WebCore:

Revert to previous behavior, which is wrong in many ways, but not as wrong as the new one.

* platform/mac/Language.mm:
(WebCore::httpStyleLanguageCode):
(WebCore::platformUserPreferredLanguages):
* platform/spi/cf/CFBundleSPI.h:

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/NavigatorLanguage.mm: Added.
(-[NavigatorLanguageDelegate webView:didFinishLoadForFrame:]):
(TestWebKitAPI::overrideAppleLanguages):
(TestWebKitAPI::languageForSystemLanguage):
(TestWebKitAPI::TEST):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformmacLanguagemm">trunk/Source/WebCore/platform/mac/Language.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformspicfCFBundleSPIh">trunk/Source/WebCore/platform/spi/cf/CFBundleSPI.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsmacNavigatorLanguagemm">trunk/Tools/TestWebKitAPI/Tests/mac/NavigatorLanguage.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (185815 => 185816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-06-22 03:25:48 UTC (rev 185815)
+++ trunk/Source/WebCore/ChangeLog        2015-06-22 04:25:18 UTC (rev 185816)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2015-06-21  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        REGRESSION (r172975): navigator.language unable to tell region for Traditional Chinese users
+        https://bugs.webkit.org/show_bug.cgi?id=146121
+        rdar://problem/21395180
+
+        Reviewed by Darin Adler.
+
+        Revert to previous behavior, which is wrong in many ways, but not as wrong as the new one.
+
+        * platform/mac/Language.mm:
+        (WebCore::httpStyleLanguageCode):
+        (WebCore::platformUserPreferredLanguages):
+        * platform/spi/cf/CFBundleSPI.h:
+
</ins><span class="cx"> 2015-06-19  Andy Estes  &lt;aestes@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Give Node::didNotifySubtreeInsertions() a better name
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacLanguagemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/Language.mm (185815 => 185816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/Language.mm        2015-06-22 03:25:48 UTC (rev 185815)
+++ trunk/Source/WebCore/platform/mac/Language.mm        2015-06-22 04:25:18 UTC (rev 185816)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #import &quot;Language.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #import &quot;BlockExceptions.h&quot;
</span><ins>+#import &quot;CFBundleSPI.h&quot;
</ins><span class="cx"> #import &quot;WebCoreNSStringExtras.h&quot;
</span><span class="cx"> #import &lt;mutex&gt;
</span><span class="cx"> #import &lt;wtf/Assertions.h&gt;
</span><span class="lines">@@ -79,7 +80,31 @@
</span><span class="cx"> 
</span><span class="cx"> static String httpStyleLanguageCode(NSString *language)
</span><span class="cx"> {
</span><del>-    return [[NSLocale canonicalLanguageIdentifierFromString:canonicalLocaleName(language)] lowercaseString];
</del><ins>+    SInt32 languageCode;
+    SInt32 regionCode; 
+    SInt32 scriptCode; 
+    CFStringEncoding stringEncoding; 
+
+    // FIXME: This transformation is very wrong:
+    // 1. There is no reason why CFBundle localization names would be at all related to language names as used on the Web.
+    // 2. Script Manager codes cannot represent all languages that are now supported by the platform, so the conversion is lossy.
+    // 3. This should probably match what is sent by the network layer as Accept-Language, but currently, that's implemented separately.
+    CFBundleGetLocalizationInfoForLocalization((CFStringRef)language, &amp;languageCode, &amp;regionCode, &amp;scriptCode, &amp;stringEncoding);
+    RetainPtr&lt;CFStringRef&gt; preferredLanguageCode = adoptCF(CFBundleCopyLocalizationForLocalizationInfo(languageCode, regionCode, scriptCode, stringEncoding));
+    if (preferredLanguageCode)
+        language = (NSString *)preferredLanguageCode.get();
+
+    // Make the string lowercase.
+    NSString *lowercaseLanguageCode = [language lowercaseString];
+
+    // Turn a '_' into a '-' if it appears after a 2-letter language code.
+    if ([lowercaseLanguageCode length] &gt;= 3 &amp;&amp; [lowercaseLanguageCode characterAtIndex:2] == '_') {
+        RetainPtr&lt;NSMutableString&gt; mutableLanguageCode = adoptNS([lowercaseLanguageCode mutableCopy]);
+        [mutableLanguageCode.get() replaceCharactersInRange:NSMakeRange(2, 1) withString:@&quot;-&quot;];
+        return mutableLanguageCode.get();
+    }
+
+    return lowercaseLanguageCode;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Vector&lt;String&gt; platformUserPreferredLanguages()
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformspicfCFBundleSPIh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/spi/cf/CFBundleSPI.h (185815 => 185816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/spi/cf/CFBundleSPI.h        2015-06-22 03:25:48 UTC (rev 185815)
+++ trunk/Source/WebCore/platform/spi/cf/CFBundleSPI.h        2015-06-22 04:25:18 UTC (rev 185816)
</span><span class="lines">@@ -36,6 +36,9 @@
</span><span class="cx"> 
</span><span class="cx"> extern &quot;C&quot; {
</span><span class="cx"> void _CFBundleSetupXPCBootstrap(xpc_object_t bootstrap);
</span><ins>+
+Boolean CFBundleGetLocalizationInfoForLocalization(CFStringRef localizationName, SInt32 *languageCode, SInt32 *regionCode, SInt32 *scriptCode, CFStringEncoding *stringEncoding);
+CFStringRef CFBundleCopyLocalizationForLocalizationInfo(SInt32 languageCode, SInt32 regionCode, SInt32 scriptCode, CFStringEncoding stringEncoding);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (185815 => 185816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2015-06-22 03:25:48 UTC (rev 185815)
+++ trunk/Tools/ChangeLog        2015-06-22 04:25:18 UTC (rev 185816)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2015-06-21  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        REGRESSION (r172975): navigator.language unable to tell region for Traditional Chinese users
+        https://bugs.webkit.org/show_bug.cgi?id=146121
+        rdar://problem/21395180
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/mac/NavigatorLanguage.mm: Added.
+        (-[NavigatorLanguageDelegate webView:didFinishLoadForFrame:]):
+        (TestWebKitAPI::overrideAppleLanguages):
+        (TestWebKitAPI::languageForSystemLanguage):
+        (TestWebKitAPI::TEST):
+
</ins><span class="cx"> 2015-06-21  Michael Catanzaro  &lt;mcatanzaro@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [CMake] Ignore warnings from system headers when compiling Tools
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (185815 => 185816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2015-06-22 03:25:48 UTC (rev 185815)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2015-06-22 04:25:18 UTC (rev 185816)
</span><span class="lines">@@ -294,6 +294,7 @@
</span><span class="cx">                 CEA6CF2819CCF69D0064F5A7 /* open-and-close-window.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */; };
</span><span class="cx">                 E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */; };
</span><span class="cx">                 E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */; };
</span><ins>+                E19DB9791B32137C00DB38D4 /* NavigatorLanguage.mm in Sources */ = {isa = PBXBuildFile; fileRef = E19DB9781B32137C00DB38D4 /* NavigatorLanguage.mm */; };
</ins><span class="cx">                 E40019331ACE9B88001B0A2A /* BloomFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E40019301ACE9B5C001B0A2A /* BloomFilter.cpp */; };
</span><span class="cx">                 F660AA1115A5F631003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */; };
</span><span class="cx">                 F660AA1515A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA1415A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp */; };
</span><span class="lines">@@ -715,6 +716,7 @@
</span><span class="cx">                 E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = MemoryCacheDisableWithinResourceLoadDelegate.html; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 E194E1BA177E5145009C4D4E /* StopLoadingFromDidReceiveResponse.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StopLoadingFromDidReceiveResponse.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = StopLoadingFromDidReceiveResponse.html; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                E19DB9781B32137C00DB38D4 /* NavigatorLanguage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NavigatorLanguage.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 E40019301ACE9B5C001B0A2A /* BloomFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BloomFilter.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 E490296714E2E3A4002BEDD1 /* TypingStyleCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TypingStyleCrash.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 E4A757D3178AEA5B00B5D7A4 /* Deque.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Deque.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -1212,6 +1214,7 @@
</span><span class="cx">                                 E1220D9F155B25480013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.mm */,
</span><span class="cx">                                 517E7DFB15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm */,
</span><span class="cx">                                 7A99D9931AD4A29D00373141 /* MenuTypesForMouseEvents.mm */,
</span><ins>+                                E19DB9781B32137C00DB38D4 /* NavigatorLanguage.mm */,
</ins><span class="cx">                                 A57A34EF16AF677200C2501F /* PageVisibilityStateWithWindowChanges.mm */,
</span><span class="cx">                                 00BC16851680FE810065F1E5 /* PublicSuffix.mm */,
</span><span class="cx">                                 37C784DE197C8F2E0010A496 /* RenderedImageFromDOMNode.mm */,
</span><span class="lines">@@ -1618,6 +1621,7 @@
</span><span class="cx">                                 26F6E1F01ADC749B00DE696B /* DFAMinimizer.cpp in Sources */,
</span><span class="cx">                                 260BA5791B1D2E7B004FA07C /* DFACombiner.cpp in Sources */,
</span><span class="cx">                                 7A99D9941AD4A29D00373141 /* MenuTypesForMouseEvents.mm in Sources */,
</span><ins>+                                E19DB9791B32137C00DB38D4 /* NavigatorLanguage.mm in Sources */,
</ins><span class="cx">                         );
</span><span class="cx">                         runOnlyForDeploymentPostprocessing = 0;
</span><span class="cx">                 };
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsmacNavigatorLanguagemm"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/mac/NavigatorLanguage.mm (0 => 185816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/mac/NavigatorLanguage.mm                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/NavigatorLanguage.mm        2015-06-22 04:25:18 UTC (rev 185816)
</span><span class="lines">@@ -0,0 +1,135 @@
</span><ins>+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &quot;config.h&quot;
+#import &quot;PlatformUtilities.h&quot;
+#import &lt;WebKit/WebViewPrivate.h&gt;
+#import &lt;WebKit/DOM.h&gt;
+#import &lt;wtf/RetainPtr.h&gt;
+
+@interface NavigatorLanguageDelegate : NSObject &lt;WebFrameLoadDelegate&gt; {
+}
+@end
+
+static bool didFinishLoad;
+
+@implementation NavigatorLanguageDelegate
+
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+    didFinishLoad = true;
+}
+
+@end
+
+namespace TestWebKitAPI {
+
+void overrideAppleLanguages(NSString *primaryLanguage)
+{
+    RetainPtr&lt;NSMutableDictionary&gt; argumentDomain = adoptNS([[[NSUserDefaults standardUserDefaults] volatileDomainForName:NSArgumentDomain] mutableCopy]);
+    if (!argumentDomain)
+        argumentDomain = adoptNS([[NSMutableDictionary alloc] init]);
+    
+    [argumentDomain addEntriesFromDictionary:@{
+        @&quot;AppleLanguages&quot;: @[primaryLanguage]
+    }];
+    [[NSUserDefaults standardUserDefaults] setVolatileDomain:argumentDomain.get() forName:NSArgumentDomain];
+
+    [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@&quot;AppleLanguagePreferencesChangedNotification&quot; object:nil userInfo:nil options:NSNotificationDeliverImmediately];
+
+    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
+}
+
+static NSString *languageForSystemLanguage(WebView* webView, NSString *systemLanguage)
+{
+    overrideAppleLanguages(systemLanguage);
+    return [webView stringByEvaluatingJavaScriptFromString:@&quot;navigator.language&quot;];
+}
+
+// These tests document current behavior. Some of the current results may not be right.
+NSArray *tests = @[
+    @[@&quot;ru&quot;, @&quot;ru-ru&quot;], // This does not match other browsers or CFNetwork's Accept-Language, which all use &quot;ru&quot;.
+    @[@&quot;en&quot;, @&quot;en-us&quot;],
+    @[@&quot;en-GB&quot;, @&quot;en-gb&quot;],
+    @[@&quot;en-US&quot;, @&quot;en-us&quot;],
+    @[@&quot;ja&quot;, @&quot;ja-jp&quot;],
+    @[@&quot;hi&quot;, @&quot;hi-in&quot;],
+    @[@&quot;zh-TW&quot;, @&quot;zh-tw&quot;], // This should not map to the generic zh-hant, see rdar://problem/21395180.
+    @[@&quot;zh-HK&quot;, @&quot;zh-tw&quot;],
+    @[@&quot;es&quot;, @&quot;es-es&quot;],
+    @[@&quot;es-MX&quot;, @&quot;es-xl&quot;],
+    @[@&quot;es-ES&quot;, @&quot;es-es&quot;],
+    @[@&quot;es-419&quot;, @&quot;es-xl&quot;],
+    @[@&quot;zh-Hans&quot;, @&quot;zh-cn&quot;],
+    @[@&quot;zh-Hant&quot;, @&quot;zh-tw&quot;],
+    @[@&quot;pt-BR&quot;, @&quot;pt-br&quot;],
+    @[@&quot;pt-PT&quot;, @&quot;pt-pt&quot;],
+    @[@&quot;fr&quot;, @&quot;fr-fr&quot;],
+    @[@&quot;fr-CA&quot;, @&quot;fr-ca&quot;],
+];
+
+TEST(WebKit1, NavigatorLanguage)
+{
+    RetainPtr&lt;WebView&gt; webView = adoptNS([[WebView alloc] initWithFrame:NSZeroRect frameName:nil groupName:nil]);
+    RetainPtr&lt;NavigatorLanguageDelegate&gt; frameLoadDelegate = adoptNS([NavigatorLanguageDelegate new]);
+
+    webView.get().frameLoadDelegate = frameLoadDelegate.get();
+    [[webView.get() mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@&quot;about:blank&quot;]]];
+
+    Util::run(&amp;didFinishLoad);
+    for (NSArray *test in tests)
+        EXPECT_WK_STREQ([test objectAtIndex:1], languageForSystemLanguage(webView.get(), [test objectAtIndex:0]));
+}
+
+#if WK_API_ENABLED
+
+TEST(WKWebView, NavigatorLanguage)
+{
+    RetainPtr&lt;WKWebView&gt; webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@&quot;about:blank&quot;]];
+    [webView loadRequest:request];
+    __block bool isDone = false;
+
+    __block void (^runTest)(NSUInteger) = ^(NSUInteger index) {
+        NSArray *test = [tests objectAtIndex:index];
+        overrideAppleLanguages([test objectAtIndex:0]);
+        [webView evaluateJavaScript:@&quot;navigator.language&quot; completionHandler:^(id result, NSError *) {
+            EXPECT_WK_STREQ([test objectAtIndex:1], result);
+            if (index + 1 &lt; [tests count])
+                runTest(index + 1);
+            else
+                isDone = true;
+        }];
+    };
+
+    runTest(0);
+
+    TestWebKitAPI::Util::run(&amp;isDone);
+}
+
+#endif
+
+} // namespace TestWebKitAPI
</ins><span class="cx">Property changes on: trunk/Tools/TestWebKitAPI/Tests/mac/NavigatorLanguage.mm
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
</div>

</body>
</html>