Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Unified Diff: third_party/WebKit/Source/core/css/CSSFontFaceSourceTest.cpp

Issue 1973153004: Fix FontCacheKey-keyed HashMap usage in core/css (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +comment Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSFontFaceSource.cpp ('k') | third_party/WebKit/Source/core/css/CSSSegmentedFontFace.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698