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

Side by Side Diff: ppapi/tests/test_browser_font.cc

Issue 9360045: Rename PPB_Font to PPB_BrowserFont_Trusted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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_browser_font.h ('k') | ppapi/thunk/interfaces_ppb_private.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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"));
50 ASSERT_TRUE(length1 > 0);
51 int32_t length2 = font.MeasureText(pp::BrowserFontTextRun("WWWWWWWW"));
52
53 ASSERT_TRUE(length2 >= length1 * 2);
54 PASS();
55 }
56
57 // Tests that the character/pixel offset functions correctly round-trip.
58 std::string TestBrowserFont::TestCharPos() {
59 pp::BrowserFontDescription desc;
60 pp::BrowserFont_Trusted font(instance_, desc);
61
62 pp::BrowserFontTextRun run("Hello, world");
63 uint32_t original_char = 3;
64 uint32_t pixel_offset = font.PixelOffsetForCharacter(run, original_char);
65 ASSERT_TRUE(pixel_offset > 0);
66
67 uint32_t computed_char = font.CharacterOffsetForPixel(
68 run, static_cast<int32_t>(pixel_offset));
69 ASSERT_TRUE(computed_char == original_char);
70
71 PASS();
72 }
73
74 // Tests that drawing some text produces "some" output.
75 std::string TestBrowserFont::TestDraw() {
76 pp::BrowserFontDescription desc;
77 desc.set_size(100);
78 pp::BrowserFont_Trusted font(instance_, desc);
79
80 const int kSize = 256;
81 pp::ImageData image(instance_, pp::ImageData::GetNativeImageDataFormat(),
82 pp::Size(kSize, kSize), true);
83 ASSERT_TRUE(!image.is_null());
84
85 const uint32_t kColor = 0xFFFFFFFF;
86 font.DrawSimpleText(&image, "Hello", pp::Point(0, 0), kColor, false);
87
88 // Expect that some pixel is nonzero. Due to blending, there may be rounding
89 // errors and checking for exact white may not be correct.
90 bool found = false;
91 for (int y = 0; y < kSize; y++) {
92 for (int x = 0; x < kSize; x++) {
93 if (*image.GetAddr32(pp::Point(x, y)) != 0) {
94 found = true;
95 break;
96 }
97 }
98 }
99 ASSERT_TRUE(found);
100 PASS();
101 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_browser_font.h ('k') | ppapi/thunk/interfaces_ppb_private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698