OLD | NEW |
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> | |
10 #include <string.h> | 9 #include <string.h> |
11 #include <algorithm> | 10 #include <algorithm> |
12 #include <limits> | 11 #include <limits> |
13 | 12 |
14 #include "ppapi/c/dev/ppb_testing_dev.h" | 13 #include "ppapi/c/dev/ppb_testing_dev.h" |
15 #include "ppapi/cpp/completion_callback.h" | 14 #include "ppapi/cpp/completion_callback.h" |
16 #include "ppapi/cpp/dev/truetype_font_dev.h" | 15 #include "ppapi/cpp/dev/truetype_font_dev.h" |
17 #include "ppapi/cpp/instance.h" | 16 #include "ppapi/cpp/instance.h" |
18 #include "ppapi/cpp/var.h" | 17 #include "ppapi/cpp/var.h" |
19 #include "ppapi/tests/test_utils.h" | 18 #include "ppapi/tests/test_utils.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 instance_->AppendError("PPB_Var interface not available"); | 78 instance_->AppendError("PPB_Var interface not available"); |
80 | 79 |
81 return true; | 80 return true; |
82 } | 81 } |
83 | 82 |
84 TestTrueTypeFont::~TestTrueTypeFont() { | 83 TestTrueTypeFont::~TestTrueTypeFont() { |
85 } | 84 } |
86 | 85 |
87 void TestTrueTypeFont::RunTests(const std::string& filter) { | 86 void TestTrueTypeFont::RunTests(const std::string& filter) { |
88 RUN_TEST(GetFontFamilies, filter); | 87 RUN_TEST(GetFontFamilies, filter); |
| 88 RUN_TEST(GetFontsInFamily, filter); |
89 RUN_TEST(Create, filter); | 89 RUN_TEST(Create, filter); |
90 RUN_TEST(Describe, filter); | 90 RUN_TEST(Describe, filter); |
91 RUN_TEST(GetTableTags, filter); | 91 RUN_TEST(GetTableTags, filter); |
92 RUN_TEST(GetTable, filter); | 92 RUN_TEST(GetTable, filter); |
93 } | 93 } |
94 | 94 |
95 std::string TestTrueTypeFont::TestGetFontFamilies() { | 95 std::string TestTrueTypeFont::TestGetFontFamilies() { |
96 { | 96 { |
97 // A valid instance should be able to enumerate fonts. | 97 // A valid instance should be able to enumerate fonts. |
98 TestCompletionCallbackWithOutput< std::vector<pp::Var> > cc( | 98 TestCompletionCallbackWithOutput< std::vector<pp::Var> > cc( |
(...skipping 17 matching lines...) Expand all Loading... |
116 cc.GetCallback().output(), | 116 cc.GetCallback().output(), |
117 cc.GetCallback().pp_completion_callback())); | 117 cc.GetCallback().pp_completion_callback())); |
118 ASSERT_TRUE(cc.result() == PP_ERROR_FAILED || | 118 ASSERT_TRUE(cc.result() == PP_ERROR_FAILED || |
119 cc.result() == PP_ERROR_BADARGUMENT); | 119 cc.result() == PP_ERROR_BADARGUMENT); |
120 ASSERT_EQ(0, cc.output().size()); | 120 ASSERT_EQ(0, cc.output().size()); |
121 } | 121 } |
122 | 122 |
123 PASS(); | 123 PASS(); |
124 } | 124 } |
125 | 125 |
| 126 std::string TestTrueTypeFont::TestGetFontsInFamily() { |
| 127 { |
| 128 // Get the list of all font families. |
| 129 TestCompletionCallbackWithOutput< std::vector<pp::Var> > cc( |
| 130 instance_->pp_instance(), false); |
| 131 cc.WaitForResult(pp::TrueTypeFont_Dev::GetFontFamilies(instance_, |
| 132 cc.GetCallback())); |
| 133 // Try to use a common family that is likely to have multiple variations. |
| 134 const std::vector<pp::Var> families = cc.output(); |
| 135 pp::Var family("Arial"); |
| 136 if (std::find(families.begin(), families.end(), family) == families.end()) { |
| 137 family = pp::Var("Times"); |
| 138 if (std::find(families.begin(), families.end(), family) == families.end()) |
| 139 family = families[0]; // Just use the first family. |
| 140 } |
| 141 |
| 142 // GetFontsInFamily: A valid instance should be able to enumerate fonts |
| 143 // in a given family. |
| 144 TestCompletionCallbackWithOutput< std::vector<pp::TrueTypeFontDesc_Dev> > |
| 145 cc2(instance_->pp_instance(), false); |
| 146 cc2.WaitForResult(pp::TrueTypeFont_Dev::GetFontsInFamily( |
| 147 instance_, |
| 148 family, |
| 149 cc2.GetCallback())); |
| 150 std::vector<pp::TrueTypeFontDesc_Dev> fonts_in_family = cc2.output(); |
| 151 ASSERT_NE(0, fonts_in_family.size()); |
| 152 ASSERT_EQ(static_cast<int32_t>(fonts_in_family.size()), cc2.result()); |
| 153 |
| 154 // We should be able to create any of the returned fonts without fallback. |
| 155 for (size_t i = 0; i < fonts_in_family.size(); ++i) { |
| 156 pp::TrueTypeFontDesc_Dev& font_in_family = fonts_in_family[i]; |
| 157 pp::TrueTypeFont_Dev font(instance_, font_in_family); |
| 158 TestCompletionCallbackWithOutput<pp::TrueTypeFontDesc_Dev> cc( |
| 159 instance_->pp_instance(), false); |
| 160 cc.WaitForResult(font.Describe(cc.GetCallback())); |
| 161 const pp::TrueTypeFontDesc_Dev desc = cc.output(); |
| 162 |
| 163 ASSERT_EQ(family, desc.family()); |
| 164 ASSERT_EQ(font_in_family.style(), desc.style()); |
| 165 ASSERT_EQ(font_in_family.weight(), desc.weight()); |
| 166 } |
| 167 } |
| 168 { |
| 169 // Using an invalid instance should fail. |
| 170 TestCompletionCallbackWithOutput< std::vector<pp::TrueTypeFontDesc_Dev> > |
| 171 cc(instance_->pp_instance(), false); |
| 172 pp::Var family("Times"); |
| 173 cc.WaitForResult( |
| 174 ppb_truetype_font_interface_->GetFontsInFamily( |
| 175 kInvalidInstance, |
| 176 family.pp_var(), |
| 177 cc.GetCallback().output(), |
| 178 cc.GetCallback().pp_completion_callback())); |
| 179 ASSERT_TRUE(cc.result() == PP_ERROR_FAILED || |
| 180 cc.result() == PP_ERROR_BADARGUMENT); |
| 181 ASSERT_EQ(0, cc.output().size()); |
| 182 } |
| 183 |
| 184 PASS(); |
| 185 } |
| 186 |
126 std::string TestTrueTypeFont::TestCreate() { | 187 std::string TestTrueTypeFont::TestCreate() { |
127 PP_Resource font; | 188 PP_Resource font; |
128 PP_TrueTypeFontDesc_Dev desc = { | 189 PP_TrueTypeFontDesc_Dev desc = { |
129 PP_MakeUndefined(), | 190 PP_MakeUndefined(), |
130 PP_TRUETYPEFONTFAMILY_SERIF, | 191 PP_TRUETYPEFONTFAMILY_SERIF, |
131 PP_TRUETYPEFONTSTYLE_NORMAL, | 192 PP_TRUETYPEFONTSTYLE_NORMAL, |
132 PP_TRUETYPEFONTWEIGHT_NORMAL, | 193 PP_TRUETYPEFONTWEIGHT_NORMAL, |
133 PP_TRUETYPEFONTWIDTH_NORMAL, | 194 PP_TRUETYPEFONTWIDTH_NORMAL, |
134 PP_TRUETYPEFONTCHARSET_DEFAULT | 195 PP_TRUETYPEFONTCHARSET_DEFAULT |
135 }; | 196 }; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 instance_->pp_instance(), false); | 420 instance_->pp_instance(), false); |
360 cc.WaitForResult(font.GetTable(MAKE_TABLE_TAG('c', 'm', 'a', 'p'), | 421 cc.WaitForResult(font.GetTable(MAKE_TABLE_TAG('c', 'm', 'a', 'p'), |
361 0, -100, | 422 0, -100, |
362 cc.GetCallback())); | 423 cc.GetCallback())); |
363 ASSERT_EQ(PP_ERROR_BADARGUMENT, cc.result()); | 424 ASSERT_EQ(PP_ERROR_BADARGUMENT, cc.result()); |
364 ASSERT_EQ(0, cc.output().size()); | 425 ASSERT_EQ(0, cc.output().size()); |
365 } | 426 } |
366 | 427 |
367 PASS(); | 428 PASS(); |
368 } | 429 } |
OLD | NEW |