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

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

Issue 9390022: Simplify handling of BiDi cursor movement (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 9 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/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 EXPECT_EQ(1U, render_text->style_ranges().size()); 280 EXPECT_EQ(1U, render_text->style_ranges().size());
281 EXPECT_EQ(ui::Range(0, 1), render_text->style_ranges()[0].range); 281 EXPECT_EQ(ui::Range(0, 1), render_text->style_ranges()[0].range);
282 } 282 }
283 283
284 void TestVisualCursorMotionInObscuredField(RenderText* render_text, 284 void TestVisualCursorMotionInObscuredField(RenderText* render_text,
285 const string16& text, 285 const string16& text,
286 bool select) { 286 bool select) {
287 render_text->SetText(text); 287 render_text->SetText(text);
288 int len = text.length(); 288 int len = text.length();
289 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, select); 289 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, select);
290 EXPECT_TRUE(render_text->selection_model().Equals(SelectionModel( 290 EXPECT_EQ(SelectionModel(ui::Range(select ? 0 : len, len), CURSOR_FORWARD),
291 select ? 0 : len, len, len - 1, SelectionModel::TRAILING))); 291 render_text->selection_model());
292 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, select); 292 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, select);
293 EXPECT_TRUE(render_text->selection_model().Equals(SelectionModel( 293 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model());
294 0, 0, SelectionModel::LEADING)));
295 for (int j = 1; j <= len; ++j) { 294 for (int j = 1; j <= len; ++j) {
296 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, select); 295 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, select);
297 EXPECT_TRUE(render_text->selection_model().Equals(SelectionModel( 296 EXPECT_EQ(SelectionModel(ui::Range(select ? 0 : j, j), CURSOR_BACKWARD),
298 select ? 0 : j, j, j - 1, SelectionModel::TRAILING))); 297 render_text->selection_model());
299 } 298 }
300 for (int j = len - 1; j >= 0; --j) { 299 for (int j = len - 1; j >= 0; --j) {
301 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, select); 300 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, select);
302 EXPECT_TRUE(render_text->selection_model().Equals(SelectionModel( 301 EXPECT_EQ(SelectionModel(ui::Range(select ? 0 : j, j), CURSOR_FORWARD),
303 select ? 0 : j, j, j, SelectionModel::LEADING))); 302 render_text->selection_model());
304 } 303 }
305 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, select); 304 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, select);
306 EXPECT_TRUE(render_text->selection_model().Equals(SelectionModel( 305 EXPECT_EQ(SelectionModel(ui::Range(select ? 0 : len, len), CURSOR_FORWARD),
307 select ? 0 : len, len, len - 1, SelectionModel::TRAILING))); 306 render_text->selection_model());
308 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, select); 307 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, select);
309 EXPECT_TRUE(render_text->selection_model().Equals(SelectionModel( 308 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model());
310 0, 0, SelectionModel::LEADING)));
311 } 309 }
312 310
313 TEST_F(RenderTextTest, PasswordCensorship) { 311 TEST_F(RenderTextTest, PasswordCensorship) {
314 const string16 seuss = ASCIIToUTF16("hop on pop"); 312 const string16 seuss = ASCIIToUTF16("hop on pop");
315 const string16 no_seuss = ASCIIToUTF16("**********"); 313 const string16 no_seuss = ASCIIToUTF16("**********");
316 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 314 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
317 315
318 // GetObscuredText returns asterisks when the obscured bit is set. 316 // GetObscuredText returns asterisks when the obscured bit is set.
319 render_text->SetText(seuss); 317 render_text->SetText(seuss);
320 render_text->SetObscured(true); 318 render_text->SetObscured(true);
321 EXPECT_EQ(seuss, render_text->text()); 319 EXPECT_EQ(seuss, render_text->text());
322 EXPECT_EQ(no_seuss, render_text->GetDisplayText()); 320 EXPECT_EQ(no_seuss, render_text->GetDisplayText());
323 render_text->SetObscured(false); 321 render_text->SetObscured(false);
324 EXPECT_EQ(seuss, render_text->text()); 322 EXPECT_EQ(seuss, render_text->text());
325 EXPECT_EQ(seuss, render_text->GetDisplayText()); 323 EXPECT_EQ(seuss, render_text->GetDisplayText());
326 324
327 // TODO(benrg): No Windows implementation yet. 325 // TODO(benrg): No Windows implementation yet.
328 #if !defined(OS_WIN) 326 #if !defined(OS_WIN)
329 327
330 render_text->SetObscured(true); 328 render_text->SetObscured(true);
331 329
332 // Surrogate pairs are counted as one code point. 330 // Surrogate pairs are counted as one code point.
333 const char16 invalid_surrogates[] = {0xDC00, 0xD800, 0}; 331 const char16 invalid_surrogates[] = {0xDC00, 0xD800, 0};
334 render_text->SetText(invalid_surrogates); 332 render_text->SetText(invalid_surrogates);
335 EXPECT_EQ(ASCIIToUTF16("**"), render_text->GetDisplayText()); 333 EXPECT_EQ(ASCIIToUTF16("**"), render_text->GetDisplayText());
336 const char16 valid_surrogates[] = {0xD800, 0xDC00, 0}; 334 const char16 valid_surrogates[] = {0xD800, 0xDC00, 0};
337 render_text->SetText(valid_surrogates); 335 render_text->SetText(valid_surrogates);
338 EXPECT_EQ(ASCIIToUTF16("*"), render_text->GetDisplayText()); 336 EXPECT_EQ(ASCIIToUTF16("*"), render_text->GetDisplayText());
339 EXPECT_EQ(0U, render_text->GetCursorPosition()); 337 EXPECT_EQ(0U, render_text->cursor_position());
340 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); 338 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
341 EXPECT_EQ(2U, render_text->GetCursorPosition()); 339 EXPECT_EQ(2U, render_text->cursor_position());
342 340
343 // Cursoring is independent of the underlying characters when the text is 341 // Cursoring is independent of the underlying characters when the text is
344 // obscured. 342 // obscured.
345 const wchar_t* const texts[] = { 343 const wchar_t* const texts[] = {
346 L"hop on pop", // word boundaries 344 L"hop on pop", // word boundaries
347 L"ab \x5D0\x5D1" L"12", // bidi embedding level of 2 345 L"ab \x5D0\x5D1" L"12", // bidi embedding level of 2
348 L"\x5D0\x5D1" L"12", // RTL paragraph direction on Linux 346 L"\x5D0\x5D1" L"12", // RTL paragraph direction on Linux
349 L"\x5D0\x5D1" // pure RTL 347 L"\x5D0\x5D1" // pure RTL
350 }; 348 };
351 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(texts); ++i) { 349 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(texts); ++i) {
352 string16 text = WideToUTF16(texts[i]); 350 string16 text = WideToUTF16(texts[i]);
353 TestVisualCursorMotionInObscuredField(render_text.get(), text, false); 351 TestVisualCursorMotionInObscuredField(render_text.get(), text, false);
354 TestVisualCursorMotionInObscuredField(render_text.get(), text, true); 352 TestVisualCursorMotionInObscuredField(render_text.get(), text, true);
355 } 353 }
356 #endif // !defined(OS_WIN) 354 #endif // !defined(OS_WIN)
357 } 355 }
358 356
359 void RunMoveCursorLeftRightTest(RenderText* render_text, 357 void RunMoveCursorLeftRightTest(RenderText* render_text,
360 const std::vector<SelectionModel>& expected, 358 const std::vector<SelectionModel>& expected,
361 bool move_right) { 359 VisualCursorDirection direction) {
362 for (int i = 0; i < static_cast<int>(expected.size()); ++i) { 360 for (size_t i = 0; i < expected.size(); ++i) {
363 SelectionModel sel = expected[i]; 361 EXPECT_EQ(expected[i], render_text->selection_model());
364 EXPECT_TRUE(render_text->selection_model().Equals(sel)); 362 render_text->MoveCursor(CHARACTER_BREAK, direction, false);
365 if (move_right)
366 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
367 else
368 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false);
369 } 363 }
370 364 // Check that cursoring is clamped at the line edge.
371 SelectionModel sel = expected[expected.size() - 1]; 365 EXPECT_EQ(expected.back(), render_text->selection_model());
372 if (move_right) 366 // Check that it is the line edge.
373 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 367 render_text->MoveCursor(LINE_BREAK, direction, false);
374 else 368 EXPECT_EQ(expected.back(), render_text->selection_model());
375 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false);
376 EXPECT_TRUE(render_text->selection_model().Equals(sel));
377 } 369 }
378 370
379 TEST_F(RenderTextTest, MoveCursorLeftRightInLtr) { 371 TEST_F(RenderTextTest, MoveCursorLeftRightInLtr) {
380 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 372 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
381 373
382 // Pure LTR. 374 // Pure LTR.
383 render_text->SetText(ASCIIToUTF16("abc")); 375 render_text->SetText(ASCIIToUTF16("abc"));
384 // |expected| saves the expected SelectionModel when moving cursor from left 376 // |expected| saves the expected SelectionModel when moving cursor from left
385 // to right. 377 // to right.
386 std::vector<SelectionModel> expected; 378 std::vector<SelectionModel> expected;
387 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 379 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
388 expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING)); 380 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
389 expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING)); 381 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
390 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 382 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
391 // The last element is to test the clamped line ends. 383 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
392 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 384 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT);
393 RunMoveCursorLeftRightTest(render_text.get(), expected, true);
394 385
395 expected.clear(); 386 expected.clear();
396 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 387 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
397 expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING)); 388 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
398 expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING)); 389 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
399 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 390 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
400 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 391 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
401 RunMoveCursorLeftRightTest(render_text.get(), expected, false); 392 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT);
402 } 393 }
403 394
404 TEST_F(RenderTextTest, MoveCursorLeftRightInLtrRtl) { 395 TEST_F(RenderTextTest, MoveCursorLeftRightInLtrRtl) {
405 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 396 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
406 // LTR-RTL 397 // LTR-RTL
407 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); 398 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2"));
408 // The last one is the expected END position. 399 // The last one is the expected END position.
409 std::vector<SelectionModel> expected; 400 std::vector<SelectionModel> expected;
410 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 401 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
411 expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING)); 402 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
412 expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING)); 403 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
413 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 404 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
414 expected.push_back(SelectionModel(5, 5, SelectionModel::LEADING)); 405 expected.push_back(SelectionModel(5, CURSOR_FORWARD));
415 expected.push_back(SelectionModel(4, 4, SelectionModel::LEADING)); 406 expected.push_back(SelectionModel(4, CURSOR_FORWARD));
416 expected.push_back(SelectionModel(3, 3, SelectionModel::LEADING)); 407 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
417 expected.push_back(SelectionModel(6, 3, SelectionModel::LEADING)); 408 expected.push_back(SelectionModel(6, CURSOR_FORWARD));
418 expected.push_back(SelectionModel(6, 3, SelectionModel::LEADING)); 409 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT);
419 RunMoveCursorLeftRightTest(render_text.get(), expected, true);
420 410
421 expected.clear(); 411 expected.clear();
422 expected.push_back(SelectionModel(6, 3, SelectionModel::LEADING)); 412 expected.push_back(SelectionModel(6, CURSOR_FORWARD));
423 expected.push_back(SelectionModel(4, 3, SelectionModel::TRAILING)); 413 expected.push_back(SelectionModel(4, CURSOR_BACKWARD));
424 expected.push_back(SelectionModel(5, 4, SelectionModel::TRAILING)); 414 expected.push_back(SelectionModel(5, CURSOR_BACKWARD));
425 expected.push_back(SelectionModel(6, 5, SelectionModel::TRAILING)); 415 expected.push_back(SelectionModel(6, CURSOR_BACKWARD));
426 expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING)); 416 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
427 expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING)); 417 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
428 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 418 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
429 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 419 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
430 RunMoveCursorLeftRightTest(render_text.get(), expected, false); 420 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT);
431 } 421 }
432 422
433 TEST_F(RenderTextTest, MoveCursorLeftRightInLtrRtlLtr) { 423 TEST_F(RenderTextTest, MoveCursorLeftRightInLtrRtlLtr) {
434 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 424 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
435 // LTR-RTL-LTR. 425 // LTR-RTL-LTR.
436 render_text->SetText(WideToUTF16(L"a"L"\x05d1"L"b")); 426 render_text->SetText(WideToUTF16(L"a"L"\x05d1"L"b"));
437 std::vector<SelectionModel> expected; 427 std::vector<SelectionModel> expected;
438 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 428 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
439 expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING)); 429 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
440 expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING)); 430 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
441 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 431 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
442 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 432 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
443 RunMoveCursorLeftRightTest(render_text.get(), expected, true); 433 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT);
444 434
445 expected.clear(); 435 expected.clear();
446 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 436 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
447 expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING)); 437 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
448 expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING)); 438 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
449 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 439 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
450 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 440 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
451 RunMoveCursorLeftRightTest(render_text.get(), expected, false); 441 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT);
452 } 442 }
453 443
454 TEST_F(RenderTextTest, MoveCursorLeftRightInRtl) { 444 TEST_F(RenderTextTest, MoveCursorLeftRightInRtl) {
455 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 445 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
456 // Pure RTL. 446 // Pure RTL.
457 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2")); 447 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"));
458 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 448 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false);
459 std::vector<SelectionModel> expected; 449 std::vector<SelectionModel> expected;
460 450
461 #if defined(OS_LINUX) 451 #if defined(OS_LINUX)
462 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 452 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
463 #else 453 #else
464 expected.push_back(SelectionModel(3, 0, SelectionModel::LEADING)); 454 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
465 #endif 455 #endif
466 expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING)); 456 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
467 expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING)); 457 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
468 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 458 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
469 #if defined(OS_LINUX) 459 #if defined(OS_LINUX)
470 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 460 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
471 #else 461 #else
472 expected.push_back(SelectionModel(0, 2, SelectionModel::TRAILING)); 462 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
473 // TODO(xji): expected (0, 2, TRAILING), actual (3, 0, LEADING).
474 // cursor moves from leftmost to rightmost.
475 // expected.push_back(SelectionModel(0, 2, SelectionModel::TRAILING));
476 #endif 463 #endif
477 RunMoveCursorLeftRightTest(render_text.get(), expected, false); 464 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT);
478 465
479 expected.clear(); 466 expected.clear();
480 467
481 #if defined(OS_LINUX) 468 #if defined(OS_LINUX)
482 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 469 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
483 #else 470 #else
484 expected.push_back(SelectionModel(0, 2, SelectionModel::TRAILING)); 471 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
485 #endif 472 #endif
486 expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING)); 473 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
487 expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING)); 474 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
488 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 475 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
489 #if defined(OS_LINUX) 476 #if defined(OS_LINUX)
490 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 477 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
491 #else 478 #else
492 expected.push_back(SelectionModel(3, 0, SelectionModel::LEADING)); 479 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
493 expected.push_back(SelectionModel(3, 0, SelectionModel::LEADING));
494 #endif 480 #endif
495 RunMoveCursorLeftRightTest(render_text.get(), expected, true); 481 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT);
496 } 482 }
497 483
498 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtr) { 484 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtr) {
499 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 485 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
500 // RTL-LTR 486 // RTL-LTR
501 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"L"abc")); 487 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"L"abc"));
502 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 488 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false);
503 std::vector<SelectionModel> expected; 489 std::vector<SelectionModel> expected;
504 #if defined(OS_LINUX) 490 #if defined(OS_LINUX)
505 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 491 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
506 expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING)); 492 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
507 expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING)); 493 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
508 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 494 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
509 expected.push_back(SelectionModel(5, 5, SelectionModel::LEADING)); 495 expected.push_back(SelectionModel(5, CURSOR_FORWARD));
510 expected.push_back(SelectionModel(4, 4, SelectionModel::LEADING)); 496 expected.push_back(SelectionModel(4, CURSOR_FORWARD));
511 expected.push_back(SelectionModel(3, 3, SelectionModel::LEADING)); 497 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
512 expected.push_back(SelectionModel(6, 3, SelectionModel::LEADING)); 498 expected.push_back(SelectionModel(6, CURSOR_FORWARD));
513 expected.push_back(SelectionModel(6, 3, SelectionModel::LEADING));
514 #else 499 #else
515 expected.push_back(SelectionModel(6, 5, SelectionModel::TRAILING)); 500 expected.push_back(SelectionModel(6, CURSOR_BACKWARD));
516 expected.push_back(SelectionModel(5, 5, SelectionModel::LEADING)); 501 expected.push_back(SelectionModel(5, CURSOR_FORWARD));
517 expected.push_back(SelectionModel(4, 4, SelectionModel::LEADING)); 502 expected.push_back(SelectionModel(4, CURSOR_FORWARD));
518 expected.push_back(SelectionModel(3, 3, SelectionModel::LEADING)); 503 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
519 expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING)); 504 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
520 expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING)); 505 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
521 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 506 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
522 expected.push_back(SelectionModel(0, 2, SelectionModel::TRAILING)); 507 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
523 // TODO(xji): expected (0, 2, TRAILING), actual (3, 0, LEADING).
524 // cursor moves from leftmost to middle.
525 // expected.push_back(SelectionModel(0, 2, SelectionModel::TRAILING));
526 #endif 508 #endif
527 509
528 RunMoveCursorLeftRightTest(render_text.get(), expected, false); 510 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT);
529 511
530 expected.clear(); 512 expected.clear();
531 #if defined(OS_LINUX) 513 #if defined(OS_LINUX)
532 expected.push_back(SelectionModel(6, 3, SelectionModel::LEADING)); 514 expected.push_back(SelectionModel(6, CURSOR_FORWARD));
533 expected.push_back(SelectionModel(4, 3, SelectionModel::TRAILING)); 515 expected.push_back(SelectionModel(4, CURSOR_BACKWARD));
534 expected.push_back(SelectionModel(5, 4, SelectionModel::TRAILING)); 516 expected.push_back(SelectionModel(5, CURSOR_BACKWARD));
535 expected.push_back(SelectionModel(6, 5, SelectionModel::TRAILING)); 517 expected.push_back(SelectionModel(6, CURSOR_BACKWARD));
536 expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING)); 518 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
537 expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING)); 519 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
538 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 520 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
539 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 521 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
540 #else 522 #else
541 expected.push_back(SelectionModel(0, 2, SelectionModel::TRAILING)); 523 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
542 expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING)); 524 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
543 expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING)); 525 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
544 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 526 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
545 expected.push_back(SelectionModel(4, 3, SelectionModel::TRAILING)); 527 expected.push_back(SelectionModel(4, CURSOR_BACKWARD));
546 expected.push_back(SelectionModel(5, 4, SelectionModel::TRAILING)); 528 expected.push_back(SelectionModel(5, CURSOR_BACKWARD));
547 expected.push_back(SelectionModel(6, 5, SelectionModel::TRAILING)); 529 expected.push_back(SelectionModel(6, CURSOR_BACKWARD));
548 expected.push_back(SelectionModel(6, 5, SelectionModel::TRAILING));
549 #endif 530 #endif
550 RunMoveCursorLeftRightTest(render_text.get(), expected, true); 531 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT);
551 } 532 }
552 533
553 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) { 534 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) {
554 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 535 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
555 // RTL-LTR-RTL. 536 // RTL-LTR-RTL.
556 render_text->SetText(WideToUTF16(L"\x05d0"L"a"L"\x05d1")); 537 render_text->SetText(WideToUTF16(L"\x05d0"L"a"L"\x05d1"));
557 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 538 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false);
558 std::vector<SelectionModel> expected; 539 std::vector<SelectionModel> expected;
559 #if defined(OS_LINUX) 540 #if defined(OS_LINUX)
560 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 541 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
561 expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING)); 542 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
562 expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING)); 543 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
563 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 544 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
564 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 545 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
565 #else 546 #else
566 expected.push_back(SelectionModel(3, 2, SelectionModel::LEADING)); 547 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
567 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 548 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
568 expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING)); 549 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
569 expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING)); 550 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
570 expected.push_back(SelectionModel(0, 0, SelectionModel::TRAILING)); 551 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
571 // TODO(xji): expected (0, 0, TRAILING), actual (2, 1, LEADING).
572 // cursor moves from leftmost to middle.
573 // expected.push_back(SelectionModel(0, 0, SelectionModel::TRAILING));
574 #endif 552 #endif
575 RunMoveCursorLeftRightTest(render_text.get(), expected, false); 553 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT);
576 554
577 expected.clear(); 555 expected.clear();
578 #if defined(OS_LINUX) 556 #if defined(OS_LINUX)
579 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); 557 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
580 expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING)); 558 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
581 expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING)); 559 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
582 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 560 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
583 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 561 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
584 #else 562 #else
585 expected.push_back(SelectionModel(0, 0, SelectionModel::TRAILING)); 563 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
586 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); 564 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
587 expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING)); 565 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
588 expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING)); 566 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
589 expected.push_back(SelectionModel(3, 2, SelectionModel::LEADING)); 567 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
590 expected.push_back(SelectionModel(3, 2, SelectionModel::LEADING));
591 #endif 568 #endif
592 RunMoveCursorLeftRightTest(render_text.get(), expected, true); 569 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT);
593 } 570 }
594 571
595 // TODO(xji): temporarily disable in platform Win since the complex script 572 // TODO(xji): temporarily disable in platform Win since the complex script
596 // characters turned into empty square due to font regression. So, not able 573 // characters turned into empty square due to font regression. So, not able
597 // to test 2 characters belong to the same grapheme. 574 // to test 2 characters belong to the same grapheme.
598 #if defined(OS_LINUX) 575 #if defined(OS_LINUX)
599 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) { 576 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) {
600 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 577 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
601 578
602 render_text->SetText(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); 579 render_text->SetText(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"));
603 EXPECT_EQ(0U, render_text->GetCursorPosition()); 580 EXPECT_EQ(0U, render_text->cursor_position());
604 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); 581 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
605 EXPECT_EQ(2U, render_text->GetCursorPosition()); 582 EXPECT_EQ(2U, render_text->cursor_position());
606 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); 583 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
607 EXPECT_EQ(4U, render_text->GetCursorPosition()); 584 EXPECT_EQ(4U, render_text->cursor_position());
608 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); 585 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
609 EXPECT_EQ(5U, render_text->GetCursorPosition()); 586 EXPECT_EQ(5U, render_text->cursor_position());
610 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); 587 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
611 EXPECT_EQ(5U, render_text->GetCursorPosition()); 588 EXPECT_EQ(5U, render_text->cursor_position());
612 589
613 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); 590 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false);
614 EXPECT_EQ(4U, render_text->GetCursorPosition()); 591 EXPECT_EQ(4U, render_text->cursor_position());
615 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); 592 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false);
616 EXPECT_EQ(2U, render_text->GetCursorPosition()); 593 EXPECT_EQ(2U, render_text->cursor_position());
617 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); 594 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false);
618 EXPECT_EQ(0U, render_text->GetCursorPosition()); 595 EXPECT_EQ(0U, render_text->cursor_position());
619 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); 596 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false);
620 EXPECT_EQ(0U, render_text->GetCursorPosition()); 597 EXPECT_EQ(0U, render_text->cursor_position());
621 } 598 }
622 #endif 599 #endif
623 600
624 TEST_F(RenderTextTest, GraphemePositions) { 601 TEST_F(RenderTextTest, GraphemePositions) {
625 // LTR 2-character grapheme, LTR abc, LTR 2-character grapheme. 602 // LTR 2-character grapheme, LTR abc, LTR 2-character grapheme.
626 const string16 kText1 = WideToUTF16(L"\x0915\x093f"L"abc"L"\x0915\x093f"); 603 const string16 kText1 = WideToUTF16(L"\x0915\x093f"L"abc"L"\x0915\x093f");
627 604
628 // LTR ab, LTR 2-character grapheme, LTR cd. 605 // LTR ab, LTR 2-character grapheme, LTR cd.
629 const string16 kText2 = WideToUTF16(L"ab"L"\x0915\x093f"L"cd"); 606 const string16 kText2 = WideToUTF16(L"ab"L"\x0915\x093f"L"cd");
630 607
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 EXPECT_EQ(cases[i].expected_next, next); 651 EXPECT_EQ(cases[i].expected_next, next);
675 EXPECT_TRUE(render_text->IsCursorablePosition(next)); 652 EXPECT_TRUE(render_text->IsCursorablePosition(next));
676 653
677 size_t previous = render_text->IndexOfAdjacentGrapheme(cases[i].index, 654 size_t previous = render_text->IndexOfAdjacentGrapheme(cases[i].index,
678 CURSOR_BACKWARD); 655 CURSOR_BACKWARD);
679 EXPECT_EQ(cases[i].expected_previous, previous); 656 EXPECT_EQ(cases[i].expected_previous, previous);
680 EXPECT_TRUE(render_text->IsCursorablePosition(previous)); 657 EXPECT_TRUE(render_text->IsCursorablePosition(previous));
681 } 658 }
682 } 659 }
683 660
684 TEST_F(RenderTextTest, SelectionModels) { 661 TEST_F(RenderTextTest, EdgeSelectionModels) {
685 // Simple Latin text. 662 // Simple Latin text.
686 const string16 kLatin = WideToUTF16(L"abc"); 663 const string16 kLatin = WideToUTF16(L"abc");
687 // LTR 2-character grapheme. 664 // LTR 2-character grapheme.
688 const string16 kLTRGrapheme = WideToUTF16(L"\x0915\x093f"); 665 const string16 kLTRGrapheme = WideToUTF16(L"\x0915\x093f");
689 // LTR 2-character grapheme, LTR a, LTR 2-character grapheme. 666 // LTR 2-character grapheme, LTR a, LTR 2-character grapheme.
690 const string16 kHindiLatin = WideToUTF16(L"\x0915\x093f"L"a"L"\x0915\x093f"); 667 const string16 kHindiLatin = WideToUTF16(L"\x0915\x093f"L"a"L"\x0915\x093f");
691 // RTL 2-character grapheme. 668 // RTL 2-character grapheme.
692 const string16 kRTLGrapheme = WideToUTF16(L"\x05e0\x05b8"); 669 const string16 kRTLGrapheme = WideToUTF16(L"\x05e0\x05b8");
693 // RTL 2-character grapheme, LTR a, RTL 2-character grapheme. 670 // RTL 2-character grapheme, LTR a, RTL 2-character grapheme.
694 const string16 kHebrewLatin = WideToUTF16(L"\x05e0\x05b8"L"a"L"\x05e0\x05b8"); 671 const string16 kHebrewLatin = WideToUTF16(L"\x05e0\x05b8"L"a"L"\x05e0\x05b8");
695 672
696 struct { 673 struct {
697 string16 text; 674 string16 text;
698 size_t expected_left_end_caret; 675 base::i18n::TextDirection expected_text_direction;
699 SelectionModel::CaretPlacement expected_left_end_placement;
700 size_t expected_right_end_caret;
701 SelectionModel::CaretPlacement expected_right_end_placement;
702 } cases[] = { 676 } cases[] = {
703 { string16(), 0, SelectionModel::LEADING, 0, SelectionModel::LEADING }, 677 { string16(), base::i18n::LEFT_TO_RIGHT },
704 { kLatin, 0, SelectionModel::LEADING, 2, SelectionModel::TRAILING }, 678 { kLatin, base::i18n::LEFT_TO_RIGHT },
705 { kLTRGrapheme, 0, SelectionModel::LEADING, 0, SelectionModel::TRAILING }, 679 { kLTRGrapheme, base::i18n::LEFT_TO_RIGHT },
706 { kHindiLatin, 0, SelectionModel::LEADING, 3, SelectionModel::TRAILING }, 680 { kHindiLatin, base::i18n::LEFT_TO_RIGHT },
707 { kRTLGrapheme, 0, SelectionModel::TRAILING, 0, SelectionModel::LEADING }, 681 { kRTLGrapheme, base::i18n::RIGHT_TO_LEFT },
708 #if defined(OS_LINUX) 682 #if defined(OS_LINUX)
709 // On Linux, the whole string is displayed RTL, rather than individual runs. 683 // On Linux, the whole string is displayed RTL, rather than individual runs.
710 { kHebrewLatin, 3, SelectionModel::TRAILING, 0, SelectionModel::LEADING }, 684 { kHebrewLatin, base::i18n::RIGHT_TO_LEFT },
711 #else 685 #else
712 { kHebrewLatin, 0, SelectionModel::TRAILING, 3, SelectionModel::LEADING }, 686 { kHebrewLatin, base::i18n::LEFT_TO_RIGHT },
713 #endif 687 #endif
714 }; 688 };
715 689
716 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete 690 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete
717 // font support for some scripts - http://crbug.com/106450 691 // font support for some scripts - http://crbug.com/106450
718 #if defined(OS_WIN) 692 #if defined(OS_WIN)
719 if (base::win::GetVersion() < base::win::VERSION_VISTA) 693 if (base::win::GetVersion() < base::win::VERSION_VISTA)
720 return; 694 return;
721 #endif 695 #endif
722 696
723 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 697 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
724 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 698 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
725 render_text->SetText(cases[i].text); 699 render_text->SetText(cases[i].text);
700 bool ltr = (cases[i].expected_text_direction == base::i18n::LEFT_TO_RIGHT);
726 701
727 SelectionModel model = render_text->EdgeSelectionModel(CURSOR_LEFT); 702 SelectionModel start_edge =
728 EXPECT_EQ(cases[i].expected_left_end_caret, model.caret_pos()); 703 render_text->EdgeSelectionModel(ltr ? CURSOR_LEFT : CURSOR_RIGHT);
729 EXPECT_TRUE(render_text->IsCursorablePosition(model.caret_pos())); 704 EXPECT_EQ(start_edge, SelectionModel(0, CURSOR_BACKWARD));
730 EXPECT_EQ(cases[i].expected_left_end_placement, model.caret_placement());
731 705
732 model = render_text->EdgeSelectionModel(CURSOR_RIGHT); 706 SelectionModel end_edge =
733 EXPECT_EQ(cases[i].expected_right_end_caret, model.caret_pos()); 707 render_text->EdgeSelectionModel(ltr ? CURSOR_RIGHT : CURSOR_LEFT);
734 EXPECT_TRUE(render_text->IsCursorablePosition(model.caret_pos())); 708 EXPECT_EQ(end_edge, SelectionModel(cases[i].text.length(), CURSOR_FORWARD));
735 EXPECT_EQ(cases[i].expected_right_end_placement, model.caret_placement());
736 } 709 }
737 } 710 }
738 711
739 TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) { 712 TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) {
740 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 713 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
741 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); 714 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2"));
742 // Left arrow on select ranging (6, 4). 715 // Left arrow on select ranging (6, 4).
743 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 716 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false);
744 EXPECT_EQ(6U, render_text->GetCursorPosition()); 717 EXPECT_EQ(ui::Range(6), render_text->selection());
745 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); 718 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false);
746 EXPECT_EQ(4U, render_text->GetCursorPosition()); 719 EXPECT_EQ(ui::Range(4), render_text->selection());
747 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); 720 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false);
748 EXPECT_EQ(5U, render_text->GetCursorPosition()); 721 EXPECT_EQ(ui::Range(5), render_text->selection());
749 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); 722 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false);
750 EXPECT_EQ(6U, render_text->GetCursorPosition()); 723 EXPECT_EQ(ui::Range(6), render_text->selection());
751 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, true); 724 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, true);
752 EXPECT_EQ(6U, render_text->GetSelectionStart()); 725 EXPECT_EQ(ui::Range(6, 5), render_text->selection());
753 EXPECT_EQ(5U, render_text->GetCursorPosition());
754 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, true); 726 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, true);
755 EXPECT_EQ(6U, render_text->GetSelectionStart()); 727 EXPECT_EQ(ui::Range(6, 4), render_text->selection());
756 EXPECT_EQ(4U, render_text->GetCursorPosition());
757 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); 728 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false);
758 EXPECT_EQ(6U, render_text->GetCursorPosition()); 729 EXPECT_EQ(ui::Range(6), render_text->selection());
759 730
760 // Right arrow on select ranging (4, 6). 731 // Right arrow on select ranging (4, 6).
761 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); 732 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false);
762 EXPECT_EQ(0U, render_text->GetCursorPosition()); 733 EXPECT_EQ(ui::Range(0), render_text->selection());
763 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); 734 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
764 EXPECT_EQ(1U, render_text->GetCursorPosition()); 735 EXPECT_EQ(ui::Range(1), render_text->selection());
765 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); 736 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
766 EXPECT_EQ(2U, render_text->GetCursorPosition()); 737 EXPECT_EQ(ui::Range(2), render_text->selection());
767 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); 738 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
768 EXPECT_EQ(3U, render_text->GetCursorPosition()); 739 EXPECT_EQ(ui::Range(3), render_text->selection());
769 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); 740 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
770 EXPECT_EQ(5U, render_text->GetCursorPosition()); 741 EXPECT_EQ(ui::Range(5), render_text->selection());
771 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); 742 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
772 EXPECT_EQ(4U, render_text->GetCursorPosition()); 743 EXPECT_EQ(ui::Range(4), render_text->selection());
773 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true); 744 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true);
774 EXPECT_EQ(4U, render_text->GetSelectionStart()); 745 EXPECT_EQ(ui::Range(4, 5), render_text->selection());
775 EXPECT_EQ(5U, render_text->GetCursorPosition());
776 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true); 746 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true);
777 EXPECT_EQ(4U, render_text->GetSelectionStart()); 747 EXPECT_EQ(ui::Range(4, 6), render_text->selection());
778 EXPECT_EQ(6U, render_text->GetCursorPosition());
779 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); 748 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
780 EXPECT_EQ(4U, render_text->GetCursorPosition()); 749 EXPECT_EQ(ui::Range(4), render_text->selection());
781 } 750 }
782 751
783 // TODO(xji): Make these work on Windows. 752 // TODO(xji): Make these work on Windows.
784 #if defined(OS_LINUX) 753 #if defined(OS_LINUX)
785 void MoveLeftRightByWordVerifier(RenderText* render_text, 754 void MoveLeftRightByWordVerifier(RenderText* render_text,
786 const wchar_t* str) { 755 const wchar_t* str) {
787 render_text->SetText(WideToUTF16(str)); 756 render_text->SetText(WideToUTF16(str));
788 757
789 // Test moving by word from left ro right. 758 // Test moving by word from left ro right.
790 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); 759 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false);
791 bool first_word = true; 760 bool first_word = true;
792 while (true) { 761 while (true) {
793 // First, test moving by word from a word break position, such as from 762 // First, test moving by word from a word break position, such as from
794 // "|abc def" to "abc| def". 763 // "|abc def" to "abc| def".
795 SelectionModel start = render_text->selection_model(); 764 SelectionModel start = render_text->selection_model();
796 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); 765 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false);
797 SelectionModel end = render_text->selection_model(); 766 SelectionModel end = render_text->selection_model();
798 if (end.Equals(start)) // reach the end. 767 if (end == start) // reach the end.
799 break; 768 break;
800 769
801 // For testing simplicity, each word is a 3-character word. 770 // For testing simplicity, each word is a 3-character word.
802 int num_of_character_moves = first_word ? 3 : 4; 771 int num_of_character_moves = first_word ? 3 : 4;
803 first_word = false; 772 first_word = false;
804 render_text->MoveCursorTo(start); 773 render_text->MoveCursorTo(start);
805 for (int j = 0; j < num_of_character_moves; ++j) 774 for (int j = 0; j < num_of_character_moves; ++j)
806 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); 775 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
807 EXPECT_TRUE(render_text->selection_model().Equals(end)); 776 EXPECT_EQ(end, render_text->selection_model());
808 777
809 // Then, test moving by word from positions inside the word, such as from 778 // Then, test moving by word from positions inside the word, such as from
810 // "a|bc def" to "abc| def", and from "ab|c def" to "abc| def". 779 // "a|bc def" to "abc| def", and from "ab|c def" to "abc| def".
811 for (int j = 1; j < num_of_character_moves; ++j) { 780 for (int j = 1; j < num_of_character_moves; ++j) {
812 render_text->MoveCursorTo(start); 781 render_text->MoveCursorTo(start);
813 for (int k = 0; k < j; ++k) 782 for (int k = 0; k < j; ++k)
814 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); 783 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
815 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); 784 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false);
816 EXPECT_TRUE(render_text->selection_model().Equals(end)); 785 EXPECT_EQ(end, render_text->selection_model());
817 } 786 }
818 } 787 }
819 788
820 // Test moving by word from right to left. 789 // Test moving by word from right to left.
821 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 790 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false);
822 first_word = true; 791 first_word = true;
823 while (true) { 792 while (true) {
824 SelectionModel start = render_text->selection_model(); 793 SelectionModel start = render_text->selection_model();
825 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); 794 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false);
826 SelectionModel end = render_text->selection_model(); 795 SelectionModel end = render_text->selection_model();
827 if (end.Equals(start)) // reach the end. 796 if (end == start) // reach the end.
828 break; 797 break;
829 798
830 int num_of_character_moves = first_word ? 3 : 4; 799 int num_of_character_moves = first_word ? 3 : 4;
831 first_word = false; 800 first_word = false;
832 render_text->MoveCursorTo(start); 801 render_text->MoveCursorTo(start);
833 for (int j = 0; j < num_of_character_moves; ++j) 802 for (int j = 0; j < num_of_character_moves; ++j)
834 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); 803 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false);
835 EXPECT_TRUE(render_text->selection_model().Equals(end)); 804 EXPECT_EQ(end, render_text->selection_model());
836 805
837 for (int j = 1; j < num_of_character_moves; ++j) { 806 for (int j = 1; j < num_of_character_moves; ++j) {
838 render_text->MoveCursorTo(start); 807 render_text->MoveCursorTo(start);
839 for (int k = 0; k < j; ++k) 808 for (int k = 0; k < j; ++k)
840 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); 809 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false);
841 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); 810 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false);
842 EXPECT_TRUE(render_text->selection_model().Equals(end)); 811 EXPECT_EQ(end, render_text->selection_model());
843 } 812 }
844 } 813 }
845 } 814 }
846 815
847 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText) { 816 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText) {
848 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 817 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
849 818
850 // For testing simplicity, each word is a 3-character word. 819 // For testing simplicity, each word is a 3-character word.
851 std::vector<const wchar_t*> test; 820 std::vector<const wchar_t*> test;
852 test.push_back(L"abc"); 821 test.push_back(L"abc");
(...skipping 29 matching lines...) Expand all
882 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText_TestEndOfText) { 851 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText_TestEndOfText) {
883 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 852 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
884 853
885 render_text->SetText(WideToUTF16(L"ab\x05E1")); 854 render_text->SetText(WideToUTF16(L"ab\x05E1"));
886 // Moving the cursor by word from "abC|" to the left should return "|abC". 855 // Moving the cursor by word from "abC|" to the left should return "|abC".
887 // But since end of text is always treated as a word break, it returns 856 // But since end of text is always treated as a word break, it returns
888 // position "ab|C". 857 // position "ab|C".
889 // TODO(xji): Need to make it work as expected. 858 // TODO(xji): Need to make it work as expected.
890 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 859 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false);
891 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); 860 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false);
892 // EXPECT_TRUE(render_text->selection_model().Equals(SelectionModel(0))); 861 // EXPECT_EQ(SelectionModel(), render_text->selection_model());
893 862
894 // Moving the cursor by word from "|abC" to the right returns "abC|". 863 // Moving the cursor by word from "|abC" to the right returns "abC|".
895 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); 864 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false);
896 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); 865 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false);
897 EXPECT_TRUE(render_text->selection_model().Equals( 866 EXPECT_EQ(SelectionModel(3, CURSOR_FORWARD), render_text->selection_model());
898 SelectionModel(3, 2, SelectionModel::LEADING)));
899 867
900 render_text->SetText(WideToUTF16(L"\x05E1\x05E2"L"a")); 868 render_text->SetText(WideToUTF16(L"\x05E1\x05E2"L"a"));
901 // For logical text "BCa", moving the cursor by word from "aCB|" to the left 869 // For logical text "BCa", moving the cursor by word from "aCB|" to the left
902 // returns "|aCB". 870 // returns "|aCB".
903 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 871 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false);
904 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); 872 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false);
905 EXPECT_TRUE(render_text->selection_model().Equals( 873 EXPECT_EQ(SelectionModel(3, CURSOR_FORWARD), render_text->selection_model());
906 SelectionModel(3, 2, SelectionModel::LEADING)));
907 874
908 // Moving the cursor by word from "|aCB" to the right should return "aCB|". 875 // Moving the cursor by word from "|aCB" to the right should return "aCB|".
909 // But since end of text is always treated as a word break, it returns 876 // But since end of text is always treated as a word break, it returns
910 // position "a|CB". 877 // position "a|CB".
911 // TODO(xji): Need to make it work as expected. 878 // TODO(xji): Need to make it work as expected.
912 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); 879 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false);
913 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); 880 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false);
914 // EXPECT_TRUE(render_text->selection_model().Equals(SelectionModel(0))); 881 // EXPECT_EQ(SelectionModel(), render_text->selection_model());
915 } 882 }
916 883
917 TEST_F(RenderTextTest, MoveLeftRightByWordInTextWithMultiSpaces) { 884 TEST_F(RenderTextTest, MoveLeftRightByWordInTextWithMultiSpaces) {
918 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 885 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
919 render_text->SetText(WideToUTF16(L"abc def")); 886 render_text->SetText(WideToUTF16(L"abc def"));
920 render_text->MoveCursorTo(SelectionModel(5)); 887 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD));
921 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); 888 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false);
922 EXPECT_EQ(11U, render_text->GetCursorPosition()); 889 EXPECT_EQ(11U, render_text->cursor_position());
923 890
924 render_text->MoveCursorTo(SelectionModel(5)); 891 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD));
925 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); 892 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false);
926 EXPECT_EQ(0U, render_text->GetCursorPosition()); 893 EXPECT_EQ(0U, render_text->cursor_position());
927 } 894 }
928 895
929 TEST_F(RenderTextTest, MoveLeftRightByWordInChineseText) { 896 TEST_F(RenderTextTest, MoveLeftRightByWordInChineseText) {
930 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 897 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
931 render_text->SetText(WideToUTF16(L"\x6211\x4EEC\x53BB\x516C\x56ED\x73A9")); 898 render_text->SetText(WideToUTF16(L"\x6211\x4EEC\x53BB\x516C\x56ED\x73A9"));
932 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); 899 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false);
933 EXPECT_EQ(0U, render_text->GetCursorPosition()); 900 EXPECT_EQ(0U, render_text->cursor_position());
934 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); 901 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false);
935 EXPECT_EQ(2U, render_text->GetCursorPosition()); 902 EXPECT_EQ(2U, render_text->cursor_position());
936 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); 903 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false);
937 EXPECT_EQ(3U, render_text->GetCursorPosition()); 904 EXPECT_EQ(3U, render_text->cursor_position());
938 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); 905 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false);
939 EXPECT_EQ(5U, render_text->GetCursorPosition()); 906 EXPECT_EQ(5U, render_text->cursor_position());
940 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); 907 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false);
941 EXPECT_EQ(6U, render_text->GetCursorPosition()); 908 EXPECT_EQ(6U, render_text->cursor_position());
942 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); 909 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false);
943 EXPECT_EQ(6U, render_text->GetCursorPosition()); 910 EXPECT_EQ(6U, render_text->cursor_position());
944 } 911 }
945 912
946 TEST_F(RenderTextTest, StringWidthTest) { 913 TEST_F(RenderTextTest, StringWidthTest) {
947 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 914 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
948 render_text->SetText(UTF8ToUTF16("Hello World")); 915 render_text->SetText(UTF8ToUTF16("Hello World"));
949 916
950 // Check that width is valid 917 // Check that width is valid
951 int width = render_text->GetStringWidth(); 918 int width = render_text->GetStringSize().width();
952 EXPECT_GT(width, 0); 919 EXPECT_GT(width, 0);
953 920
954 // Apply a bold style and check that the new width is greater. 921 // Apply a bold style and check that the new width is greater.
955 StyleRange bold; 922 StyleRange bold;
956 bold.font_style |= gfx::Font::BOLD; 923 bold.font_style |= gfx::Font::BOLD;
957 render_text->set_default_style(bold); 924 render_text->set_default_style(bold);
958 render_text->ApplyDefaultStyle(); 925 render_text->ApplyDefaultStyle();
959 EXPECT_GT(render_text->GetStringWidth(), width); 926 EXPECT_GT(render_text->GetStringSize().width(), width);
960 } 927 }
961 928
962 #endif 929 #endif
963 930
964 TEST_F(RenderTextTest, CursorBoundsInReplacementMode) { 931 TEST_F(RenderTextTest, CursorBoundsInReplacementMode) {
965 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 932 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
966 render_text->SetText(ASCIIToUTF16("abcdefg")); 933 render_text->SetText(ASCIIToUTF16("abcdefg"));
967 render_text->SetDisplayRect(Rect(100, 17)); 934 render_text->SetDisplayRect(Rect(100, 17));
968 SelectionModel sel_b(1); 935 SelectionModel sel_b(1, CURSOR_FORWARD);
969 SelectionModel sel_c(2); 936 SelectionModel sel_c(2, CURSOR_FORWARD);
970 Rect cursor_around_b = render_text->GetCursorBounds(sel_b, false); 937 Rect cursor_around_b = render_text->GetCursorBounds(sel_b, false);
971 Rect cursor_before_b = render_text->GetCursorBounds(sel_b, true); 938 Rect cursor_before_b = render_text->GetCursorBounds(sel_b, true);
972 Rect cursor_before_c = render_text->GetCursorBounds(sel_c, true); 939 Rect cursor_before_c = render_text->GetCursorBounds(sel_c, true);
973 EXPECT_EQ(cursor_around_b.x(), cursor_before_b.x()); 940 EXPECT_EQ(cursor_around_b.x(), cursor_before_b.x());
974 EXPECT_EQ(cursor_around_b.right(), cursor_before_c.x()); 941 EXPECT_EQ(cursor_around_b.right(), cursor_before_c.x());
975 } 942 }
976 943
977 TEST_F(RenderTextTest, OriginForSkiaDrawing) { 944 TEST_F(RenderTextTest, OriginForSkiaDrawing) {
978 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 945 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
979 render_text->SetText(ASCIIToUTF16("abcdefg")); 946 render_text->SetText(ASCIIToUTF16("abcdefg"));
(...skipping 13 matching lines...) Expand all
993 render_text->SetDisplayRect(display_rect); 960 render_text->SetDisplayRect(display_rect);
994 961
995 origin = render_text->GetOriginForSkiaDrawing(); 962 origin = render_text->GetOriginForSkiaDrawing();
996 EXPECT_EQ(origin.x(), 0); 963 EXPECT_EQ(origin.x(), 0);
997 EXPECT_EQ(origin.y(), 14); 964 EXPECT_EQ(origin.y(), 14);
998 } 965 }
999 966
1000 TEST_F(RenderTextTest, DisplayRectShowsCursorLTR) { 967 TEST_F(RenderTextTest, DisplayRectShowsCursorLTR) {
1001 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 968 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
1002 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg")); 969 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg"));
1003 render_text->MoveCursorTo(SelectionModel(render_text->text().length())); 970 render_text->MoveCursorTo(SelectionModel(render_text->text().length(),
1004 int width = render_text->GetStringWidth(); 971 CURSOR_FORWARD));
972 int width = render_text->GetStringSize().width();
1005 973
1006 // Ensure that the cursor is placed at the width of its preceding text. 974 // Ensure that the cursor is placed at the width of its preceding text.
1007 render_text->SetDisplayRect(Rect(width + 10, 1)); 975 render_text->SetDisplayRect(Rect(width + 10, 1));
1008 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); 976 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x());
1009 977
1010 // Ensure that shrinking the display rectangle keeps the cursor in view. 978 // Ensure that shrinking the display rectangle keeps the cursor in view.
1011 render_text->SetDisplayRect(Rect(width - 10, 1)); 979 render_text->SetDisplayRect(Rect(width - 10, 1));
1012 EXPECT_EQ(render_text->display_rect().width() - 1, 980 EXPECT_EQ(render_text->display_rect().width() - 1,
1013 render_text->GetUpdatedCursorBounds().x()); 981 render_text->GetUpdatedCursorBounds().x());
1014 982
1015 // Ensure that the text will pan to fill its expanding display rectangle. 983 // Ensure that the text will pan to fill its expanding display rectangle.
1016 render_text->SetDisplayRect(Rect(width - 5, 1)); 984 render_text->SetDisplayRect(Rect(width - 5, 1));
1017 EXPECT_EQ(render_text->display_rect().width() - 1, 985 EXPECT_EQ(render_text->display_rect().width() - 1,
1018 render_text->GetUpdatedCursorBounds().x()); 986 render_text->GetUpdatedCursorBounds().x());
1019 987
1020 // Ensure that a sufficiently large display rectangle shows all the text. 988 // Ensure that a sufficiently large display rectangle shows all the text.
1021 render_text->SetDisplayRect(Rect(width + 10, 1)); 989 render_text->SetDisplayRect(Rect(width + 10, 1));
1022 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); 990 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x());
1023 991
1024 // Repeat the test with RTL text. 992 // Repeat the test with RTL text.
1025 render_text->SetText(WideToUTF16(L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7" 993 render_text->SetText(WideToUTF16(L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7"
1026 L"\x5d8\x5d9\x5da\x5db\x5dc\x5dd\x5de\x5df")); 994 L"\x5d8\x5d9\x5da\x5db\x5dc\x5dd\x5de\x5df"));
1027 render_text->MoveCursorTo(SelectionModel(0)); 995 render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD));
1028 width = render_text->GetStringWidth(); 996 width = render_text->GetStringSize().width();
1029 997
1030 // Ensure that the cursor is placed at the width of its preceding text. 998 // Ensure that the cursor is placed at the width of its preceding text.
1031 render_text->SetDisplayRect(Rect(width + 10, 1)); 999 render_text->SetDisplayRect(Rect(width + 10, 1));
1032 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); 1000 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x());
1033 1001
1034 // Ensure that shrinking the display rectangle keeps the cursor in view. 1002 // Ensure that shrinking the display rectangle keeps the cursor in view.
1035 render_text->SetDisplayRect(Rect(width - 10, 1)); 1003 render_text->SetDisplayRect(Rect(width - 10, 1));
1036 EXPECT_EQ(render_text->display_rect().width() - 1, 1004 EXPECT_EQ(render_text->display_rect().width() - 1,
1037 render_text->GetUpdatedCursorBounds().x()); 1005 render_text->GetUpdatedCursorBounds().x());
1038 1006
1039 // Ensure that the text will pan to fill its expanding display rectangle. 1007 // Ensure that the text will pan to fill its expanding display rectangle.
1040 render_text->SetDisplayRect(Rect(width - 5, 1)); 1008 render_text->SetDisplayRect(Rect(width - 5, 1));
1041 EXPECT_EQ(render_text->display_rect().width() - 1, 1009 EXPECT_EQ(render_text->display_rect().width() - 1,
1042 render_text->GetUpdatedCursorBounds().x()); 1010 render_text->GetUpdatedCursorBounds().x());
1043 1011
1044 // Ensure that a sufficiently large display rectangle shows all the text. 1012 // Ensure that a sufficiently large display rectangle shows all the text.
1045 render_text->SetDisplayRect(Rect(width + 10, 1)); 1013 render_text->SetDisplayRect(Rect(width + 10, 1));
1046 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); 1014 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x());
1047 } 1015 }
1048 1016
1049 TEST_F(RenderTextTest, DisplayRectShowsCursorRTL) { 1017 TEST_F(RenderTextTest, DisplayRectShowsCursorRTL) {
1050 // Set the locale to Hebrew for RTL UI. 1018 // Set the locale to Hebrew for RTL UI.
1051 std::string locale = l10n_util::GetApplicationLocale(""); 1019 std::string locale = l10n_util::GetApplicationLocale("");
1052 base::i18n::SetICUDefaultLocale("he"); 1020 base::i18n::SetICUDefaultLocale("he");
1053 1021
1054 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 1022 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
1055 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg")); 1023 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg"));
1056 render_text->MoveCursorTo(SelectionModel(0)); 1024 render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD));
1057 int width = render_text->GetStringWidth(); 1025 int width = render_text->GetStringSize().width();
1058 1026
1059 // Ensure that the cursor is placed at the width of its preceding text. 1027 // Ensure that the cursor is placed at the width of its preceding text.
1060 render_text->SetDisplayRect(Rect(width + 10, 1)); 1028 render_text->SetDisplayRect(Rect(width + 10, 1));
1061 EXPECT_EQ(render_text->display_rect().width() - width - 1, 1029 EXPECT_EQ(render_text->display_rect().width() - width - 1,
1062 render_text->GetUpdatedCursorBounds().x()); 1030 render_text->GetUpdatedCursorBounds().x());
1063 1031
1064 // Ensure that shrinking the display rectangle keeps the cursor in view. 1032 // Ensure that shrinking the display rectangle keeps the cursor in view.
1065 render_text->SetDisplayRect(Rect(width - 10, 1)); 1033 render_text->SetDisplayRect(Rect(width - 10, 1));
1066 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); 1034 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x());
1067 1035
1068 // Ensure that the text will pan to fill its expanding display rectangle. 1036 // Ensure that the text will pan to fill its expanding display rectangle.
1069 render_text->SetDisplayRect(Rect(width - 5, 1)); 1037 render_text->SetDisplayRect(Rect(width - 5, 1));
1070 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); 1038 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x());
1071 1039
1072 // Ensure that a sufficiently large display rectangle shows all the text. 1040 // Ensure that a sufficiently large display rectangle shows all the text.
1073 render_text->SetDisplayRect(Rect(width + 10, 1)); 1041 render_text->SetDisplayRect(Rect(width + 10, 1));
1074 EXPECT_EQ(render_text->display_rect().width() - width - 1, 1042 EXPECT_EQ(render_text->display_rect().width() - width - 1,
1075 render_text->GetUpdatedCursorBounds().x()); 1043 render_text->GetUpdatedCursorBounds().x());
1076 1044
1077 // Repeat the test with RTL text. 1045 // Repeat the test with RTL text.
1078 render_text->SetText(WideToUTF16(L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7" 1046 render_text->SetText(WideToUTF16(L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7"
1079 L"\x5d8\x5d9\x5da\x5db\x5dc\x5dd\x5de\x5df")); 1047 L"\x5d8\x5d9\x5da\x5db\x5dc\x5dd\x5de\x5df"));
1080 render_text->MoveCursorTo(SelectionModel(render_text->text().length())); 1048 render_text->MoveCursorTo(SelectionModel(render_text->text().length(),
1081 width = render_text->GetStringWidth(); 1049 CURSOR_FORWARD));
1050 width = render_text->GetStringSize().width();
1082 1051
1083 // Ensure that the cursor is placed at the width of its preceding text. 1052 // Ensure that the cursor is placed at the width of its preceding text.
1084 render_text->SetDisplayRect(Rect(width + 10, 1)); 1053 render_text->SetDisplayRect(Rect(width + 10, 1));
1085 EXPECT_EQ(render_text->display_rect().width() - width - 1, 1054 EXPECT_EQ(render_text->display_rect().width() - width - 1,
1086 render_text->GetUpdatedCursorBounds().x()); 1055 render_text->GetUpdatedCursorBounds().x());
1087 1056
1088 // Ensure that shrinking the display rectangle keeps the cursor in view. 1057 // Ensure that shrinking the display rectangle keeps the cursor in view.
1089 render_text->SetDisplayRect(Rect(width - 10, 1)); 1058 render_text->SetDisplayRect(Rect(width - 10, 1));
1090 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); 1059 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x());
1091 1060
1092 // Ensure that the text will pan to fill its expanding display rectangle. 1061 // Ensure that the text will pan to fill its expanding display rectangle.
1093 render_text->SetDisplayRect(Rect(width - 5, 1)); 1062 render_text->SetDisplayRect(Rect(width - 5, 1));
1094 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); 1063 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x());
1095 1064
1096 // Ensure that a sufficiently large display rectangle shows all the text. 1065 // Ensure that a sufficiently large display rectangle shows all the text.
1097 render_text->SetDisplayRect(Rect(width + 10, 1)); 1066 render_text->SetDisplayRect(Rect(width + 10, 1));
1098 EXPECT_EQ(render_text->display_rect().width() - width - 1, 1067 EXPECT_EQ(render_text->display_rect().width() - width - 1,
1099 render_text->GetUpdatedCursorBounds().x()); 1068 render_text->GetUpdatedCursorBounds().x());
1100 1069
1101 // Reset locale. 1070 // Reset locale.
1102 base::i18n::SetICUDefaultLocale(locale); 1071 base::i18n::SetICUDefaultLocale(locale);
1103 } 1072 }
1104 1073
1105 } // namespace gfx 1074 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698