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

Side by Side Diff: third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp

Issue 2650113004: [WIP] Add support for Android SuggestionSpans when editing text (Closed)
Patch Set: Uploading the latest version from my repo so I can reference it Created 3 years, 7 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
OLDNEW
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"
11 #include "core/editing/Editor.h" 11 #include "core/editing/Editor.h"
12 #include "core/editing/FrameSelection.h" 12 #include "core/editing/FrameSelection.h"
13 #include "core/editing/markers/DocumentMarkerController.h" 13 #include "core/editing/markers/DocumentMarkerController.h"
14 #include "core/editing/markers/SuggestionMarker.h"
14 #include "core/events/MouseEvent.h" 15 #include "core/events/MouseEvent.h"
15 #include "core/frame/FrameView.h" 16 #include "core/frame/FrameView.h"
16 #include "core/frame/LocalFrame.h" 17 #include "core/frame/LocalFrame.h"
17 #include "core/frame/Settings.h" 18 #include "core/frame/Settings.h"
18 #include "core/html/HTMLInputElement.h" 19 #include "core/html/HTMLInputElement.h"
19 #include "core/html/HTMLTextAreaElement.h" 20 #include "core/html/HTMLTextAreaElement.h"
20 #include "core/testing/DummyPageHolder.h" 21 #include "core/testing/DummyPageHolder.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 namespace blink { 24 namespace blink {
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 } 1374 }
1374 1375
1375 TEST_F(InputMethodControllerTest, CommitPlainTextWithUnderlineReplace) { 1376 TEST_F(InputMethodControllerTest, CommitPlainTextWithUnderlineReplace) {
1376 insertHTMLElement("<div id='sample' contenteditable>Initial text.</div>", 1377 insertHTMLElement("<div id='sample' contenteditable>Initial text.</div>",
1377 "sample"); 1378 "sample");
1378 1379
1379 Vector<CompositionUnderline> underlines; 1380 Vector<CompositionUnderline> underlines;
1380 1381
1381 controller().setCompositionFromExistingText(underlines, 8, 12); 1382 controller().setCompositionFromExistingText(underlines, 8, 12);
1382 1383
1383 underlines.push_back(CompositionUnderline(1, 11, Color(255, 0, 0), false, 0)); 1384 // Adding an empty string as a suggestion causes the CompositionUnderline to
1385 // persist across editing operations, which is required for this and the next
1386 // few tests
1387 underlines.push_back(
1388 CompositionUnderline(1, 11, Color(255, 0, 0), false, 0, {""}));
1384 1389
1385 controller().commitText(String("string"), underlines, 0); 1390 controller().commitText(String("string"), underlines, 0);
1386 1391
1387 ASSERT_EQ(1u, document().markers().markers().size()); 1392 ASSERT_EQ(1u, document().markers().markers().size());
1388 1393
1389 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset()); 1394 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset());
1390 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset()); 1395 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset());
1391 } 1396 }
1392 1397
1393 TEST_F(InputMethodControllerTest, 1398 TEST_F(InputMethodControllerTest,
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); 1619 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1615 controller().commitText(String(""), emptyUnderlines, 0); 1620 controller().commitText(String(""), emptyUnderlines, 0);
1616 1621
1617 // Delete "blah" 1622 // Delete "blah"
1618 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); 1623 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10);
1619 controller().commitText(String(""), emptyUnderlines, 0); 1624 controller().commitText(String(""), emptyUnderlines, 0);
1620 1625
1621 // Check that the marker is still attached to " text " and includes both the 1626 // Check that the marker is still attached to " text " and includes both the
1622 // space before "text" and the space after 1627 // space before "text" and the space after
1623 EXPECT_EQ(1u, document().markers().markers().size()); 1628 EXPECT_EQ(1u, document().markers().markers().size());
1629 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1630 EXPECT_EQ(6u, document().markers().markers()[0]->endOffset());
1631 }
1632
1633 TEST_F(InputMethodControllerTest, WhitespaceFixupAroundUnsplittableMarker) {
1634 Element* div = insertHTMLElement(
1635 "<div id='sample' contenteditable>Initial text blah</div>", "sample");
1636
1637 // Add marker under "text" (use TextMatch since Composition markers don't
1638 // persist across editing operations)
1639 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1640 document().markers().addSuggestionMarker(markerRange, Color::black, false, Col or::black, Vector<String>());
1641
1642 // Delete "Initial"
1643 Vector<CompositionUnderline> emptyUnderlines;
1644 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1645 controller().commitText(String(""), emptyUnderlines, 0);
1646
1647 // Delete "blah"
1648 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10);
1649 controller().commitText(String(""), emptyUnderlines, 0);
1650
1651 // Check that the marker is still attached to "text" and doesn't include
1652 // either space around it
1653 EXPECT_EQ(1u, document().markers().markers().size());
1654 EXPECT_EQ(1u, document().markers().markers()[0]->startOffset());
1655 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
1656 }
1657
1658 TEST_F(InputMethodControllerTest, WhitespaceFixupAroundUnsplittableMarker2) {
1659 Element* div = insertHTMLElement(
1660 "<div id='sample' contenteditable>Initial text blah</div>", "sample");
1661
1662 // Add marker under " text" (use TextMatch since Composition markers don't
1663 // persist across editing operations)
1664 EphemeralRange markerRange = PlainTextRange(7, 12).createRange(*div);
1665 document().markers().addSuggestionMarker(markerRange, Color::black, false, Col or::black, Vector<String>());
1666
1667 // Delete "Initial"
1668 Vector<CompositionUnderline> emptyUnderlines;
1669 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1670 controller().commitText(String(""), emptyUnderlines, 0);
1671
1672 // Delete "blah"
1673 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10);
1674 controller().commitText(String(""), emptyUnderlines, 0);
1675
1676 // Check that the marker is still attached to " text" and includes the space
1677 // before "text" but not the space after
1678 EXPECT_EQ(1u, document().markers().markers().size());
1679 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1680 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
1681 }
1682
1683 TEST_F(InputMethodControllerTest, WhitespaceFixupAroundUnsplittableMarker3) {
1684 Element* div = insertHTMLElement(
1685 "<div id='sample' contenteditable>Initial text blah</div>", "sample");
1686
1687 // Add marker under "text " (use TextMatch since Composition markers don't
1688 // persist across editing operations)
1689 EphemeralRange markerRange = PlainTextRange(8, 13).createRange(*div);
1690 document().markers().addSuggestionMarker(markerRange, Color::black, false, Col or::black, Vector<String>());
1691
1692 // Delete "Initial"
1693 Vector<CompositionUnderline> emptyUnderlines;
1694 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1695 controller().commitText(String(""), emptyUnderlines, 0);
1696
1697 // Delete "blah"
1698 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10);
1699 controller().commitText(String(""), emptyUnderlines, 0);
1700
1701 // Check that the marker is still attached to "text " and includes the space
1702 // after "text" but not the space before
1703 EXPECT_EQ(1u, document().markers().markers().size());
1704 EXPECT_EQ(1u, document().markers().markers()[0]->startOffset());
1705 EXPECT_EQ(6u, document().markers().markers()[0]->endOffset());
1706 }
1707
1708 TEST_F(InputMethodControllerTest, WhitespaceFixupAroundUnsplittableMarker4) {
1709 Element* div = insertHTMLElement(
1710 "<div id='sample' contenteditable>Initial text blah</div>", "sample");
1711
1712 // Add marker under " text " (use TextMatch since Composition markers don't
1713 // persist across editing operations)
1714 EphemeralRange markerRange = PlainTextRange(7, 13).createRange(*div);
1715 document().markers().addSuggestionMarker(markerRange, Color::black, false, Col or::black, Vector<String>());
1716
1717 // Delete "Initial"
1718 Vector<CompositionUnderline> emptyUnderlines;
1719 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1720 controller().commitText(String(""), emptyUnderlines, 0);
1721
1722 // Delete "blah"
1723 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10);
1724 controller().commitText(String(""), emptyUnderlines, 0);
1725
1726 // Check that the marker is still attached to " text " and includes both the
1727 // space before "text" and the space after
1728 EXPECT_EQ(1u, document().markers().markers().size());
1624 ASSERT_STREQ( 1729 ASSERT_STREQ(
1625 "\xC2\xA0text\xC2\xA0", 1730 "\xC2\xA0text\xC2\xA0",
1626 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); 1731 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data());
1627 } 1732 }
1628 1733
1629 TEST_F(InputMethodControllerTest, Marker_ReplaceStartOfMarker) { 1734 TEST_F(InputMethodControllerTest, Marker_ReplaceStartOfMarker) {
1630 Element* div = insertHTMLElement( 1735 Element* div = insertHTMLElement(
1631 "<div id='sample' contenteditable>Initial text</div>", "sample"); 1736 "<div id='sample' contenteditable>Initial text</div>", "sample");
1632 1737
1633 // Add marker under "Initial text" 1738 // Add marker under "Initial text"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 // Verify marker is under "string" 1836 // Verify marker is under "string"
1732 EXPECT_EQ(1u, document().markers().markers().size()); 1837 EXPECT_EQ(1u, document().markers().markers().size());
1733 ASSERT_STREQ( 1838 ASSERT_STREQ(
1734 "string", 1839 "string",
1735 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); 1840 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data());
1736 } 1841 }
1737 1842
1738 TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtBeginning) { 1843 TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtBeginning) {
1739 Element* div = insertHTMLElement( 1844 Element* div = insertHTMLElement(
1740 "<div id='sample' contenteditable>Initial text</div>", "sample"); 1845 "<div id='sample' contenteditable>Initial text</div>", "sample");
1741
1742 // Add marker under "Initial" 1846 // Add marker under "Initial"
1743 EphemeralRange markerRange = PlainTextRange(0, 7).createRange(*div); 1847 EphemeralRange markerRange = PlainTextRange(0, 7).createRange(*div);
1744 document().markers().addTextMatchMarker( 1848 document().markers().addTextMatchMarker(
1745 markerRange, TextMatchMarker::MatchStatus::kInactive); 1849 markerRange, TextMatchMarker::MatchStatus::kInactive);
1746 1850
1747 EXPECT_EQ(1u, document().markers().markers().size()); 1851 EXPECT_EQ(1u, document().markers().markers().size());
1748
1749 // Replace "Initial text" with "New string" 1852 // Replace "Initial text" with "New string"
1750 Vector<CompositionUnderline> emptyUnderlines; 1853 Vector<CompositionUnderline> emptyUnderlines;
1751 controller().setCompositionFromExistingText(emptyUnderlines, 0, 12); 1854 controller().setCompositionFromExistingText(emptyUnderlines, 0, 12);
1752 controller().commitText(String("New string"), emptyUnderlines, 0); 1855 controller().commitText(String("New string"), emptyUnderlines, 0);
1753 1856
1754 // Verify marker was removed 1857 // Verify marker was removed
1755 EXPECT_EQ(0u, document().markers().markers().size()); 1858 EXPECT_EQ(0u, document().markers().markers().size());
1756 } 1859 }
1757 1860
1758 TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtEnd) { 1861 TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtEnd) {
1759 Element* div = insertHTMLElement( 1862 Element* div = insertHTMLElement(
1760 "<div id='sample' contenteditable>Initial text</div>", "sample"); 1863 "<div id='sample' contenteditable>Initial text</div>", "sample");
1761 1864
1762 // Add marker under "text" 1865 // Add marker under "text"
1763 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div); 1866 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1764 document().markers().addTextMatchMarker( 1867 document().markers().addTextMatchMarker(
1765 markerRange, TextMatchMarker::MatchStatus::kInactive); 1868 markerRange, TextMatchMarker::MatchStatus::kInactive);
1766 1869
1767 EXPECT_EQ(1u, document().markers().markers().size()); 1870 EXPECT_EQ(1u, document().markers().markers().size());
1768 1871
1769 // Replace "Initial text" with "New string" 1872 // Replace "Initial text" with "New string"
1770 Vector<CompositionUnderline> emptyUnderlines; 1873 Vector<CompositionUnderline> emptyUnderlines;
1771 controller().setCompositionFromExistingText(emptyUnderlines, 0, 12); 1874 controller().setCompositionFromExistingText(emptyUnderlines, 0, 12);
1772 controller().commitText(String("New string"), emptyUnderlines, 0); 1875 controller().commitText(String("New string"), emptyUnderlines, 0);
1773 1876
1774 // Verify marker was removed 1877 // Verify marker was removed
1775 EXPECT_EQ(0u, document().markers().markers().size()); 1878 EXPECT_EQ(0u, document().markers().markers().size());
1776 } 1879 }
1777 1880
1778 TEST_F(InputMethodControllerTest, Marker_Deletions) { 1881 TEST_F(InputMethodControllerTest, Marker_DeleteStartOfMarker) {
1779 Element* div = insertHTMLElement( 1882 Element* div = insertHTMLElement(
1780 "<div id='sample' contenteditable>1111122222333334444455555</div>", 1883 "<div id='sample' contenteditable>Initial text.</div>", "sample");
1781 "sample");
1782 1884
1783 EphemeralRange markerRange = PlainTextRange(0, 5).createRange(*div); 1885 // Add marker to "Initial"
1784 document().markers().addTextMatchMarker( 1886 EphemeralRange markerRange = PlainTextRange(0, 7).createRange(*div);
1785 markerRange, TextMatchMarker::MatchStatus::kInactive); 1887 document().markers().addTextMatchMarker(markerRange, false);
1786 1888
1787 markerRange = PlainTextRange(5, 10).createRange(*div);
1788 document().markers().addTextMatchMarker(
1789 markerRange, TextMatchMarker::MatchStatus::kInactive);
1790
1791 markerRange = PlainTextRange(10, 15).createRange(*div);
1792 document().markers().addTextMatchMarker(
1793 markerRange, TextMatchMarker::MatchStatus::kInactive);
1794
1795 markerRange = PlainTextRange(15, 20).createRange(*div);
1796 document().markers().addTextMatchMarker(
1797 markerRange, TextMatchMarker::MatchStatus::kInactive);
1798
1799 markerRange = PlainTextRange(20, 25).createRange(*div);
1800 document().markers().addTextMatchMarker(
1801 markerRange, TextMatchMarker::MatchStatus::kInactive);
1802
1803 EXPECT_EQ(5u, document().markers().markers().size());
1804
1805 // Delete third marker and portions of second and fourth
1806 Vector<CompositionUnderline> emptyUnderlines; 1889 Vector<CompositionUnderline> emptyUnderlines;
1807 controller().setCompositionFromExistingText(emptyUnderlines, 8, 17); 1890 // Set composition to "Ini"
1891 controller().setCompositionFromExistingText(emptyUnderlines, 0, 3);
1892 // Delete "Ini"
1808 controller().commitText(String(""), emptyUnderlines, 0); 1893 controller().commitText(String(""), emptyUnderlines, 0);
1809 1894
1810 // Verify markers were updated correctly 1895 // Check that the marker is still attached to "tial"
1811 EXPECT_EQ(4u, document().markers().markers().size()); 1896 EXPECT_EQ(1u, document().markers().markers().size());
1897 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1898 EXPECT_EQ(4u, document().markers().markers()[0]->endOffset());
1899 }
1812 1900
1813 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset()); 1901 TEST_F(InputMethodControllerTest, Marker_DeleteBeforeStartOfMarker) {
1814 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset()); 1902 Element* div = insertHTMLElement(
1903 "<div id='sample' contenteditable>Initial text.</div>", "sample");
1815 1904
1816 EXPECT_EQ(5u, document().markers().markers()[1]->startOffset()); 1905 // Add marker to "text"
1817 EXPECT_EQ(8u, document().markers().markers()[1]->endOffset()); 1906 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1907 document().markers().addTextMatchMarker(markerRange, false);
1818 1908
1819 EXPECT_EQ(8u, document().markers().markers()[2]->startOffset()); 1909 Vector<CompositionUnderline> emptyUnderlines;
1820 EXPECT_EQ(11u, document().markers().markers()[2]->endOffset()); 1910 // Set composition to "Initial"
1911 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1821 1912
1822 EXPECT_EQ(11u, document().markers().markers()[3]->startOffset()); 1913 // Delete "Initial"
1823 EXPECT_EQ(16u, document().markers().markers()[3]->endOffset());
1824
1825 document().markers().clear();
1826
1827 markerRange = PlainTextRange(5, 10).createRange(*div);
1828 document().markers().addTextMatchMarker(
1829 markerRange, TextMatchMarker::MatchStatus::kInactive);
1830
1831 // Delete exactly on a marker
1832 controller().setCompositionFromExistingText(emptyUnderlines, 5, 10);
1833 controller().commitText(String(""), emptyUnderlines, 0);
1834 EXPECT_EQ(0u, document().markers().markers().size());
1835
1836 markerRange = PlainTextRange(5, 10).createRange(*div);
1837 document().markers().addTextMatchMarker(
1838 markerRange, TextMatchMarker::MatchStatus::kInactive);
1839
1840 // Delete middle of marker
1841 controller().setCompositionFromExistingText(emptyUnderlines, 6, 9);
1842 controller().commitText(String(""), emptyUnderlines, 0); 1914 controller().commitText(String(""), emptyUnderlines, 0);
1843 1915
1916 // Check that the marker is still attached to "text"
1844 EXPECT_EQ(1u, document().markers().markers().size()); 1917 EXPECT_EQ(1u, document().markers().markers().size());
1845 1918 EXPECT_EQ(1u, document().markers().markers()[0]->startOffset());
1846 EXPECT_EQ(5u, document().markers().markers()[0]->startOffset()); 1919 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
1847 EXPECT_EQ(7u, document().markers().markers()[0]->endOffset());
1848 } 1920 }
1849 1921
1850 TEST_F(InputMethodControllerTest, Marker_Insertions) { 1922 TEST_F(InputMethodControllerTest,
1923 Marker_DeleteBeforeAndIncludingStartOfMarker) {
1851 Element* div = insertHTMLElement( 1924 Element* div = insertHTMLElement(
1852 "<div id='sample' contenteditable>1111122222333334444455555</div>", 1925 "<div id='sample' contenteditable>Initial text.</div>", "sample");
1853 "sample");
1854 1926
1855 EphemeralRange markerRange = PlainTextRange(0, 5).createRange(*div); 1927 // Add marker to "text"
1856 document().markers().addTextMatchMarker( 1928 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1857 markerRange, TextMatchMarker::MatchStatus::kInactive); 1929 document().markers().addTextMatchMarker(markerRange, false);
1858 1930
1859 markerRange = PlainTextRange(5, 10).createRange(*div); 1931 Vector<CompositionUnderline> emptyUnderlines;
1860 document().markers().addTextMatchMarker( 1932 // Set composition to "Initial te"
1861 markerRange, TextMatchMarker::MatchStatus::kInactive); 1933 controller().setCompositionFromExistingText(emptyUnderlines, 0, 10);
1862 1934
1863 markerRange = PlainTextRange(10, 15).createRange(*div); 1935 // Delete "Initial te"
1864 document().markers().addTextMatchMarker( 1936 controller().commitText(String(""), emptyUnderlines, 0);
1865 markerRange, TextMatchMarker::MatchStatus::kInactive);
1866 1937
1867 // insert in middle of second marker 1938 // Check that the marker is still attached to "xt"
1939 EXPECT_EQ(1u, document().markers().markers().size());
1940 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1941 EXPECT_EQ(2u, document().markers().markers()[0]->endOffset());
1942 }
1943
1944 TEST_F(InputMethodControllerTest, Marker_DeleteEndOfMarker) {
1945 Element* div = insertHTMLElement(
1946 "<div id='sample' contenteditable>Initial text.</div>", "sample");
1947
1948 // Add marker to "text"
1949 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1950 document().markers().addTextMatchMarker(markerRange, false);
1951
1868 Vector<CompositionUnderline> emptyUnderlines; 1952 Vector<CompositionUnderline> emptyUnderlines;
1869 controller().setComposition("", emptyUnderlines, 7, 7); 1953 // Set composition to "xt."
1870 controller().commitText(String("66666"), emptyUnderlines, -7); 1954 controller().setCompositionFromExistingText(emptyUnderlines, 10, 13);
1955
1956 // Delete "xt."
1957 controller().commitText(String(""), emptyUnderlines, 0);
1958
1959 // Check that the marker is still attached to "te"
1960 EXPECT_EQ(1u, document().markers().markers().size());
1961 EXPECT_EQ(8u, document().markers().markers()[0]->startOffset());
1962 EXPECT_EQ(10u, document().markers().markers()[0]->endOffset());
1963 }
1964
1965 TEST_F(InputMethodControllerTest, Marker_DeleteBeforeEndOfMarker) {
1966 Element* div = insertHTMLElement(
1967 "<div id='sample' contenteditable>Initial text.</div>", "sample");
1968 // Add marker to "text"
1969 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
1970 document().markers().addTextMatchMarker(markerRange, false);
1971
1972 Vector<CompositionUnderline> emptyUnderlines;
1973 // Set composition to "Initial"
1974 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
1975
1976 // Delete "Initial"
1977 controller().commitText(String(""), emptyUnderlines, 0);
1978
1979 // Check that the marker is still attached to "text"
1980 EXPECT_EQ(1u, document().markers().markers().size());
1981 EXPECT_EQ(1u, document().markers().markers()[0]->startOffset());
1982 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
1983 }
1984
1985 TEST_F(InputMethodControllerTest, Marker_DeleteNestedMarkers) {
1986 Element* div = insertHTMLElement(
1987 "<div id='sample' contenteditable>Initial text.</div>", "sample");
1988
1989 EphemeralRange markerRange = PlainTextRange(0, 6).createRange(*div);
1990 document().markers().addSuggestionMarker(markerRange, Color::black, false, Col or::black, Vector<String>());
1991
1992 markerRange = PlainTextRange(1, 9).createRange(*div);
1993 document().markers().addSuggestionMarker(markerRange, Color::black, false, Col or::black, Vector<String>());
1994
1995 markerRange = PlainTextRange(2, 3).createRange(*div);
1996 document().markers().addSuggestionMarker(markerRange, Color::black, false, Col or::black, Vector<String>());
1997
1998 Vector<CompositionUnderline> emptyUnderlines;
1999 controller().setCompositionFromExistingText(emptyUnderlines, 5, 7);
2000
2001 controller().commitText(String(""), emptyUnderlines, 0);
1871 2002
1872 EXPECT_EQ(3u, document().markers().markers().size()); 2003 EXPECT_EQ(3u, document().markers().markers().size());
1873 2004
1874 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset()); 2005 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1875 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset()); 2006 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
1876 2007
1877 EXPECT_EQ(5u, document().markers().markers()[1]->startOffset()); 2008 EXPECT_EQ(1u, document().markers().markers()[1]->startOffset());
1878 EXPECT_EQ(15u, document().markers().markers()[1]->endOffset()); 2009 EXPECT_EQ(7u, document().markers().markers()[1]->endOffset());
1879 2010
1880 EXPECT_EQ(15u, document().markers().markers()[2]->startOffset()); 2011 EXPECT_EQ(2u, document().markers().markers()[2]->startOffset());
1881 EXPECT_EQ(20u, document().markers().markers()[2]->endOffset()); 2012 EXPECT_EQ(3u, document().markers().markers()[2]->endOffset());
1882
1883 // insert between first and second markers (cursor is at position 5)
1884 controller().commitText(String("77777"), emptyUnderlines, 0);
1885
1886 EXPECT_EQ(3u, document().markers().markers().size());
1887
1888 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
1889 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
1890
1891 EXPECT_EQ(10u, document().markers().markers()[1]->startOffset());
1892 EXPECT_EQ(20u, document().markers().markers()[1]->endOffset());
1893
1894 EXPECT_EQ(20u, document().markers().markers()[2]->startOffset());
1895 EXPECT_EQ(25u, document().markers().markers()[2]->endOffset());
1896 } 2013 }
1897 2014
1898 } // namespace blink 2015 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698