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

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

Powered by Google App Engine
This is Rietveld 408576698