TEST_F(LocalFrameTest, nodeImageWithChangingLayoutObject) { setBodyContent( "<style>" "#sample { color: blue; }" "#sample:-webkit-drag { display: inline-block; color: red; }" "</style>" "<span id=sample>foo</span>"); Element* sample = document().getElementById("sample"); updateAllLifecyclePhases(); LayoutObject* beforeLayoutObject = sample->layoutObject(); const std::unique_ptr<DragImage> image = frame().nodeImage(*sample); EXPECT_TRUE(sample->layoutObject() != beforeLayoutObject) << ":-webkit-drag causes sample to have different layout object."; EXPECT_EQ(Color(255, 0, 0), sample->layoutObject()->resolveColor(CSSPropertyColor)) << "#sample has :-webkit-drag."; // Layout w/o :-webkit-drag updateAllLifecyclePhases(); EXPECT_EQ(Color(0, 0, 255), sample->layoutObject()->resolveColor(CSSPropertyColor)) << "#sample doesn't have :-webkit-drag."; }
TEST_F(VisiblePositionTest, ShadowV0DistributedNodes) { const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>"; const char* shadowContent = "<a><span id='s4'>44</span><content select=#two></content><span " "id='s5'>55</span><content select=#one></content><span " "id='s6'>66</span></a>"; setBodyContent(bodyContent); ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); Element* body = document().body(); Element* one = body->querySelector("#one"); Element* two = body->querySelector("#two"); Element* four = shadowRoot->querySelector("#s4"); Element* five = shadowRoot->querySelector("#s5"); EXPECT_EQ(Position(one->firstChild(), 0), canonicalPositionOf(Position(one, 0))); EXPECT_EQ(Position(one->firstChild(), 0), createVisiblePosition(Position(one, 0)).deepEquivalent()); EXPECT_EQ(Position(one->firstChild(), 2), canonicalPositionOf(Position(two, 0))); EXPECT_EQ(Position(one->firstChild(), 2), createVisiblePosition(Position(two, 0)).deepEquivalent()); EXPECT_EQ(PositionInFlatTree(five->firstChild(), 2), canonicalPositionOf(PositionInFlatTree(one, 0))); EXPECT_EQ(PositionInFlatTree(five->firstChild(), 2), createVisiblePosition(PositionInFlatTree(one, 0)).deepEquivalent()); EXPECT_EQ(PositionInFlatTree(four->firstChild(), 2), canonicalPositionOf(PositionInFlatTree(two, 0))); EXPECT_EQ(PositionInFlatTree(four->firstChild(), 2), createVisiblePosition(PositionInFlatTree(two, 0)).deepEquivalent()); }
TEST_F(VisiblePositionTest, NonNullIsValidBeforeMutation) { setBodyContent("<p>one</p>"); Element* paragraph = document().querySelector("p"); Position position(paragraph->firstChild(), 1); EXPECT_TRUE(createVisiblePosition(position).isValid()); }
// This is a regression test for https://crbug.com/619131 TEST_F(ReplaceSelectionCommandTest, pastingEmptySpan) { document().setDesignMode("on"); setBodyContent("foo"); LocalFrame* frame = document().frame(); frame->selection().setSelection(SelectionInDOMTree::Builder() .collapse(Position(document().body(), 0)) .build()); DocumentFragment* fragment = document().createDocumentFragment(); fragment->appendChild(document().createElement("span", ASSERT_NO_EXCEPTION)); // |options| are taken from |Editor::replaceSelectionWithFragment()| with // |selectReplacement| and |smartReplace|. ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::PreventNesting | ReplaceSelectionCommand::SanitizeFragment | ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::SmartReplace; ReplaceSelectionCommand* command = ReplaceSelectionCommand::create(document(), fragment, options); EXPECT_TRUE(command->apply()) << "the replace command should have succeeded"; EXPECT_EQ("foo", document().body()->innerHTML()) << "no DOM tree mutation"; }
TEST_F(PositionTest, NodeAsRangeLastNode) { const char* bodyContent = "<p id='p1'>11</p><p id='p2'></p><p id='p3'>33</p>"; setBodyContent(bodyContent); Node* p1 = document().getElementById("p1"); Node* p2 = document().getElementById("p2"); Node* p3 = document().getElementById("p3"); Node* body = EditingStrategy::parent(*p1); Node* t1 = EditingStrategy::firstChild(*p1); Node* t3 = EditingStrategy::firstChild(*p3); EXPECT_EQ(body, Position::inParentBeforeNode(*p1).nodeAsRangeLastNode()); EXPECT_EQ(t1, Position::inParentBeforeNode(*p2).nodeAsRangeLastNode()); EXPECT_EQ(p2, Position::inParentBeforeNode(*p3).nodeAsRangeLastNode()); EXPECT_EQ(t1, Position::inParentAfterNode(*p1).nodeAsRangeLastNode()); EXPECT_EQ(p2, Position::inParentAfterNode(*p2).nodeAsRangeLastNode()); EXPECT_EQ(t3, Position::inParentAfterNode(*p3).nodeAsRangeLastNode()); EXPECT_EQ(t3, Position::afterNode(p3).nodeAsRangeLastNode()); EXPECT_EQ(body, PositionInFlatTree::inParentBeforeNode(*p1).nodeAsRangeLastNode()); EXPECT_EQ(t1, PositionInFlatTree::inParentBeforeNode(*p2).nodeAsRangeLastNode()); EXPECT_EQ(p2, PositionInFlatTree::inParentBeforeNode(*p3).nodeAsRangeLastNode()); EXPECT_EQ(t1, PositionInFlatTree::inParentAfterNode(*p1).nodeAsRangeLastNode()); EXPECT_EQ(p2, PositionInFlatTree::inParentAfterNode(*p2).nodeAsRangeLastNode()); EXPECT_EQ(t3, PositionInFlatTree::inParentAfterNode(*p3).nodeAsRangeLastNode()); EXPECT_EQ(t3, PositionInFlatTree::afterNode(p3).nodeAsRangeLastNode()); }
// This is a regression test for https://crbug.com/585048 TEST_F(TypingCommandTest, insertLineBreakWithIllFormedHTML) { setBodyContent("<div contenteditable></div>"); // <input><form></form></input> Element* input1 = document().createElement("input"); Element* form = document().createElement("form"); input1->appendChild(form); // <tr><input><header></header></input><rbc></rbc></tr> Element* tr = document().createElement("tr"); Element* input2 = document().createElement("input"); Element* header = document().createElement("header"); Element* rbc = document().createElement("rbc"); input2->appendChild(header); tr->appendChild(input2); tr->appendChild(rbc); Element* div = document().querySelector("div"); div->appendChild(input1); div->appendChild(tr); LocalFrame* frame = document().frame(); frame->selection().setSelection(SelectionInDOMTree::Builder() .collapse(Position(form, 0)) .extend(Position(header, 0)) .build()); // Inserting line break should not crash or hit assertion. TypingCommand::insertLineBreak(document()); }
TEST_F(PositionTest, NodeAsRangeLastNodeShadow) { const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>"; const char* shadowContent = "<a id='a'><content select=#two></content><content select=#one></content></a>"; setBodyContent(bodyContent); RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); Node* host = document().getElementById("host"); Node* n1 = document().getElementById("one"); Node* n2 = document().getElementById("two"); Node* t0 = EditingStrategy::firstChild(*host); Node* t1 = EditingStrategy::firstChild(*n1); Node* t2 = EditingStrategy::firstChild(*n2); Node* t3 = EditingStrategy::lastChild(*host); Node* a = shadowRoot->getElementById("a"); EXPECT_EQ(t0, Position::inParentBeforeNode(*n1).nodeAsRangeLastNode()); EXPECT_EQ(t1, Position::inParentBeforeNode(*n2).nodeAsRangeLastNode()); EXPECT_EQ(t1, Position::inParentAfterNode(*n1).nodeAsRangeLastNode()); EXPECT_EQ(t2, Position::inParentAfterNode(*n2).nodeAsRangeLastNode()); EXPECT_EQ(t3, Position::afterNode(host).nodeAsRangeLastNode()); EXPECT_EQ(t2, PositionInFlatTree::inParentBeforeNode(*n1).nodeAsRangeLastNode()); EXPECT_EQ(a, PositionInFlatTree::inParentBeforeNode(*n2).nodeAsRangeLastNode()); EXPECT_EQ(t1, PositionInFlatTree::inParentAfterNode(*n1).nodeAsRangeLastNode()); EXPECT_EQ(t2, PositionInFlatTree::inParentAfterNode(*n2).nodeAsRangeLastNode()); EXPECT_EQ(t1, PositionInFlatTree::afterNode(host).nodeAsRangeLastNode()); }
// This test comes from "editing/style/block-style-progress-crash.html". TEST_F(PositionTest, ToPositionInFlatTreeWithNotDistributed) { setBodyContent("<progress id=sample>foo</progress>"); Element* sample = document().getElementById("sample"); EXPECT_EQ(PositionInFlatTree(sample, PositionAnchorType::AfterChildren), toPositionInFlatTree(Position(sample, 0))); }
TEST_F(EditingUtilitiesTest, isFirstPositionAfterTable) { const char* bodyContent = "<div contenteditable id=host><table id=table><tr><td>1</td></tr></table><b id=two>22</b></div>"; const char* shadowContent = "<content select=#two></content><content select=#table></content>"; setBodyContent(bodyContent); setShadowContent(shadowContent, "host"); updateLayoutAndStyleForPainting(); Node* host = document().getElementById("host"); Node* table = document().getElementById("table"); EXPECT_EQ(table, isFirstPositionAfterTable(createVisiblePosition(Position::afterNode(table)))); EXPECT_EQ(table, isFirstPositionAfterTable(createVisiblePosition(PositionInComposedTree::afterNode(table)))); EXPECT_EQ(table, isFirstPositionAfterTable(createVisiblePosition(Position::lastPositionInNode(table)))); EXPECT_EQ(table, isFirstPositionAfterTable(createVisiblePosition(PositionInComposedTree::lastPositionInNode(table)))); EXPECT_EQ(nullptr, isFirstPositionAfterTable(createVisiblePosition(Position(host, 2)))); EXPECT_EQ(table, isFirstPositionAfterTable(createVisiblePosition(PositionInComposedTree(host, 2)))); EXPECT_EQ(nullptr, isFirstPositionAfterTable(createVisiblePosition(Position::afterNode(host)))); EXPECT_EQ(nullptr, isFirstPositionAfterTable(createVisiblePosition(PositionInComposedTree::afterNode(host)))); EXPECT_EQ(nullptr, isFirstPositionAfterTable(createVisiblePosition(Position::lastPositionInNode(host)))); EXPECT_EQ(table, isFirstPositionAfterTable(createVisiblePosition(PositionInComposedTree::lastPositionInNode(host)))); }
TEST_F(PositionTest, ToPositionInFlatTreeWithInactiveInsertionPoint) { const char* bodyContent = "<p id='p'><content></content></p>"; setBodyContent(bodyContent); RefPtrWillBeRawPtr<Element> anchor = document().getElementById("p"); EXPECT_EQ(PositionInFlatTree(anchor.get(), 0), toPositionInFlatTree(Position(anchor.get(), 0))); EXPECT_EQ(PositionInFlatTree(anchor, PositionAnchorType::AfterChildren), toPositionInFlatTree(Position(anchor.get(), 1))); }
TEST_F(SimplifiedBackwardsTextIteratorTest, characterAt) { const char* bodyContent = "<a id=host><b id=one>one</b> not appeared <b id=two>two</b></a>"; const char* shadowContent = "three <content select=#two></content> <content select=#one></content> " "zero"; setBodyContent(bodyContent); setShadowContent(shadowContent, "host"); Element* host = document().getElementById("host"); EphemeralRangeTemplate<EditingStrategy> range1( EphemeralRangeTemplate<EditingStrategy>::rangeOfContents(*host)); SimplifiedBackwardsTextIteratorAlgorithm<EditingStrategy> backIter1( range1.startPosition(), range1.endPosition()); const char* message1 = "|backIter1| should emit 'one' and 'two' in reverse order."; EXPECT_EQ('o', backIter1.characterAt(0)) << message1; EXPECT_EQ('w', backIter1.characterAt(1)) << message1; EXPECT_EQ('t', backIter1.characterAt(2)) << message1; backIter1.advance(); EXPECT_EQ('e', backIter1.characterAt(0)) << message1; EXPECT_EQ('n', backIter1.characterAt(1)) << message1; EXPECT_EQ('o', backIter1.characterAt(2)) << message1; EphemeralRangeTemplate<EditingInFlatTreeStrategy> range2( EphemeralRangeTemplate<EditingInFlatTreeStrategy>::rangeOfContents( *host)); SimplifiedBackwardsTextIteratorAlgorithm<EditingInFlatTreeStrategy> backIter2( range2.startPosition(), range2.endPosition()); const char* message2 = "|backIter2| should emit 'three ', 'two', ' ', 'one' and ' zero' in " "reverse order."; EXPECT_EQ('o', backIter2.characterAt(0)) << message2; EXPECT_EQ('r', backIter2.characterAt(1)) << message2; EXPECT_EQ('e', backIter2.characterAt(2)) << message2; EXPECT_EQ('z', backIter2.characterAt(3)) << message2; EXPECT_EQ(' ', backIter2.characterAt(4)) << message2; backIter2.advance(); EXPECT_EQ('e', backIter2.characterAt(0)) << message2; EXPECT_EQ('n', backIter2.characterAt(1)) << message2; EXPECT_EQ('o', backIter2.characterAt(2)) << message2; backIter2.advance(); EXPECT_EQ(' ', backIter2.characterAt(0)) << message2; backIter2.advance(); EXPECT_EQ('o', backIter2.characterAt(0)) << message2; EXPECT_EQ('w', backIter2.characterAt(1)) << message2; EXPECT_EQ('t', backIter2.characterAt(2)) << message2; backIter2.advance(); EXPECT_EQ(' ', backIter2.characterAt(0)) << message2; EXPECT_EQ('e', backIter2.characterAt(1)) << message2; EXPECT_EQ('e', backIter2.characterAt(2)) << message2; EXPECT_EQ('r', backIter2.characterAt(3)) << message2; EXPECT_EQ('h', backIter2.characterAt(4)) << message2; EXPECT_EQ('t', backIter2.characterAt(5)) << message2; }
TEST_F(PositionTest, ToPositionInFlatTreeWithEmptyShadowRoot) { const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; const char* shadowContent = ""; setBodyContent(bodyContent); RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); EXPECT_EQ(PositionInFlatTree(host, PositionAnchorType::AfterChildren), toPositionInFlatTree(Position(shadowRoot.get(), 0))); }
TEST_F(LocalFrameTest, nodeImage) { setBodyContent( "<style>" "#sample { width: 100px; height: 100px; }" "</style>" "<div id=sample></div>"); Element* sample = document().getElementById("sample"); const std::unique_ptr<DragImage> image = frame().nodeImage(*sample); EXPECT_EQ(IntSize(100, 100), image->size()); }
TEST_F(SpellCheckerTest, AdvanceToNextMisspellingWithEmptyInputNoCrash) { setBodyContent("<input placeholder='placeholder'>abc"); updateLayoutAndStyleForPainting(); RawPtr<Element> input = document().querySelector("input", ASSERT_NO_EXCEPTION); input->focus(); document().settings()->setUnifiedTextCheckerEnabled(true); // Do not crash in AdvanceToNextMisspelling command. EXPECT_TRUE(document().frame()->editor().executeCommand("AdvanceToNextMisspelling")); document().settings()->setUnifiedTextCheckerEnabled(false); }
TEST_F(PositionTest, ToPositionInFlatTreeWithShadowRootContainingSingleContent) { const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; const char* shadowContent = "<content select=#one></content>"; setBodyContent(bodyContent); ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); Element* host = document().getElementById("host"); EXPECT_EQ(PositionInFlatTree(host, 0), toPositionInFlatTree(Position(shadowRoot, 0))); EXPECT_EQ(PositionInFlatTree(host, PositionAnchorType::AfterChildren), toPositionInFlatTree(Position(shadowRoot, 1))); }
TEST_F(LocalFrameTest, nodeImageWithoutDraggedLayoutObject) { setBodyContent( "<style>" "#sample { width: 100px; height: 100px; }" "#sample:-webkit-drag { display:none }" "</style>" "<div id=sample></div>"); Element* sample = document().getElementById("sample"); const std::unique_ptr<DragImage> image = frame().nodeImage(*sample); EXPECT_EQ(nullptr, image.get()) << ":-webkit-drag blows away layout object"; }
TEST_F(PositionTest, ToPositionInComposedTreeWithShadowRootContainingSingleContent) { const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; const char* shadowContent = "<content select=#one></content>"; setBodyContent(bodyContent); RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); EXPECT_EQ(PositionInComposedTree(host.get(), 0), toPositionInComposedTree(Position(shadowRoot.get(), 0))); EXPECT_EQ(PositionInComposedTree(host.get(), PositionAnchorType::AfterChildren), toPositionInComposedTree(Position(shadowRoot.get(), 1))); }
TEST_F(NodeTest, canStartSelectionWithShadowDOM) { const char* bodyContent = "<div id=host><span id=one>one</span></div>"; const char* shadowContent = "<a href='http://www.msn.com'><content></content></a>"; setBodyContent(bodyContent); setShadowContent(shadowContent, "host"); updateLayoutAndStyleForPainting(); Node* one = document().getElementById("one"); EXPECT_FALSE(one->canStartSelection()); EXPECT_FALSE(one->firstChild()->canStartSelection()); }
TEST_F(EditingUtilitiesTest, NextNodeIndex) { const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>"; const char* shadowContent = "<content select=#two></content><content select=#one></content>"; setBodyContent(bodyContent); setShadowContent(shadowContent, "host"); Node* host = document().getElementById("host"); Node* two = document().getElementById("two"); EXPECT_EQ(Position(host, 3), nextPositionOf(Position(two, 2), PositionMoveType::CodePoint)); EXPECT_EQ(PositionInComposedTree(host, 1), nextPositionOf(PositionInComposedTree(two, 2), PositionMoveType::CodePoint)); }
TEST_F(LocalFrameTest, nodeImageWithPsuedoClassWebKitDrag) { setBodyContent( "<style>" "#sample { width: 100px; height: 100px; }" "#sample:-webkit-drag { width: 200px; height: 200px; }" "</style>" "<div id=sample></div>"); Element* sample = document().getElementById("sample"); const std::unique_ptr<DragImage> image = frame().nodeImage(*sample); EXPECT_EQ(IntSize(200, 200), image->size()) << ":-webkit-drag should affect dragged image."; }
TEST_F(EditingUtilitiesTest, directionOfEnclosingBlock) { const char* bodyContent = "<p id='host'><b id='one'></b><b id='two'>22</b></p>"; const char* shadowContent = "<content select=#two></content><p dir=rtl><content select=#one></content><p>"; setBodyContent(bodyContent); setShadowContent(shadowContent, "host"); updateLayoutAndStyleForPainting(); Node* one = document().getElementById("one"); EXPECT_EQ(LTR, directionOfEnclosingBlock(Position(one, 0))); EXPECT_EQ(RTL, directionOfEnclosingBlock(PositionInComposedTree(one, 0))); }
TEST_F(PositionTest, ToPositionInFlatTreeWithActiveInsertionPoint) { const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; const char* shadowContent = "<a id='a'><content select=#one id='content'></content><content></content></a>"; setBodyContent(bodyContent); RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); RefPtrWillBeRawPtr<Element> anchor = shadowRoot->getElementById("a"); EXPECT_EQ(PositionInFlatTree(anchor.get(), 0), toPositionInFlatTree(Position(anchor.get(), 0))); EXPECT_EQ(PositionInFlatTree(anchor.get(), 1), toPositionInFlatTree(Position(anchor.get(), 1))); EXPECT_EQ(PositionInFlatTree(anchor, PositionAnchorType::AfterChildren), toPositionInFlatTree(Position(anchor.get(), 2))); }
TEST_F(NodeTest, canStartSelection) { const char* bodyContent = "<a id=one href='http://www.msn.com'>one</a><b id=two>two</b>"; setBodyContent(bodyContent); updateLayoutAndStyleForPainting(); Node* one = document().getElementById("one"); Node* two = document().getElementById("two"); EXPECT_FALSE(one->canStartSelection()); EXPECT_FALSE(one->firstChild()->canStartSelection()); EXPECT_TRUE(two->canStartSelection()); EXPECT_TRUE(two->firstChild()->canStartSelection()); }
TEST_F(LocalFrameTest, nodeImageWithNestedElement) { setBodyContent( "<style>" "div { -webkit-user-drag: element }" "span:-webkit-drag { color: #0F0 }" "</style>" "<div id=sample><span>Green when dragged</span></div>"); Element* sample = document().getElementById("sample"); const std::unique_ptr<DragImage> image = frame().nodeImage(*sample); EXPECT_EQ( Color(0, 255, 0), sample->firstChild()->layoutObject()->resolveColor(CSSPropertyColor)) << "Descendants node should have :-webkit-drag."; }
TEST_F(EditingUtilitiesTest, NextVisuallyDistinctCandidate) { const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</b><b id='three'>33</b></p>"; const char* shadowContent = "<content select=#two></content><content select=#one></content><content select=#three></content>"; setBodyContent(bodyContent); setShadowContent(shadowContent, "host"); updateLayoutAndStyleForPainting(); Node* one = document().getElementById("one"); Node* two = document().getElementById("two"); Node* three = document().getElementById("three"); EXPECT_EQ(Position(two->firstChild(), 1), nextVisuallyDistinctCandidate(Position(one, 1))); EXPECT_EQ(PositionInComposedTree(three->firstChild(), 1), nextVisuallyDistinctCandidate(PositionInComposedTree(one, 1))); }
TEST_F(EditingUtilitiesTest, enclosingNodeOfType) { const char* bodyContent = "<p id='host'><b id='one'>11</b></p>"; const char* shadowContent = "<content select=#two></content><div id='three'><content select=#one></div></content>"; setBodyContent(bodyContent); RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); updateLayoutAndStyleForPainting(); Node* host = document().getElementById("host"); Node* one = document().getElementById("one"); Node* three = shadowRoot->getElementById("three"); EXPECT_EQ(host, enclosingNodeOfType(Position(one, 0), isEnclosingBlock)); EXPECT_EQ(three, enclosingNodeOfType(PositionInComposedTree(one, 0), isEnclosingBlock)); }
TEST_F(CharacterIteratorTest, SubrangeWithReplacedElements) { static const char* bodyContent = "<div id='div' contenteditable='true'>1<img src='foo.png'>345</div>"; setBodyContent(bodyContent); document().view()->updateAllLifecyclePhases(); Node* divNode = document().getElementById("div"); Range* entireRange = Range::create(document(), divNode, 0, divNode, 3); EphemeralRange result = calculateCharacterSubrange(EphemeralRange(entireRange), 2, 3); Node* textNode = divNode->lastChild(); EXPECT_EQ(Position(textNode, 0), result.startPosition()); EXPECT_EQ(Position(textNode, 3), result.endPosition()); }
TEST_F(SelectionAdjusterTest, adjustSelectionInFlatTree) { setBodyContent("<div id=sample>foo</div>"); MockVisibleSelectionChangeObserver selectionObserver; VisibleSelectionInFlatTree selectionInFlatTree; selectionInFlatTree.setChangeObserver(selectionObserver); Node* const sample = document().getElementById("sample"); Node* const foo = sample->firstChild(); // Select "foo" VisibleSelection selection(Position(foo, 0), Position(foo, 3)); SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection); EXPECT_EQ(PositionInFlatTree(foo, 0), selectionInFlatTree.start()); EXPECT_EQ(PositionInFlatTree(foo, 3), selectionInFlatTree.end()); EXPECT_EQ(1, selectionObserver.callCounter()) << "adjustSelectionInFlatTree() should call didChangeVisibleSelection()"; }
TEST_F(SimplifiedBackwardsTextIteratorTest, SubrangeWithReplacedElements) { static const char* bodyContent = "<a id=host><b id=one>one</b> not appeared <b id=two>two</b></a>"; const char* shadowContent = "three <content select=#two></content> <content select=#one></content> zero"; setBodyContent(bodyContent); setShadowContent(shadowContent, "host"); updateLayoutAndStyleForPainting(); Element* host = document().getElementById("host"); // We should not apply DOM tree version to containing shadow tree in // general. To record current behavior, we have this test. even if it // isn't intuitive. EXPECT_EQ("onetwo", extractString<EditingStrategy>(*host)); EXPECT_EQ("three two one zero", extractString<EditingInComposedTreeStrategy>(*host)); }
TEST_F(SelectionTest, caret) { setBodyContent("<div id='sample'>abcdef</div>"); Element* sample = document().getElementById("sample"); Position position(Position(sample->firstChild(), 2)); SelectionInDOMTree::Builder builder; builder.collapse(position); const SelectionInDOMTree& selection = builder.build(); EXPECT_EQ(TextAffinity::Downstream, selection.affinity()); EXPECT_EQ(CharacterGranularity, selection.granularity()); EXPECT_FALSE(selection.hasTrailingWhitespace()); EXPECT_FALSE(selection.isDirectional()); EXPECT_FALSE(selection.isNone()); EXPECT_EQ(position, selection.base()); EXPECT_EQ(position, selection.extent()); }