| 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..d5e045aa1dcf538209e929d690b3117e0961533f
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/css/CSSFontFaceSourceTest.cpp
|
| @@ -0,0 +1,53 @@
|
| +// 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;
|
| + // Even if the hash value collide, fontface cache should return different value for different fonts.
|
| + EXPECT_EQ(simulateHashCalculation(2821), simulateHashCalculation(3346));
|
| + EXPECT_NE(fontFaceSource.getFontDataForSize(2821), fontFaceSource.getFontDataForSize(3346));
|
| +}
|
| +
|
| +} // namespace blink
|
|
|