| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/css/CSSFontFaceSource.h" |
| 6 |
| 7 #include "platform/fonts/FontCacheKey.h" |
| 8 #include "platform/fonts/FontDescription.h" |
| 9 #include "platform/fonts/FontPlatformData.h" |
| 10 #include "platform/fonts/SimpleFontData.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 class DummyFontFaceSource : public CSSFontFaceSource { |
| 16 public: |
| 17 PassRefPtr<SimpleFontData> createFontData(const FontDescription&) override |
| 18 { |
| 19 return SimpleFontData::create(FontPlatformData(adoptRef(SkTypeface::RefD
efault()), "", 0, false, false)); |
| 20 } |
| 21 |
| 22 DummyFontFaceSource() { } |
| 23 |
| 24 PassRefPtr<SimpleFontData> getFontDataForSize(float size) |
| 25 { |
| 26 FontDescription fontDescription; |
| 27 fontDescription.setSizeAdjust(size); |
| 28 fontDescription.setAdjustedSize(size); |
| 29 return getFontData(fontDescription); |
| 30 } |
| 31 }; |
| 32 |
| 33 namespace { |
| 34 |
| 35 unsigned simulateHashCalculation(float size) |
| 36 { |
| 37 FontDescription fontDescription; |
| 38 fontDescription.setSizeAdjust(size); |
| 39 fontDescription.setAdjustedSize(size); |
| 40 return fontDescription.cacheKey(FontFaceCreationParams()).hash(); |
| 41 } |
| 42 |
| 43 } |
| 44 |
| 45 TEST(CSSFontFaceSourceTest, HashCollision) |
| 46 { |
| 47 DummyFontFaceSource fontFaceSource; |
| 48 // Even if the hash value collide, fontface cache should return different va
lue for different fonts. |
| 49 EXPECT_EQ(simulateHashCalculation(2821), simulateHashCalculation(3346)); |
| 50 EXPECT_NE(fontFaceSource.getFontDataForSize(2821), fontFaceSource.getFontDat
aForSize(3346)); |
| 51 } |
| 52 |
| 53 } // namespace blink |
| OLD | NEW |