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

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

Powered by Google App Engine
This is Rietveld 408576698