OLD | NEW |
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" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 void SetRTL(bool rtl) { | 58 void SetRTL(bool rtl) { |
59 // Override the current locale/direction. | 59 // Override the current locale/direction. |
60 base::i18n::SetICUDefaultLocale(rtl ? "he" : "en"); | 60 base::i18n::SetICUDefaultLocale(rtl ? "he" : "en"); |
61 #if defined(TOOLKIT_GTK) | 61 #if defined(TOOLKIT_GTK) |
62 // Do the same for GTK, which does not rely on the ICU default locale. | 62 // Do the same for GTK, which does not rely on the ICU default locale. |
63 gtk_widget_set_default_direction(rtl ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); | 63 gtk_widget_set_default_direction(rtl ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); |
64 #endif | 64 #endif |
65 EXPECT_EQ(rtl, base::i18n::IsRTL()); | 65 EXPECT_EQ(rtl, base::i18n::IsRTL()); |
66 } | 66 } |
67 | 67 |
| 68 #if !defined(OS_MACOSX) |
68 // Ensure cursor movement in the specified |direction| yields |expected| values. | 69 // Ensure cursor movement in the specified |direction| yields |expected| values. |
69 void RunMoveCursorLeftRightTest(RenderText* render_text, | 70 void RunMoveCursorLeftRightTest(RenderText* render_text, |
70 const std::vector<SelectionModel>& expected, | 71 const std::vector<SelectionModel>& expected, |
71 VisualCursorDirection direction) { | 72 VisualCursorDirection direction) { |
72 for (size_t i = 0; i < expected.size(); ++i) { | 73 for (size_t i = 0; i < expected.size(); ++i) { |
73 SCOPED_TRACE(base::StringPrintf("Going %s; expected value index %d.", | 74 SCOPED_TRACE(base::StringPrintf("Going %s; expected value index %d.", |
74 direction == CURSOR_LEFT ? "left" : "right", static_cast<int>(i))); | 75 direction == CURSOR_LEFT ? "left" : "right", static_cast<int>(i))); |
75 EXPECT_EQ(expected[i], render_text->selection_model()); | 76 EXPECT_EQ(expected[i], render_text->selection_model()); |
76 render_text->MoveCursor(CHARACTER_BREAK, direction, false); | 77 render_text->MoveCursor(CHARACTER_BREAK, direction, false); |
77 } | 78 } |
78 // Check that cursoring is clamped at the line edge. | 79 // Check that cursoring is clamped at the line edge. |
79 EXPECT_EQ(expected.back(), render_text->selection_model()); | 80 EXPECT_EQ(expected.back(), render_text->selection_model()); |
80 // Check that it is the line edge. | 81 // Check that it is the line edge. |
81 render_text->MoveCursor(LINE_BREAK, direction, false); | 82 render_text->MoveCursor(LINE_BREAK, direction, false); |
82 EXPECT_EQ(expected.back(), render_text->selection_model()); | 83 EXPECT_EQ(expected.back(), render_text->selection_model()); |
83 } | 84 } |
| 85 #endif // !defined(OS_MACOSX) |
84 | 86 |
85 } // namespace | 87 } // namespace |
86 | 88 |
87 class RenderTextTest : public testing::Test { | 89 class RenderTextTest : public testing::Test { |
88 }; | 90 }; |
89 | 91 |
90 TEST_F(RenderTextTest, DefaultStyle) { | 92 TEST_F(RenderTextTest, DefaultStyle) { |
91 // Check the default styles applied to new instances and adjusted text. | 93 // Check the default styles applied to new instances and adjusted text. |
92 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 94 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
93 EXPECT_TRUE(render_text->text().empty()); | 95 EXPECT_TRUE(render_text->text().empty()); |
(...skipping 1650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1744 render_text->SetText(WideToUTF16(L"x \x25B6 y")); | 1746 render_text->SetText(WideToUTF16(L"x \x25B6 y")); |
1745 render_text->EnsureLayout(); | 1747 render_text->EnsureLayout(); |
1746 ASSERT_EQ(3U, render_text->runs_.size()); | 1748 ASSERT_EQ(3U, render_text->runs_.size()); |
1747 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); | 1749 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); |
1748 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); | 1750 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); |
1749 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); | 1751 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); |
1750 } | 1752 } |
1751 #endif // defined(OS_WIN) | 1753 #endif // defined(OS_WIN) |
1752 | 1754 |
1753 } // namespace gfx | 1755 } // namespace gfx |
OLD | NEW |