Chromium Code Reviews| Index: third_party/WebKit/Source/core/css/CSSFontFaceSourceTest.cpp |
| diff --git a/third_party/WebKit/Source/core/css/CSSFontFaceSourceTest.cpp b/third_party/WebKit/Source/core/css/CSSFontFaceSourceTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..33b450a50dc1a7798191563ef67b2029e66d9318 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/css/CSSFontFaceSourceTest.cpp |
| @@ -0,0 +1,52 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/css/CSSFontFaceSource.h" |
| + |
| +#include "platform/fonts/FontCacheKey.h" |
| +#include "platform/fonts/FontDescription.h" |
| +#include "platform/fonts/FontPlatformData.h" |
| +#include "platform/fonts/SimpleFontData.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace blink { |
| + |
| +class DummyFontFaceSource : public CSSFontFaceSource { |
| +public: |
| + PassRefPtr<SimpleFontData> createFontData(const FontDescription&) override |
| + { |
| + return SimpleFontData::create(FontPlatformData(adoptRef(SkTypeface::RefDefault()), "", 0, false, false)); |
| + } |
| + |
| + DummyFontFaceSource() { } |
| + |
| + PassRefPtr<SimpleFontData> getFontDataForSize(float size) |
| + { |
| + FontDescription fontDescription; |
| + fontDescription.setSizeAdjust(size); |
| + fontDescription.setAdjustedSize(size); |
| + return getFontData(fontDescription); |
| + } |
| +}; |
| + |
| +namespace { |
| + |
| +unsigned simulateHashCalculation(float size) |
| +{ |
| + FontDescription fontDescription; |
| + fontDescription.setSizeAdjust(size); |
| + fontDescription.setAdjustedSize(size); |
| + return fontDescription.cacheKey(FontFaceCreationParams()).hash(); |
| +} |
| + |
| +} |
| + |
| +TEST(CSSFontFaceSourceTest, HashCollision) |
| +{ |
| + DummyFontFaceSource fontFaceSource; |
|
kouhei (in TOK)
2016/05/13 09:06:40
// Even if the hash value collide, fontface cache
tzik
2016/05/14 11:57:16
Done
|
| + EXPECT_EQ(simulateHashCalculation(2821), simulateHashCalculation(3346)); |
| + EXPECT_NE(fontFaceSource.getFontDataForSize(2821), fontFaceSource.getFontDataForSize(3346)); |
| +} |
| + |
| +} // namespace blink |