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.
6 #include "core/dom/Attr.h"
8 #include "core/dom/Document.h"
9 #include <gmock/gmock.h>
10 #include <gtest/gtest.h>
14 class AttrTest
: public ::testing::Test
{
16 void SetUp() override
;
18 PassRefPtrWillBeRawPtr
<Attr
> createAttribute();
19 const AtomicString
& value() const { return m_value
; }
22 RefPtrWillBePersistent
<Document
> m_document
;
26 void AttrTest::SetUp()
28 m_document
= Document::create();
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());