OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "platform/fonts/SymbolsIterator.h" |
| 6 |
| 7 #include "platform/Logging.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include <string> |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 struct TestRun { |
| 14 std::string text; |
| 15 FontFallbackPriority fontFallbackPriority; |
| 16 }; |
| 17 |
| 18 struct ExpectedRun { |
| 19 unsigned limit; |
| 20 FontFallbackPriority fontFallbackPriority; |
| 21 |
| 22 ExpectedRun(unsigned theLimit, FontFallbackPriority theFontFallbackPriority) |
| 23 : limit(theLimit) |
| 24 , fontFallbackPriority(theFontFallbackPriority) |
| 25 { |
| 26 } |
| 27 }; |
| 28 |
| 29 class SymbolsIteratorTest : public testing::Test { |
| 30 protected: |
| 31 #if !LOG_DISABLED |
| 32 static void SetUpTestCase() |
| 33 { |
| 34 LogFonts = { WTFLogChannelOn }; |
| 35 } |
| 36 #endif |
| 37 |
| 38 void CheckRuns(const Vector<TestRun>& runs) |
| 39 { |
| 40 String text(String::make16BitFrom8BitSource(0, 0)); |
| 41 Vector<ExpectedRun> expect; |
| 42 for (auto& run : runs) { |
| 43 text.append(String::fromUTF8(run.text.c_str())); |
| 44 expect.append(ExpectedRun(text.length(), run.fontFallbackPriority)); |
| 45 } |
| 46 SymbolsIterator symbolsIterator(text.characters16(), text.length()); |
| 47 VerifyRuns(&symbolsIterator, expect); |
| 48 } |
| 49 |
| 50 void VerifyRuns(SymbolsIterator* symbolsIterator, |
| 51 const Vector<ExpectedRun>& expect) |
| 52 { |
| 53 unsigned limit; |
| 54 FontFallbackPriority fontFallbackPriority; |
| 55 unsigned long runCount = 0; |
| 56 while (symbolsIterator->consume(&limit, &fontFallbackPriority)) { |
| 57 ASSERT_LT(runCount, expect.size()); |
| 58 ASSERT_EQ(expect[runCount].limit, limit); |
| 59 ASSERT_EQ(expect[runCount].fontFallbackPriority, fontFallbackPriorit
y); |
| 60 ++runCount; |
| 61 } |
| 62 WTF_LOG(Fonts, "Expected %zu runs, got %lu ", expect.size(), runCount); |
| 63 ASSERT_EQ(expect.size(), runCount); |
| 64 } |
| 65 }; |
| 66 |
| 67 // Some of our compilers cannot initialize a vector from an array yet. |
| 68 #define DECLARE_RUNSVECTOR(...) \ |
| 69 static const TestRun runsArray[] = __VA_ARGS__; \ |
| 70 Vector<TestRun> runs; \ |
| 71 runs.append(runsArray, sizeof(runsArray) / sizeof(*runsArray)); |
| 72 |
| 73 #define CHECK_RUNS(...) \ |
| 74 DECLARE_RUNSVECTOR(__VA_ARGS__); \ |
| 75 CheckRuns(runs); |
| 76 |
| 77 |
| 78 TEST_F(SymbolsIteratorTest, Empty) |
| 79 { |
| 80 String empty(String::make16BitFrom8BitSource(0, 0)); |
| 81 SymbolsIterator symbolsIterator(empty.characters16(), empty.length()); |
| 82 unsigned limit = 0; |
| 83 FontFallbackPriority symbolsFont = FontFallbackPriority::Invalid; |
| 84 ASSERT(!symbolsIterator.consume(&limit, &symbolsFont)); |
| 85 ASSERT_EQ(limit, 0u); |
| 86 ASSERT_EQ(symbolsFont, FontFallbackPriority::Invalid); |
| 87 } |
| 88 |
| 89 TEST_F(SymbolsIteratorTest, Space) |
| 90 { |
| 91 CHECK_RUNS({ { " ", FontFallbackPriority::Text } }); |
| 92 } |
| 93 |
| 94 TEST_F(SymbolsIteratorTest, Latin) |
| 95 { |
| 96 CHECK_RUNS({ { "Aa", FontFallbackPriority::Text } }); |
| 97 } |
| 98 |
| 99 TEST_F(SymbolsIteratorTest, LatinColorEmojiTextEmoji) |
| 100 { |
| 101 CHECK_RUNS({ { "a", FontFallbackPriority::Text }, |
| 102 { "⌚", FontFallbackPriority::EmojiEmoji }, |
| 103 { "☎", FontFallbackPriority::EmojiText } }); |
| 104 } |
| 105 |
| 106 TEST_F(SymbolsIteratorTest, IgnoreVSInMath) |
| 107 { |
| 108 CHECK_RUNS({ { "⊆⊇⊈\xEF\xB8\x8E⊙⊚⊚", FontFallbackPriority::Math } }); |
| 109 } |
| 110 |
| 111 TEST_F(SymbolsIteratorTest, IgnoreVS15InText) |
| 112 { |
| 113 CHECK_RUNS({ { "abcdef\xEF\xB8\x8Eghji", FontFallbackPriority::Text } }); |
| 114 } |
| 115 |
| 116 TEST_F(SymbolsIteratorTest, IgnoreVS16InText) |
| 117 { |
| 118 CHECK_RUNS({ { "abcdef\xEF\xB8\x8Fghji", FontFallbackPriority::Text } }); |
| 119 } |
| 120 |
| 121 TEST_F(SymbolsIteratorTest, NumbersAndHashNormalAndEmoji) |
| 122 { |
| 123 CHECK_RUNS({ { "0123456789#", FontFallbackPriority::Text }, |
| 124 { "0⃣1⃣2⃣3⃣4⃣5⃣6⃣7⃣8⃣9⃣#⃣", FontFallbackPriority::EmojiEmoji }, |
| 125 { "0123456789#", FontFallbackPriority::Text } }); |
| 126 } |
| 127 |
| 128 |
| 129 TEST_F(SymbolsIteratorTest, SingleFlag) |
| 130 { |
| 131 CHECK_RUNS({ { "🇺", FontFallbackPriority::Text } }); |
| 132 } |
| 133 |
| 134 // TODO: Perhaps check for invalid country indicator combinations? |
| 135 |
| 136 TEST_F(SymbolsIteratorTest, FlagsVsNonFlags) |
| 137 { |
| 138 CHECK_RUNS({ { "🇺🇸🇸", FontFallbackPriority::EmojiEmoji }, // "US" |
| 139 { "abc", FontFallbackPriority::Text }, |
| 140 { "🇺🇸", FontFallbackPriority::EmojiEmoji }, |
| 141 { "a🇿", FontFallbackPriority::Text } }); |
| 142 } |
| 143 |
| 144 |
| 145 TEST_F(SymbolsIteratorTest, EmojiVS15) |
| 146 { |
| 147 // A VS15 after the anchor must trigger text display. |
| 148 CHECK_RUNS({ { "⚓\xEF\xB8\x8E", FontFallbackPriority::EmojiText }, |
| 149 { "⛵", FontFallbackPriority::EmojiEmoji } }); |
| 150 } |
| 151 |
| 152 TEST_F(SymbolsIteratorTest, EmojiZWSSequences) |
| 153 { |
| 154 CHECK_RUNS({ { "👩👩👧👦👩❤️💋👨", FontFallbackPriority::EmojiEmoji }, |
| 155 { "abcd", FontFallbackPriority::Text }, |
| 156 { "👩👩", FontFallbackPriority::EmojiEmoji }, |
| 157 { "efgh", FontFallbackPriority::Text } }); |
| 158 } |
| 159 |
| 160 TEST_F(SymbolsIteratorTest, AllEmojiZWSSequences) |
| 161 { |
| 162 CHECK_RUNS({ { "💏👩❤️💋👨👨❤️💋👨👩❤️💋👩💑👩❤️👨👨❤️👨👩❤️" |
| 163 "👩👪👨👩👦👨👩👧👨👩👧👦👨👩👦👦👨👩👧👧👨👨👦👨👨👧👨👨👧👦👨👨👦👦👨👨👧👧" |
| 164 "👩👩👦👩👩👧👩👩👧👦👩👩👦👦👩👩👧👧👁🗨", |
| 165 FontFallbackPriority::EmojiEmoji } }); |
| 166 } |
| 167 |
| 168 TEST_F(SymbolsIteratorTest, EyeSpeechBubble) |
| 169 { |
| 170 CHECK_RUNS({ { "👁🗨", FontFallbackPriority::EmojiEmoji } }); |
| 171 } |
| 172 |
| 173 TEST_F(SymbolsIteratorTest, Modifier) |
| 174 { |
| 175 CHECK_RUNS({ { "👶🏿", FontFallbackPriority::EmojiEmoji } }); |
| 176 } |
| 177 |
| 178 TEST_F(SymbolsIteratorTest, ExtraZWJPrefix) |
| 179 { |
| 180 CHECK_RUNS({ { "\xE2\x80\x8D", FontFallbackPriority::Text }, |
| 181 { "\xF0\x9F\x91\xA9\xE2\x80\x8D\xE2" |
| 182 "\x9D\xA4\xEF\xB8\x8F\xE2\x80\x8D" |
| 183 "\xF0\x9F\x92\x8B\xE2\x80\x8D\xF0\x9F\x91\xA8", |
| 184 FontFallbackPriority::EmojiEmoji } }); |
| 185 } |
| 186 |
| 187 TEST_F(SymbolsIteratorTest, Arrows) |
| 188 { |
| 189 CHECK_RUNS({ { "x", FontFallbackPriority::Text }, |
| 190 { "→←", FontFallbackPriority::Math }, |
| 191 { "x", FontFallbackPriority::Text }, |
| 192 { "←↑↓→", FontFallbackPriority::Math } }); |
| 193 } |
| 194 |
| 195 } // namespace blink |
OLD | NEW |