OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 test fixture. | 5 // Include test fixture. |
6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js', | 6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js', |
7 '../../testing/assert_additions.js']); | 7 '../../testing/assert_additions.js']); |
8 | 8 |
9 GEN_INCLUDE(['../../testing/mock_feedback.js']); | 9 GEN_INCLUDE(['../../testing/mock_feedback.js']); |
10 | 10 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 <p>hello <b>world</b></p> | 485 <p>hello <b>world</b></p> |
486 </div> | 486 </div> |
487 */}, function(root) { | 487 */}, function(root) { |
488 var thisIsATest = root.findAll({role: RoleType.PARAGRAPH})[0].firstChild; | 488 var thisIsATest = root.findAll({role: RoleType.PARAGRAPH})[0].firstChild; |
489 var hello = root.findAll({role: RoleType.PARAGRAPH})[1].firstChild; | 489 var hello = root.findAll({role: RoleType.PARAGRAPH})[1].firstChild; |
490 var world = root.findAll({role: RoleType.PARAGRAPH})[1].lastChild; | 490 var world = root.findAll({role: RoleType.PARAGRAPH})[1].lastChild; |
491 | 491 |
492 // The same position -- sanity check. | 492 // The same position -- sanity check. |
493 var e1 = new editing.EditableLine(thisIsATest, 0, thisIsATest, 0); | 493 var e1 = new editing.EditableLine(thisIsATest, 0, thisIsATest, 0); |
494 assertEquals('this ', e1.text); | 494 assertEquals('this ', e1.text); |
495 assertTrue(e1.equals(e1)); | 495 assertTrue(e1.isSameLine(e1)); |
496 | 496 |
497 // Offset into the same soft line. | 497 // Offset into the same soft line. |
498 var e2 = new editing.EditableLine(thisIsATest, 1, thisIsATest, 1); | 498 var e2 = new editing.EditableLine(thisIsATest, 1, thisIsATest, 1); |
499 assertTrue(e1.equals(e2)); | 499 assertTrue(e1.isSameLine(e2)); |
500 | 500 |
501 // Boundary. | 501 // Boundary. |
502 e2 = new editing.EditableLine(thisIsATest, 4, thisIsATest, 4); | 502 e2 = new editing.EditableLine(thisIsATest, 4, thisIsATest, 4); |
503 assertTrue(e1.equals(e2)); | 503 assertTrue(e1.isSameLine(e2)); |
504 | 504 |
505 // Offsets into different soft lines. | 505 // Offsets into different soft lines. |
506 e2 = new editing.EditableLine(thisIsATest, 5, thisIsATest, 5); | 506 e2 = new editing.EditableLine(thisIsATest, 5, thisIsATest, 5); |
507 assertEquals('is ', e2.text); | 507 assertEquals('is ', e2.text); |
508 assertFalse(e1.equals(e2)); | 508 assertFalse(e1.isSameLine(e2)); |
509 | 509 |
510 // Sanity check; second soft line. | 510 // Sanity check; second soft line. |
511 assertTrue(e2.equals(e2)); | 511 assertTrue(e2.isSameLine(e2)); |
512 | 512 |
513 // Different offsets into second soft line. | 513 // Different offsets into second soft line. |
514 e1 = new editing.EditableLine(thisIsATest, 6, thisIsATest, 6); | 514 e1 = new editing.EditableLine(thisIsATest, 6, thisIsATest, 6); |
515 assertTrue(e1.equals(e2)); | 515 assertTrue(e1.isSameLine(e2)); |
516 | 516 |
517 // Boundary. | 517 // Boundary. |
518 e1 = new editing.EditableLine(thisIsATest, 7, thisIsATest, 7); | 518 e1 = new editing.EditableLine(thisIsATest, 7, thisIsATest, 7); |
519 assertTrue(e1.equals(e2)); | 519 assertTrue(e1.isSameLine(e2)); |
520 | 520 |
521 // Third line. | 521 // Third line. |
522 e1 = new editing.EditableLine(thisIsATest, 8, thisIsATest, 8); | 522 e1 = new editing.EditableLine(thisIsATest, 8, thisIsATest, 8); |
523 assertEquals('a ', e1.text); | 523 assertEquals('a ', e1.text); |
524 assertFalse(e1.equals(e2)); | 524 assertFalse(e1.isSameLine(e2)); |
525 | 525 |
526 // Last line. | 526 // Last line. |
527 e2 = new editing.EditableLine(thisIsATest, 10, thisIsATest, 10); | 527 e2 = new editing.EditableLine(thisIsATest, 10, thisIsATest, 10); |
528 assertEquals('test', e2.text); | 528 assertEquals('test', e2.text); |
529 assertFalse(e1.equals(e2)); | 529 assertFalse(e1.isSameLine(e2)); |
530 | 530 |
531 // Boundary. | 531 // Boundary. |
532 e1 = new editing.EditableLine(thisIsATest, 13, thisIsATest, 13); | 532 e1 = new editing.EditableLine(thisIsATest, 13, thisIsATest, 13); |
533 assertTrue(e1.equals(e2)); | 533 assertTrue(e1.isSameLine(e2)); |
534 | 534 |
535 // Cross into new paragraph. | 535 // Cross into new paragraph. |
536 e2 = new editing.EditableLine(hello, 0, hello, 0); | 536 e2 = new editing.EditableLine(hello, 0, hello, 0); |
537 assertEquals('hello world', e2.text); | 537 assertEquals('hello world', e2.text); |
538 assertFalse(e1.equals(e2)); | 538 assertFalse(e1.isSameLine(e2)); |
539 | 539 |
540 // On same node, with multi-static text line. | 540 // On same node, with multi-static text line. |
541 e1 = new editing.EditableLine(hello, 1, hello, 1); | 541 e1 = new editing.EditableLine(hello, 1, hello, 1); |
542 assertTrue(e1.equals(e2)); | 542 assertTrue(e1.isSameLine(e2)); |
543 | 543 |
544 // On same node, with multi-static text line; boundary. | 544 // On same node, with multi-static text line; boundary. |
545 e1 = new editing.EditableLine(hello, 5, hello, 5); | 545 e1 = new editing.EditableLine(hello, 5, hello, 5); |
546 assertTrue(e1.equals(e2)); | 546 assertTrue(e1.isSameLine(e2)); |
547 | 547 |
548 // On different node, with multi-static text line. | 548 // On different node, with multi-static text line. |
549 e1 = new editing.EditableLine(world, 1, world, 1); | 549 e1 = new editing.EditableLine(world, 1, world, 1); |
550 assertTrue(e1.equals(e2)); | 550 assertTrue(e1.isSameLine(e2)); |
551 | 551 |
552 // Another mix of lines. | 552 // Another mix of lines. |
553 e2 = new editing.EditableLine(thisIsATest, 9, thisIsATest, 9); | 553 e2 = new editing.EditableLine(thisIsATest, 9, thisIsATest, 9); |
554 assertFalse(e1.equals(e2)); | 554 assertFalse(e1.isSameLine(e2)); |
555 }); | 555 }); |
556 }); | 556 }); |
| 557 |
| 558 TEST_F('EditingTest', 'EditableLineStrictEquality', function() { |
| 559 this.runWithLoadedTree(function() {/*! |
| 560 <div contenteditable role="textbox"> |
| 561 <p style="word-spacing:100000px">this is a test</p> |
| 562 <p>hello <b>world</b></p> |
| 563 </div> |
| 564 */}, function(root) { |
| 565 var thisIsATest = root.findAll({role: RoleType.PARAGRAPH})[0].firstChild; |
| 566 var hello = root.findAll({role: RoleType.PARAGRAPH})[1].firstChild; |
| 567 var world = root.findAll({role: RoleType.PARAGRAPH})[1].lastChild; |
| 568 |
| 569 // The same position -- sanity check. |
| 570 var e1 = new editing.EditableLine(thisIsATest, 0, thisIsATest, 0); |
| 571 assertEquals('this ', e1.text); |
| 572 assertTrue(e1.isSameLineAndSelection(e1)); |
| 573 |
| 574 // Offset into the same soft line. |
| 575 var e2 = new editing.EditableLine(thisIsATest, 1, thisIsATest, 1); |
| 576 assertFalse(e1.isSameLineAndSelection(e2)); |
| 577 |
| 578 // Boundary. |
| 579 e2 = new editing.EditableLine(thisIsATest, 4, thisIsATest, 4); |
| 580 assertFalse(e1.isSameLineAndSelection(e2)); |
| 581 |
| 582 // Offsets into different soft lines. |
| 583 e2 = new editing.EditableLine(thisIsATest, 5, thisIsATest, 5); |
| 584 assertEquals('is ', e2.text); |
| 585 assertFalse(e1.isSameLineAndSelection(e2)); |
| 586 |
| 587 // Sanity check; second soft line. |
| 588 assertTrue(e2.isSameLineAndSelection(e2)); |
| 589 |
| 590 // Different offsets into second soft line. |
| 591 e1 = new editing.EditableLine(thisIsATest, 6, thisIsATest, 6); |
| 592 assertFalse(e1.isSameLineAndSelection(e2)); |
| 593 |
| 594 // Boundary. |
| 595 e1 = new editing.EditableLine(thisIsATest, 7, thisIsATest, 7); |
| 596 assertFalse(e1.isSameLineAndSelection(e2)); |
| 597 |
| 598 // Cross into new paragraph. |
| 599 e2 = new editing.EditableLine(hello, 0, hello, 0); |
| 600 assertEquals('hello world', e2.text); |
| 601 assertFalse(e1.isSameLineAndSelection(e2)); |
| 602 |
| 603 // On same node, with multi-static text line. |
| 604 e1 = new editing.EditableLine(hello, 1, hello, 1); |
| 605 assertFalse(e1.isSameLineAndSelection(e2)); |
| 606 |
| 607 // On same node, with multi-static text line; boundary. |
| 608 e1 = new editing.EditableLine(hello, 5, hello, 5); |
| 609 assertFalse(e1.isSameLineAndSelection(e2)); |
| 610 }); |
| 611 }); |
| 612 |
| 613 TEST_F('EditingTest', 'EditableLineBaseLineAnchorOrFocus', function() { |
| 614 this.runWithLoadedTree(function() {/*! |
| 615 <div contenteditable role="textbox"> |
| 616 <p style="word-spacing:100000px">this is a test</p> |
| 617 <p>hello <b>world</b></p> |
| 618 </div> |
| 619 */}, function(root) { |
| 620 var thisIsATest = root.findAll({role: RoleType.PARAGRAPH})[0].firstChild; |
| 621 var hello = root.findAll({role: RoleType.PARAGRAPH})[1].firstChild; |
| 622 var world = root.findAll({role: RoleType.PARAGRAPH})[1].lastChild; |
| 623 |
| 624 // The same position -- sanity check. |
| 625 var e1 = new editing.EditableLine(thisIsATest, 0, thisIsATest, 0, true); |
| 626 assertEquals('this ', e1.text); |
| 627 |
| 628 // Offsets into different soft lines; base on focus (default). |
| 629 e1 = new editing.EditableLine(thisIsATest, 0, thisIsATest, 6); |
| 630 assertEquals('is ', e1.text); |
| 631 // Notice that the offset is truncated at the beginning of the line. |
| 632 assertEquals(0, e1.startOffset); |
| 633 // Notice that the end offset is properly retained. |
| 634 assertEquals(1, e1.endOffset); |
| 635 |
| 636 // Offsets into different soft lines; base on anchor. |
| 637 e1 = new editing.EditableLine(thisIsATest, 0, thisIsATest, 6, true); |
| 638 assertEquals('this ', e1.text); |
| 639 assertEquals(0, e1.startOffset); |
| 640 // Notice that the end offset is truncated up to the end of line. |
| 641 assertEquals(5, e1.endOffset); |
| 642 |
| 643 // Across paragraph selection with base line on focus. |
| 644 e1 = new editing.EditableLine(thisIsATest, 5, hello, 2); |
| 645 assertEquals('hello world', e1.text); |
| 646 assertEquals(0, e1.startOffset); |
| 647 assertEquals(2, e1.endOffset); |
| 648 |
| 649 // Across paragraph selection with base line on anchor. |
| 650 e1 = new editing.EditableLine(thisIsATest, 5, hello, 2, true); |
| 651 assertEquals('is ', e1.text); |
| 652 assertEquals(0, e1.startOffset); |
| 653 assertEquals(3, e1.endOffset); |
| 654 }) |
| 655 }); |
OLD | NEW |