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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/gfx/break_list.h" | 10 #include "ui/gfx/break_list.h" |
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 } | 1101 } |
1102 | 1102 |
1103 // Make sure the caret width is always >=1 so that the correct | 1103 // Make sure the caret width is always >=1 so that the correct |
1104 // caret is drawn at high DPI. crbug.com/164100. | 1104 // caret is drawn at high DPI. crbug.com/164100. |
1105 TEST_F(RenderTextTest, CaretWidth) { | 1105 TEST_F(RenderTextTest, CaretWidth) { |
1106 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1106 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1107 render_text->SetText(ASCIIToUTF16("abcdefg")); | 1107 render_text->SetText(ASCIIToUTF16("abcdefg")); |
1108 EXPECT_GE(render_text->GetUpdatedCursorBounds().width(), 1); | 1108 EXPECT_GE(render_text->GetUpdatedCursorBounds().width(), 1); |
1109 } | 1109 } |
1110 | 1110 |
| 1111 // Make sure the last word is selected when the cursor is at text.length(). |
| 1112 TEST_F(RenderTextTest, LastWordSelected) { |
| 1113 const std::string kTestURL1 = "http://www.google.com"; |
| 1114 const std::string kTestURL2 = "http://www.google.com/something/"; |
| 1115 |
| 1116 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| 1117 |
| 1118 render_text->SetText(ASCIIToUTF16(kTestURL1)); |
| 1119 render_text->SetCursorPosition(kTestURL1.length()); |
| 1120 render_text->SelectWord(); |
| 1121 EXPECT_EQ(ui::Range(kTestURL1.length() - 3, kTestURL1.length()), |
| 1122 render_text->selection()); |
| 1123 |
| 1124 render_text->SetText(ASCIIToUTF16(kTestURL2)); |
| 1125 render_text->SetCursorPosition(kTestURL2.length()); |
| 1126 render_text->SelectWord(); |
| 1127 EXPECT_EQ(ui::Range(kTestURL2.length() - 1, kTestURL2.length()), |
| 1128 render_text->selection()); |
| 1129 } |
| 1130 |
1111 // TODO(asvitkine): Cursor movements tests disabled on Mac because RenderTextMac | 1131 // TODO(asvitkine): Cursor movements tests disabled on Mac because RenderTextMac |
1112 // does not implement this yet. http://crbug.com/131618 | 1132 // does not implement this yet. http://crbug.com/131618 |
1113 #if !defined(OS_MACOSX) | 1133 #if !defined(OS_MACOSX) |
1114 TEST_F(RenderTextTest, DisplayRectShowsCursorLTR) { | 1134 TEST_F(RenderTextTest, DisplayRectShowsCursorLTR) { |
1115 ASSERT_FALSE(base::i18n::IsRTL()); | 1135 ASSERT_FALSE(base::i18n::IsRTL()); |
1116 ASSERT_FALSE(base::i18n::ICUIsRTL()); | 1136 ASSERT_FALSE(base::i18n::ICUIsRTL()); |
1117 | 1137 |
1118 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1138 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1119 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg")); | 1139 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg")); |
1120 render_text->MoveCursorTo(SelectionModel(render_text->text().length(), | 1140 render_text->MoveCursorTo(SelectionModel(render_text->text().length(), |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 EXPECT_EQ(render_text->display_rect().width() - width - 1, | 1244 EXPECT_EQ(render_text->display_rect().width() - width - 1, |
1225 render_text->GetUpdatedCursorBounds().x()); | 1245 render_text->GetUpdatedCursorBounds().x()); |
1226 | 1246 |
1227 // Reset the application default text direction to LTR. | 1247 // Reset the application default text direction to LTR. |
1228 SetRTL(was_rtl); | 1248 SetRTL(was_rtl); |
1229 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); | 1249 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); |
1230 } | 1250 } |
1231 #endif // !defined(OS_MACOSX) | 1251 #endif // !defined(OS_MACOSX) |
1232 | 1252 |
1233 } // namespace gfx | 1253 } // namespace gfx |
OLD | NEW |