Index: Source/core/css/CSSValueTest.cpp |
diff --git a/Source/core/css/CSSValueTest.cpp b/Source/core/css/CSSValueTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..78d2205e932d4e793d5d3e24310f5cad1baf18d4 |
--- /dev/null |
+++ b/Source/core/css/CSSValueTest.cpp |
@@ -0,0 +1,94 @@ |
+// 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/css/CSSValue.h" |
+ |
+#include "core/css/CSSPrimitiveValue.h" |
+#include "core/css/CSSValueTestHelper.h" |
+#include <gtest/gtest.h> |
+ |
+using namespace blink; |
+ |
+namespace { |
+ |
+// Helper functions since PassRefPtrWillBeRawPtr cannot be a member variable. |
+CSSValue makeCSSValueWithPassRefPtr(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValue) |
+{ |
+ return CSSValue(primitiveValue); |
+} |
+NullableCSSValue makeNullableCSSValueWithPassRefPtr(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValue) |
+{ |
+ return NullableCSSValue(primitiveValue); |
+} |
+ |
+TEST(CSSValueTest, CSSValueTest) |
+{ |
+ RefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValueRef = CSSPrimitiveValue::createIdentifier(CSSValueBold); |
+ |
+ CSSValue passRefPtrConstructor = makeCSSValueWithPassRefPtr(CSSPrimitiveValue::createIdentifier(CSSValueBold)); |
+ EXPECT_STREQ("bold", passRefPtrConstructor.cssText().utf8().data()); |
+ |
+ CSSValue refPtrConstructor(primitiveValueRef); |
+ EXPECT_STREQ("bold", refPtrConstructor.cssText().utf8().data()); |
+ |
+ CSSValue copyConstructor(refPtrConstructor); |
+ EXPECT_STREQ("bold", copyConstructor.cssText().utf8().data()); |
+ |
+ CSSValue constCopyConstructor(*const_cast<const CSSValue*>(&refPtrConstructor)); |
+ EXPECT_STREQ("bold", constCopyConstructor.cssText().utf8().data()); |
+ |
+ CSSValue newAssignmentOperator = refPtrConstructor; |
+ EXPECT_STREQ("bold", newAssignmentOperator.cssText().utf8().data()); |
+ EXPECT_STREQ("bold", refPtrConstructor.cssText().utf8().data()); |
+ |
+ CSSValue existingAssignmentOperator(primitiveValueRef); |
+ existingAssignmentOperator = passRefPtrConstructor; |
+ EXPECT_STREQ("bold", existingAssignmentOperator.cssText().utf8().data()); |
+ EXPECT_STREQ("bold", refPtrConstructor.cssText().utf8().data()); |
+ |
+ CSSValue selfAssignmentOperator(primitiveValueRef); |
+ selfAssignmentOperator = refPtrConstructor; |
+ EXPECT_STREQ("bold", selfAssignmentOperator.cssText().utf8().data()); |
+ EXPECT_STREQ("bold", refPtrConstructor.cssText().utf8().data()); |
+} |
+ |
+TEST(CSSValueTest, NullableCSSValueTest) |
+{ |
+ RefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValueRef = CSSPrimitiveValue::createIdentifier(CSSValueBold); |
+ |
+ NullableCSSValue defaultConstructor; |
+ EXPECT_FALSE(defaultConstructor); |
+ |
+ NullableCSSValue nullPtrConstructor(nullptr); |
+ EXPECT_FALSE(nullPtrConstructor); |
+ |
+ NullableCSSValue passRefPtrConstructor = makeNullableCSSValueWithPassRefPtr(CSSPrimitiveValue::createIdentifier(CSSValueBold)); |
+ EXPECT_STREQ("bold", passRefPtrConstructor->cssText().utf8().data()); |
+ |
+ NullableCSSValue refPtrConstructor(primitiveValueRef); |
+ EXPECT_STREQ("bold", refPtrConstructor->cssText().utf8().data()); |
+ |
+ NullableCSSValue copyConstructor(refPtrConstructor); |
+ EXPECT_STREQ("bold", copyConstructor->cssText().utf8().data()); |
+ |
+ NullableCSSValue constCopyConstructor(*const_cast<const NullableCSSValue*>(&refPtrConstructor)); |
+ EXPECT_STREQ("bold", constCopyConstructor->cssText().utf8().data()); |
+ |
+ NullableCSSValue nullCopyConstructor(nullPtrConstructor); |
+ EXPECT_FALSE(nullCopyConstructor); |
+ |
+ NullableCSSValue nullConstCopyConstructor(*const_cast<const NullableCSSValue*>(&nullPtrConstructor)); |
+ EXPECT_FALSE(nullConstCopyConstructor); |
+ |
+ CSSValue cssValue(primitiveValueRef); |
+ NullableCSSValue cssValueCopyConstructor(cssValue); |
+ EXPECT_STREQ("bold", cssValueCopyConstructor->cssText().utf8().data()); |
+ |
+ const CSSValue constCssValue(primitiveValueRef); |
+ NullableCSSValue constCssValueCopyConstructor(constCssValue); |
+ EXPECT_STREQ("bold", constCssValueCopyConstructor->cssText().utf8().data()); |
+} |
+ |
+} // namespace |