| 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 1446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 } | 1457 } |
| 1458 | 1458 |
| 1459 TEST_F(InputMethodControllerTest, | 1459 TEST_F(InputMethodControllerTest, |
| 1460 Marker_WhitespaceFixupAroundMarkerNotContainingSpace) { | 1460 Marker_WhitespaceFixupAroundMarkerNotContainingSpace) { |
| 1461 Element* div = insertHTMLElement( | 1461 Element* div = insertHTMLElement( |
| 1462 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); | 1462 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); |
| 1463 | 1463 |
| 1464 // Add marker under "text" (use TextMatch since Composition markers don't | 1464 // Add marker under "text" (use TextMatch since Composition markers don't |
| 1465 // persist across editing operations) | 1465 // persist across editing operations) |
| 1466 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div); | 1466 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div); |
| 1467 document().markers().addMarker(markerRange.startPosition(), | 1467 document().markers().addTextMatchMarker(markerRange.startPosition(), |
| 1468 markerRange.endPosition(), | 1468 markerRange.endPosition(), false); |
| 1469 DocumentMarker::TextMatch); | |
| 1470 // Delete "Initial" | 1469 // Delete "Initial" |
| 1471 Vector<CompositionUnderline> emptyUnderlines; | 1470 Vector<CompositionUnderline> emptyUnderlines; |
| 1472 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); | 1471 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); |
| 1473 controller().commitText(String(""), emptyUnderlines, 0); | 1472 controller().commitText(String(""), emptyUnderlines, 0); |
| 1474 | 1473 |
| 1475 // Delete "blah" | 1474 // Delete "blah" |
| 1476 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); | 1475 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); |
| 1477 controller().commitText(String(""), emptyUnderlines, 0); | 1476 controller().commitText(String(""), emptyUnderlines, 0); |
| 1478 | 1477 |
| 1479 // Check that the marker is still attached to "text" and doesn't include | 1478 // Check that the marker is still attached to "text" and doesn't include |
| 1480 // either space around it | 1479 // either space around it |
| 1481 EXPECT_EQ(1u, document().markers().markersFor(div->firstChild()).size()); | 1480 EXPECT_EQ(1u, document().markers().markersFor(div->firstChild()).size()); |
| 1482 EXPECT_STREQ( | 1481 EXPECT_STREQ( |
| 1483 "text", | 1482 "text", |
| 1484 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1483 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| 1485 } | 1484 } |
| 1486 | 1485 |
| 1487 // TODO(rlanday): The behavior tested in the following DocumentMarker tests is | 1486 // TODO(rlanday): The behavior tested in the following DocumentMarker tests is |
| 1488 // going to be changed so markers are not split when text they contain is | 1487 // going to be changed so markers are not split when text they contain is |
| 1489 // deleted | 1488 // deleted |
| 1490 | 1489 |
| 1491 TEST_F(InputMethodControllerTest, | 1490 TEST_F(InputMethodControllerTest, |
| 1492 Marker_WhitespaceFixupAroundMarkerBeginningWithSpace) { | 1491 Marker_WhitespaceFixupAroundMarkerBeginningWithSpace) { |
| 1493 Element* div = insertHTMLElement( | 1492 Element* div = insertHTMLElement( |
| 1494 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); | 1493 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); |
| 1495 | 1494 |
| 1496 // Add marker under " text" (use TextMatch since Composition markers don't | 1495 // Add marker under " text" (use TextMatch since Composition markers don't |
| 1497 // persist across editing operations) | 1496 // persist across editing operations) |
| 1498 EphemeralRange markerRange = PlainTextRange(7, 12).createRange(*div); | 1497 EphemeralRange markerRange = PlainTextRange(7, 12).createRange(*div); |
| 1499 document().markers().addMarker(markerRange.startPosition(), | 1498 document().markers().addTextMatchMarker(markerRange.startPosition(), |
| 1500 markerRange.endPosition(), | 1499 markerRange.endPosition(), false); |
| 1501 DocumentMarker::TextMatch); | |
| 1502 // Delete "Initial" | 1500 // Delete "Initial" |
| 1503 Vector<CompositionUnderline> emptyUnderlines; | 1501 Vector<CompositionUnderline> emptyUnderlines; |
| 1504 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); | 1502 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); |
| 1505 controller().commitText(String(""), emptyUnderlines, 0); | 1503 controller().commitText(String(""), emptyUnderlines, 0); |
| 1506 | 1504 |
| 1507 // Delete "blah" | 1505 // Delete "blah" |
| 1508 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); | 1506 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); |
| 1509 controller().commitText(String(""), emptyUnderlines, 0); | 1507 controller().commitText(String(""), emptyUnderlines, 0); |
| 1510 | 1508 |
| 1511 // Check that the marker is still attached to " text" and includes the space | 1509 // Check that the marker is still attached to " text" and includes the space |
| 1512 // before "text" but not the space after | 1510 // before "text" but not the space after |
| 1513 EXPECT_EQ(1u, document().markers().markers().size()); | 1511 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1514 ASSERT_STREQ( | 1512 ASSERT_STREQ( |
| 1515 "\xC2\xA0text", | 1513 "\xC2\xA0text", |
| 1516 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1514 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| 1517 } | 1515 } |
| 1518 | 1516 |
| 1519 TEST_F(InputMethodControllerTest, | 1517 TEST_F(InputMethodControllerTest, |
| 1520 Marker_WhitespaceFixupAroundMarkerEndingWithSpace) { | 1518 Marker_WhitespaceFixupAroundMarkerEndingWithSpace) { |
| 1521 Element* div = insertHTMLElement( | 1519 Element* div = insertHTMLElement( |
| 1522 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); | 1520 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); |
| 1523 | 1521 |
| 1524 // Add marker under "text " (use TextMatch since Composition markers don't | 1522 // Add marker under "text " (use TextMatch since Composition markers don't |
| 1525 // persist across editing operations) | 1523 // persist across editing operations) |
| 1526 EphemeralRange markerRange = PlainTextRange(8, 13).createRange(*div); | 1524 EphemeralRange markerRange = PlainTextRange(8, 13).createRange(*div); |
| 1527 document().markers().addMarker(markerRange.startPosition(), | 1525 document().markers().addTextMatchMarker(markerRange.startPosition(), |
| 1528 markerRange.endPosition(), | 1526 markerRange.endPosition(), false); |
| 1529 DocumentMarker::TextMatch); | |
| 1530 // Delete "Initial" | 1527 // Delete "Initial" |
| 1531 Vector<CompositionUnderline> emptyUnderlines; | 1528 Vector<CompositionUnderline> emptyUnderlines; |
| 1532 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); | 1529 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); |
| 1533 controller().commitText(String(""), emptyUnderlines, 0); | 1530 controller().commitText(String(""), emptyUnderlines, 0); |
| 1534 | 1531 |
| 1535 // Delete "blah" | 1532 // Delete "blah" |
| 1536 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); | 1533 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); |
| 1537 controller().commitText(String(""), emptyUnderlines, 0); | 1534 controller().commitText(String(""), emptyUnderlines, 0); |
| 1538 | 1535 |
| 1539 // Check that the marker is still attached to "text " and includes the space | 1536 // Check that the marker is still attached to "text " and includes the space |
| 1540 // after "text" but not the space before | 1537 // after "text" but not the space before |
| 1541 EXPECT_EQ(1u, document().markers().markers().size()); | 1538 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1542 ASSERT_STREQ( | 1539 ASSERT_STREQ( |
| 1543 "text\xC2\xA0", | 1540 "text\xC2\xA0", |
| 1544 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1541 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| 1545 } | 1542 } |
| 1546 | 1543 |
| 1547 TEST_F(InputMethodControllerTest, | 1544 TEST_F(InputMethodControllerTest, |
| 1548 Marker_WhitespaceFixupAroundMarkerBeginningAndEndingWithSpaces) { | 1545 Marker_WhitespaceFixupAroundMarkerBeginningAndEndingWithSpaces) { |
| 1549 Element* div = insertHTMLElement( | 1546 Element* div = insertHTMLElement( |
| 1550 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); | 1547 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); |
| 1551 | 1548 |
| 1552 // Add marker under " text " (use TextMatch since Composition markers don't | 1549 // Add marker under " text " (use TextMatch since Composition markers don't |
| 1553 // persist across editing operations) | 1550 // persist across editing operations) |
| 1554 EphemeralRange markerRange = PlainTextRange(7, 13).createRange(*div); | 1551 EphemeralRange markerRange = PlainTextRange(7, 13).createRange(*div); |
| 1555 document().markers().addMarker(markerRange.startPosition(), | 1552 document().markers().addTextMatchMarker(markerRange.startPosition(), |
| 1556 markerRange.endPosition(), | 1553 markerRange.endPosition(), false); |
| 1557 DocumentMarker::TextMatch); | |
| 1558 | 1554 |
| 1559 // Delete "Initial" | 1555 // Delete "Initial" |
| 1560 Vector<CompositionUnderline> emptyUnderlines; | 1556 Vector<CompositionUnderline> emptyUnderlines; |
| 1561 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); | 1557 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); |
| 1562 controller().commitText(String(""), emptyUnderlines, 0); | 1558 controller().commitText(String(""), emptyUnderlines, 0); |
| 1563 | 1559 |
| 1564 // Delete "blah" | 1560 // Delete "blah" |
| 1565 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); | 1561 controller().setCompositionFromExistingText(emptyUnderlines, 6, 10); |
| 1566 controller().commitText(String(""), emptyUnderlines, 0); | 1562 controller().commitText(String(""), emptyUnderlines, 0); |
| 1567 | 1563 |
| 1568 // Check that the marker is still attached to " text " and includes both the | 1564 // Check that the marker is still attached to " text " and includes both the |
| 1569 // space before "text" and the space after | 1565 // space before "text" and the space after |
| 1570 EXPECT_EQ(1u, document().markers().markers().size()); | 1566 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1571 ASSERT_STREQ( | 1567 ASSERT_STREQ( |
| 1572 "\xC2\xA0text\xC2\xA0", | 1568 "\xC2\xA0text\xC2\xA0", |
| 1573 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1569 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| 1574 } | 1570 } |
| 1575 | 1571 |
| 1576 TEST_F(InputMethodControllerTest, Marker_ReplaceStartOfMarker) { | 1572 TEST_F(InputMethodControllerTest, Marker_ReplaceStartOfMarker) { |
| 1577 Element* div = insertHTMLElement( | 1573 Element* div = insertHTMLElement( |
| 1578 "<div id='sample' contenteditable>Initial text</div>", "sample"); | 1574 "<div id='sample' contenteditable>Initial text</div>", "sample"); |
| 1579 | 1575 |
| 1580 // Add marker under "Initial text" | 1576 // Add marker under "Initial text" |
| 1581 EphemeralRange markerRange = PlainTextRange(0, 12).createRange(*div); | 1577 EphemeralRange markerRange = PlainTextRange(0, 12).createRange(*div); |
| 1582 document().markers().addMarker(markerRange.startPosition(), | 1578 document().markers().addTextMatchMarker(markerRange.startPosition(), |
| 1583 markerRange.endPosition(), | 1579 markerRange.endPosition(), false); |
| 1584 DocumentMarker::TextMatch); | |
| 1585 | 1580 |
| 1586 // Replace "Initial" with "Original" | 1581 // Replace "Initial" with "Original" |
| 1587 Vector<CompositionUnderline> emptyUnderlines; | 1582 Vector<CompositionUnderline> emptyUnderlines; |
| 1588 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); | 1583 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); |
| 1589 controller().commitText(String("Original"), emptyUnderlines, 0); | 1584 controller().commitText(String("Original"), emptyUnderlines, 0); |
| 1590 | 1585 |
| 1591 // Verify marker is under "Original text" | 1586 // Verify marker is under "Original text" |
| 1592 EXPECT_EQ(1u, document().markers().markers().size()); | 1587 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1593 ASSERT_STREQ( | 1588 ASSERT_STREQ( |
| 1594 "Original text", | 1589 "Original text", |
| 1595 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1590 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| 1596 } | 1591 } |
| 1597 | 1592 |
| 1598 TEST_F(InputMethodControllerTest, Marker_ReplaceTextContainsStartOfMarker) { | 1593 TEST_F(InputMethodControllerTest, Marker_ReplaceTextContainsStartOfMarker) { |
| 1599 Element* div = insertHTMLElement( | 1594 Element* div = insertHTMLElement( |
| 1600 "<div id='sample' contenteditable>This is some initial text</div>", | 1595 "<div id='sample' contenteditable>This is some initial text</div>", |
| 1601 "sample"); | 1596 "sample"); |
| 1602 | 1597 |
| 1603 // Add marker under "initial text" | 1598 // Add marker under "initial text" |
| 1604 EphemeralRange markerRange = PlainTextRange(13, 25).createRange(*div); | 1599 EphemeralRange markerRange = PlainTextRange(13, 25).createRange(*div); |
| 1605 document().markers().addMarker(markerRange.startPosition(), | 1600 document().markers().addTextMatchMarker(markerRange.startPosition(), |
| 1606 markerRange.endPosition(), | 1601 markerRange.endPosition(), false); |
| 1607 DocumentMarker::TextMatch); | |
| 1608 | 1602 |
| 1609 // Replace "some initial" with "boring" | 1603 // Replace "some initial" with "boring" |
| 1610 Vector<CompositionUnderline> emptyUnderlines; | 1604 Vector<CompositionUnderline> emptyUnderlines; |
| 1611 controller().setCompositionFromExistingText(emptyUnderlines, 8, 20); | 1605 controller().setCompositionFromExistingText(emptyUnderlines, 8, 20); |
| 1612 controller().commitText(String("boring"), emptyUnderlines, 0); | 1606 controller().commitText(String("boring"), emptyUnderlines, 0); |
| 1613 | 1607 |
| 1614 // Verify marker is under " text" | 1608 // Verify marker is under " text" |
| 1615 EXPECT_EQ(1u, document().markers().markers().size()); | 1609 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1616 EXPECT_STREQ( | 1610 EXPECT_STREQ( |
| 1617 " text", | 1611 " text", |
| 1618 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1612 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| 1619 } | 1613 } |
| 1620 | 1614 |
| 1621 TEST_F(InputMethodControllerTest, Marker_ReplaceEndOfMarker) { | 1615 TEST_F(InputMethodControllerTest, Marker_ReplaceEndOfMarker) { |
| 1622 Element* div = insertHTMLElement( | 1616 Element* div = insertHTMLElement( |
| 1623 "<div id='sample' contenteditable>Initial text</div>", "sample"); | 1617 "<div id='sample' contenteditable>Initial text</div>", "sample"); |
| 1624 | 1618 |
| 1625 // Add marker under "Initial text" | 1619 // Add marker under "Initial text" |
| 1626 EphemeralRange markerRange = PlainTextRange(0, 12).createRange(*div); | 1620 EphemeralRange markerRange = PlainTextRange(0, 12).createRange(*div); |
| 1627 document().markers().addMarker(markerRange.startPosition(), | 1621 document().markers().addTextMatchMarker(markerRange.startPosition(), |
| 1628 markerRange.endPosition(), | 1622 markerRange.endPosition(), false); |
| 1629 DocumentMarker::TextMatch); | |
| 1630 | 1623 |
| 1631 // Replace "text" with "string" | 1624 // Replace "text" with "string" |
| 1632 Vector<CompositionUnderline> emptyUnderlines; | 1625 Vector<CompositionUnderline> emptyUnderlines; |
| 1633 controller().setCompositionFromExistingText(emptyUnderlines, 8, 12); | 1626 controller().setCompositionFromExistingText(emptyUnderlines, 8, 12); |
| 1634 controller().commitText(String("string"), emptyUnderlines, 0); | 1627 controller().commitText(String("string"), emptyUnderlines, 0); |
| 1635 | 1628 |
| 1636 // Verify marker is under "Initial string" | 1629 // Verify marker is under "Initial string" |
| 1637 EXPECT_EQ(1u, document().markers().markers().size()); | 1630 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1638 ASSERT_STREQ( | 1631 ASSERT_STREQ( |
| 1639 "Initial string", | 1632 "Initial string", |
| 1640 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1633 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| 1641 } | 1634 } |
| 1642 | 1635 |
| 1643 TEST_F(InputMethodControllerTest, Marker_ReplaceTextContainsEndOfMarker) { | 1636 TEST_F(InputMethodControllerTest, Marker_ReplaceTextContainsEndOfMarker) { |
| 1644 Element* div = insertHTMLElement( | 1637 Element* div = insertHTMLElement( |
| 1645 "<div id='sample' contenteditable>This is some initial text</div>", | 1638 "<div id='sample' contenteditable>This is some initial text</div>", |
| 1646 "sample"); | 1639 "sample"); |
| 1647 | 1640 |
| 1648 // Add marker under "some initial" | 1641 // Add marker under "some initial" |
| 1649 EphemeralRange markerRange = PlainTextRange(8, 20).createRange(*div); | 1642 EphemeralRange markerRange = PlainTextRange(8, 20).createRange(*div); |
| 1650 document().markers().addMarker(markerRange.startPosition(), | 1643 document().markers().addTextMatchMarker(markerRange.startPosition(), |
| 1651 markerRange.endPosition(), | 1644 markerRange.endPosition(), false); |
| 1652 DocumentMarker::TextMatch); | |
| 1653 | 1645 |
| 1654 // Replace "initial text" with "content" | 1646 // Replace "initial text" with "content" |
| 1655 Vector<CompositionUnderline> emptyUnderlines; | 1647 Vector<CompositionUnderline> emptyUnderlines; |
| 1656 controller().setCompositionFromExistingText(emptyUnderlines, 13, 25); | 1648 controller().setCompositionFromExistingText(emptyUnderlines, 13, 25); |
| 1657 controller().commitText(String("content"), emptyUnderlines, 0); | 1649 controller().commitText(String("content"), emptyUnderlines, 0); |
| 1658 | 1650 |
| 1659 EXPECT_STREQ("This is some content", div->innerHTML().utf8().data()); | 1651 EXPECT_STREQ("This is some content", div->innerHTML().utf8().data()); |
| 1660 | 1652 |
| 1661 // Verify marker is under "some " | 1653 // Verify marker is under "some " |
| 1662 EXPECT_EQ(1u, document().markers().markers().size()); | 1654 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1663 EXPECT_STREQ( | 1655 EXPECT_STREQ( |
| 1664 "some ", | 1656 "some ", |
| 1665 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1657 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| 1666 } | 1658 } |
| 1667 | 1659 |
| 1668 TEST_F(InputMethodControllerTest, Marker_ReplaceEntireMarker) { | 1660 TEST_F(InputMethodControllerTest, Marker_ReplaceEntireMarker) { |
| 1669 Element* div = insertHTMLElement( | 1661 Element* div = insertHTMLElement( |
| 1670 "<div id='sample' contenteditable>Initial text</div>", "sample"); | 1662 "<div id='sample' contenteditable>Initial text</div>", "sample"); |
| 1671 | 1663 |
| 1672 // Add marker under "text" | 1664 // Add marker under "text" |
| 1673 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div); | 1665 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div); |
| 1674 document().markers().addMarker(markerRange.startPosition(), | 1666 document().markers().addTextMatchMarker(markerRange.startPosition(), |
| 1675 markerRange.endPosition(), | 1667 markerRange.endPosition(), false); |
| 1676 DocumentMarker::TextMatch); | |
| 1677 | 1668 |
| 1678 // Replace "text" with "string" | 1669 // Replace "text" with "string" |
| 1679 Vector<CompositionUnderline> emptyUnderlines; | 1670 Vector<CompositionUnderline> emptyUnderlines; |
| 1680 controller().setCompositionFromExistingText(emptyUnderlines, 8, 12); | 1671 controller().setCompositionFromExistingText(emptyUnderlines, 8, 12); |
| 1681 controller().commitText(String("string"), emptyUnderlines, 0); | 1672 controller().commitText(String("string"), emptyUnderlines, 0); |
| 1682 | 1673 |
| 1683 // Verify marker is under "string" | 1674 // Verify marker is under "string" |
| 1684 EXPECT_EQ(1u, document().markers().markers().size()); | 1675 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1685 ASSERT_STREQ( | 1676 ASSERT_STREQ( |
| 1686 "string", | 1677 "string", |
| 1687 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); | 1678 getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| 1688 } | 1679 } |
| 1689 | 1680 |
| 1690 TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtBeginning) { | 1681 TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtBeginning) { |
| 1691 Element* div = insertHTMLElement( | 1682 Element* div = insertHTMLElement( |
| 1692 "<div id='sample' contenteditable>Initial text</div>", "sample"); | 1683 "<div id='sample' contenteditable>Initial text</div>", "sample"); |
| 1693 | 1684 |
| 1694 // Add marker under "Initial" | 1685 // Add marker under "Initial" |
| 1695 EphemeralRange markerRange = PlainTextRange(0, 7).createRange(*div); | 1686 EphemeralRange markerRange = PlainTextRange(0, 7).createRange(*div); |
| 1696 document().markers().addMarker(markerRange.startPosition(), | 1687 document().markers().addTextMatchMarker(markerRange.startPosition(), |
| 1697 markerRange.endPosition(), | 1688 markerRange.endPosition(), false); |
| 1698 DocumentMarker::TextMatch); | |
| 1699 | 1689 |
| 1700 EXPECT_EQ(1u, document().markers().markers().size()); | 1690 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1701 | 1691 |
| 1702 // Replace "Initial text" with "New string" | 1692 // Replace "Initial text" with "New string" |
| 1703 Vector<CompositionUnderline> emptyUnderlines; | 1693 Vector<CompositionUnderline> emptyUnderlines; |
| 1704 controller().setCompositionFromExistingText(emptyUnderlines, 0, 12); | 1694 controller().setCompositionFromExistingText(emptyUnderlines, 0, 12); |
| 1705 controller().commitText(String("New string"), emptyUnderlines, 0); | 1695 controller().commitText(String("New string"), emptyUnderlines, 0); |
| 1706 | 1696 |
| 1707 // Verify marker was removed | 1697 // Verify marker was removed |
| 1708 EXPECT_EQ(0u, document().markers().markers().size()); | 1698 EXPECT_EQ(0u, document().markers().markers().size()); |
| 1709 } | 1699 } |
| 1710 | 1700 |
| 1711 TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtEnd) { | 1701 TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtEnd) { |
| 1712 Element* div = insertHTMLElement( | 1702 Element* div = insertHTMLElement( |
| 1713 "<div id='sample' contenteditable>Initial text</div>", "sample"); | 1703 "<div id='sample' contenteditable>Initial text</div>", "sample"); |
| 1714 | 1704 |
| 1715 // Add marker under "text" | 1705 // Add marker under "text" |
| 1716 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div); | 1706 EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div); |
| 1717 document().markers().addMarker(markerRange.startPosition(), | 1707 document().markers().addTextMatchMarker(markerRange.startPosition(), |
| 1718 markerRange.endPosition(), | 1708 markerRange.endPosition(), false); |
| 1719 DocumentMarker::TextMatch); | |
| 1720 | 1709 |
| 1721 EXPECT_EQ(1u, document().markers().markers().size()); | 1710 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1722 | 1711 |
| 1723 // Replace "Initial text" with "New string" | 1712 // Replace "Initial text" with "New string" |
| 1724 Vector<CompositionUnderline> emptyUnderlines; | 1713 Vector<CompositionUnderline> emptyUnderlines; |
| 1725 controller().setCompositionFromExistingText(emptyUnderlines, 0, 12); | 1714 controller().setCompositionFromExistingText(emptyUnderlines, 0, 12); |
| 1726 controller().commitText(String("New string"), emptyUnderlines, 0); | 1715 controller().commitText(String("New string"), emptyUnderlines, 0); |
| 1727 | 1716 |
| 1728 // Verify marker was removed | 1717 // Verify marker was removed |
| 1729 EXPECT_EQ(0u, document().markers().markers().size()); | 1718 EXPECT_EQ(0u, document().markers().markers().size()); |
| 1730 } | 1719 } |
| 1731 | 1720 |
| 1732 } // namespace blink | 1721 } // namespace blink |
| OLD | NEW |