OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/dom/Attr.h" |
| 7 |
| 8 #include "core/dom/Document.h" |
| 9 #include <gmock/gmock.h> |
| 10 #include <gtest/gtest.h> |
| 11 |
| 12 using namespace blink; |
| 13 |
| 14 namespace { |
| 15 |
| 16 class AttrTest : public ::testing::Test { |
| 17 protected: |
| 18 virtual void SetUp() override; |
| 19 |
| 20 PassRefPtrWillBeRawPtr<Attr> createAttribute(); |
| 21 const AtomicString& value() const { return m_value; } |
| 22 |
| 23 private: |
| 24 RefPtrWillBePersistent<Document> m_document; |
| 25 AtomicString m_value; |
| 26 }; |
| 27 |
| 28 void AttrTest::SetUp() |
| 29 { |
| 30 m_document = Document::create(); |
| 31 m_value = "value"; |
| 32 } |
| 33 |
| 34 PassRefPtrWillBeRawPtr<Attr> AttrTest::createAttribute() |
| 35 { |
| 36 return m_document->createAttribute("name", ASSERT_NO_EXCEPTION); |
| 37 } |
| 38 |
| 39 TEST_F(AttrTest, InitialValueState) |
| 40 { |
| 41 RefPtrWillBeRawPtr<Attr> attr = createAttribute(); |
| 42 EXPECT_EQ(emptyAtom, attr->value()); |
| 43 EXPECT_EQ(emptyString(), attr->toNode()->nodeValue()); |
| 44 EXPECT_EQ(String(), attr->textContent()); |
| 45 } |
| 46 |
| 47 TEST_F(AttrTest, SetValue) |
| 48 { |
| 49 RefPtrWillBeRawPtr<Attr> attr = createAttribute(); |
| 50 attr->setValue(value()); |
| 51 EXPECT_EQ(value(), attr->value()); |
| 52 EXPECT_EQ(value(), attr->toNode()->nodeValue()); |
| 53 // Node::textContent() always returns String() for Attr. |
| 54 EXPECT_EQ(String(), attr->textContent()); |
| 55 } |
| 56 |
| 57 TEST_F(AttrTest, SetNodeValue) |
| 58 { |
| 59 RefPtrWillBeRawPtr<Attr> attr = createAttribute(); |
| 60 attr->toNode()->setNodeValue(value()); |
| 61 EXPECT_EQ(value(), attr->value()); |
| 62 EXPECT_EQ(value(), attr->toNode()->nodeValue()); |
| 63 // Node::textContent() always returns String() for Attr. |
| 64 EXPECT_EQ(String(), attr->textContent()); |
| 65 } |
| 66 |
| 67 TEST_F(AttrTest, SetTextContent) |
| 68 { |
| 69 RefPtrWillBeRawPtr<Attr> attr = createAttribute(); |
| 70 // Node::setTextContent() does nothing for Attr. |
| 71 attr->setTextContent(value()); |
| 72 EXPECT_EQ(emptyAtom, attr->value()); |
| 73 EXPECT_EQ(emptyString(), attr->toNode()->nodeValue()); |
| 74 EXPECT_EQ(String(), attr->textContent()); |
| 75 } |
| 76 |
| 77 TEST_F(AttrTest, LengthOfContents) |
| 78 { |
| 79 RefPtrWillBeRawPtr<Attr> attr = createAttribute(); |
| 80 EXPECT_EQ(0u, attr->lengthOfContents()); |
| 81 attr->setValue(value()); |
| 82 EXPECT_EQ(0u, attr->lengthOfContents()); |
| 83 } |
| 84 |
| 85 } // unnamed namespace |
OLD | NEW |