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

Unified Diff: Source/platform/fonts/opentype/OpenTypeSanitizerTest.cpp

Issue 316343004: Add unittest for OpenTypeSanitizer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix compile error Created 6 years, 6 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
« no previous file with comments | « Source/platform/fonts/opentype/OpenTypeSanitizer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/fonts/opentype/OpenTypeSanitizerTest.cpp
diff --git a/Source/platform/fonts/opentype/OpenTypeSanitizerTest.cpp b/Source/platform/fonts/opentype/OpenTypeSanitizerTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8edb04cfd751b5978bcc50fa1ac5cfb29c258698
--- /dev/null
+++ b/Source/platform/fonts/opentype/OpenTypeSanitizerTest.cpp
@@ -0,0 +1,85 @@
+// Copyright 2014 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 "config.h"
+
+#include "platform/fonts/opentype/OpenTypeSanitizer.h"
+
+#include "platform/RuntimeEnabledFeatures.h"
+#include "platform/SharedBuffer.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebUnitTestSupport.h"
+#include <gtest/gtest.h>
+
+using namespace WebCore;
+using namespace blink;
+
+namespace {
+
+static PassRefPtr<SharedBuffer> readFont(const char* fileName)
+{
+ String filePath = Platform::current()->unitTestSupport()->webKitRootDir();
+ filePath.append("/LayoutTests/resources/");
+ filePath.append(fileName);
+
+ return Platform::current()->unitTestSupport()->readFromFile(filePath);
+}
+
+TEST(OpenTypeSanitizerTest, TestOTF)
+{
+ RefPtr<SharedBuffer> buffer = readFont("Ahem.otf");
+ OpenTypeSanitizer sanitizer(buffer.get());
+ RefPtr<SharedBuffer> sanitized = sanitizer.sanitize();
+ EXPECT_GE(sanitized->size(), 4u);
+ const char* data = sanitized->data();
+ // Sfnt version: 'OTTO'
+ EXPECT_TRUE(data[0] == 'O' && data[1] == 'T' && data[2] == 'T' && data[3] == 'O');
+}
+
+TEST(OpenTypeSanitizerTest, TestTTF)
+{
+ RefPtr<SharedBuffer> buffer = readFont("Ahem.ttf");
+ OpenTypeSanitizer sanitizer(buffer.get());
+ RefPtr<SharedBuffer> sanitized = sanitizer.sanitize();
+ EXPECT_GE(sanitized->size(), 4u);
+ const char* data = sanitized->data();
+ // Sfnt version: 0x00010000
+ EXPECT_TRUE(data[0] == 0 && data[1] == 1 && data[2] == 0 && data[3] == 0);
+}
+
+TEST(OpenTypeSanitizerTest, TestWOFF)
+{
+ RefPtr<SharedBuffer> buffer = readFont("Ahem.woff");
+ EXPECT_GE(buffer->size(), 4u);
+ const char* originalData = buffer->data();
+ // Sfnt version: 'wOFF'
+ EXPECT_TRUE(originalData[0] == 'w' && originalData[1] == 'O' && originalData[2] == 'F' && originalData[3] == 'F');
+
+ OpenTypeSanitizer sanitizer(buffer.get());
+ RefPtr<SharedBuffer> sanitized = sanitizer.sanitize();
+ EXPECT_GE(sanitized->size(), 4u);
jamesr 2014/06/20 19:31:40 this should probably be an ASSERT_GT() so that if
+ const char* data = sanitized->data();
+ // Decompressed sfnt version: 'OTTO'
+ EXPECT_TRUE(data[0] == 'O' && data[1] == 'T' && data[2] == 'T' && data[3] == 'O');
+}
+
+TEST(OpenTypeSanitizerTest, TestWOFF2)
+{
+ RuntimeEnabledFeatures::setWOFF2Enabled(true);
+
+ RefPtr<SharedBuffer> buffer = readFont("Ahem.woff2");
+ EXPECT_GE(buffer->size(), 4u);
+ const char* originalData = buffer->data();
+ // Sfnt version: 'wOF2'
+ EXPECT_TRUE(originalData[0] == 'w' && originalData[1] == 'O' && originalData[2] == 'F' && originalData[3] == '2');
+
+ OpenTypeSanitizer sanitizer(buffer.get());
+ RefPtr<SharedBuffer> sanitized = sanitizer.sanitize();
+ EXPECT_GE(sanitized->size(), 4u);
+ const char* data = sanitized->data();
+ // Decompressed sfnt version: 0x00010000
+ EXPECT_TRUE(data[0] == 0 && data[1] == 1 && data[2] == 0 && data[3] == 0);
+}
+
+} // namespace
« no previous file with comments | « Source/platform/fonts/opentype/OpenTypeSanitizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698