OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ppapi/tests/test_browser_font.h" | |
6 | |
7 #include <stdio.h>// ERASEME | |
8 | |
9 #include "ppapi/tests/test_utils.h" | |
10 #include "ppapi/tests/testing_instance.h" | |
11 #include "ppapi/cpp/image_data.h" | |
12 #include "ppapi/cpp/trusted/browser_font_trusted.h" | |
13 | |
14 REGISTER_TEST_CASE(BrowserFont); | |
15 | |
16 bool TestBrowserFont::Init() { | |
17 return true; | |
18 } | |
19 | |
20 void TestBrowserFont::RunTests(const std::string& filter) { | |
21 RUN_TEST(FontFamilies, filter); | |
22 RUN_TEST(Measure, filter); | |
23 RUN_TEST(CharPos, filter); | |
24 RUN_TEST(Draw, filter); | |
25 } | |
26 | |
27 // Just tests that GetFontFamilies is hooked up & returns something. | |
28 std::string TestBrowserFont::TestFontFamilies() { | |
29 // This function is only supported out-of-process. | |
30 const PPB_Testing_Dev* testing_interface = GetTestingInterface(); | |
31 if (testing_interface && !testing_interface->IsOutOfProcess()) | |
32 PASS(); | |
33 | |
34 pp::Var families = pp::BrowserFont_Trusted::GetFontFamilies(instance_); | |
35 | |
36 ASSERT_TRUE(families.is_string()); | |
37 ASSERT_TRUE(!families.AsString().empty()); | |
38 PASS(); | |
39 } | |
40 | |
41 // Tests that measuring text behaves reasonably. We aren't sure if the browser | |
42 // will be doing kerning or something for the particular default font, so we | |
43 // just make a string that we're pretty sure should be more than twice as long | |
44 // as another one, and verify that condition. | |
45 std::string TestBrowserFont::TestMeasure() { | |
46 pp::BrowserFontDescription desc; | |
47 pp::BrowserFont_Trusted font(instance_, desc); | |
48 | |
49 int32_t length1 = font.MeasureText(pp::BrowserFontTextRun("WWW")); | |
viettrungluu
2012/02/16 20:31:18
Do you also want to check that length1 > 0?
| |
50 int32_t length2 = font.MeasureText(pp::BrowserFontTextRun("WWWWWWWW")); | |
51 | |
52 ASSERT_TRUE(length2 >= length1 * 2); | |
53 PASS(); | |
54 } | |
55 | |
56 // Tests that the character/pixel offset functions correctly round-trip. | |
57 std::string TestBrowserFont::TestCharPos() { | |
58 pp::BrowserFontDescription desc; | |
59 pp::BrowserFont_Trusted font(instance_, desc); | |
60 | |
61 pp::BrowserFontTextRun run("Hello, world"); | |
62 uint32_t original_char = 3; | |
63 uint32_t pixel_offset = font.PixelOffsetForCharacter(run, original_char); | |
64 ASSERT_TRUE(pixel_offset > 0); | |
65 | |
66 uint32_t computed_char = font.CharacterOffsetForPixel( | |
67 run, static_cast<int32_t>(pixel_offset)); | |
68 ASSERT_TRUE(computed_char == original_char); | |
69 | |
70 PASS(); | |
71 } | |
72 | |
73 // Tests that drawing some text produces "some" output. | |
74 std::string TestBrowserFont::TestDraw() { | |
75 pp::BrowserFontDescription desc; | |
76 desc.set_size(100); | |
77 pp::BrowserFont_Trusted font(instance_, desc); | |
78 | |
79 const int kSize = 256; | |
80 pp::ImageData image(instance_, pp::ImageData::GetNativeImageDataFormat(), | |
81 pp::Size(kSize, kSize), true); | |
82 ASSERT_TRUE(!image.is_null()); | |
83 | |
84 const uint32_t kColor = 0xFFFFFFFF; | |
85 font.DrawSimpleText(&image, "Hello", pp::Point(0, 0), kColor, false); | |
86 | |
87 // Expect that some pixel is nonzero. Due to blending, there may be rounding | |
88 // errors and checking for exact white may not be correct. | |
89 bool found = false; | |
90 for (int y = 0; y < kSize; y++) { | |
91 for (int x = 0; x < kSize; x++) { | |
92 if (*image.GetAddr32(pp::Point(x, y)) != 0) { | |
93 found = true; | |
94 break; | |
95 } | |
96 } | |
97 } | |
98 ASSERT_TRUE(found); | |
99 PASS(); | |
100 } | |
OLD | NEW |