Chromium Code Reviews| 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> | |
|
dmichael (off chromium)
2013/04/12 23:34:18
nit: I'm guessing you don't want this anymore
bbudge
2013/04/13 00:44:44
Done.
| |
| 9 #include <string.h> | 10 #include <string.h> |
| 10 #include <algorithm> | 11 #include <algorithm> |
| 11 #include <limits> | 12 #include <limits> |
| 12 | 13 |
| 13 #include "ppapi/c/dev/ppb_testing_dev.h" | 14 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 14 #include "ppapi/cpp/completion_callback.h" | 15 #include "ppapi/cpp/completion_callback.h" |
| 15 #include "ppapi/cpp/dev/truetype_font_dev.h" | 16 #include "ppapi/cpp/dev/truetype_font_dev.h" |
| 16 #include "ppapi/cpp/instance.h" | 17 #include "ppapi/cpp/instance.h" |
| 17 #include "ppapi/cpp/var.h" | 18 #include "ppapi/cpp/var.h" |
| 18 #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 Loading... | |
| 78 instance_->AppendError("PPB_Var interface not available"); | 79 instance_->AppendError("PPB_Var interface not available"); |
| 79 | 80 |
| 80 return true; | 81 return true; |
| 81 } | 82 } |
| 82 | 83 |
| 83 TestTrueTypeFont::~TestTrueTypeFont() { | 84 TestTrueTypeFont::~TestTrueTypeFont() { |
| 84 } | 85 } |
| 85 | 86 |
| 86 void TestTrueTypeFont::RunTests(const std::string& filter) { | 87 void TestTrueTypeFont::RunTests(const std::string& filter) { |
| 87 RUN_TEST(GetFontFamilies, filter); | 88 RUN_TEST(GetFontFamilies, filter); |
| 89 RUN_TEST(GetFontsInFamily, filter); | |
| 88 RUN_TEST(Create, filter); | 90 RUN_TEST(Create, filter); |
| 89 RUN_TEST(Describe, filter); | 91 RUN_TEST(Describe, filter); |
| 90 RUN_TEST(GetTableTags, filter); | 92 RUN_TEST(GetTableTags, filter); |
| 91 RUN_TEST(GetTable, filter); | 93 RUN_TEST(GetTable, filter); |
| 92 } | 94 } |
| 93 | 95 |
| 94 std::string TestTrueTypeFont::TestGetFontFamilies() { | 96 std::string TestTrueTypeFont::TestGetFontFamilies() { |
| 95 { | 97 { |
| 96 // A valid instance should be able to enumerate fonts. | 98 // A valid instance should be able to enumerate fonts. |
| 97 TestCompletionCallbackWithOutput< std::vector<pp::Var> > cc( | 99 TestCompletionCallbackWithOutput< std::vector<pp::Var> > cc( |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 114 kInvalidInstance, | 116 kInvalidInstance, |
| 115 cc.GetCallback().output(), | 117 cc.GetCallback().output(), |
| 116 cc.GetCallback().pp_completion_callback())); | 118 cc.GetCallback().pp_completion_callback())); |
| 117 ASSERT_EQ(PP_ERROR_FAILED, cc.result()); | 119 ASSERT_EQ(PP_ERROR_FAILED, cc.result()); |
| 118 ASSERT_EQ(0, cc.output().size()); | 120 ASSERT_EQ(0, cc.output().size()); |
| 119 } | 121 } |
| 120 | 122 |
| 121 PASS(); | 123 PASS(); |
| 122 } | 124 } |
| 123 | 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_EQ(PP_ERROR_FAILED, cc.result()); | |
| 180 ASSERT_EQ(0, cc.output().size()); | |
| 181 } | |
| 182 | |
| 183 PASS(); | |
| 184 } | |
| 185 | |
| 124 std::string TestTrueTypeFont::TestCreate() { | 186 std::string TestTrueTypeFont::TestCreate() { |
| 125 PP_Resource font; | 187 PP_Resource font; |
| 126 PP_TrueTypeFontDesc_Dev desc = { | 188 PP_TrueTypeFontDesc_Dev desc = { |
| 127 PP_MakeUndefined(), | 189 PP_MakeUndefined(), |
| 128 PP_TRUETYPEFONTFAMILY_SERIF, | 190 PP_TRUETYPEFONTFAMILY_SERIF, |
| 129 PP_TRUETYPEFONTSTYLE_NORMAL, | 191 PP_TRUETYPEFONTSTYLE_NORMAL, |
| 130 PP_TRUETYPEFONTWEIGHT_NORMAL, | 192 PP_TRUETYPEFONTWEIGHT_NORMAL, |
| 131 PP_TRUETYPEFONTWIDTH_NORMAL, | 193 PP_TRUETYPEFONTWIDTH_NORMAL, |
| 132 PP_TRUETYPEFONTCHARSET_DEFAULT | 194 PP_TRUETYPEFONTCHARSET_DEFAULT |
| 133 }; | 195 }; |
| 134 // Creating a font from an invalid instance returns an invalid resource. | 196 // Creating a font from an invalid instance returns an invalid resource. |
| 135 font = ppb_truetype_font_interface_->Create(kInvalidInstance, &desc); | 197 font = ppb_truetype_font_interface_->Create(kInvalidInstance, &desc); |
| 136 ASSERT_EQ(kInvalidResource, font); | 198 ASSERT_EQ(kInvalidResource, font); |
| 137 ASSERT_NE(PP_TRUE, ppb_truetype_font_interface_->IsFont(font)); | 199 ASSERT_NE(PP_TRUE, ppb_truetype_font_interface_->IsTrueTypeFont(font)); |
| 138 | 200 |
| 139 // Creating a font from a valid instance returns a font resource. | 201 // Creating a font from a valid instance returns a font resource. |
| 140 font = ppb_truetype_font_interface_->Create(instance_->pp_instance(), &desc); | 202 font = ppb_truetype_font_interface_->Create(instance_->pp_instance(), &desc); |
| 141 ASSERT_NE(kInvalidResource, font); | 203 ASSERT_NE(kInvalidResource, font); |
| 142 ASSERT_EQ(PP_TRUE, ppb_truetype_font_interface_->IsFont(font)); | 204 ASSERT_EQ(PP_TRUE, ppb_truetype_font_interface_->IsTrueTypeFont(font)); |
| 143 | 205 |
| 144 ppb_core_interface_->ReleaseResource(font); | 206 ppb_core_interface_->ReleaseResource(font); |
| 145 // Once released, the resource shouldn't be a font. | 207 // Once released, the resource shouldn't be a font. |
| 146 ASSERT_NE(PP_TRUE, ppb_truetype_font_interface_->IsFont(font)); | 208 ASSERT_NE(PP_TRUE, ppb_truetype_font_interface_->IsTrueTypeFont(font)); |
| 147 | 209 |
| 148 PASS(); | 210 PASS(); |
| 149 } | 211 } |
| 150 | 212 |
| 151 std::string TestTrueTypeFont::TestDescribe() { | 213 std::string TestTrueTypeFont::TestDescribe() { |
| 152 pp::TrueTypeFontDesc_Dev create_desc; | 214 pp::TrueTypeFontDesc_Dev create_desc; |
| 153 create_desc.set_generic_family(PP_TRUETYPEFONTFAMILY_SERIF); | 215 create_desc.set_generic_family(PP_TRUETYPEFONTFAMILY_SERIF); |
| 154 create_desc.set_style(PP_TRUETYPEFONTSTYLE_NORMAL); | 216 create_desc.set_style(PP_TRUETYPEFONTSTYLE_NORMAL); |
| 155 create_desc.set_weight(PP_TRUETYPEFONTWEIGHT_NORMAL); | 217 create_desc.set_weight(PP_TRUETYPEFONTWEIGHT_NORMAL); |
| 156 pp::TrueTypeFont_Dev font(instance_, create_desc); | 218 pp::TrueTypeFont_Dev font(instance_, create_desc); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 instance_->pp_instance(), false); | 419 instance_->pp_instance(), false); |
| 358 cc.WaitForResult(font.GetTable(MAKE_TABLE_TAG('c', 'm', 'a', 'p'), | 420 cc.WaitForResult(font.GetTable(MAKE_TABLE_TAG('c', 'm', 'a', 'p'), |
| 359 0, -100, | 421 0, -100, |
| 360 cc.GetCallback())); | 422 cc.GetCallback())); |
| 361 ASSERT_EQ(PP_ERROR_BADARGUMENT, cc.result()); | 423 ASSERT_EQ(PP_ERROR_BADARGUMENT, cc.result()); |
| 362 ASSERT_EQ(0, cc.output().size()); | 424 ASSERT_EQ(0, cc.output().size()); |
| 363 } | 425 } |
| 364 | 426 |
| 365 PASS(); | 427 PASS(); |
| 366 } | 428 } |
| OLD | NEW |