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

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

Issue 15746013: Fix cursor positioning regression from r201136. GetCursorPos() shouldn't assume (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 7 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
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 "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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // FindCursorPosition() should not return positions between a surrogate pair. 278 // FindCursorPosition() should not return positions between a surrogate pair.
279 render_text->SetDisplayRect(Rect(0, 0, 20, 20)); 279 render_text->SetDisplayRect(Rect(0, 0, 20, 20));
280 EXPECT_EQ(render_text->FindCursorPosition(Point(0, 0)).caret_pos(), 0U); 280 EXPECT_EQ(render_text->FindCursorPosition(Point(0, 0)).caret_pos(), 0U);
281 EXPECT_EQ(render_text->FindCursorPosition(Point(20, 0)).caret_pos(), 2U); 281 EXPECT_EQ(render_text->FindCursorPosition(Point(20, 0)).caret_pos(), 2U);
282 for (int x = -1; x <= 20; ++x) { 282 for (int x = -1; x <= 20; ++x) {
283 SelectionModel selection = render_text->FindCursorPosition(Point(x, 0)); 283 SelectionModel selection = render_text->FindCursorPosition(Point(x, 0));
284 EXPECT_TRUE(selection.caret_pos() == 0U || selection.caret_pos() == 2U); 284 EXPECT_TRUE(selection.caret_pos() == 0U || selection.caret_pos() == 2U);
285 } 285 }
286 286
287 // GetGlyphBounds() should yield the entire string bounds for text index 0. 287 // GetGlyphBounds() should yield the entire string bounds for text index 0.
288 int height = 0;
289 ui::Range bounds; 288 ui::Range bounds;
290 render_text->GetGlyphBounds(0U, &bounds, &height); 289 render_text->GetGlyphBounds(0U, &bounds);
291 EXPECT_EQ(render_text->GetStringSize().width(), 290 EXPECT_EQ(render_text->GetStringSize().width(),
292 static_cast<int>(bounds.length())); 291 static_cast<int>(bounds.length()));
293 292
294 // Cursoring is independent of underlying characters when text is obscured. 293 // Cursoring is independent of underlying characters when text is obscured.
295 const wchar_t* const texts[] = { 294 const wchar_t* const texts[] = {
296 kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl, 295 kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl,
297 L"hop on pop", // Check LTR word boundaries. 296 L"hop on pop", // Check LTR word boundaries.
298 L"\x05d0\x05d1 \x05d0\x05d2 \x05d1\x05d2", // Check RTL word boundaries. 297 L"\x05d0\x05d1 \x05d0\x05d2 \x05d1\x05d2", // Check RTL word boundaries.
299 }; 298 };
300 for (size_t i = 0; i < arraysize(texts); ++i) { 299 for (size_t i = 0; i < arraysize(texts); ++i) {
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 EXPECT_EQ(render_text->display_rect().width() - width - 1, 1308 EXPECT_EQ(render_text->display_rect().width() - width - 1,
1310 render_text->GetUpdatedCursorBounds().x()); 1309 render_text->GetUpdatedCursorBounds().x());
1311 1310
1312 // Reset the application default text direction to LTR. 1311 // Reset the application default text direction to LTR.
1313 SetRTL(was_rtl); 1312 SetRTL(was_rtl);
1314 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); 1313 EXPECT_EQ(was_rtl, base::i18n::IsRTL());
1315 } 1314 }
1316 #endif // !defined(OS_MACOSX) 1315 #endif // !defined(OS_MACOSX)
1317 1316
1318 } // namespace gfx 1317 } // namespace gfx
OLDNEW
« ui/gfx/render_text.h ('K') | « ui/gfx/render_text_mac.cc ('k') | ui/gfx/render_text_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698