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 1527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 | 1538 |
1539 // Check that the marker is still attached to "text" and doesn't include | 1539 // Check that the marker is still attached to "text" and doesn't include |
1540 // either space around it | 1540 // either space around it |
1541 EXPECT_EQ(1u, GetDocument().Markers().MarkersFor(div->FirstChild()).size()); | 1541 EXPECT_EQ(1u, GetDocument().Markers().MarkersFor(div->FirstChild()).size()); |
1542 EXPECT_STREQ("text", | 1542 EXPECT_STREQ("text", |
1543 GetMarkedText(GetDocument().Markers(), div->FirstChild(), 0) | 1543 GetMarkedText(GetDocument().Markers(), div->FirstChild(), 0) |
1544 .Utf8() | 1544 .Utf8() |
1545 .Data()); | 1545 .Data()); |
1546 } | 1546 } |
1547 | 1547 |
1548 // TODO(rlanday): The behavior tested in the following DocumentMarker tests is | |
1549 // going to be changed so markers are not split when text they contain is | |
1550 // deleted | |
1551 | |
1552 TEST_F(InputMethodControllerTest, | 1548 TEST_F(InputMethodControllerTest, |
1553 Marker_WhitespaceFixupAroundMarkerBeginningWithSpace) { | 1549 Marker_WhitespaceFixupAroundMarkerBeginningWithSpace) { |
1554 Element* div = InsertHTMLElement( | 1550 Element* div = InsertHTMLElement( |
1555 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); | 1551 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); |
1556 | 1552 |
1557 // Add marker under " text" (use TextMatch since Composition markers don't | 1553 // Add marker under " text" (use TextMatch since Composition markers don't |
1558 // persist across editing operations) | 1554 // persist across editing operations) |
1559 EphemeralRange marker_range = PlainTextRange(7, 12).CreateRange(*div); | 1555 EphemeralRange marker_range = PlainTextRange(7, 12).CreateRange(*div); |
1560 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1556 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1561 marker_range.EndPosition(), | 1557 marker_range.EndPosition(), |
1562 DocumentMarker::kTextMatch); | 1558 DocumentMarker::kTextMatch); |
1563 // Delete "Initial" | 1559 // Delete "Initial" |
1564 Vector<CompositionUnderline> empty_underlines; | 1560 Vector<CompositionUnderline> empty_underlines; |
1565 Controller().SetCompositionFromExistingText(empty_underlines, 0, 7); | 1561 Controller().SetCompositionFromExistingText(empty_underlines, 0, 7); |
1566 Controller().CommitText(String(""), empty_underlines, 0); | 1562 Controller().CommitText(String(""), empty_underlines, 0); |
1567 | 1563 |
1568 // Delete "blah" | 1564 // Delete "blah" |
1569 Controller().SetCompositionFromExistingText(empty_underlines, 6, 10); | 1565 Controller().SetCompositionFromExistingText(empty_underlines, 6, 10); |
1570 Controller().CommitText(String(""), empty_underlines, 0); | 1566 Controller().CommitText(String(""), empty_underlines, 0); |
1571 | 1567 |
1572 // Check that the marker was split when the space at the beginning was | 1568 // Check that the marker is still attached to " text" and includes the space |
1573 // converted to an nbsp | 1569 // before "text" but not the space after |
1574 EXPECT_EQ(2u, GetDocument().Markers().Markers().size()); | 1570 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); |
1575 EXPECT_STREQ("\xC2\xA0", // UTF-8 for an nbsp | 1571 ASSERT_STREQ("\xC2\xA0text", |
1576 GetMarkedText(GetDocument().Markers(), div->FirstChild(), 0) | 1572 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) |
1577 .Utf8() | |
1578 .Data()); | |
1579 EXPECT_STREQ("text", | |
1580 GetMarkedText(GetDocument().Markers(), div->FirstChild(), 1) | |
1581 .Utf8() | 1573 .Utf8() |
1582 .Data()); | 1574 .Data()); |
1583 } | 1575 } |
1584 | 1576 |
1585 TEST_F(InputMethodControllerTest, | 1577 TEST_F(InputMethodControllerTest, |
1586 Marker_WhitespaceFixupAroundMarkerEndingWithSpace) { | 1578 Marker_WhitespaceFixupAroundMarkerEndingWithSpace) { |
1587 Element* div = InsertHTMLElement( | 1579 Element* div = InsertHTMLElement( |
1588 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); | 1580 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); |
1589 | 1581 |
1590 // Add marker under "text " (use TextMatch since Composition markers don't | 1582 // Add marker under "text " (use TextMatch since Composition markers don't |
1591 // persist across editing operations) | 1583 // persist across editing operations) |
1592 EphemeralRange marker_range = PlainTextRange(8, 13).CreateRange(*div); | 1584 EphemeralRange marker_range = PlainTextRange(8, 13).CreateRange(*div); |
1593 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1585 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1594 marker_range.EndPosition(), | 1586 marker_range.EndPosition(), |
1595 DocumentMarker::kTextMatch); | 1587 DocumentMarker::kTextMatch); |
1596 // Delete "Initial" | 1588 // Delete "Initial" |
1597 Vector<CompositionUnderline> empty_underlines; | 1589 Vector<CompositionUnderline> empty_underlines; |
1598 Controller().SetCompositionFromExistingText(empty_underlines, 0, 7); | 1590 Controller().SetCompositionFromExistingText(empty_underlines, 0, 7); |
1599 Controller().CommitText(String(""), empty_underlines, 0); | 1591 Controller().CommitText(String(""), empty_underlines, 0); |
1600 | 1592 |
1601 // Delete "blah" | 1593 // Delete "blah" |
1602 Controller().SetCompositionFromExistingText(empty_underlines, 6, 10); | 1594 Controller().SetCompositionFromExistingText(empty_underlines, 6, 10); |
1603 Controller().CommitText(String(""), empty_underlines, 0); | 1595 Controller().CommitText(String(""), empty_underlines, 0); |
1604 | 1596 |
1605 // Check that the marker was split when the space at the end was | 1597 // Check that the marker is still attached to "text " and includes the space |
1606 // converted to an nbsp | 1598 // after "text" but not the space before |
1607 EXPECT_EQ(2u, GetDocument().Markers().Markers().size()); | 1599 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); |
1608 EXPECT_STREQ("text", | 1600 ASSERT_STREQ("text\xC2\xA0", |
1609 GetMarkedText(GetDocument().Markers(), div->FirstChild(), 0) | 1601 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) |
1610 .Utf8() | |
1611 .Data()); | |
1612 EXPECT_STREQ("\xC2\xA0", // UTF-8 for an nbsp | |
1613 GetMarkedText(GetDocument().Markers(), div->FirstChild(), 1) | |
1614 .Utf8() | 1602 .Utf8() |
1615 .Data()); | 1603 .Data()); |
1616 } | 1604 } |
1617 | 1605 |
1618 TEST_F(InputMethodControllerTest, | 1606 TEST_F(InputMethodControllerTest, |
1619 Marker_WhitespaceFixupAroundMarkerBeginningAndEndingWithSpaces) { | 1607 Marker_WhitespaceFixupAroundMarkerBeginningAndEndingWithSpaces) { |
1620 Element* div = InsertHTMLElement( | 1608 Element* div = InsertHTMLElement( |
1621 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); | 1609 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); |
1622 | 1610 |
1623 // Add marker under " text " (use TextMatch since Composition markers don't | 1611 // Add marker under " text " (use TextMatch since Composition markers don't |
1624 // persist across editing operations) | 1612 // persist across editing operations) |
1625 EphemeralRange marker_range = PlainTextRange(7, 13).CreateRange(*div); | 1613 EphemeralRange marker_range = PlainTextRange(7, 13).CreateRange(*div); |
1626 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1614 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1627 marker_range.EndPosition(), | 1615 marker_range.EndPosition(), |
1628 DocumentMarker::kTextMatch); | 1616 DocumentMarker::kTextMatch); |
1629 | 1617 |
1630 // Delete "Initial" | 1618 // Delete "Initial" |
1631 Vector<CompositionUnderline> empty_underlines; | 1619 Vector<CompositionUnderline> empty_underlines; |
1632 Controller().SetCompositionFromExistingText(empty_underlines, 0, 7); | 1620 Controller().SetCompositionFromExistingText(empty_underlines, 0, 7); |
1633 Controller().CommitText(String(""), empty_underlines, 0); | 1621 Controller().CommitText(String(""), empty_underlines, 0); |
1634 | 1622 |
1635 // Delete "blah" | 1623 // Delete "blah" |
1636 Controller().SetCompositionFromExistingText(empty_underlines, 6, 10); | 1624 Controller().SetCompositionFromExistingText(empty_underlines, 6, 10); |
1637 Controller().CommitText(String(""), empty_underlines, 0); | 1625 Controller().CommitText(String(""), empty_underlines, 0); |
1638 | 1626 |
1639 // Check that the marker was split into three pieces when the two spaces were | 1627 // Check that the marker is still attached to " text " and includes both the |
1640 // converted to nbsps | 1628 // space before "text" and the space after |
1641 EXPECT_EQ(3u, GetDocument().Markers().Markers().size()); | 1629 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); |
1642 EXPECT_STREQ("\xC2\xA0", // UTF-8 for an nbsp | 1630 ASSERT_STREQ("\xC2\xA0text\xC2\xA0", |
1643 GetMarkedText(GetDocument().Markers(), div->FirstChild(), 0) | 1631 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) |
1644 .Utf8() | |
1645 .Data()); | |
1646 EXPECT_STREQ("text", | |
1647 GetMarkedText(GetDocument().Markers(), div->FirstChild(), 1) | |
1648 .Utf8() | |
1649 .Data()); | |
1650 EXPECT_STREQ("\xC2\xA0", // UTF-8 for an nbsp | |
1651 GetMarkedText(GetDocument().Markers(), div->FirstChild(), 2) | |
1652 .Utf8() | 1632 .Utf8() |
1653 .Data()); | 1633 .Data()); |
1654 } | 1634 } |
1655 | 1635 |
1656 TEST_F(InputMethodControllerTest, Marker_ReplaceStartOfMarker) { | 1636 TEST_F(InputMethodControllerTest, Marker_ReplaceStartOfMarker) { |
1657 Element* div = InsertHTMLElement( | 1637 Element* div = InsertHTMLElement( |
1658 "<div id='sample' contenteditable>Initial text</div>", "sample"); | 1638 "<div id='sample' contenteditable>Initial text</div>", "sample"); |
1659 | 1639 |
1660 // Add marker under "Initial text" | 1640 // Add marker under "Initial text" |
1661 EphemeralRange marker_range = PlainTextRange(0, 12).CreateRange(*div); | 1641 EphemeralRange marker_range = PlainTextRange(0, 12).CreateRange(*div); |
1662 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1642 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1663 marker_range.EndPosition(), | 1643 marker_range.EndPosition(), |
1664 DocumentMarker::kTextMatch); | 1644 DocumentMarker::kTextMatch); |
1665 | 1645 |
1666 // Replace "Initial" with "Original" | 1646 // Replace "Initial" with "Original" |
1667 Vector<CompositionUnderline> empty_underlines; | 1647 Vector<CompositionUnderline> empty_underlines; |
1668 Controller().SetCompositionFromExistingText(empty_underlines, 0, 7); | 1648 Controller().SetCompositionFromExistingText(empty_underlines, 0, 7); |
1669 Controller().CommitText(String("Original"), empty_underlines, 0); | 1649 Controller().CommitText(String("Original"), empty_underlines, 0); |
1670 | 1650 |
1671 // Verify marker is under "al text" | 1651 // Verify marker is under "Original text" |
1672 // ("Initial" and "Original" have "al" as a common suffix) | |
1673 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); | 1652 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); |
1674 EXPECT_STREQ("al text", | 1653 ASSERT_STREQ("Original text", |
1675 GetMarkedText(GetDocument().Markers(), div->FirstChild(), 0) | 1654 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) |
1676 .Utf8() | 1655 .Utf8() |
1677 .Data()); | 1656 .Data()); |
1678 } | 1657 } |
1679 | 1658 |
1680 TEST_F(InputMethodControllerTest, Marker_ReplaceTextContainsStartOfMarker) { | 1659 TEST_F(InputMethodControllerTest, Marker_ReplaceTextContainsStartOfMarker) { |
1681 Element* div = InsertHTMLElement( | 1660 Element* div = InsertHTMLElement( |
1682 "<div id='sample' contenteditable>This is some initial text</div>", | 1661 "<div id='sample' contenteditable>This is some initial text</div>", |
1683 "sample"); | 1662 "sample"); |
1684 | 1663 |
1685 // Add marker under "initial text" | 1664 // Add marker under "initial text" |
(...skipping 23 matching lines...) Expand all Loading... |
1709 EphemeralRange marker_range = PlainTextRange(0, 12).CreateRange(*div); | 1688 EphemeralRange marker_range = PlainTextRange(0, 12).CreateRange(*div); |
1710 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1689 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1711 marker_range.EndPosition(), | 1690 marker_range.EndPosition(), |
1712 DocumentMarker::kTextMatch); | 1691 DocumentMarker::kTextMatch); |
1713 | 1692 |
1714 // Replace "text" with "string" | 1693 // Replace "text" with "string" |
1715 Vector<CompositionUnderline> empty_underlines; | 1694 Vector<CompositionUnderline> empty_underlines; |
1716 Controller().SetCompositionFromExistingText(empty_underlines, 8, 12); | 1695 Controller().SetCompositionFromExistingText(empty_underlines, 8, 12); |
1717 Controller().CommitText(String("string"), empty_underlines, 0); | 1696 Controller().CommitText(String("string"), empty_underlines, 0); |
1718 | 1697 |
1719 // Verify marker is under "Initial " | 1698 // Verify marker is under "Initial string" |
1720 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); | 1699 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); |
1721 EXPECT_STREQ("Initial ", | 1700 ASSERT_STREQ("Initial string", |
1722 GetMarkedText(GetDocument().Markers(), div->FirstChild(), 0) | 1701 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) |
1723 .Utf8() | 1702 .Utf8() |
1724 .Data()); | 1703 .Data()); |
1725 } | 1704 } |
1726 | 1705 |
1727 TEST_F(InputMethodControllerTest, Marker_ReplaceTextContainsEndOfMarker) { | 1706 TEST_F(InputMethodControllerTest, Marker_ReplaceTextContainsEndOfMarker) { |
1728 Element* div = InsertHTMLElement( | 1707 Element* div = InsertHTMLElement( |
1729 "<div id='sample' contenteditable>This is some initial text</div>", | 1708 "<div id='sample' contenteditable>This is some initial text</div>", |
1730 "sample"); | 1709 "sample"); |
1731 | 1710 |
1732 // Add marker under "some initial" | 1711 // Add marker under "some initial" |
(...skipping 25 matching lines...) Expand all Loading... |
1758 EphemeralRange marker_range = PlainTextRange(8, 12).CreateRange(*div); | 1737 EphemeralRange marker_range = PlainTextRange(8, 12).CreateRange(*div); |
1759 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1738 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1760 marker_range.EndPosition(), | 1739 marker_range.EndPosition(), |
1761 DocumentMarker::kTextMatch); | 1740 DocumentMarker::kTextMatch); |
1762 | 1741 |
1763 // Replace "text" with "string" | 1742 // Replace "text" with "string" |
1764 Vector<CompositionUnderline> empty_underlines; | 1743 Vector<CompositionUnderline> empty_underlines; |
1765 Controller().SetCompositionFromExistingText(empty_underlines, 8, 12); | 1744 Controller().SetCompositionFromExistingText(empty_underlines, 8, 12); |
1766 Controller().CommitText(String("string"), empty_underlines, 0); | 1745 Controller().CommitText(String("string"), empty_underlines, 0); |
1767 | 1746 |
1768 // Verify marker was removed | 1747 // Verify marker is under "string" |
1769 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); | 1748 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); |
| 1749 ASSERT_STREQ("string", |
| 1750 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) |
| 1751 .Utf8() |
| 1752 .Data()); |
1770 } | 1753 } |
1771 | 1754 |
1772 TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtBeginning) { | 1755 TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtBeginning) { |
1773 Element* div = InsertHTMLElement( | 1756 Element* div = InsertHTMLElement( |
1774 "<div id='sample' contenteditable>Initial text</div>", "sample"); | 1757 "<div id='sample' contenteditable>Initial text</div>", "sample"); |
1775 | 1758 |
1776 // Add marker under "Initial" | 1759 // Add marker under "Initial" |
1777 EphemeralRange marker_range = PlainTextRange(0, 7).CreateRange(*div); | 1760 EphemeralRange marker_range = PlainTextRange(0, 7).CreateRange(*div); |
1778 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1761 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1779 marker_range.EndPosition(), | 1762 marker_range.EndPosition(), |
(...skipping 24 matching lines...) Expand all Loading... |
1804 | 1787 |
1805 // Replace "Initial text" with "New string" | 1788 // Replace "Initial text" with "New string" |
1806 Vector<CompositionUnderline> empty_underlines; | 1789 Vector<CompositionUnderline> empty_underlines; |
1807 Controller().SetCompositionFromExistingText(empty_underlines, 0, 12); | 1790 Controller().SetCompositionFromExistingText(empty_underlines, 0, 12); |
1808 Controller().CommitText(String("New string"), empty_underlines, 0); | 1791 Controller().CommitText(String("New string"), empty_underlines, 0); |
1809 | 1792 |
1810 // Verify marker was removed | 1793 // Verify marker was removed |
1811 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); | 1794 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); |
1812 } | 1795 } |
1813 | 1796 |
| 1797 TEST_F(InputMethodControllerTest, Marker_Deletions) { |
| 1798 Element* div = InsertHTMLElement( |
| 1799 "<div id='sample' contenteditable>1111122222333334444455555</div>", |
| 1800 "sample"); |
| 1801 |
| 1802 EphemeralRange marker_range = PlainTextRange(0, 5).CreateRange(*div); |
| 1803 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
| 1804 marker_range.EndPosition(), |
| 1805 DocumentMarker::kTextMatch); |
| 1806 |
| 1807 marker_range = PlainTextRange(5, 10).CreateRange(*div); |
| 1808 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
| 1809 marker_range.EndPosition(), |
| 1810 DocumentMarker::kTextMatch); |
| 1811 |
| 1812 marker_range = PlainTextRange(10, 15).CreateRange(*div); |
| 1813 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
| 1814 marker_range.EndPosition(), |
| 1815 DocumentMarker::kTextMatch); |
| 1816 |
| 1817 marker_range = PlainTextRange(15, 20).CreateRange(*div); |
| 1818 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
| 1819 marker_range.EndPosition(), |
| 1820 DocumentMarker::kTextMatch); |
| 1821 |
| 1822 marker_range = PlainTextRange(20, 25).CreateRange(*div); |
| 1823 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
| 1824 marker_range.EndPosition(), |
| 1825 DocumentMarker::kTextMatch); |
| 1826 |
| 1827 EXPECT_EQ(5u, GetDocument().Markers().Markers().size()); |
| 1828 |
| 1829 // Delete third marker and portions of second and fourth |
| 1830 Vector<CompositionUnderline> empty_underlines; |
| 1831 Controller().SetCompositionFromExistingText(empty_underlines, 8, 17); |
| 1832 Controller().CommitText(String(""), empty_underlines, 0); |
| 1833 |
| 1834 // Verify markers were updated correctly |
| 1835 EXPECT_EQ(4u, GetDocument().Markers().Markers().size()); |
| 1836 |
| 1837 EXPECT_EQ(0u, GetDocument().Markers().Markers()[0]->StartOffset()); |
| 1838 EXPECT_EQ(5u, GetDocument().Markers().Markers()[0]->EndOffset()); |
| 1839 |
| 1840 EXPECT_EQ(5u, GetDocument().Markers().Markers()[1]->StartOffset()); |
| 1841 EXPECT_EQ(8u, GetDocument().Markers().Markers()[1]->EndOffset()); |
| 1842 |
| 1843 EXPECT_EQ(8u, GetDocument().Markers().Markers()[2]->StartOffset()); |
| 1844 EXPECT_EQ(11u, GetDocument().Markers().Markers()[2]->EndOffset()); |
| 1845 |
| 1846 EXPECT_EQ(11u, GetDocument().Markers().Markers()[3]->StartOffset()); |
| 1847 EXPECT_EQ(16u, GetDocument().Markers().Markers()[3]->EndOffset()); |
| 1848 } |
| 1849 |
| 1850 TEST_F(InputMethodControllerTest, Marker_DeleteExactlyOnMarker) { |
| 1851 Element* div = InsertHTMLElement( |
| 1852 "<div id='sample' contenteditable>1111122222333334444455555</div>", |
| 1853 "sample"); |
| 1854 |
| 1855 EphemeralRange marker_range = PlainTextRange(5, 10).CreateRange(*div); |
| 1856 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
| 1857 marker_range.EndPosition(), |
| 1858 DocumentMarker::kTextMatch); |
| 1859 |
| 1860 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); |
| 1861 |
| 1862 // Delete exactly on the marker |
| 1863 Vector<CompositionUnderline> empty_underlines; |
| 1864 Controller().SetCompositionFromExistingText(empty_underlines, 5, 10); |
| 1865 Controller().CommitText(String(""), empty_underlines, 0); |
| 1866 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); |
| 1867 } |
| 1868 |
| 1869 TEST_F(InputMethodControllerTest, Marker_DeleteMiddleOfMarker) { |
| 1870 Element* div = InsertHTMLElement( |
| 1871 "<div id='sample' contenteditable>1111122222333334444455555</div>", |
| 1872 "sample"); |
| 1873 |
| 1874 EphemeralRange marker_range = PlainTextRange(5, 10).CreateRange(*div); |
| 1875 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
| 1876 marker_range.EndPosition(), |
| 1877 DocumentMarker::kTextMatch); |
| 1878 |
| 1879 // Delete middle of marker |
| 1880 Vector<CompositionUnderline> empty_underlines; |
| 1881 Controller().SetCompositionFromExistingText(empty_underlines, 6, 9); |
| 1882 Controller().CommitText(String(""), empty_underlines, 0); |
| 1883 |
| 1884 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); |
| 1885 |
| 1886 EXPECT_EQ(5u, GetDocument().Markers().Markers()[0]->StartOffset()); |
| 1887 EXPECT_EQ(7u, GetDocument().Markers().Markers()[0]->EndOffset()); |
| 1888 } |
| 1889 |
| 1890 TEST_F(InputMethodControllerTest, Marker_InsertInMarkerInterior) { |
| 1891 Element* div = InsertHTMLElement( |
| 1892 "<div id='sample' contenteditable>1111122222333334444455555</div>", |
| 1893 "sample"); |
| 1894 |
| 1895 EphemeralRange marker_range = PlainTextRange(0, 5).CreateRange(*div); |
| 1896 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
| 1897 marker_range.EndPosition(), |
| 1898 DocumentMarker::kTextMatch); |
| 1899 |
| 1900 marker_range = PlainTextRange(5, 10).CreateRange(*div); |
| 1901 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
| 1902 marker_range.EndPosition(), |
| 1903 DocumentMarker::kTextMatch); |
| 1904 |
| 1905 marker_range = PlainTextRange(10, 15).CreateRange(*div); |
| 1906 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
| 1907 marker_range.EndPosition(), |
| 1908 DocumentMarker::kTextMatch); |
| 1909 |
| 1910 EXPECT_EQ(3u, GetDocument().Markers().Markers().size()); |
| 1911 |
| 1912 // insert in middle of second marker |
| 1913 Vector<CompositionUnderline> empty_underlines; |
| 1914 Controller().SetComposition("", empty_underlines, 7, 7); |
| 1915 Controller().CommitText(String("66666"), empty_underlines, -7); |
| 1916 |
| 1917 EXPECT_EQ(3u, GetDocument().Markers().Markers().size()); |
| 1918 |
| 1919 EXPECT_EQ(0u, GetDocument().Markers().Markers()[0]->StartOffset()); |
| 1920 EXPECT_EQ(5u, GetDocument().Markers().Markers()[0]->EndOffset()); |
| 1921 |
| 1922 EXPECT_EQ(5u, GetDocument().Markers().Markers()[1]->StartOffset()); |
| 1923 EXPECT_EQ(15u, GetDocument().Markers().Markers()[1]->EndOffset()); |
| 1924 |
| 1925 EXPECT_EQ(15u, GetDocument().Markers().Markers()[2]->StartOffset()); |
| 1926 EXPECT_EQ(20u, GetDocument().Markers().Markers()[2]->EndOffset()); |
| 1927 } |
| 1928 |
| 1929 TEST_F(InputMethodControllerTest, Marker_InsertBetweenMarkers) { |
| 1930 Element* div = InsertHTMLElement( |
| 1931 "<div id='sample' contenteditable>1111122222333334444455555</div>", |
| 1932 "sample"); |
| 1933 |
| 1934 EphemeralRange marker_range = PlainTextRange(0, 5).CreateRange(*div); |
| 1935 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
| 1936 marker_range.EndPosition(), |
| 1937 DocumentMarker::kTextMatch); |
| 1938 |
| 1939 marker_range = PlainTextRange(5, 15).CreateRange(*div); |
| 1940 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
| 1941 marker_range.EndPosition(), |
| 1942 DocumentMarker::kTextMatch); |
| 1943 |
| 1944 marker_range = PlainTextRange(15, 20).CreateRange(*div); |
| 1945 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
| 1946 marker_range.EndPosition(), |
| 1947 DocumentMarker::kTextMatch); |
| 1948 |
| 1949 EXPECT_EQ(3u, GetDocument().Markers().Markers().size()); |
| 1950 |
| 1951 Vector<CompositionUnderline> empty_underlines; |
| 1952 Controller().SetComposition("", empty_underlines, 5, 5); |
| 1953 Controller().CommitText(String("77777"), empty_underlines, 0); |
| 1954 |
| 1955 EXPECT_EQ(3u, GetDocument().Markers().Markers().size()); |
| 1956 |
| 1957 EXPECT_EQ(0u, GetDocument().Markers().Markers()[0]->StartOffset()); |
| 1958 EXPECT_EQ(5u, GetDocument().Markers().Markers()[0]->EndOffset()); |
| 1959 |
| 1960 EXPECT_EQ(10u, GetDocument().Markers().Markers()[1]->StartOffset()); |
| 1961 EXPECT_EQ(20u, GetDocument().Markers().Markers()[1]->EndOffset()); |
| 1962 |
| 1963 EXPECT_EQ(20u, GetDocument().Markers().Markers()[2]->StartOffset()); |
| 1964 EXPECT_EQ(25u, GetDocument().Markers().Markers()[2]->EndOffset()); |
| 1965 } |
| 1966 |
1814 } // namespace blink | 1967 } // namespace blink |
OLD | NEW |