Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / core / dom / AttrTest.cpp
blob85fce9aa8e9b074db2136ce6c855178ce8565ba1
1 // Copyright 2015 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 "core/dom/Attr.h"
8 #include "core/dom/Document.h"
9 #include <gmock/gmock.h>
10 #include <gtest/gtest.h>
12 namespace blink {
14 class AttrTest : public ::testing::Test {
15 protected:
16 void SetUp() override;
18 PassRefPtrWillBeRawPtr<Attr> createAttribute();
19 const AtomicString& value() const { return m_value; }
21 private:
22 RefPtrWillBePersistent<Document> m_document;
23 AtomicString m_value;
26 void AttrTest::SetUp()
28 m_document = Document::create();
29 m_value = "value";
32 PassRefPtrWillBeRawPtr<Attr> AttrTest::createAttribute()
34 return m_document->createAttribute("name", ASSERT_NO_EXCEPTION);
37 TEST_F(AttrTest, InitialValueState)
39 RefPtrWillBeRawPtr<Attr> attr = createAttribute();
40 EXPECT_EQ(emptyAtom, attr->value());
41 EXPECT_EQ(emptyString(), attr->toNode()->nodeValue());
42 EXPECT_EQ(String(), attr->textContent());
45 TEST_F(AttrTest, SetValue)
47 RefPtrWillBeRawPtr<Attr> attr = createAttribute();
48 attr->setValue(value());
49 EXPECT_EQ(value(), attr->value());
50 EXPECT_EQ(value(), attr->toNode()->nodeValue());
51 // Node::textContent() always returns String() for Attr.
52 EXPECT_EQ(String(), attr->textContent());
55 TEST_F(AttrTest, SetNodeValue)
57 RefPtrWillBeRawPtr<Attr> attr = createAttribute();
58 attr->toNode()->setNodeValue(value());
59 EXPECT_EQ(value(), attr->value());
60 EXPECT_EQ(value(), attr->toNode()->nodeValue());
61 // Node::textContent() always returns String() for Attr.
62 EXPECT_EQ(String(), attr->textContent());
65 TEST_F(AttrTest, SetTextContent)
67 RefPtrWillBeRawPtr<Attr> attr = createAttribute();
68 // Node::setTextContent() does nothing for Attr.
69 attr->setTextContent(value());
70 EXPECT_EQ(emptyAtom, attr->value());
71 EXPECT_EQ(emptyString(), attr->toNode()->nodeValue());
72 EXPECT_EQ(String(), attr->textContent());
75 TEST_F(AttrTest, LengthOfContents)
77 RefPtrWillBeRawPtr<Attr> attr = createAttribute();
78 EXPECT_EQ(0u, attr->lengthOfContents());
79 attr->setValue(value());
80 EXPECT_EQ(0u, attr->lengthOfContents());
83 } // namespace blink