Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / web / WebElementTest.cpp
blobea3542ddede3a647f361c5d05e471b80570fe4b0
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.
5 #include "config.h"
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>
14 namespace blink {
16 static const char s_blockWithContinuations[] =
17 "<head> <style> form {display: inline;} </style> </head>"
18 "<body>"
19 " <form>"
20 " <div id='testElement'>"
21 " <input type='password' id='password'/>"
22 " </div>"
23 " </form>"
24 "</body>";
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>"
35 "<body>"
36 " <form id='testElement'>"
37 " <div>"
38 " <input type='password' id='password'/>"
39 " </div>"
40 " </form>"
41 "</body>";
43 static const char s_blockWithContent[] =
44 "<div id='testElement'>"
45 " <div>Hello</div> "
46 "</div>";
48 static const char s_blockWithText[] =
49 "<div id='testElement'>"
50 " <div>Hello</div> "
51 "</div>";
53 static const char s_blockWithInlines[] =
54 "<div id='testElement'>"
55 " <span>Hello</span> "
56 "</div>";
58 static const char s_blockWithEmptyInlines[] =
59 "<div id='testElement'>"
60 " <span></span> "
61 "</div>";
63 class WebElementTest : public testing::Test {
64 protected:
65 Document& document() { return m_pageHolder->document(); }
66 void insertHTML(String html);
67 WebElement testElement();
69 private:
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");
83 ASSERT(element);
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());
132 insertHTML(
133 "<div style='-webkit-user-modify: read-write'>"
134 " <div id=testElement></div>"
135 "</div>"
137 EXPECT_TRUE(testElement().isEditable());
139 insertHTML(
140 "<div style='-webkit-user-modify: read-write'>"
141 " <div id=testElement style='-webkit-user-modify: read-only'></div>"
142 "</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());
159 } // namespace blink