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

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; 288 ui::Range bounds(render_text->GetGlyphBounds(0U));
msw 2013/05/23 21:07:27 nit: you can inline this call below and eliminate
Peter Kasting 2013/05/23 21:09:11 Good point.
289 ui::Range bounds;
290 render_text->GetGlyphBounds(0U, &bounds, &height);
291 EXPECT_EQ(render_text->GetStringSize().width(), 289 EXPECT_EQ(render_text->GetStringSize().width(),
292 static_cast<int>(bounds.length())); 290 static_cast<int>(bounds.length()));
293 291
294 // Cursoring is independent of underlying characters when text is obscured. 292 // Cursoring is independent of underlying characters when text is obscured.
295 const wchar_t* const texts[] = { 293 const wchar_t* const texts[] = {
296 kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl, 294 kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl,
297 L"hop on pop", // Check LTR word boundaries. 295 L"hop on pop", // Check LTR word boundaries.
298 L"\x05d0\x05d1 \x05d0\x05d2 \x05d1\x05d2", // Check RTL word boundaries. 296 L"\x05d0\x05d1 \x05d0\x05d2 \x05d1\x05d2", // Check RTL word boundaries.
299 }; 297 };
300 for (size_t i = 0; i < arraysize(texts); ++i) { 298 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, 1307 EXPECT_EQ(render_text->display_rect().width() - width - 1,
1310 render_text->GetUpdatedCursorBounds().x()); 1308 render_text->GetUpdatedCursorBounds().x());
1311 1309
1312 // Reset the application default text direction to LTR. 1310 // Reset the application default text direction to LTR.
1313 SetRTL(was_rtl); 1311 SetRTL(was_rtl);
1314 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); 1312 EXPECT_EQ(was_rtl, base::i18n::IsRTL());
1315 } 1313 }
1316 #endif // !defined(OS_MACOSX) 1314 #endif // !defined(OS_MACOSX)
1317 1315
1318 } // namespace gfx 1316 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698