OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "core/editing/InputMethodController.h" | 5 #include "core/editing/InputMethodController.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/dom/Element.h" | 9 #include "core/dom/Element.h" |
10 #include "core/dom/Range.h" | 10 #include "core/dom/Range.h" |
(...skipping 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1535 controller().commitText(String(""), emptyUnderlines, 0); | 1535 controller().commitText(String(""), emptyUnderlines, 0); |
1536 | 1536 |
1537 // Check that the marker is still attached to "text" and doesn't include | 1537 // Check that the marker is still attached to "text" and doesn't include |
1538 // either space around it | 1538 // either space around it |
1539 EXPECT_EQ(1u, document().markers().markersFor(div->firstChild()).size()); | 1539 EXPECT_EQ(1u, document().markers().markersFor(div->firstChild()).size()); |
1540 EXPECT_STREQ( | 1540 EXPECT_STREQ( |
1541 "text", | 1541 "text", |
1542 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1542 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
1543 } | 1543 } |
1544 | 1544 |
1545 // TODO(rlanday): The behavior tested in the following DocumentMarker tests is | |
1546 // going to be changed so markers are not split when text they contain is | |
1547 // deleted | |
1548 | |
1549 TEST_F(InputMethodControllerTest, | 1545 TEST_F(InputMethodControllerTest, |
1550 Marker_WhitespaceFixupAroundMarkerBeginningWithSpace) { | 1546 Marker_WhitespaceFixupAroundMarkerBeginningWithSpace) { |
1551 Element* div = insertHTMLElement( | 1547 Element* div = insertHTMLElement( |
1552 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); | 1548 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); |
1553 | 1549 |
1554 // Add marker under " text" (use TextMatch since Composition markers don't | 1550 // Add marker under " text" (use TextMatch since Composition markers don't |
1555 // persist across editing operations) | 1551 // persist across editing operations) |
1556 EphemeralRange markerRange = PlainTextRange(7, 12).createRange(*div); | 1552 EphemeralRange markerRange = PlainTextRange(7, 12).createRange(*div); |
1557 document().markers().addMarker(markerRange.startPosition(), | 1553 document().markers().addMarker(markerRange.startPosition(), |
1558 markerRange.endPosition(), | 1554 markerRange.endPosition(), |
1559 DocumentMarker::TextMatch); | 1555 DocumentMarker::TextMatch); |
1560 // Delete "Initial" | 1556 // Delete "Initial" |
1561 Vector<CompositionUnderline> emptyUnderlines; | 1557 Vector<CompositionUnderline> emptyUnderlines; |
1562 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); | 1558 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); |
1563 controller().commitText(String(""), emptyUnderlines, 0); | 1559 controller().commitText(String(""), emptyUnderlines, 0); |
1564 | 1560 |
1565 // Delete "blah" | 1561 // Delete "blah" |
1566 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); | 1562 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); |
1567 controller().commitText(String(""), emptyUnderlines, 0); | 1563 controller().commitText(String(""), emptyUnderlines, 0); |
1568 | 1564 |
1569 // Check that the marker was split when the space at the beginning was | 1565 // Check that the marker is still attached to " text" and includes the space |
1570 // converted to an nbsp | 1566 // before "text" but not the space after |
1571 EXPECT_EQ(2u, document().markers().markers().size()); | 1567 EXPECT_EQ(1u, document().markers().markers().size()); |
1572 EXPECT_STREQ( | 1568 ASSERT_STREQ( |
1573 "\xC2\xA0", // UTF-8 for an nbsp | 1569 "\xC2\xA0text", |
1574 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1570 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
1575 EXPECT_STREQ( | |
1576 "text", | |
1577 getMarkedText(document().markers(), div->firstChild(), 1).utf8().data()); | |
1578 } | 1571 } |
1579 | 1572 |
1580 TEST_F(InputMethodControllerTest, | 1573 TEST_F(InputMethodControllerTest, |
1581 Marker_WhitespaceFixupAroundMarkerEndingWithSpace) { | 1574 Marker_WhitespaceFixupAroundMarkerEndingWithSpace) { |
1582 Element* div = insertHTMLElement( | 1575 Element* div = insertHTMLElement( |
1583 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); | 1576 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); |
1584 | 1577 |
1585 // Add marker under "text " (use TextMatch since Composition markers don't | 1578 // Add marker under "text " (use TextMatch since Composition markers don't |
1586 // persist across editing operations) | 1579 // persist across editing operations) |
1587 EphemeralRange markerRange = PlainTextRange(8, 13).createRange(*div); | 1580 EphemeralRange markerRange = PlainTextRange(8, 13).createRange(*div); |
1588 document().markers().addMarker(markerRange.startPosition(), | 1581 document().markers().addMarker(markerRange.startPosition(), |
1589 markerRange.endPosition(), | 1582 markerRange.endPosition(), |
1590 DocumentMarker::TextMatch); | 1583 DocumentMarker::TextMatch); |
1591 // Delete "Initial" | 1584 // Delete "Initial" |
1592 Vector<CompositionUnderline> emptyUnderlines; | 1585 Vector<CompositionUnderline> emptyUnderlines; |
1593 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); | 1586 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); |
1594 controller().commitText(String(""), emptyUnderlines, 0); | 1587 controller().commitText(String(""), emptyUnderlines, 0); |
1595 | 1588 |
1596 // Delete "blah" | 1589 // Delete "blah" |
1597 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); | 1590 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); |
1598 controller().commitText(String(""), emptyUnderlines, 0); | 1591 controller().commitText(String(""), emptyUnderlines, 0); |
1599 | 1592 |
1600 // Check that the marker was split when the space at the end was | 1593 // Check that the marker is still attached to "text " and includes the space |
1601 // converted to an nbsp | 1594 // after "text" but not the space before |
1602 EXPECT_EQ(2u, document().markers().markers().size()); | 1595 EXPECT_EQ(1u, document().markers().markers().size()); |
1603 EXPECT_STREQ( | 1596 ASSERT_STREQ( |
1604 "text", | 1597 "text\xC2\xA0", |
1605 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1598 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
1606 EXPECT_STREQ( | |
1607 "\xC2\xA0", // UTF-8 for an nbsp | |
1608 getMarkedText(document().markers(), div->firstChild(), 1).utf8().data()); | |
1609 } | 1599 } |
1610 | 1600 |
1611 TEST_F(InputMethodControllerTest, | 1601 TEST_F(InputMethodControllerTest, |
1612 Marker_WhitespaceFixupAroundMarkerBeginningAndEndingWithSpaces) { | 1602 Marker_WhitespaceFixupAroundMarkerBeginningAndEndingWithSpaces) { |
1613 Element* div = insertHTMLElement( | 1603 Element* div = insertHTMLElement( |
1614 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); | 1604 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); |
1615 | 1605 |
1616 // Add marker under " text " (use TextMatch since Composition markers don't | 1606 // Add marker under " text " (use TextMatch since Composition markers don't |
1617 // persist across editing operations) | 1607 // persist across editing operations) |
1618 EphemeralRange markerRange = PlainTextRange(7, 13).createRange(*div); | 1608 EphemeralRange markerRange = PlainTextRange(7, 13).createRange(*div); |
1619 document().markers().addMarker(markerRange.startPosition(), | 1609 document().markers().addMarker(markerRange.startPosition(), |
1620 markerRange.endPosition(), | 1610 markerRange.endPosition(), |
1621 DocumentMarker::TextMatch); | 1611 DocumentMarker::TextMatch); |
1622 | 1612 |
1623 // Delete "Initial" | 1613 // Delete "Initial" |
1624 Vector<CompositionUnderline> emptyUnderlines; | 1614 Vector<CompositionUnderline> emptyUnderlines; |
1625 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); | 1615 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); |
1626 controller().commitText(String(""), emptyUnderlines, 0); | 1616 controller().commitText(String(""), emptyUnderlines, 0); |
1627 | 1617 |
1628 // Delete "blah" | 1618 // Delete "blah" |
1629 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); | 1619 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); |
1630 controller().commitText(String(""), emptyUnderlines, 0); | 1620 controller().commitText(String(""), emptyUnderlines, 0); |
1631 | 1621 |
1632 // Check that the marker was split into three pieces when the two spaces were | 1622 // Check that the marker is still attached to " text " and includes both the |
1633 // converted to nbsps | 1623 // space before "text" and the space after |
1634 EXPECT_EQ(3u, document().markers().markers().size()); | 1624 EXPECT_EQ(1u, document().markers().markers().size()); |
1635 EXPECT_STREQ( | 1625 ASSERT_STREQ( |
1636 "\xC2\xA0", // UTF-8 for an nbsp | 1626 "\xC2\xA0text\xC2\xA0", |
1637 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1627 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
1638 EXPECT_STREQ( | |
1639 "text", | |
1640 getMarkedText(document().markers(), div->firstChild(), 1).utf8().data()); | |
1641 EXPECT_STREQ( | |
1642 "\xC2\xA0", // UTF-8 for an nbsp | |
1643 getMarkedText(document().markers(), div->firstChild(), 2).utf8().data()); | |
1644 } | 1628 } |
1645 | 1629 |
1646 TEST_F(InputMethodControllerTest, Marker_ReplaceStartOfMarker) { | 1630 TEST_F(InputMethodControllerTest, Marker_ReplaceStartOfMarker) { |
1647 Element* div = insertHTMLElement( | 1631 Element* div = insertHTMLElement( |
1648 "<div id='sample' contenteditable>Initial text</div>", "sample"); | 1632 "<div id='sample' contenteditable>Initial text</div>", "sample"); |
1649 | 1633 |
1650 // Add marker under "Initial text" | 1634 // Add marker under "Initial text" |
1651 EphemeralRange markerRange = PlainTextRange(0, 12).createRange(*div); | 1635 EphemeralRange markerRange = PlainTextRange(0, 12).createRange(*div); |
1652 document().markers().addMarker(markerRange.startPosition(), | 1636 document().markers().addMarker(markerRange.startPosition(), |
1653 markerRange.endPosition(), | 1637 markerRange.endPosition(), |
1654 DocumentMarker::TextMatch); | 1638 DocumentMarker::TextMatch); |
1655 | 1639 |
1656 // Replace "Initial" with "Original" | 1640 // Replace "Initial" with "Original" |
1657 Vector<CompositionUnderline> emptyUnderlines; | 1641 Vector<CompositionUnderline> emptyUnderlines; |
1658 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); | 1642 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); |
1659 controller().commitText(String("Original"), emptyUnderlines, 0); | 1643 controller().commitText(String("Original"), emptyUnderlines, 0); |
1660 | 1644 |
1661 // Verify marker is under "al text" | 1645 // Verify marker is under "Original text" |
1662 // ("Initial" and "Original" have "al" as a common suffix) | |
1663 EXPECT_EQ(1u, document().markers().markers().size()); | 1646 EXPECT_EQ(1u, document().markers().markers().size()); |
1664 EXPECT_STREQ( | 1647 ASSERT_STREQ( |
1665 "al text", | 1648 "Original text", |
1666 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1649 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
1667 } | 1650 } |
1668 | 1651 |
1669 TEST_F(InputMethodControllerTest, Marker_ReplaceTextContainsStartOfMarker) { | 1652 TEST_F(InputMethodControllerTest, Marker_ReplaceTextContainsStartOfMarker) { |
1670 Element* div = insertHTMLElement( | 1653 Element* div = insertHTMLElement( |
1671 "<div id='sample' contenteditable>This is some initial text</div>", | 1654 "<div id='sample' contenteditable>This is some initial text</div>", |
1672 "sample"); | 1655 "sample"); |
1673 | 1656 |
1674 // Add marker under "initial text" | 1657 // Add marker under "initial text" |
1675 EphemeralRange markerRange = PlainTextRange(13, 25).createRange(*div); | 1658 EphemeralRange markerRange = PlainTextRange(13, 25).createRange(*div); |
(...skipping 21 matching lines...) Expand all Loading... | |
1697 EphemeralRange markerRange = PlainTextRange(0, 12).createRange(*div); | 1680 EphemeralRange markerRange = PlainTextRange(0, 12).createRange(*div); |
1698 document().markers().addMarker(markerRange.startPosition(), | 1681 document().markers().addMarker(markerRange.startPosition(), |
1699 markerRange.endPosition(), | 1682 markerRange.endPosition(), |
1700 DocumentMarker::TextMatch); | 1683 DocumentMarker::TextMatch); |
1701 | 1684 |
1702 // Replace "text" with "string" | 1685 // Replace "text" with "string" |
1703 Vector<CompositionUnderline> emptyUnderlines; | 1686 Vector<CompositionUnderline> emptyUnderlines; |
1704 controller().setCompositionFromExistingText(emptyUnderlines, 8, 12); | 1687 controller().setCompositionFromExistingText(emptyUnderlines, 8, 12); |
1705 controller().commitText(String("string"), emptyUnderlines, 0); | 1688 controller().commitText(String("string"), emptyUnderlines, 0); |
1706 | 1689 |
1707 // Verify marker is under "Initial " | 1690 // Verify marker is under "Initial string" |
1708 EXPECT_EQ(1u, document().markers().markers().size()); | 1691 EXPECT_EQ(1u, document().markers().markers().size()); |
1709 EXPECT_STREQ( | 1692 ASSERT_STREQ( |
1710 "Initial ", | 1693 "Initial string", |
1711 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1694 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
1712 } | 1695 } |
1713 | 1696 |
1714 TEST_F(InputMethodControllerTest, Marker_ReplaceTextContainsEndOfMarker) { | 1697 TEST_F(InputMethodControllerTest, Marker_ReplaceTextContainsEndOfMarker) { |
1715 Element* div = insertHTMLElement( | 1698 Element* div = insertHTMLElement( |
1716 "<div id='sample' contenteditable>This is some initial text</div>", | 1699 "<div id='sample' contenteditable>This is some initial text</div>", |
1717 "sample"); | 1700 "sample"); |
1718 | 1701 |
1719 // Add marker under "some initial" | 1702 // Add marker under "some initial" |
1720 EphemeralRange markerRange = PlainTextRange(8, 20).createRange(*div); | 1703 EphemeralRange markerRange = PlainTextRange(8, 20).createRange(*div); |
(...skipping 23 matching lines...) Expand all Loading... | |
1744 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div); | 1727 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div); |
1745 document().markers().addMarker(markerRange.startPosition(), | 1728 document().markers().addMarker(markerRange.startPosition(), |
1746 markerRange.endPosition(), | 1729 markerRange.endPosition(), |
1747 DocumentMarker::TextMatch); | 1730 DocumentMarker::TextMatch); |
1748 | 1731 |
1749 // Replace "text" with "string" | 1732 // Replace "text" with "string" |
1750 Vector<CompositionUnderline> emptyUnderlines; | 1733 Vector<CompositionUnderline> emptyUnderlines; |
1751 controller().setCompositionFromExistingText(emptyUnderlines, 8, 12); | 1734 controller().setCompositionFromExistingText(emptyUnderlines, 8, 12); |
1752 controller().commitText(String("string"), emptyUnderlines, 0); | 1735 controller().commitText(String("string"), emptyUnderlines, 0); |
1753 | 1736 |
1754 // Verify marker was removed | 1737 // Verify marker is under "string" |
1755 EXPECT_EQ(0u, document().markers().markers().size()); | 1738 EXPECT_EQ(1u, document().markers().markers().size()); |
1739 ASSERT_STREQ( | |
1740 "string", | |
1741 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | |
1756 } | 1742 } |
1757 | 1743 |
1758 TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtBeginning) { | 1744 TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtBeginning) { |
1759 Element* div = insertHTMLElement( | 1745 Element* div = insertHTMLElement( |
1760 "<div id='sample' contenteditable>Initial text</div>", "sample"); | 1746 "<div id='sample' contenteditable>Initial text</div>", "sample"); |
1761 | 1747 |
1762 // Add marker under "Initial" | 1748 // Add marker under "Initial" |
1763 EphemeralRange markerRange = PlainTextRange(0, 7).createRange(*div); | 1749 EphemeralRange markerRange = PlainTextRange(0, 7).createRange(*div); |
1764 document().markers().addMarker(markerRange.startPosition(), | 1750 document().markers().addMarker(markerRange.startPosition(), |
1765 markerRange.endPosition(), | 1751 markerRange.endPosition(), |
(...skipping 24 matching lines...) Expand all Loading... | |
1790 | 1776 |
1791 // Replace "Initial text" with "New string" | 1777 // Replace "Initial text" with "New string" |
1792 Vector<CompositionUnderline> emptyUnderlines; | 1778 Vector<CompositionUnderline> emptyUnderlines; |
1793 controller().setCompositionFromExistingText(emptyUnderlines, 0, 12); | 1779 controller().setCompositionFromExistingText(emptyUnderlines, 0, 12); |
1794 controller().commitText(String("New string"), emptyUnderlines, 0); | 1780 controller().commitText(String("New string"), emptyUnderlines, 0); |
1795 | 1781 |
1796 // Verify marker was removed | 1782 // Verify marker was removed |
1797 EXPECT_EQ(0u, document().markers().markers().size()); | 1783 EXPECT_EQ(0u, document().markers().markers().size()); |
1798 } | 1784 } |
1799 | 1785 |
1786 TEST_F(InputMethodControllerTest, Marker_Deletions) { | |
Xiaocheng
2017/03/29 18:31:02
Could you split it into three tests?
| |
1787 Element* div = insertHTMLElement( | |
1788 "<div id='sample' contenteditable>1111122222333334444455555</div>", | |
1789 "sample"); | |
1790 | |
1791 EphemeralRange markerRange = PlainTextRange(0, 5).createRange(*div); | |
1792 document().markers().addMarker(markerRange.startPosition(), | |
1793 markerRange.endPosition(), | |
1794 DocumentMarker::TextMatch); | |
1795 | |
1796 markerRange = PlainTextRange(5, 10).createRange(*div); | |
1797 document().markers().addMarker(markerRange.startPosition(), | |
1798 markerRange.endPosition(), | |
1799 DocumentMarker::TextMatch); | |
1800 | |
1801 markerRange = PlainTextRange(10, 15).createRange(*div); | |
1802 document().markers().addMarker(markerRange.startPosition(), | |
1803 markerRange.endPosition(), | |
1804 DocumentMarker::TextMatch); | |
1805 | |
1806 markerRange = PlainTextRange(15, 20).createRange(*div); | |
1807 document().markers().addMarker(markerRange.startPosition(), | |
1808 markerRange.endPosition(), | |
1809 DocumentMarker::TextMatch); | |
1810 | |
1811 markerRange = PlainTextRange(20, 25).createRange(*div); | |
1812 document().markers().addMarker(markerRange.startPosition(), | |
1813 markerRange.endPosition(), | |
1814 DocumentMarker::TextMatch); | |
1815 | |
1816 EXPECT_EQ(5u, document().markers().markers().size()); | |
1817 | |
1818 // Delete third marker and portions of second and fourth | |
1819 Vector<CompositionUnderline> emptyUnderlines; | |
1820 controller().setCompositionFromExistingText(emptyUnderlines, 8, 17); | |
1821 controller().commitText(String(""), emptyUnderlines, 0); | |
1822 | |
1823 // Verify markers were updated correctly | |
1824 EXPECT_EQ(4u, document().markers().markers().size()); | |
1825 | |
1826 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset()); | |
1827 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset()); | |
1828 | |
1829 EXPECT_EQ(5u, document().markers().markers()[1]->startOffset()); | |
1830 EXPECT_EQ(8u, document().markers().markers()[1]->endOffset()); | |
1831 | |
1832 EXPECT_EQ(8u, document().markers().markers()[2]->startOffset()); | |
1833 EXPECT_EQ(11u, document().markers().markers()[2]->endOffset()); | |
1834 | |
1835 EXPECT_EQ(11u, document().markers().markers()[3]->startOffset()); | |
1836 EXPECT_EQ(16u, document().markers().markers()[3]->endOffset()); | |
1837 | |
1838 document().markers().clear(); | |
1839 | |
1840 markerRange = PlainTextRange(5, 10).createRange(*div); | |
1841 document().markers().addMarker(markerRange.startPosition(), | |
1842 markerRange.endPosition(), | |
1843 DocumentMarker::TextMatch); | |
1844 | |
1845 // Delete exactly on a marker | |
1846 controller().setCompositionFromExistingText(emptyUnderlines, 5, 10); | |
1847 controller().commitText(String(""), emptyUnderlines, 0); | |
1848 EXPECT_EQ(0u, document().markers().markers().size()); | |
1849 | |
1850 markerRange = PlainTextRange(5, 10).createRange(*div); | |
1851 document().markers().addMarker(markerRange.startPosition(), | |
1852 markerRange.endPosition(), | |
1853 DocumentMarker::TextMatch); | |
1854 | |
1855 // Delete middle of marker | |
1856 controller().setCompositionFromExistingText(emptyUnderlines, 6, 9); | |
1857 controller().commitText(String(""), emptyUnderlines, 0); | |
1858 | |
1859 EXPECT_EQ(2u, document().markers().markers().size()); | |
1860 | |
1861 EXPECT_EQ(5u, document().markers().markers()[0]->startOffset()); | |
1862 EXPECT_EQ(6u, document().markers().markers()[0]->endOffset()); | |
1863 | |
1864 EXPECT_EQ(6u, document().markers().markers()[1]->startOffset()); | |
1865 EXPECT_EQ(7u, document().markers().markers()[1]->endOffset()); | |
1866 } | |
1867 | |
1868 TEST_F(InputMethodControllerTest, Marker_Insertions) { | |
Xiaocheng
2017/03/29 18:31:02
Could you split it into two tests?
| |
1869 Element* div = insertHTMLElement( | |
1870 "<div id='sample' contenteditable>1111122222333334444455555</div>", | |
1871 "sample"); | |
1872 | |
1873 EphemeralRange markerRange = PlainTextRange(0, 5).createRange(*div); | |
1874 document().markers().addMarker(markerRange.startPosition(), | |
1875 markerRange.endPosition(), | |
1876 DocumentMarker::TextMatch); | |
1877 | |
1878 markerRange = PlainTextRange(5, 10).createRange(*div); | |
1879 document().markers().addMarker(markerRange.startPosition(), | |
1880 markerRange.endPosition(), | |
1881 DocumentMarker::TextMatch); | |
1882 | |
1883 markerRange = PlainTextRange(10, 15).createRange(*div); | |
1884 document().markers().addMarker(markerRange.startPosition(), | |
1885 markerRange.endPosition(), | |
1886 DocumentMarker::TextMatch); | |
1887 | |
1888 // insert in middle of second marker | |
1889 Vector<CompositionUnderline> emptyUnderlines; | |
1890 controller().setComposition("", emptyUnderlines, 7, 7); | |
1891 controller().commitText(String("66666"), emptyUnderlines, -7); | |
1892 | |
1893 EXPECT_EQ(3u, document().markers().markers().size()); | |
1894 | |
1895 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset()); | |
1896 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset()); | |
1897 | |
1898 EXPECT_EQ(5u, document().markers().markers()[1]->startOffset()); | |
1899 EXPECT_EQ(15u, document().markers().markers()[1]->endOffset()); | |
1900 | |
1901 EXPECT_EQ(15u, document().markers().markers()[2]->startOffset()); | |
1902 EXPECT_EQ(20u, document().markers().markers()[2]->endOffset()); | |
1903 | |
1904 // insert between first and second markers (cursor is at position 5) | |
1905 controller().commitText(String("77777"), emptyUnderlines, 0); | |
1906 | |
1907 EXPECT_EQ(3u, document().markers().markers().size()); | |
1908 | |
1909 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset()); | |
1910 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset()); | |
1911 | |
1912 EXPECT_EQ(10u, document().markers().markers()[1]->startOffset()); | |
1913 EXPECT_EQ(20u, document().markers().markers()[1]->endOffset()); | |
1914 | |
1915 EXPECT_EQ(20u, document().markers().markers()[2]->startOffset()); | |
1916 EXPECT_EQ(25u, document().markers().markers()[2]->endOffset()); | |
1917 } | |
1918 | |
1800 } // namespace blink | 1919 } // namespace blink |
OLD | NEW |