| 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/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 Loading... |
| 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_FORWARD)); |
| 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)); | 530 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); |
| 549 #endif | 531 #endif |
| 550 RunMoveCursorLeftRightTest(render_text.get(), expected, true); | 532 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
| 551 } | 533 } |
| 552 | 534 |
| 553 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) { | 535 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) { |
| 554 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 536 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 555 // RTL-LTR-RTL. | 537 // RTL-LTR-RTL. |
| 556 render_text->SetText(WideToUTF16(L"\x05d0"L"a"L"\x05d1")); | 538 render_text->SetText(WideToUTF16(L"\x05d0"L"a"L"\x05d1")); |
| 557 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 539 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); |
| 558 std::vector<SelectionModel> expected; | 540 std::vector<SelectionModel> expected; |
| 559 #if defined(OS_LINUX) | 541 #if defined(OS_LINUX) |
| 560 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); | 542 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
| 561 expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING)); | 543 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
| 562 expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING)); | 544 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
| 563 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); | 545 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); |
| 564 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); | 546 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
| 565 #else | 547 #else |
| 566 expected.push_back(SelectionModel(3, 2, SelectionModel::LEADING)); | 548 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
| 567 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); | 549 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); |
| 568 expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING)); | 550 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
| 569 expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING)); | 551 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
| 570 expected.push_back(SelectionModel(0, 0, SelectionModel::TRAILING)); | 552 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 | 553 #endif |
| 575 RunMoveCursorLeftRightTest(render_text.get(), expected, false); | 554 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
| 576 | 555 |
| 577 expected.clear(); | 556 expected.clear(); |
| 578 #if defined(OS_LINUX) | 557 #if defined(OS_LINUX) |
| 579 expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING)); | 558 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
| 580 expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING)); | 559 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); |
| 581 expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING)); | 560 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); |
| 582 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); | 561 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
| 583 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); | 562 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
| 584 #else | 563 #else |
| 585 expected.push_back(SelectionModel(0, 0, SelectionModel::TRAILING)); | 564 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
| 586 expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING)); | 565 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
| 587 expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING)); | 566 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); |
| 588 expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING)); | 567 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); |
| 589 expected.push_back(SelectionModel(3, 2, SelectionModel::LEADING)); | 568 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
| 590 expected.push_back(SelectionModel(3, 2, SelectionModel::LEADING)); | |
| 591 #endif | 569 #endif |
| 592 RunMoveCursorLeftRightTest(render_text.get(), expected, true); | 570 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
| 593 } | 571 } |
| 594 | 572 |
| 595 // TODO(xji): temporarily disable in platform Win since the complex script | 573 // TODO(xji): temporarily disable in platform Win since the complex script |
| 596 // characters turned into empty square due to font regression. So, not able | 574 // characters turned into empty square due to font regression. So, not able |
| 597 // to test 2 characters belong to the same grapheme. | 575 // to test 2 characters belong to the same grapheme. |
| 598 #if defined(OS_LINUX) | 576 #if defined(OS_LINUX) |
| 599 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) { | 577 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) { |
| 600 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 578 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 601 | 579 |
| 602 render_text->SetText(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); | 580 render_text->SetText(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); |
| 603 EXPECT_EQ(0U, render_text->GetCursorPosition()); | 581 EXPECT_EQ(0U, render_text->cursor_position()); |
| 604 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 582 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
| 605 EXPECT_EQ(2U, render_text->GetCursorPosition()); | 583 EXPECT_EQ(2U, render_text->cursor_position()); |
| 606 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 584 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
| 607 EXPECT_EQ(4U, render_text->GetCursorPosition()); | 585 EXPECT_EQ(4U, render_text->cursor_position()); |
| 608 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 586 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
| 609 EXPECT_EQ(5U, render_text->GetCursorPosition()); | 587 EXPECT_EQ(5U, render_text->cursor_position()); |
| 610 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 588 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
| 611 EXPECT_EQ(5U, render_text->GetCursorPosition()); | 589 EXPECT_EQ(5U, render_text->cursor_position()); |
| 612 | 590 |
| 613 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 591 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); |
| 614 EXPECT_EQ(4U, render_text->GetCursorPosition()); | 592 EXPECT_EQ(4U, render_text->cursor_position()); |
| 615 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 593 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); |
| 616 EXPECT_EQ(2U, render_text->GetCursorPosition()); | 594 EXPECT_EQ(2U, render_text->cursor_position()); |
| 617 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 595 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); |
| 618 EXPECT_EQ(0U, render_text->GetCursorPosition()); | 596 EXPECT_EQ(0U, render_text->cursor_position()); |
| 619 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 597 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); |
| 620 EXPECT_EQ(0U, render_text->GetCursorPosition()); | 598 EXPECT_EQ(0U, render_text->cursor_position()); |
| 621 } | 599 } |
| 622 #endif | 600 #endif |
| 623 | 601 |
| 624 TEST_F(RenderTextTest, GraphemePositions) { | 602 TEST_F(RenderTextTest, GraphemePositions) { |
| 625 // LTR 2-character grapheme, LTR abc, LTR 2-character grapheme. | 603 // LTR 2-character grapheme, LTR abc, LTR 2-character grapheme. |
| 626 const string16 kText1 = WideToUTF16(L"\x0915\x093f"L"abc"L"\x0915\x093f"); | 604 const string16 kText1 = WideToUTF16(L"\x0915\x093f"L"abc"L"\x0915\x093f"); |
| 627 | 605 |
| 628 // LTR ab, LTR 2-character grapheme, LTR cd. | 606 // LTR ab, LTR 2-character grapheme, LTR cd. |
| 629 const string16 kText2 = WideToUTF16(L"ab"L"\x0915\x093f"L"cd"); | 607 const string16 kText2 = WideToUTF16(L"ab"L"\x0915\x093f"L"cd"); |
| 630 | 608 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 EXPECT_EQ(cases[i].expected_next, next); | 652 EXPECT_EQ(cases[i].expected_next, next); |
| 675 EXPECT_TRUE(render_text->IsCursorablePosition(next)); | 653 EXPECT_TRUE(render_text->IsCursorablePosition(next)); |
| 676 | 654 |
| 677 size_t previous = render_text->IndexOfAdjacentGrapheme(cases[i].index, | 655 size_t previous = render_text->IndexOfAdjacentGrapheme(cases[i].index, |
| 678 CURSOR_BACKWARD); | 656 CURSOR_BACKWARD); |
| 679 EXPECT_EQ(cases[i].expected_previous, previous); | 657 EXPECT_EQ(cases[i].expected_previous, previous); |
| 680 EXPECT_TRUE(render_text->IsCursorablePosition(previous)); | 658 EXPECT_TRUE(render_text->IsCursorablePosition(previous)); |
| 681 } | 659 } |
| 682 } | 660 } |
| 683 | 661 |
| 684 TEST_F(RenderTextTest, SelectionModels) { | 662 TEST_F(RenderTextTest, EdgeSelectionModels) { |
| 685 // Simple Latin text. | 663 // Simple Latin text. |
| 686 const string16 kLatin = WideToUTF16(L"abc"); | 664 const string16 kLatin = WideToUTF16(L"abc"); |
| 687 // LTR 2-character grapheme. | 665 // LTR 2-character grapheme. |
| 688 const string16 kLTRGrapheme = WideToUTF16(L"\x0915\x093f"); | 666 const string16 kLTRGrapheme = WideToUTF16(L"\x0915\x093f"); |
| 689 // LTR 2-character grapheme, LTR a, LTR 2-character grapheme. | 667 // LTR 2-character grapheme, LTR a, LTR 2-character grapheme. |
| 690 const string16 kHindiLatin = WideToUTF16(L"\x0915\x093f"L"a"L"\x0915\x093f"); | 668 const string16 kHindiLatin = WideToUTF16(L"\x0915\x093f"L"a"L"\x0915\x093f"); |
| 691 // RTL 2-character grapheme. | 669 // RTL 2-character grapheme. |
| 692 const string16 kRTLGrapheme = WideToUTF16(L"\x05e0\x05b8"); | 670 const string16 kRTLGrapheme = WideToUTF16(L"\x05e0\x05b8"); |
| 693 // RTL 2-character grapheme, LTR a, RTL 2-character grapheme. | 671 // RTL 2-character grapheme, LTR a, RTL 2-character grapheme. |
| 694 const string16 kHebrewLatin = WideToUTF16(L"\x05e0\x05b8"L"a"L"\x05e0\x05b8"); | 672 const string16 kHebrewLatin = WideToUTF16(L"\x05e0\x05b8"L"a"L"\x05e0\x05b8"); |
| 695 | 673 |
| 696 struct { | 674 struct { |
| 697 string16 text; | 675 string16 text; |
| 698 size_t expected_left_end_caret; | 676 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[] = { | 677 } cases[] = { |
| 703 { string16(), 0, SelectionModel::LEADING, 0, SelectionModel::LEADING }, | 678 { string16(), base::i18n::LEFT_TO_RIGHT }, |
| 704 { kLatin, 0, SelectionModel::LEADING, 2, SelectionModel::TRAILING }, | 679 { kLatin, base::i18n::LEFT_TO_RIGHT }, |
| 705 { kLTRGrapheme, 0, SelectionModel::LEADING, 0, SelectionModel::TRAILING }, | 680 { kLTRGrapheme, base::i18n::LEFT_TO_RIGHT }, |
| 706 { kHindiLatin, 0, SelectionModel::LEADING, 3, SelectionModel::TRAILING }, | 681 { kHindiLatin, base::i18n::LEFT_TO_RIGHT }, |
| 707 { kRTLGrapheme, 0, SelectionModel::TRAILING, 0, SelectionModel::LEADING }, | |
| 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 { kRTLGrapheme, base::i18n::RIGHT_TO_LEFT }, |
| 685 { kHebrewLatin, base::i18n::RIGHT_TO_LEFT }, |
| 711 #else | 686 #else |
| 712 { kHebrewLatin, 0, SelectionModel::TRAILING, 3, SelectionModel::LEADING }, | 687 { kRTLGrapheme, base::i18n::LEFT_TO_RIGHT }, |
| 688 { kHebrewLatin, base::i18n::LEFT_TO_RIGHT }, |
| 713 #endif | 689 #endif |
| 714 }; | 690 }; |
| 715 | 691 |
| 716 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete | 692 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete |
| 717 // font support for some scripts - http://crbug.com/106450 | 693 // font support for some scripts - http://crbug.com/106450 |
| 718 #if defined(OS_WIN) | 694 #if defined(OS_WIN) |
| 719 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 695 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
| 720 return; | 696 return; |
| 721 #endif | 697 #endif |
| 722 | 698 |
| 723 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 699 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 724 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 700 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 725 render_text->SetText(cases[i].text); | 701 render_text->SetText(cases[i].text); |
| 702 bool ltr = (cases[i].expected_text_direction == base::i18n::LEFT_TO_RIGHT); |
| 726 | 703 |
| 727 SelectionModel model = render_text->EdgeSelectionModel(CURSOR_LEFT); | 704 SelectionModel start_edge = |
| 728 EXPECT_EQ(cases[i].expected_left_end_caret, model.caret_pos()); | 705 render_text->EdgeSelectionModel(ltr ? CURSOR_LEFT : CURSOR_RIGHT); |
| 729 EXPECT_TRUE(render_text->IsCursorablePosition(model.caret_pos())); | 706 EXPECT_EQ(start_edge, SelectionModel(0, CURSOR_BACKWARD)); |
| 730 EXPECT_EQ(cases[i].expected_left_end_placement, model.caret_placement()); | |
| 731 | 707 |
| 732 model = render_text->EdgeSelectionModel(CURSOR_RIGHT); | 708 SelectionModel end_edge = |
| 733 EXPECT_EQ(cases[i].expected_right_end_caret, model.caret_pos()); | 709 render_text->EdgeSelectionModel(ltr ? CURSOR_RIGHT : CURSOR_LEFT); |
| 734 EXPECT_TRUE(render_text->IsCursorablePosition(model.caret_pos())); | 710 EXPECT_EQ(end_edge, SelectionModel(cases[i].text.length(), CURSOR_FORWARD)); |
| 735 EXPECT_EQ(cases[i].expected_right_end_placement, model.caret_placement()); | |
| 736 } | 711 } |
| 737 } | 712 } |
| 738 | 713 |
| 739 TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) { | 714 TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) { |
| 740 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 715 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 741 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); | 716 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); |
| 742 // Left arrow on select ranging (6, 4). | 717 // Left arrow on select ranging (6, 4). |
| 743 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 718 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); |
| 744 EXPECT_EQ(6U, render_text->GetCursorPosition()); | 719 EXPECT_EQ(ui::Range(6), render_text->selection()); |
| 745 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 720 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); |
| 746 EXPECT_EQ(4U, render_text->GetCursorPosition()); | 721 EXPECT_EQ(ui::Range(4), render_text->selection()); |
| 747 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 722 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); |
| 748 EXPECT_EQ(5U, render_text->GetCursorPosition()); | 723 EXPECT_EQ(ui::Range(5), render_text->selection()); |
| 749 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 724 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); |
| 750 EXPECT_EQ(6U, render_text->GetCursorPosition()); | 725 EXPECT_EQ(ui::Range(6), render_text->selection()); |
| 751 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, true); | 726 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, true); |
| 752 EXPECT_EQ(6U, render_text->GetSelectionStart()); | 727 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); | 728 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, true); |
| 755 EXPECT_EQ(6U, render_text->GetSelectionStart()); | 729 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); | 730 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); |
| 758 EXPECT_EQ(6U, render_text->GetCursorPosition()); | 731 EXPECT_EQ(ui::Range(6), render_text->selection()); |
| 759 | 732 |
| 760 // Right arrow on select ranging (4, 6). | 733 // Right arrow on select ranging (4, 6). |
| 761 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 734 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); |
| 762 EXPECT_EQ(0U, render_text->GetCursorPosition()); | 735 EXPECT_EQ(ui::Range(0), render_text->selection()); |
| 763 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 736 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
| 764 EXPECT_EQ(1U, render_text->GetCursorPosition()); | 737 EXPECT_EQ(ui::Range(1), render_text->selection()); |
| 765 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 738 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
| 766 EXPECT_EQ(2U, render_text->GetCursorPosition()); | 739 EXPECT_EQ(ui::Range(2), render_text->selection()); |
| 767 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 740 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
| 768 EXPECT_EQ(3U, render_text->GetCursorPosition()); | 741 EXPECT_EQ(ui::Range(3), render_text->selection()); |
| 769 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 742 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
| 770 EXPECT_EQ(5U, render_text->GetCursorPosition()); | 743 EXPECT_EQ(ui::Range(5), render_text->selection()); |
| 771 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 744 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
| 772 EXPECT_EQ(4U, render_text->GetCursorPosition()); | 745 EXPECT_EQ(ui::Range(4), render_text->selection()); |
| 773 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true); | 746 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true); |
| 774 EXPECT_EQ(4U, render_text->GetSelectionStart()); | 747 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); | 748 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true); |
| 777 EXPECT_EQ(4U, render_text->GetSelectionStart()); | 749 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); | 750 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
| 780 EXPECT_EQ(4U, render_text->GetCursorPosition()); | 751 EXPECT_EQ(ui::Range(4), render_text->selection()); |
| 781 } | 752 } |
| 782 | 753 |
| 783 // TODO(xji): Make these work on Windows. | 754 // TODO(xji): Make these work on Windows. |
| 784 #if defined(OS_LINUX) | 755 #if defined(OS_LINUX) |
| 785 void MoveLeftRightByWordVerifier(RenderText* render_text, | 756 void MoveLeftRightByWordVerifier(RenderText* render_text, |
| 786 const wchar_t* str) { | 757 const wchar_t* str) { |
| 787 render_text->SetText(WideToUTF16(str)); | 758 render_text->SetText(WideToUTF16(str)); |
| 788 | 759 |
| 789 // Test moving by word from left ro right. | 760 // Test moving by word from left ro right. |
| 790 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 761 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); |
| 791 bool first_word = true; | 762 bool first_word = true; |
| 792 while (true) { | 763 while (true) { |
| 793 // First, test moving by word from a word break position, such as from | 764 // First, test moving by word from a word break position, such as from |
| 794 // "|abc def" to "abc| def". | 765 // "|abc def" to "abc| def". |
| 795 SelectionModel start = render_text->selection_model(); | 766 SelectionModel start = render_text->selection_model(); |
| 796 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 767 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); |
| 797 SelectionModel end = render_text->selection_model(); | 768 SelectionModel end = render_text->selection_model(); |
| 798 if (end.Equals(start)) // reach the end. | 769 if (end == start) // reach the end. |
| 799 break; | 770 break; |
| 800 | 771 |
| 801 // For testing simplicity, each word is a 3-character word. | 772 // For testing simplicity, each word is a 3-character word. |
| 802 int num_of_character_moves = first_word ? 3 : 4; | 773 int num_of_character_moves = first_word ? 3 : 4; |
| 803 first_word = false; | 774 first_word = false; |
| 804 render_text->MoveCursorTo(start); | 775 render_text->MoveCursorTo(start); |
| 805 for (int j = 0; j < num_of_character_moves; ++j) | 776 for (int j = 0; j < num_of_character_moves; ++j) |
| 806 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 777 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
| 807 EXPECT_TRUE(render_text->selection_model().Equals(end)); | 778 EXPECT_EQ(end, render_text->selection_model()); |
| 808 | 779 |
| 809 // Then, test moving by word from positions inside the word, such as from | 780 // 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". | 781 // "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) { | 782 for (int j = 1; j < num_of_character_moves; ++j) { |
| 812 render_text->MoveCursorTo(start); | 783 render_text->MoveCursorTo(start); |
| 813 for (int k = 0; k < j; ++k) | 784 for (int k = 0; k < j; ++k) |
| 814 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 785 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
| 815 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 786 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); |
| 816 EXPECT_TRUE(render_text->selection_model().Equals(end)); | 787 EXPECT_EQ(end, render_text->selection_model()); |
| 817 } | 788 } |
| 818 } | 789 } |
| 819 | 790 |
| 820 // Test moving by word from right to left. | 791 // Test moving by word from right to left. |
| 821 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 792 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); |
| 822 first_word = true; | 793 first_word = true; |
| 823 while (true) { | 794 while (true) { |
| 824 SelectionModel start = render_text->selection_model(); | 795 SelectionModel start = render_text->selection_model(); |
| 825 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 796 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); |
| 826 SelectionModel end = render_text->selection_model(); | 797 SelectionModel end = render_text->selection_model(); |
| 827 if (end.Equals(start)) // reach the end. | 798 if (end == start) // reach the end. |
| 828 break; | 799 break; |
| 829 | 800 |
| 830 int num_of_character_moves = first_word ? 3 : 4; | 801 int num_of_character_moves = first_word ? 3 : 4; |
| 831 first_word = false; | 802 first_word = false; |
| 832 render_text->MoveCursorTo(start); | 803 render_text->MoveCursorTo(start); |
| 833 for (int j = 0; j < num_of_character_moves; ++j) | 804 for (int j = 0; j < num_of_character_moves; ++j) |
| 834 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 805 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); |
| 835 EXPECT_TRUE(render_text->selection_model().Equals(end)); | 806 EXPECT_EQ(end, render_text->selection_model()); |
| 836 | 807 |
| 837 for (int j = 1; j < num_of_character_moves; ++j) { | 808 for (int j = 1; j < num_of_character_moves; ++j) { |
| 838 render_text->MoveCursorTo(start); | 809 render_text->MoveCursorTo(start); |
| 839 for (int k = 0; k < j; ++k) | 810 for (int k = 0; k < j; ++k) |
| 840 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 811 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); |
| 841 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 812 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); |
| 842 EXPECT_TRUE(render_text->selection_model().Equals(end)); | 813 EXPECT_EQ(end, render_text->selection_model()); |
| 843 } | 814 } |
| 844 } | 815 } |
| 845 } | 816 } |
| 846 | 817 |
| 847 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText) { | 818 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText) { |
| 848 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 819 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 849 | 820 |
| 850 // For testing simplicity, each word is a 3-character word. | 821 // For testing simplicity, each word is a 3-character word. |
| 851 std::vector<const wchar_t*> test; | 822 std::vector<const wchar_t*> test; |
| 852 test.push_back(L"abc"); | 823 test.push_back(L"abc"); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 882 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText_TestEndOfText) { | 853 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText_TestEndOfText) { |
| 883 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 854 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 884 | 855 |
| 885 render_text->SetText(WideToUTF16(L"ab\x05E1")); | 856 render_text->SetText(WideToUTF16(L"ab\x05E1")); |
| 886 // Moving the cursor by word from "abC|" to the left should return "|abC". | 857 // 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 | 858 // But since end of text is always treated as a word break, it returns |
| 888 // position "ab|C". | 859 // position "ab|C". |
| 889 // TODO(xji): Need to make it work as expected. | 860 // TODO(xji): Need to make it work as expected. |
| 890 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 861 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); |
| 891 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 862 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); |
| 892 // EXPECT_TRUE(render_text->selection_model().Equals(SelectionModel(0))); | 863 // EXPECT_EQ(SelectionModel(), render_text->selection_model()); |
| 893 | 864 |
| 894 // Moving the cursor by word from "|abC" to the right returns "abC|". | 865 // Moving the cursor by word from "|abC" to the right returns "abC|". |
| 895 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 866 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); |
| 896 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 867 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); |
| 897 EXPECT_TRUE(render_text->selection_model().Equals( | 868 EXPECT_EQ(SelectionModel(3, CURSOR_FORWARD), render_text->selection_model()); |
| 898 SelectionModel(3, 2, SelectionModel::LEADING))); | |
| 899 | 869 |
| 900 render_text->SetText(WideToUTF16(L"\x05E1\x05E2"L"a")); | 870 render_text->SetText(WideToUTF16(L"\x05E1\x05E2"L"a")); |
| 901 // For logical text "BCa", moving the cursor by word from "aCB|" to the left | 871 // For logical text "BCa", moving the cursor by word from "aCB|" to the left |
| 902 // returns "|aCB". | 872 // returns "|aCB". |
| 903 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 873 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); |
| 904 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 874 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); |
| 905 EXPECT_TRUE(render_text->selection_model().Equals( | 875 EXPECT_EQ(SelectionModel(3, CURSOR_FORWARD), render_text->selection_model()); |
| 906 SelectionModel(3, 2, SelectionModel::LEADING))); | |
| 907 | 876 |
| 908 // Moving the cursor by word from "|aCB" to the right should return "aCB|". | 877 // 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 | 878 // But since end of text is always treated as a word break, it returns |
| 910 // position "a|CB". | 879 // position "a|CB". |
| 911 // TODO(xji): Need to make it work as expected. | 880 // TODO(xji): Need to make it work as expected. |
| 912 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 881 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); |
| 913 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 882 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); |
| 914 // EXPECT_TRUE(render_text->selection_model().Equals(SelectionModel(0))); | 883 // EXPECT_EQ(SelectionModel(), render_text->selection_model()); |
| 915 } | 884 } |
| 916 | 885 |
| 917 TEST_F(RenderTextTest, MoveLeftRightByWordInTextWithMultiSpaces) { | 886 TEST_F(RenderTextTest, MoveLeftRightByWordInTextWithMultiSpaces) { |
| 918 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 887 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 919 render_text->SetText(WideToUTF16(L"abc def")); | 888 render_text->SetText(WideToUTF16(L"abc def")); |
| 920 render_text->MoveCursorTo(SelectionModel(5)); | 889 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); |
| 921 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 890 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); |
| 922 EXPECT_EQ(11U, render_text->GetCursorPosition()); | 891 EXPECT_EQ(11U, render_text->cursor_position()); |
| 923 | 892 |
| 924 render_text->MoveCursorTo(SelectionModel(5)); | 893 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); |
| 925 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 894 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); |
| 926 EXPECT_EQ(0U, render_text->GetCursorPosition()); | 895 EXPECT_EQ(0U, render_text->cursor_position()); |
| 927 } | 896 } |
| 928 | 897 |
| 929 TEST_F(RenderTextTest, MoveLeftRightByWordInChineseText) { | 898 TEST_F(RenderTextTest, MoveLeftRightByWordInChineseText) { |
| 930 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 899 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 931 render_text->SetText(WideToUTF16(L"\x6211\x4EEC\x53BB\x516C\x56ED\x73A9")); | 900 render_text->SetText(WideToUTF16(L"\x6211\x4EEC\x53BB\x516C\x56ED\x73A9")); |
| 932 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 901 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); |
| 933 EXPECT_EQ(0U, render_text->GetCursorPosition()); | 902 EXPECT_EQ(0U, render_text->cursor_position()); |
| 934 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 903 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); |
| 935 EXPECT_EQ(2U, render_text->GetCursorPosition()); | 904 EXPECT_EQ(2U, render_text->cursor_position()); |
| 936 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 905 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); |
| 937 EXPECT_EQ(3U, render_text->GetCursorPosition()); | 906 EXPECT_EQ(3U, render_text->cursor_position()); |
| 938 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 907 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); |
| 939 EXPECT_EQ(5U, render_text->GetCursorPosition()); | 908 EXPECT_EQ(5U, render_text->cursor_position()); |
| 940 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 909 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); |
| 941 EXPECT_EQ(6U, render_text->GetCursorPosition()); | 910 EXPECT_EQ(6U, render_text->cursor_position()); |
| 942 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 911 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); |
| 943 EXPECT_EQ(6U, render_text->GetCursorPosition()); | 912 EXPECT_EQ(6U, render_text->cursor_position()); |
| 944 } | 913 } |
| 945 | 914 |
| 946 TEST_F(RenderTextTest, StringWidthTest) { | 915 TEST_F(RenderTextTest, StringWidthTest) { |
| 947 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 916 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 948 render_text->SetText(UTF8ToUTF16("Hello World")); | 917 render_text->SetText(UTF8ToUTF16("Hello World")); |
| 949 | 918 |
| 950 // Check that width is valid | 919 // Check that width is valid |
| 951 int width = render_text->GetStringWidth(); | 920 int width = render_text->GetStringSize().width(); |
| 952 EXPECT_GT(width, 0); | 921 EXPECT_GT(width, 0); |
| 953 | 922 |
| 954 // Apply a bold style and check that the new width is greater. | 923 // Apply a bold style and check that the new width is greater. |
| 955 StyleRange bold; | 924 StyleRange bold; |
| 956 bold.font_style |= gfx::Font::BOLD; | 925 bold.font_style |= gfx::Font::BOLD; |
| 957 render_text->set_default_style(bold); | 926 render_text->set_default_style(bold); |
| 958 render_text->ApplyDefaultStyle(); | 927 render_text->ApplyDefaultStyle(); |
| 959 EXPECT_GT(render_text->GetStringWidth(), width); | 928 EXPECT_GT(render_text->GetStringSize().width(), width); |
| 960 } | 929 } |
| 961 | 930 |
| 962 #endif | 931 #endif |
| 963 | 932 |
| 964 TEST_F(RenderTextTest, CursorBoundsInReplacementMode) { | 933 TEST_F(RenderTextTest, CursorBoundsInReplacementMode) { |
| 965 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 934 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 966 render_text->SetText(ASCIIToUTF16("abcdefg")); | 935 render_text->SetText(ASCIIToUTF16("abcdefg")); |
| 967 render_text->SetDisplayRect(Rect(100, 17)); | 936 render_text->SetDisplayRect(Rect(100, 17)); |
| 968 SelectionModel sel_b(1); | 937 SelectionModel sel_b(1, CURSOR_FORWARD); |
| 969 SelectionModel sel_c(2); | 938 SelectionModel sel_c(2, CURSOR_FORWARD); |
| 970 Rect cursor_around_b = render_text->GetCursorBounds(sel_b, false); | 939 Rect cursor_around_b = render_text->GetCursorBounds(sel_b, false); |
| 971 Rect cursor_before_b = render_text->GetCursorBounds(sel_b, true); | 940 Rect cursor_before_b = render_text->GetCursorBounds(sel_b, true); |
| 972 Rect cursor_before_c = render_text->GetCursorBounds(sel_c, true); | 941 Rect cursor_before_c = render_text->GetCursorBounds(sel_c, true); |
| 973 EXPECT_EQ(cursor_around_b.x(), cursor_before_b.x()); | 942 EXPECT_EQ(cursor_around_b.x(), cursor_before_b.x()); |
| 974 EXPECT_EQ(cursor_around_b.right(), cursor_before_c.x()); | 943 EXPECT_EQ(cursor_around_b.right(), cursor_before_c.x()); |
| 975 } | 944 } |
| 976 | 945 |
| 977 TEST_F(RenderTextTest, OriginForSkiaDrawing) { | 946 TEST_F(RenderTextTest, OriginForSkiaDrawing) { |
| 978 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 947 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 979 render_text->SetText(ASCIIToUTF16("abcdefg")); | 948 render_text->SetText(ASCIIToUTF16("abcdefg")); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 993 render_text->SetDisplayRect(display_rect); | 962 render_text->SetDisplayRect(display_rect); |
| 994 | 963 |
| 995 origin = render_text->GetOriginForSkiaDrawing(); | 964 origin = render_text->GetOriginForSkiaDrawing(); |
| 996 EXPECT_EQ(origin.x(), 0); | 965 EXPECT_EQ(origin.x(), 0); |
| 997 EXPECT_EQ(origin.y(), 14); | 966 EXPECT_EQ(origin.y(), 14); |
| 998 } | 967 } |
| 999 | 968 |
| 1000 TEST_F(RenderTextTest, DisplayRectShowsCursorLTR) { | 969 TEST_F(RenderTextTest, DisplayRectShowsCursorLTR) { |
| 1001 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 970 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 1002 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg")); | 971 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg")); |
| 1003 render_text->MoveCursorTo(SelectionModel(render_text->text().length())); | 972 render_text->MoveCursorTo(SelectionModel(render_text->text().length(), |
| 1004 int width = render_text->GetStringWidth(); | 973 CURSOR_FORWARD)); |
| 974 int width = render_text->GetStringSize().width(); |
| 1005 | 975 |
| 1006 // Ensure that the cursor is placed at the width of its preceding text. | 976 // Ensure that the cursor is placed at the width of its preceding text. |
| 1007 render_text->SetDisplayRect(Rect(width + 10, 1)); | 977 render_text->SetDisplayRect(Rect(width + 10, 1)); |
| 1008 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); | 978 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); |
| 1009 | 979 |
| 1010 // Ensure that shrinking the display rectangle keeps the cursor in view. | 980 // Ensure that shrinking the display rectangle keeps the cursor in view. |
| 1011 render_text->SetDisplayRect(Rect(width - 10, 1)); | 981 render_text->SetDisplayRect(Rect(width - 10, 1)); |
| 1012 EXPECT_EQ(render_text->display_rect().width() - 1, | 982 EXPECT_EQ(render_text->display_rect().width() - 1, |
| 1013 render_text->GetUpdatedCursorBounds().x()); | 983 render_text->GetUpdatedCursorBounds().x()); |
| 1014 | 984 |
| 1015 // Ensure that the text will pan to fill its expanding display rectangle. | 985 // Ensure that the text will pan to fill its expanding display rectangle. |
| 1016 render_text->SetDisplayRect(Rect(width - 5, 1)); | 986 render_text->SetDisplayRect(Rect(width - 5, 1)); |
| 1017 EXPECT_EQ(render_text->display_rect().width() - 1, | 987 EXPECT_EQ(render_text->display_rect().width() - 1, |
| 1018 render_text->GetUpdatedCursorBounds().x()); | 988 render_text->GetUpdatedCursorBounds().x()); |
| 1019 | 989 |
| 1020 // Ensure that a sufficiently large display rectangle shows all the text. | 990 // Ensure that a sufficiently large display rectangle shows all the text. |
| 1021 render_text->SetDisplayRect(Rect(width + 10, 1)); | 991 render_text->SetDisplayRect(Rect(width + 10, 1)); |
| 1022 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); | 992 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); |
| 1023 | 993 |
| 1024 // Repeat the test with RTL text. | 994 // Repeat the test with RTL text. |
| 1025 render_text->SetText(WideToUTF16(L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7" | 995 render_text->SetText(WideToUTF16(L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7" |
| 1026 L"\x5d8\x5d9\x5da\x5db\x5dc\x5dd\x5de\x5df")); | 996 L"\x5d8\x5d9\x5da\x5db\x5dc\x5dd\x5de\x5df")); |
| 1027 render_text->MoveCursorTo(SelectionModel(0)); | 997 render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD)); |
| 1028 width = render_text->GetStringWidth(); | 998 width = render_text->GetStringSize().width(); |
| 1029 | 999 |
| 1030 // Ensure that the cursor is placed at the width of its preceding text. | 1000 // Ensure that the cursor is placed at the width of its preceding text. |
| 1031 render_text->SetDisplayRect(Rect(width + 10, 1)); | 1001 render_text->SetDisplayRect(Rect(width + 10, 1)); |
| 1032 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); | 1002 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); |
| 1033 | 1003 |
| 1034 // Ensure that shrinking the display rectangle keeps the cursor in view. | 1004 // Ensure that shrinking the display rectangle keeps the cursor in view. |
| 1035 render_text->SetDisplayRect(Rect(width - 10, 1)); | 1005 render_text->SetDisplayRect(Rect(width - 10, 1)); |
| 1036 EXPECT_EQ(render_text->display_rect().width() - 1, | 1006 EXPECT_EQ(render_text->display_rect().width() - 1, |
| 1037 render_text->GetUpdatedCursorBounds().x()); | 1007 render_text->GetUpdatedCursorBounds().x()); |
| 1038 | 1008 |
| 1039 // Ensure that the text will pan to fill its expanding display rectangle. | 1009 // Ensure that the text will pan to fill its expanding display rectangle. |
| 1040 render_text->SetDisplayRect(Rect(width - 5, 1)); | 1010 render_text->SetDisplayRect(Rect(width - 5, 1)); |
| 1041 EXPECT_EQ(render_text->display_rect().width() - 1, | 1011 EXPECT_EQ(render_text->display_rect().width() - 1, |
| 1042 render_text->GetUpdatedCursorBounds().x()); | 1012 render_text->GetUpdatedCursorBounds().x()); |
| 1043 | 1013 |
| 1044 // Ensure that a sufficiently large display rectangle shows all the text. | 1014 // Ensure that a sufficiently large display rectangle shows all the text. |
| 1045 render_text->SetDisplayRect(Rect(width + 10, 1)); | 1015 render_text->SetDisplayRect(Rect(width + 10, 1)); |
| 1046 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); | 1016 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); |
| 1047 } | 1017 } |
| 1048 | 1018 |
| 1049 TEST_F(RenderTextTest, DisplayRectShowsCursorRTL) { | 1019 TEST_F(RenderTextTest, DisplayRectShowsCursorRTL) { |
| 1050 // Set the locale to Hebrew for RTL UI. | 1020 // Set the locale to Hebrew for RTL UI. |
| 1051 std::string locale = l10n_util::GetApplicationLocale(""); | 1021 std::string locale = l10n_util::GetApplicationLocale(""); |
| 1052 base::i18n::SetICUDefaultLocale("he"); | 1022 base::i18n::SetICUDefaultLocale("he"); |
| 1053 | 1023 |
| 1054 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 1024 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 1055 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg")); | 1025 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg")); |
| 1056 render_text->MoveCursorTo(SelectionModel(0)); | 1026 render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD)); |
| 1057 int width = render_text->GetStringWidth(); | 1027 int width = render_text->GetStringSize().width(); |
| 1058 | 1028 |
| 1059 // Ensure that the cursor is placed at the width of its preceding text. | 1029 // Ensure that the cursor is placed at the width of its preceding text. |
| 1060 render_text->SetDisplayRect(Rect(width + 10, 1)); | 1030 render_text->SetDisplayRect(Rect(width + 10, 1)); |
| 1061 EXPECT_EQ(render_text->display_rect().width() - width - 1, | 1031 EXPECT_EQ(render_text->display_rect().width() - width - 1, |
| 1062 render_text->GetUpdatedCursorBounds().x()); | 1032 render_text->GetUpdatedCursorBounds().x()); |
| 1063 | 1033 |
| 1064 // Ensure that shrinking the display rectangle keeps the cursor in view. | 1034 // Ensure that shrinking the display rectangle keeps the cursor in view. |
| 1065 render_text->SetDisplayRect(Rect(width - 10, 1)); | 1035 render_text->SetDisplayRect(Rect(width - 10, 1)); |
| 1066 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); | 1036 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); |
| 1067 | 1037 |
| 1068 // Ensure that the text will pan to fill its expanding display rectangle. | 1038 // Ensure that the text will pan to fill its expanding display rectangle. |
| 1069 render_text->SetDisplayRect(Rect(width - 5, 1)); | 1039 render_text->SetDisplayRect(Rect(width - 5, 1)); |
| 1070 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); | 1040 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); |
| 1071 | 1041 |
| 1072 // Ensure that a sufficiently large display rectangle shows all the text. | 1042 // Ensure that a sufficiently large display rectangle shows all the text. |
| 1073 render_text->SetDisplayRect(Rect(width + 10, 1)); | 1043 render_text->SetDisplayRect(Rect(width + 10, 1)); |
| 1074 EXPECT_EQ(render_text->display_rect().width() - width - 1, | 1044 EXPECT_EQ(render_text->display_rect().width() - width - 1, |
| 1075 render_text->GetUpdatedCursorBounds().x()); | 1045 render_text->GetUpdatedCursorBounds().x()); |
| 1076 | 1046 |
| 1077 // Repeat the test with RTL text. | 1047 // Repeat the test with RTL text. |
| 1078 render_text->SetText(WideToUTF16(L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7" | 1048 render_text->SetText(WideToUTF16(L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7" |
| 1079 L"\x5d8\x5d9\x5da\x5db\x5dc\x5dd\x5de\x5df")); | 1049 L"\x5d8\x5d9\x5da\x5db\x5dc\x5dd\x5de\x5df")); |
| 1080 render_text->MoveCursorTo(SelectionModel(render_text->text().length())); | 1050 render_text->MoveCursorTo(SelectionModel(render_text->text().length(), |
| 1081 width = render_text->GetStringWidth(); | 1051 CURSOR_FORWARD)); |
| 1052 width = render_text->GetStringSize().width(); |
| 1082 | 1053 |
| 1083 // Ensure that the cursor is placed at the width of its preceding text. | 1054 // Ensure that the cursor is placed at the width of its preceding text. |
| 1084 render_text->SetDisplayRect(Rect(width + 10, 1)); | 1055 render_text->SetDisplayRect(Rect(width + 10, 1)); |
| 1085 EXPECT_EQ(render_text->display_rect().width() - width - 1, | 1056 EXPECT_EQ(render_text->display_rect().width() - width - 1, |
| 1086 render_text->GetUpdatedCursorBounds().x()); | 1057 render_text->GetUpdatedCursorBounds().x()); |
| 1087 | 1058 |
| 1088 // Ensure that shrinking the display rectangle keeps the cursor in view. | 1059 // Ensure that shrinking the display rectangle keeps the cursor in view. |
| 1089 render_text->SetDisplayRect(Rect(width - 10, 1)); | 1060 render_text->SetDisplayRect(Rect(width - 10, 1)); |
| 1090 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); | 1061 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); |
| 1091 | 1062 |
| 1092 // Ensure that the text will pan to fill its expanding display rectangle. | 1063 // Ensure that the text will pan to fill its expanding display rectangle. |
| 1093 render_text->SetDisplayRect(Rect(width - 5, 1)); | 1064 render_text->SetDisplayRect(Rect(width - 5, 1)); |
| 1094 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); | 1065 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); |
| 1095 | 1066 |
| 1096 // Ensure that a sufficiently large display rectangle shows all the text. | 1067 // Ensure that a sufficiently large display rectangle shows all the text. |
| 1097 render_text->SetDisplayRect(Rect(width + 10, 1)); | 1068 render_text->SetDisplayRect(Rect(width + 10, 1)); |
| 1098 EXPECT_EQ(render_text->display_rect().width() - width - 1, | 1069 EXPECT_EQ(render_text->display_rect().width() - width - 1, |
| 1099 render_text->GetUpdatedCursorBounds().x()); | 1070 render_text->GetUpdatedCursorBounds().x()); |
| 1100 | 1071 |
| 1101 // Reset locale. | 1072 // Reset locale. |
| 1102 base::i18n::SetICUDefaultLocale(locale); | 1073 base::i18n::SetICUDefaultLocale(locale); |
| 1103 } | 1074 } |
| 1104 | 1075 |
| 1105 } // namespace gfx | 1076 } // namespace gfx |
| OLD | NEW |