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
3 // found in the LICENSE file.
6 #include "public/web/WebElement.h"
8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h"
10 #include "core/dom/shadow/ShadowRoot.h"
11 #include "core/testing/DummyPageHolder.h"
12 #include <gtest/gtest.h>
16 static const char s_blockWithContinuations
[] =
17 "<head> <style> form {display: inline;} </style> </head>"
20 " <div id='testElement'>"
21 " <input type='password' id='password'/>"
26 static const char s_emptyBlock
[] =
27 "<head> <style> form {display: inline;} </style> </head>"
28 "<body> <form id='testElement'> </form> </body>";
30 static const char s_emptyInline
[] =
31 "<body> <span id='testElement'> </span> </body>";
33 static const char s_blockWithDisplayNone
[] =
34 "<head> <style> form {display: none;} </style> </head>"
36 " <form id='testElement'>"
38 " <input type='password' id='password'/>"
43 static const char s_blockWithContent
[] =
44 "<div id='testElement'>"
48 static const char s_blockWithText
[] =
49 "<div id='testElement'>"
53 static const char s_blockWithInlines
[] =
54 "<div id='testElement'>"
55 " <span>Hello</span> "
58 static const char s_blockWithEmptyInlines
[] =
59 "<div id='testElement'>"
63 class WebElementTest
: public testing::Test
{
65 Document
& document() { return m_pageHolder
->document(); }
66 void insertHTML(String html
);
67 WebElement
testElement();
70 void SetUp() override
;
72 OwnPtr
<DummyPageHolder
> m_pageHolder
;
75 void WebElementTest::insertHTML(String html
)
77 document().documentElement()->setInnerHTML(html
, ASSERT_NO_EXCEPTION
);
80 WebElement
WebElementTest::testElement()
82 Element
* element
= document().getElementById("testElement");
84 return WebElement(element
);
87 void WebElementTest::SetUp()
89 m_pageHolder
= DummyPageHolder::create(IntSize(800, 600));
92 TEST_F(WebElementTest
, HasNonEmptyLayoutSize
)
94 insertHTML(s_emptyBlock
);
95 EXPECT_FALSE(testElement().hasNonEmptyLayoutSize());
97 insertHTML(s_emptyInline
);
98 EXPECT_FALSE(testElement().hasNonEmptyLayoutSize());
100 insertHTML(s_blockWithDisplayNone
);
101 EXPECT_FALSE(testElement().hasNonEmptyLayoutSize());
103 insertHTML(s_blockWithEmptyInlines
);
104 EXPECT_FALSE(testElement().hasNonEmptyLayoutSize());
106 insertHTML(s_blockWithContinuations
);
107 EXPECT_TRUE(testElement().hasNonEmptyLayoutSize());
109 insertHTML(s_blockWithInlines
);
110 EXPECT_TRUE(testElement().hasNonEmptyLayoutSize());
112 insertHTML(s_blockWithContent
);
113 EXPECT_TRUE(testElement().hasNonEmptyLayoutSize());
115 insertHTML(s_blockWithText
);
116 EXPECT_TRUE(testElement().hasNonEmptyLayoutSize());
118 insertHTML(s_emptyBlock
);
119 RefPtrWillBeRawPtr
<ShadowRoot
> root
= document().getElementById("testElement")->createShadowRootInternal(ShadowRootType::OpenByDefault
, ASSERT_NO_EXCEPTION
);
120 root
->setInnerHTML("<div>Hello World</div>", ASSERT_NO_EXCEPTION
);
121 EXPECT_TRUE(testElement().hasNonEmptyLayoutSize());
124 TEST_F(WebElementTest
, IsEditable
)
126 insertHTML("<div id=testElement></div>");
127 EXPECT_FALSE(testElement().isEditable());
129 insertHTML("<div id=testElement contenteditable=true></div>");
130 EXPECT_TRUE(testElement().isEditable());
133 "<div style='-webkit-user-modify: read-write'>"
134 " <div id=testElement></div>"
137 EXPECT_TRUE(testElement().isEditable());
140 "<div style='-webkit-user-modify: read-write'>"
141 " <div id=testElement style='-webkit-user-modify: read-only'></div>"
144 EXPECT_FALSE(testElement().isEditable());
146 insertHTML("<input id=testElement>");
147 EXPECT_TRUE(testElement().isEditable());
149 insertHTML("<input id=testElement readonly>");
150 EXPECT_FALSE(testElement().isEditable());
152 insertHTML("<input id=testElement disabled>");
153 EXPECT_FALSE(testElement().isEditable());
155 insertHTML("<fieldset disabled><div><input id=testElement></div></fieldset>");
156 EXPECT_FALSE(testElement().isEditable());