| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/dom/Attr.h" | 5 #include "core/dom/Attr.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 class AttrTest : public ::testing::Test { | 13 class AttrTest : public ::testing::Test { |
| 14 protected: | 14 protected: |
| 15 void SetUp() override; | 15 void SetUp() override; |
| 16 | 16 |
| 17 PassRefPtrWillBeRawPtr<Attr> createAttribute(); | 17 RawPtr<Attr> createAttribute(); |
| 18 const AtomicString& value() const { return m_value; } | 18 const AtomicString& value() const { return m_value; } |
| 19 | 19 |
| 20 private: | 20 private: |
| 21 RefPtrWillBePersistent<Document> m_document; | 21 Persistent<Document> m_document; |
| 22 AtomicString m_value; | 22 AtomicString m_value; |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 void AttrTest::SetUp() | 25 void AttrTest::SetUp() |
| 26 { | 26 { |
| 27 m_document = Document::create(); | 27 m_document = Document::create(); |
| 28 m_value = "value"; | 28 m_value = "value"; |
| 29 } | 29 } |
| 30 | 30 |
| 31 PassRefPtrWillBeRawPtr<Attr> AttrTest::createAttribute() | 31 RawPtr<Attr> AttrTest::createAttribute() |
| 32 { | 32 { |
| 33 return m_document->createAttribute("name", ASSERT_NO_EXCEPTION); | 33 return m_document->createAttribute("name", ASSERT_NO_EXCEPTION); |
| 34 } | 34 } |
| 35 | 35 |
| 36 TEST_F(AttrTest, InitialValueState) | 36 TEST_F(AttrTest, InitialValueState) |
| 37 { | 37 { |
| 38 RefPtrWillBeRawPtr<Attr> attr = createAttribute(); | 38 RawPtr<Attr> attr = createAttribute(); |
| 39 EXPECT_EQ(emptyAtom, attr->value()); | 39 EXPECT_EQ(emptyAtom, attr->value()); |
| 40 EXPECT_EQ(emptyString(), attr->toNode()->nodeValue()); | 40 EXPECT_EQ(emptyString(), attr->toNode()->nodeValue()); |
| 41 EXPECT_EQ(String(), attr->textContent()); | 41 EXPECT_EQ(String(), attr->textContent()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 TEST_F(AttrTest, SetValue) | 44 TEST_F(AttrTest, SetValue) |
| 45 { | 45 { |
| 46 RefPtrWillBeRawPtr<Attr> attr = createAttribute(); | 46 RawPtr<Attr> attr = createAttribute(); |
| 47 attr->setValue(value()); | 47 attr->setValue(value()); |
| 48 EXPECT_EQ(value(), attr->value()); | 48 EXPECT_EQ(value(), attr->value()); |
| 49 EXPECT_EQ(value(), attr->toNode()->nodeValue()); | 49 EXPECT_EQ(value(), attr->toNode()->nodeValue()); |
| 50 // Node::textContent() always returns String() for Attr. | 50 // Node::textContent() always returns String() for Attr. |
| 51 EXPECT_EQ(String(), attr->textContent()); | 51 EXPECT_EQ(String(), attr->textContent()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 TEST_F(AttrTest, SetNodeValue) | 54 TEST_F(AttrTest, SetNodeValue) |
| 55 { | 55 { |
| 56 RefPtrWillBeRawPtr<Attr> attr = createAttribute(); | 56 RawPtr<Attr> attr = createAttribute(); |
| 57 attr->toNode()->setNodeValue(value()); | 57 attr->toNode()->setNodeValue(value()); |
| 58 EXPECT_EQ(value(), attr->value()); | 58 EXPECT_EQ(value(), attr->value()); |
| 59 EXPECT_EQ(value(), attr->toNode()->nodeValue()); | 59 EXPECT_EQ(value(), attr->toNode()->nodeValue()); |
| 60 // Node::textContent() always returns String() for Attr. | 60 // Node::textContent() always returns String() for Attr. |
| 61 EXPECT_EQ(String(), attr->textContent()); | 61 EXPECT_EQ(String(), attr->textContent()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 TEST_F(AttrTest, SetTextContent) | 64 TEST_F(AttrTest, SetTextContent) |
| 65 { | 65 { |
| 66 RefPtrWillBeRawPtr<Attr> attr = createAttribute(); | 66 RawPtr<Attr> attr = createAttribute(); |
| 67 // Node::setTextContent() does nothing for Attr. | 67 // Node::setTextContent() does nothing for Attr. |
| 68 attr->setTextContent(value()); | 68 attr->setTextContent(value()); |
| 69 EXPECT_EQ(emptyAtom, attr->value()); | 69 EXPECT_EQ(emptyAtom, attr->value()); |
| 70 EXPECT_EQ(emptyString(), attr->toNode()->nodeValue()); | 70 EXPECT_EQ(emptyString(), attr->toNode()->nodeValue()); |
| 71 EXPECT_EQ(String(), attr->textContent()); | 71 EXPECT_EQ(String(), attr->textContent()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 TEST_F(AttrTest, LengthOfContents) | 74 TEST_F(AttrTest, LengthOfContents) |
| 75 { | 75 { |
| 76 RefPtrWillBeRawPtr<Attr> attr = createAttribute(); | 76 RawPtr<Attr> attr = createAttribute(); |
| 77 EXPECT_EQ(0u, attr->lengthOfContents()); | 77 EXPECT_EQ(0u, attr->lengthOfContents()); |
| 78 attr->setValue(value()); | 78 attr->setValue(value()); |
| 79 EXPECT_EQ(0u, attr->lengthOfContents()); | 79 EXPECT_EQ(0u, attr->lengthOfContents()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // namespace blink | 82 } // namespace blink |
| OLD | NEW |