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."; }
// This is a regression test for https://crbug.com/121163 TEST_F(ReplaceSelectionCommandTest, styleTagsInPastedHeadIncludedInContent) { document().setDesignMode("on"); updateAllLifecyclePhases(); dummyPageHolder().frame().selection().setSelection( SelectionInDOMTree::Builder() .collapse(Position(document().body(), 0)) .build()); DocumentFragment* fragment = document().createDocumentFragment(); fragment->parseHTML( "<head><style>foo { bar: baz; }</style></head>" "<body><p>Text</p></body>", document().documentElement(), DisallowScriptingAndPluginContent); ReplaceSelectionCommand::CommandOptions options = 0; ReplaceSelectionCommand* command = ReplaceSelectionCommand::create(document(), fragment, options); EXPECT_TRUE(command->apply()) << "the replace command should have succeeded"; EXPECT_EQ( "<head><style>foo { bar: baz; }</style></head>" "<body><p>Text</p></body>", document().body()->innerHTML()) << "the STYLE and P elements should have been pasted into the body " << "of the document"; }
TEST_F(LocalFrameTest, dragImageForSelectionUsesPageScaleFactor) { setBodyContent( "<div>Hello world! This tests that the bitmap for drag image is scaled " "by page scale factor</div>"); frame().host()->visualViewport().setScale(1); frame().selection().selectAll(); updateAllLifecyclePhases(); const std::unique_ptr<DragImage> image1(frame().dragImageForSelection(0.75f)); frame().host()->visualViewport().setScale(2); frame().selection().selectAll(); updateAllLifecyclePhases(); const std::unique_ptr<DragImage> image2(frame().dragImageForSelection(0.75f)); EXPECT_GT(image1->size().width(), 0); EXPECT_GT(image1->size().height(), 0); EXPECT_EQ(image1->size().width() * 2, image2->size().width()); EXPECT_EQ(image1->size().height() * 2, image2->size().height()); }
TEST_F(VisiblePositionTest, NonNullInvalidatedAfterStyleChange) { setBodyContent("<div>one</div><p>two</p>"); Element* paragraph = document().querySelector("p"); Element* div = document().querySelector("div"); Position position(paragraph->firstChild(), 1); VisiblePosition visiblePosition1 = createVisiblePosition(position); div->style()->setProperty("color", "red", "important", ASSERT_NO_EXCEPTION); EXPECT_FALSE(visiblePosition1.isValid()); updateAllLifecyclePhases(); VisiblePosition visiblePosition2 = createVisiblePosition(position); div->style()->setProperty("display", "none", "important", ASSERT_NO_EXCEPTION); EXPECT_FALSE(visiblePosition2.isValid()); updateAllLifecyclePhases(); // Invalid VisiblePosition can never become valid again. EXPECT_FALSE(visiblePosition1.isValid()); EXPECT_FALSE(visiblePosition2.isValid()); }
TEST_F(VisiblePositionTest, NonNullInvalidatedAfterDOMChange) { setBodyContent("<p>one</p>"); Element* paragraph = document().querySelector("p"); Position position(paragraph->firstChild(), 1); VisiblePosition nullVisiblePosition; VisiblePosition nonNullVisiblePosition = createVisiblePosition(position); Element* div = document().createElement("div"); document().body()->appendChild(div); EXPECT_TRUE(nullVisiblePosition.isValid()); EXPECT_FALSE(nonNullVisiblePosition.isValid()); updateAllLifecyclePhases(); // Invalid VisiblePosition can never become valid again. EXPECT_FALSE(nonNullVisiblePosition.isValid()); }
// This is a regression test for https://crbug.com/660801 TEST_F(ApplyBlockElementCommandTest, visibilityChangeDuringCommand) { document().head()->insertAdjacentHTML( "afterbegin", "<style>li:first-child { visibility:visible; }</style>", ASSERT_NO_EXCEPTION); setBodyContent("<ul style='visibility:hidden'><li>xyz</li></ul>"); document().setDesignMode("on"); updateAllLifecyclePhases(); selection().setSelection( SelectionInDOMTree::Builder() .collapse(Position(document().querySelector("li"), 0)) .build()); IndentOutdentCommand* command = IndentOutdentCommand::create(document(), IndentOutdentCommand::Indent); command->apply(); EXPECT_EQ( "<head><style>li:first-child { visibility:visible; }</style></head>" "<body><ul style=\"visibility:hidden\"><ul></ul><li>xyz</li></ul></body>", document().documentElement()->innerHTML()); }
void EditingTestBase::setBodyContent(const std::string& bodyContent) { document().body()->setInnerHTML(String::fromUTF8(bodyContent.c_str()), ASSERT_NO_EXCEPTION); updateAllLifecyclePhases(); }