OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/LayoutLocale.h" | 5 #include "platform/LayoutLocale.h" |
6 | 6 |
7 #include "platform/Logging.h" | 7 #include "platform/Logging.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 | 11 |
12 TEST(LayoutLocaleTest, Get) | 12 TEST(LayoutLocaleTest, Get) |
13 { | 13 { |
14 LayoutLocale::clearForTesting(); | 14 LayoutLocale::clearForTesting(); |
15 | 15 |
16 EXPECT_EQ(nullptr, LayoutLocale::get(nullAtom)); | 16 EXPECT_EQ(nullptr, LayoutLocale::get(nullAtom)); |
17 | 17 |
18 EXPECT_EQ(emptyAtom, LayoutLocale::get(emptyAtom)->localeString()); | 18 EXPECT_EQ(emptyAtom, LayoutLocale::get(emptyAtom)->localeString()); |
19 | 19 |
20 EXPECT_TRUE(equalIgnoringCase("en-us", LayoutLocale::get("en-us")->localeStr
ing())); | 20 EXPECT_STRCASEEQ("en-us", LayoutLocale::get("en-us")->localeString().ascii()
.data()); |
21 EXPECT_TRUE(equalIgnoringCase("ja-jp", LayoutLocale::get("ja-jp")->localeStr
ing())); | 21 EXPECT_STRCASEEQ("ja-jp", LayoutLocale::get("ja-jp")->localeString().ascii()
.data()); |
22 | 22 |
23 LayoutLocale::clearForTesting(); | 23 LayoutLocale::clearForTesting(); |
24 } | 24 } |
25 | 25 |
26 TEST(LayoutLocaleTest, GetCaseInsensitive) | 26 TEST(LayoutLocaleTest, GetCaseInsensitive) |
27 { | 27 { |
28 const LayoutLocale* enUS = LayoutLocale::get("en-us"); | 28 const LayoutLocale* enUS = LayoutLocale::get("en-us"); |
29 EXPECT_EQ(enUS, LayoutLocale::get("en-US")); | 29 EXPECT_EQ(enUS, LayoutLocale::get("en-US")); |
30 } | 30 } |
31 | 31 |
| 32 TEST(LayoutLocaleTest, ScriptTest) |
| 33 { |
| 34 // Test combinations of BCP 47 locales. |
| 35 // https://tools.ietf.org/html/bcp47 |
| 36 struct { |
| 37 const char* locale; |
| 38 UScriptCode script; |
| 39 bool hasScriptForHan; |
| 40 UScriptCode scriptForHan; |
| 41 } tests[] = { |
| 42 { "en-US", USCRIPT_LATIN }, |
| 43 |
| 44 // Common lang-region in East Asia. |
| 45 { "ja-JP", USCRIPT_KATAKANA_OR_HIRAGANA, true }, |
| 46 { "ko-KR", USCRIPT_HANGUL, true }, |
| 47 { "zh", USCRIPT_SIMPLIFIED_HAN, true }, |
| 48 { "zh-CN", USCRIPT_SIMPLIFIED_HAN, true }, |
| 49 { "zh-HK", USCRIPT_TRADITIONAL_HAN, true }, |
| 50 { "zh-MO", USCRIPT_TRADITIONAL_HAN, true }, |
| 51 { "zh-SG", USCRIPT_SIMPLIFIED_HAN, true }, |
| 52 { "zh-TW", USCRIPT_TRADITIONAL_HAN, true }, |
| 53 |
| 54 // Encompassed languages within the Chinese macrolanguage. |
| 55 // Both "lang" and "lang-extlang" should work. |
| 56 { "nan", USCRIPT_TRADITIONAL_HAN, true }, |
| 57 { "wuu", USCRIPT_SIMPLIFIED_HAN, true }, |
| 58 { "yue", USCRIPT_TRADITIONAL_HAN, true }, |
| 59 { "zh-nan", USCRIPT_TRADITIONAL_HAN, true }, |
| 60 { "zh-wuu", USCRIPT_SIMPLIFIED_HAN, true }, |
| 61 { "zh-yue", USCRIPT_TRADITIONAL_HAN, true }, |
| 62 |
| 63 // Script has priority over other subtags. |
| 64 { "zh-Hant", USCRIPT_TRADITIONAL_HAN, true }, |
| 65 { "en-Hans", USCRIPT_SIMPLIFIED_HAN, true }, |
| 66 { "en-Hant", USCRIPT_TRADITIONAL_HAN, true }, |
| 67 { "en-Hans-TW", USCRIPT_SIMPLIFIED_HAN, true }, |
| 68 { "en-Hant-CN", USCRIPT_TRADITIONAL_HAN, true }, |
| 69 { "wuu-Hant", USCRIPT_TRADITIONAL_HAN, true }, |
| 70 { "yue-Hans", USCRIPT_SIMPLIFIED_HAN, true }, |
| 71 { "zh-wuu-Hant", USCRIPT_TRADITIONAL_HAN, true }, |
| 72 { "zh-yue-Hans", USCRIPT_SIMPLIFIED_HAN, true }, |
| 73 |
| 74 // Lang has priority over region. |
| 75 // icu::Locale::getDefault() returns other combinations if, for instnace
, |
| 76 // English Windows with the display language set to Japanese. |
| 77 { "ja", USCRIPT_KATAKANA_OR_HIRAGANA, true }, |
| 78 { "ja-US", USCRIPT_KATAKANA_OR_HIRAGANA, true }, |
| 79 { "ko", USCRIPT_HANGUL, true }, |
| 80 { "ko-US", USCRIPT_HANGUL, true }, |
| 81 { "wuu-TW", USCRIPT_SIMPLIFIED_HAN, true }, |
| 82 { "yue-CN", USCRIPT_TRADITIONAL_HAN, true }, |
| 83 { "zh-wuu-TW", USCRIPT_SIMPLIFIED_HAN, true }, |
| 84 { "zh-yue-CN", USCRIPT_TRADITIONAL_HAN, true }, |
| 85 |
| 86 // Region should not affect script, but it can influence scriptForHan. |
| 87 { "en-CN", USCRIPT_LATIN, false }, |
| 88 { "en-HK", USCRIPT_LATIN, true, USCRIPT_TRADITIONAL_HAN }, |
| 89 { "en-MO", USCRIPT_LATIN, true, USCRIPT_TRADITIONAL_HAN }, |
| 90 { "en-SG", USCRIPT_LATIN, false }, |
| 91 { "en-TW", USCRIPT_LATIN, true, USCRIPT_TRADITIONAL_HAN }, |
| 92 { "en-JP", USCRIPT_LATIN, true, USCRIPT_KATAKANA_OR_HIRAGANA }, |
| 93 { "en-KR", USCRIPT_LATIN, true, USCRIPT_HANGUL }, |
| 94 |
| 95 // Multiple regions are invalid, but it can still give hints for the fon
t selection. |
| 96 { "en-US-JP", USCRIPT_LATIN, true, USCRIPT_KATAKANA_OR_HIRAGANA }, |
| 97 }; |
| 98 |
| 99 for (const auto& test : tests) { |
| 100 RefPtr<LayoutLocale> locale = LayoutLocale::createForTesting(test.locale
); |
| 101 EXPECT_EQ(test.script, locale->script()) << test.locale; |
| 102 EXPECT_EQ(test.hasScriptForHan, locale->hasScriptForHan()) << test.local
e; |
| 103 if (!test.hasScriptForHan) |
| 104 EXPECT_EQ(USCRIPT_SIMPLIFIED_HAN, locale->scriptForHan()) << test.lo
cale; |
| 105 else if (test.scriptForHan) |
| 106 EXPECT_EQ(test.scriptForHan, locale->scriptForHan()) << test.locale; |
| 107 else |
| 108 EXPECT_EQ(test.script, locale->scriptForHan()) << test.locale; |
| 109 } |
| 110 } |
| 111 |
32 } // namespace blink | 112 } // namespace blink |
OLD | NEW |