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

Side by Side Diff: ui/gfx/render_text_unittest.cc

Issue 26541007: ozone: Allow building for ozone without depending on pango (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: prepare-land Created 7 years, 1 month 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 | « ui/gfx/render_text_pango.cc ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 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 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 #include "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/gfx/break_list.h" 14 #include "ui/gfx/break_list.h"
15 #include "ui/gfx/canvas.h" 15 #include "ui/gfx/canvas.h"
16 16
17 #if defined(OS_WIN) 17 #if defined(OS_WIN)
18 #include "base/win/windows_version.h" 18 #include "base/win/windows_version.h"
19 #include "ui/gfx/render_text_win.h" 19 #include "ui/gfx/render_text_win.h"
20 #endif 20 #endif
21 21
22 #if defined(OS_LINUX) 22 #if defined(OS_LINUX) && !defined(USE_OZONE)
23 #include "ui/gfx/render_text_linux.h" 23 #include "ui/gfx/render_text_pango.h"
24 #endif 24 #endif
25 25
26 #if defined(TOOLKIT_GTK) 26 #if defined(TOOLKIT_GTK)
27 #include <gtk/gtk.h> 27 #include <gtk/gtk.h>
28 #endif 28 #endif
29 29
30 namespace gfx { 30 namespace gfx {
31 31
32 namespace { 32 namespace {
33 33
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); 177 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic));
178 render_text->SetText(ASCIIToUTF16("01234")); 178 render_text->SetText(ASCIIToUTF16("01234"));
179 expected_italic.resize(3); 179 expected_italic.resize(3);
180 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); 180 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic));
181 181
182 // Appending text should extend the terminal styles without changing breaks. 182 // Appending text should extend the terminal styles without changing breaks.
183 render_text->SetText(ASCIIToUTF16("012345678")); 183 render_text->SetText(ASCIIToUTF16("012345678"));
184 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); 184 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic));
185 } 185 }
186 186
187 #if defined(OS_LINUX) 187 #if defined(OS_LINUX) && !defined(USE_OZONE)
188 TEST_F(RenderTextTest, PangoAttributes) { 188 TEST_F(RenderTextTest, PangoAttributes) {
189 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 189 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
190 render_text->SetText(ASCIIToUTF16("012345678")); 190 render_text->SetText(ASCIIToUTF16("012345678"));
191 191
192 // Apply ranged BOLD/ITALIC styles and check the resulting Pango attributes. 192 // Apply ranged BOLD/ITALIC styles and check the resulting Pango attributes.
193 render_text->ApplyStyle(BOLD, true, Range(2, 4)); 193 render_text->ApplyStyle(BOLD, true, Range(2, 4));
194 render_text->ApplyStyle(ITALIC, true, Range(1, 3)); 194 render_text->ApplyStyle(ITALIC, true, Range(1, 3));
195 195
196 struct { 196 struct {
197 int start; 197 int start;
198 int end; 198 int end;
199 bool bold; 199 bool bold;
200 bool italic; 200 bool italic;
201 } cases[] = { 201 } cases[] = {
202 { 0, 1, false, false }, 202 { 0, 1, false, false },
203 { 1, 2, false, true }, 203 { 1, 2, false, true },
204 { 2, 3, true, true }, 204 { 2, 3, true, true },
205 { 3, 4, true, false }, 205 { 3, 4, true, false },
206 { 4, INT_MAX, false, false }, 206 { 4, INT_MAX, false, false },
207 }; 207 };
208 208
209 int start = 0, end = 0; 209 int start = 0, end = 0;
210 RenderTextLinux* rt_linux = static_cast<RenderTextLinux*>(render_text.get()); 210 RenderTextPango* rt_linux = static_cast<RenderTextPango*>(render_text.get());
211 rt_linux->EnsureLayout(); 211 rt_linux->EnsureLayout();
212 PangoAttrList* attributes = pango_layout_get_attributes(rt_linux->layout_); 212 PangoAttrList* attributes = pango_layout_get_attributes(rt_linux->layout_);
213 PangoAttrIterator* iter = pango_attr_list_get_iterator(attributes); 213 PangoAttrIterator* iter = pango_attr_list_get_iterator(attributes);
214 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 214 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
215 pango_attr_iterator_range(iter, &start, &end); 215 pango_attr_iterator_range(iter, &start, &end);
216 EXPECT_EQ(cases[i].start, start); 216 EXPECT_EQ(cases[i].start, start);
217 EXPECT_EQ(cases[i].end, end); 217 EXPECT_EQ(cases[i].end, end);
218 PangoFontDescription* font = pango_font_description_new(); 218 PangoFontDescription* font = pango_font_description_new();
219 pango_attr_iterator_get_font(iter, font, NULL, NULL); 219 pango_attr_iterator_get_font(iter, font, NULL, NULL);
220 char* description_string = pango_font_description_to_string(font); 220 char* description_string = pango_font_description_to_string(font);
(...skipping 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 render_text->SetText(WideToUTF16(L"x \x25B6 y")); 1744 render_text->SetText(WideToUTF16(L"x \x25B6 y"));
1745 render_text->EnsureLayout(); 1745 render_text->EnsureLayout();
1746 ASSERT_EQ(3U, render_text->runs_.size()); 1746 ASSERT_EQ(3U, render_text->runs_.size());
1747 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); 1747 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range);
1748 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); 1748 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range);
1749 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); 1749 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range);
1750 } 1750 }
1751 #endif // defined(OS_WIN) 1751 #endif // defined(OS_WIN)
1752 1752
1753 } // namespace gfx 1753 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text_pango.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698