Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / web / WebNodeTest.cpp
blob32288caca2cb2db468fcf9cd06c3a50d4e3a4b54
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/WebNode.h"
8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h"
10 #include "core/testing/DummyPageHolder.h"
11 #include "public/web/WebElement.h"
12 #include "public/web/WebElementCollection.h"
13 #include <gtest/gtest.h>
15 namespace blink {
17 class WebNodeTest : public testing::Test {
18 protected:
19 Document& document()
21 return m_pageHolder->document();
24 void setInnerHTML(const String& html)
26 document().documentElement()->setInnerHTML(html, ASSERT_NO_EXCEPTION);
29 WebNode root()
31 return WebNode(document().documentElement());
34 private:
35 void SetUp() override;
37 OwnPtr<DummyPageHolder> m_pageHolder;
40 void WebNodeTest::SetUp()
42 m_pageHolder = DummyPageHolder::create(IntSize(800, 600));
45 TEST_F(WebNodeTest, QuerySelectorMatches)
47 setInnerHTML("<div id=x><span class=a></span></div>");
48 WebExceptionCode ec;
49 WebElement element = root().querySelector(".a", ec);
50 EXPECT_EQ(0, ec);
51 EXPECT_FALSE(element.isNull());
52 EXPECT_TRUE(element.hasHTMLTagName("span"));
55 TEST_F(WebNodeTest, QuerySelectorDoesNotMatch)
57 setInnerHTML("<div id=x><span class=a></span></div>");
58 WebExceptionCode ec;
59 WebElement element = root().querySelector("section", ec);
60 EXPECT_EQ(0, ec);
61 EXPECT_TRUE(element.isNull());
64 TEST_F(WebNodeTest, QuerySelectorError)
66 setInnerHTML("<div></div>");
67 WebExceptionCode ec;
68 WebElement element = root().querySelector("@invalid-selector", ec);
69 EXPECT_NE(0, ec);
70 EXPECT_TRUE(element.isNull());
73 TEST_F(WebNodeTest, QuerySelectorAllMatches)
75 setInnerHTML("<div id=x><span class=a></span></div>");
76 WebExceptionCode ec;
77 WebVector<WebElement> results;
78 root().querySelectorAll(".a, #x", results, ec);
79 EXPECT_EQ(0, ec);
80 EXPECT_EQ(2u, results.size());
81 EXPECT_TRUE(results[0].hasHTMLTagName("div"));
82 EXPECT_TRUE(results[1].hasHTMLTagName("span"));
85 TEST_F(WebNodeTest, QuerySelectorAllDoesNotMatch)
87 setInnerHTML("<div id=x><span class=a></span></div>");
88 WebExceptionCode ec;
89 WebVector<WebElement> results;
90 root().querySelectorAll(".bar, #foo", results, ec);
91 EXPECT_EQ(0, ec);
92 EXPECT_TRUE(results.isEmpty());
95 TEST_F(WebNodeTest, QuerySelectorAllError)
97 setInnerHTML("<div></div>");
98 WebExceptionCode ec;
99 WebVector<WebElement> results;
100 root().querySelectorAll("@invalid-selector", results, ec);
101 EXPECT_NE(0, ec);
102 EXPECT_TRUE(results.isEmpty());
105 TEST_F(WebNodeTest, GetElementsByHTMLTagName)
107 setInnerHTML("<body><LABEL></LABEL><svg xmlns='http://www.w3.org/2000/svg'><label></label></svg></body>");
108 // WebNode::getElementsByHTMLTagName returns only HTML elements.
109 WebElementCollection collection = root().getElementsByHTMLTagName("label");
110 EXPECT_EQ(1u, collection.length());
111 EXPECT_TRUE(collection.firstItem().hasHTMLTagName("label"));
112 // The argument should be lower-case.
113 collection = root().getElementsByHTMLTagName("LABEL");
114 EXPECT_EQ(0u, collection.length());
117 } // namespace blink