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

Unified Diff: ppapi/tests/test_truetype_font.cc

Issue 13913006: Add Pepper TrueType font API call to enumerate fonts in a given family. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Windows build. Created 7 years, 8 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: ppapi/tests/test_truetype_font.cc
diff --git a/ppapi/tests/test_truetype_font.cc b/ppapi/tests/test_truetype_font.cc
index 7644b95e1184db26bf19133090a0369e082f7f72..67587a08a6a3d4e126103348bbc68dc5b619507f 100644
--- a/ppapi/tests/test_truetype_font.cc
+++ b/ppapi/tests/test_truetype_font.cc
@@ -6,7 +6,6 @@
#include "ppapi/tests/test_truetype_font.h"
-#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <limits>
@@ -86,6 +85,7 @@ TestTrueTypeFont::~TestTrueTypeFont() {
void TestTrueTypeFont::RunTests(const std::string& filter) {
RUN_TEST(GetFontFamilies, filter);
+ RUN_TEST(GetFontsInFamily, filter);
RUN_TEST(Create, filter);
RUN_TEST(Describe, filter);
RUN_TEST(GetTableTags, filter);
@@ -123,6 +123,67 @@ std::string TestTrueTypeFont::TestGetFontFamilies() {
PASS();
}
+std::string TestTrueTypeFont::TestGetFontsInFamily() {
+ {
+ // Get the list of all font families.
+ TestCompletionCallbackWithOutput< std::vector<pp::Var> > cc(
+ instance_->pp_instance(), false);
+ cc.WaitForResult(pp::TrueTypeFont_Dev::GetFontFamilies(instance_,
+ cc.GetCallback()));
+ // Try to use a common family that is likely to have multiple variations.
+ const std::vector<pp::Var> families = cc.output();
+ pp::Var family("Arial");
+ if (std::find(families.begin(), families.end(), family) == families.end()) {
+ family = pp::Var("Times");
+ if (std::find(families.begin(), families.end(), family) == families.end())
+ family = families[0]; // Just use the first family.
+ }
+
+ // GetFontsInFamily: A valid instance should be able to enumerate fonts
+ // in a given family.
+ TestCompletionCallbackWithOutput< std::vector<pp::TrueTypeFontDesc_Dev> >
+ cc2(instance_->pp_instance(), false);
+ cc2.WaitForResult(pp::TrueTypeFont_Dev::GetFontsInFamily(
+ instance_,
+ family,
+ cc2.GetCallback()));
+ std::vector<pp::TrueTypeFontDesc_Dev> fonts_in_family = cc2.output();
+ ASSERT_NE(0, fonts_in_family.size());
+ ASSERT_EQ(static_cast<int32_t>(fonts_in_family.size()), cc2.result());
+
+ // We should be able to create any of the returned fonts without fallback.
+ for (size_t i = 0; i < fonts_in_family.size(); ++i) {
+ pp::TrueTypeFontDesc_Dev& font_in_family = fonts_in_family[i];
+ pp::TrueTypeFont_Dev font(instance_, font_in_family);
+ TestCompletionCallbackWithOutput<pp::TrueTypeFontDesc_Dev> cc(
+ instance_->pp_instance(), false);
+ cc.WaitForResult(font.Describe(cc.GetCallback()));
+ const pp::TrueTypeFontDesc_Dev desc = cc.output();
+
+ ASSERT_EQ(family, desc.family());
+ ASSERT_EQ(font_in_family.style(), desc.style());
+ ASSERT_EQ(font_in_family.weight(), desc.weight());
+ }
+ }
+ {
+ // Using an invalid instance should fail.
+ TestCompletionCallbackWithOutput< std::vector<pp::TrueTypeFontDesc_Dev> >
+ cc(instance_->pp_instance(), false);
+ pp::Var family("Times");
+ cc.WaitForResult(
+ ppb_truetype_font_interface_->GetFontsInFamily(
+ kInvalidInstance,
+ family.pp_var(),
+ cc.GetCallback().output(),
+ cc.GetCallback().pp_completion_callback()));
+ ASSERT_TRUE(cc.result() == PP_ERROR_FAILED ||
+ cc.result() == PP_ERROR_BADARGUMENT);
+ ASSERT_EQ(0, cc.output().size());
+ }
+
+ PASS();
+}
+
std::string TestTrueTypeFont::TestCreate() {
PP_Resource font;
PP_TrueTypeFontDesc_Dev desc = {

Powered by Google App Engine
This is Rietveld 408576698