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

Side by Side 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 again. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/tests/test_truetype_font.h ('k') | ppapi/thunk/ppb_truetype_font_dev_thunk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Tests PPB_TrueTypeFont interface. 5 // Tests PPB_TrueTypeFont interface.
6 6
7 #include "ppapi/tests/test_truetype_font.h" 7 #include "ppapi/tests/test_truetype_font.h"
8 8
9 #include <stdio.h> 9 #include <stdio.h>
dmichael (off chromium) 2013/04/18 16:55:33 Oops, it's still there
bbudge 2013/04/18 17:21:06 git troubles. Done. On 2013/04/18 16:55:33, dmicha
10 #include <string.h> 10 #include <string.h>
11 #include <algorithm> 11 #include <algorithm>
12 #include <limits> 12 #include <limits>
13 13
14 #include "ppapi/c/dev/ppb_testing_dev.h" 14 #include "ppapi/c/dev/ppb_testing_dev.h"
15 #include "ppapi/cpp/completion_callback.h" 15 #include "ppapi/cpp/completion_callback.h"
16 #include "ppapi/cpp/dev/truetype_font_dev.h" 16 #include "ppapi/cpp/dev/truetype_font_dev.h"
17 #include "ppapi/cpp/instance.h" 17 #include "ppapi/cpp/instance.h"
18 #include "ppapi/cpp/var.h" 18 #include "ppapi/cpp/var.h"
19 #include "ppapi/tests/test_utils.h" 19 #include "ppapi/tests/test_utils.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 instance_->AppendError("PPB_Var interface not available"); 79 instance_->AppendError("PPB_Var interface not available");
80 80
81 return true; 81 return true;
82 } 82 }
83 83
84 TestTrueTypeFont::~TestTrueTypeFont() { 84 TestTrueTypeFont::~TestTrueTypeFont() {
85 } 85 }
86 86
87 void TestTrueTypeFont::RunTests(const std::string& filter) { 87 void TestTrueTypeFont::RunTests(const std::string& filter) {
88 RUN_TEST(GetFontFamilies, filter); 88 RUN_TEST(GetFontFamilies, filter);
89 RUN_TEST(GetFontsInFamily, filter);
89 RUN_TEST(Create, filter); 90 RUN_TEST(Create, filter);
90 RUN_TEST(Describe, filter); 91 RUN_TEST(Describe, filter);
91 RUN_TEST(GetTableTags, filter); 92 RUN_TEST(GetTableTags, filter);
92 RUN_TEST(GetTable, filter); 93 RUN_TEST(GetTable, filter);
93 } 94 }
94 95
95 std::string TestTrueTypeFont::TestGetFontFamilies() { 96 std::string TestTrueTypeFont::TestGetFontFamilies() {
96 { 97 {
97 // A valid instance should be able to enumerate fonts. 98 // A valid instance should be able to enumerate fonts.
98 TestCompletionCallbackWithOutput< std::vector<pp::Var> > cc( 99 TestCompletionCallbackWithOutput< std::vector<pp::Var> > cc(
(...skipping 17 matching lines...) Expand all
116 cc.GetCallback().output(), 117 cc.GetCallback().output(),
117 cc.GetCallback().pp_completion_callback())); 118 cc.GetCallback().pp_completion_callback()));
118 ASSERT_TRUE(cc.result() == PP_ERROR_FAILED || 119 ASSERT_TRUE(cc.result() == PP_ERROR_FAILED ||
119 cc.result() == PP_ERROR_BADARGUMENT); 120 cc.result() == PP_ERROR_BADARGUMENT);
120 ASSERT_EQ(0, cc.output().size()); 121 ASSERT_EQ(0, cc.output().size());
121 } 122 }
122 123
123 PASS(); 124 PASS();
124 } 125 }
125 126
127 std::string TestTrueTypeFont::TestGetFontsInFamily() {
128 {
129 // Get the list of all font families.
130 TestCompletionCallbackWithOutput< std::vector<pp::Var> > cc(
131 instance_->pp_instance(), false);
132 cc.WaitForResult(pp::TrueTypeFont_Dev::GetFontFamilies(instance_,
133 cc.GetCallback()));
134 // Try to use a common family that is likely to have multiple variations.
135 const std::vector<pp::Var> families = cc.output();
136 pp::Var family("Arial");
137 if (std::find(families.begin(), families.end(), family) == families.end()) {
138 family = pp::Var("Times");
139 if (std::find(families.begin(), families.end(), family) == families.end())
140 family = families[0]; // Just use the first family.
141 }
142
143 // GetFontsInFamily: A valid instance should be able to enumerate fonts
144 // in a given family.
145 TestCompletionCallbackWithOutput< std::vector<pp::TrueTypeFontDesc_Dev> >
146 cc2(instance_->pp_instance(), false);
147 cc2.WaitForResult(pp::TrueTypeFont_Dev::GetFontsInFamily(
148 instance_,
149 family,
150 cc2.GetCallback()));
151 std::vector<pp::TrueTypeFontDesc_Dev> fonts_in_family = cc2.output();
152 ASSERT_NE(0, fonts_in_family.size());
153 ASSERT_EQ(static_cast<int32_t>(fonts_in_family.size()), cc2.result());
154
155 // We should be able to create any of the returned fonts without fallback.
156 for (size_t i = 0; i < fonts_in_family.size(); ++i) {
157 pp::TrueTypeFontDesc_Dev& font_in_family = fonts_in_family[i];
158 pp::TrueTypeFont_Dev font(instance_, font_in_family);
159 TestCompletionCallbackWithOutput<pp::TrueTypeFontDesc_Dev> cc(
160 instance_->pp_instance(), false);
161 cc.WaitForResult(font.Describe(cc.GetCallback()));
162 const pp::TrueTypeFontDesc_Dev desc = cc.output();
163
164 ASSERT_EQ(family, desc.family());
165 ASSERT_EQ(font_in_family.style(), desc.style());
166 ASSERT_EQ(font_in_family.weight(), desc.weight());
167 }
168 }
169 {
170 // Using an invalid instance should fail.
171 TestCompletionCallbackWithOutput< std::vector<pp::TrueTypeFontDesc_Dev> >
172 cc(instance_->pp_instance(), false);
173 pp::Var family("Times");
174 cc.WaitForResult(
175 ppb_truetype_font_interface_->GetFontsInFamily(
176 kInvalidInstance,
177 family.pp_var(),
178 cc.GetCallback().output(),
179 cc.GetCallback().pp_completion_callback()));
180 ASSERT_TRUE(cc.result() == PP_ERROR_FAILED ||
181 cc.result() == PP_ERROR_BADARGUMENT);
182 ASSERT_EQ(0, cc.output().size());
183 }
184
185 PASS();
186 }
187
126 std::string TestTrueTypeFont::TestCreate() { 188 std::string TestTrueTypeFont::TestCreate() {
127 PP_Resource font; 189 PP_Resource font;
128 PP_TrueTypeFontDesc_Dev desc = { 190 PP_TrueTypeFontDesc_Dev desc = {
129 PP_MakeUndefined(), 191 PP_MakeUndefined(),
130 PP_TRUETYPEFONTFAMILY_SERIF, 192 PP_TRUETYPEFONTFAMILY_SERIF,
131 PP_TRUETYPEFONTSTYLE_NORMAL, 193 PP_TRUETYPEFONTSTYLE_NORMAL,
132 PP_TRUETYPEFONTWEIGHT_NORMAL, 194 PP_TRUETYPEFONTWEIGHT_NORMAL,
133 PP_TRUETYPEFONTWIDTH_NORMAL, 195 PP_TRUETYPEFONTWIDTH_NORMAL,
134 PP_TRUETYPEFONTCHARSET_DEFAULT 196 PP_TRUETYPEFONTCHARSET_DEFAULT
135 }; 197 };
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 instance_->pp_instance(), false); 421 instance_->pp_instance(), false);
360 cc.WaitForResult(font.GetTable(MAKE_TABLE_TAG('c', 'm', 'a', 'p'), 422 cc.WaitForResult(font.GetTable(MAKE_TABLE_TAG('c', 'm', 'a', 'p'),
361 0, -100, 423 0, -100,
362 cc.GetCallback())); 424 cc.GetCallback()));
363 ASSERT_EQ(PP_ERROR_BADARGUMENT, cc.result()); 425 ASSERT_EQ(PP_ERROR_BADARGUMENT, cc.result());
364 ASSERT_EQ(0, cc.output().size()); 426 ASSERT_EQ(0, cc.output().size());
365 } 427 }
366 428
367 PASS(); 429 PASS();
368 } 430 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_truetype_font.h ('k') | ppapi/thunk/ppb_truetype_font_dev_thunk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698