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