// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "public/web/WebElement.h" #include "core/dom/Document.h" #include "core/dom/Element.h" #include "core/dom/shadow/ShadowRoot.h" #include "core/testing/DummyPageHolder.h" #include "testing/gtest/include/gtest/gtest.h" namespace blink { static const char s_blockWithContinuations[] = " " "" "
" "
" " " "
" "
" ""; static const char s_emptyBlock[] = " " "
"; static const char s_emptyInline[] = " "; static const char s_blockWithDisplayNone[] = " " "" "
" "
" " " "
" "
" ""; static const char s_blockWithContent[] = "
" "
Hello
" "
"; static const char s_blockWithText[] = "
" "
Hello
" "
"; static const char s_blockWithInlines[] = "
" " Hello " "
"; static const char s_blockWithEmptyInlines[] = "
" " " "
"; class WebElementTest : public testing::Test { protected: Document& document() { return m_pageHolder->document(); } void insertHTML(String html); WebElement testElement(); private: void SetUp() override; OwnPtr m_pageHolder; }; void WebElementTest::insertHTML(String html) { document().documentElement()->setInnerHTML(html, ASSERT_NO_EXCEPTION); } WebElement WebElementTest::testElement() { Element* element = document().getElementById("testElement"); ASSERT(element); return WebElement(element); } void WebElementTest::SetUp() { m_pageHolder = DummyPageHolder::create(IntSize(800, 600)); } TEST_F(WebElementTest, HasNonEmptyLayoutSize) { insertHTML(s_emptyBlock); EXPECT_FALSE(testElement().hasNonEmptyLayoutSize()); insertHTML(s_emptyInline); EXPECT_FALSE(testElement().hasNonEmptyLayoutSize()); insertHTML(s_blockWithDisplayNone); EXPECT_FALSE(testElement().hasNonEmptyLayoutSize()); insertHTML(s_blockWithEmptyInlines); EXPECT_FALSE(testElement().hasNonEmptyLayoutSize()); insertHTML(s_blockWithContinuations); EXPECT_TRUE(testElement().hasNonEmptyLayoutSize()); insertHTML(s_blockWithInlines); EXPECT_TRUE(testElement().hasNonEmptyLayoutSize()); insertHTML(s_blockWithContent); EXPECT_TRUE(testElement().hasNonEmptyLayoutSize()); insertHTML(s_blockWithText); EXPECT_TRUE(testElement().hasNonEmptyLayoutSize()); insertHTML(s_emptyBlock); RefPtrWillBeRawPtr root = document().getElementById("testElement")->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); root->setInnerHTML("
Hello World
", ASSERT_NO_EXCEPTION); EXPECT_TRUE(testElement().hasNonEmptyLayoutSize()); } TEST_F(WebElementTest, IsEditable) { insertHTML("
"); EXPECT_FALSE(testElement().isEditable()); insertHTML("
"); EXPECT_TRUE(testElement().isEditable()); insertHTML( "
" "
" "
" ); EXPECT_TRUE(testElement().isEditable()); insertHTML( "
" "
" "
" ); EXPECT_FALSE(testElement().isEditable()); insertHTML(""); EXPECT_TRUE(testElement().isEditable()); insertHTML(""); EXPECT_FALSE(testElement().isEditable()); insertHTML(""); EXPECT_FALSE(testElement().isEditable()); insertHTML("
"); EXPECT_FALSE(testElement().isEditable()); } } // namespace blink