Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Unified Diff: Source/core/dom/AttrTest.cpp

Issue 1148003007: Never cast Attr to ContainerNode based on nodeType ATTRIBUTE_NODE (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: new deal: setTextContent(attr) does nothing Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/dom/Node.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/AttrTest.cpp
diff --git a/Source/core/dom/AttrTest.cpp b/Source/core/dom/AttrTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..7ae6eabfe8cdbe1ca9a8cee5c76fcd232a97d452
--- /dev/null
+++ b/Source/core/dom/AttrTest.cpp
@@ -0,0 +1,85 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/dom/Attr.h"
+
+#include "core/dom/Document.h"
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+using namespace blink;
+
+namespace {
+
+class AttrTest : public ::testing::Test {
+protected:
+ virtual void SetUp() override;
+
+ PassRefPtrWillBeRawPtr<Attr> createAttribute();
+ const AtomicString& value() const { return m_value; }
+
+private:
+ RefPtrWillBePersistent<Document> m_document;
+ AtomicString m_value;
+};
+
+void AttrTest::SetUp()
+{
+ m_document = Document::create();
+ m_value = "value";
+}
+
+PassRefPtrWillBeRawPtr<Attr> AttrTest::createAttribute()
+{
+ return m_document->createAttribute("name", ASSERT_NO_EXCEPTION);
+}
+
+TEST_F(AttrTest, InitialValueState)
+{
+ RefPtrWillBeRawPtr<Attr> attr = createAttribute();
+ EXPECT_EQ(emptyAtom, attr->value());
+ EXPECT_EQ(emptyString(), attr->toNode()->nodeValue());
+ EXPECT_EQ(String(), attr->textContent());
+}
+
+TEST_F(AttrTest, SetValue)
+{
+ RefPtrWillBeRawPtr<Attr> attr = createAttribute();
+ attr->setValue(value());
+ EXPECT_EQ(value(), attr->value());
+ EXPECT_EQ(value(), attr->toNode()->nodeValue());
+ // Node::textContent() always returns String() for Attr.
+ EXPECT_EQ(String(), attr->textContent());
+}
+
+TEST_F(AttrTest, SetNodeValue)
+{
+ RefPtrWillBeRawPtr<Attr> attr = createAttribute();
+ attr->toNode()->setNodeValue(value());
+ EXPECT_EQ(value(), attr->value());
+ EXPECT_EQ(value(), attr->toNode()->nodeValue());
+ // Node::textContent() always returns String() for Attr.
+ EXPECT_EQ(String(), attr->textContent());
+}
+
+TEST_F(AttrTest, SetTextContent)
+{
+ RefPtrWillBeRawPtr<Attr> attr = createAttribute();
+ // Node::setTextContent() does nothing for Attr.
+ attr->setTextContent(value());
+ EXPECT_EQ(emptyAtom, attr->value());
+ EXPECT_EQ(emptyString(), attr->toNode()->nodeValue());
+ EXPECT_EQ(String(), attr->textContent());
+}
+
+TEST_F(AttrTest, LengthOfContents)
+{
+ RefPtrWillBeRawPtr<Attr> attr = createAttribute();
+ EXPECT_EQ(0u, attr->lengthOfContents());
+ attr->setValue(value());
+ EXPECT_EQ(0u, attr->lengthOfContents());
+}
+
+} // unnamed namespace
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/dom/Node.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698