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

Unified Diff: Source/core/css/CSSValueTest.cpp

Issue 1164573002: CSSValue Immediates: Change CSSValue to an object instead of a pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase and oilpan feedback Created 5 years, 6 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
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..43e4ab184cc4ed196b2188fe3a123de86d77de0e
--- /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_EQ(false, (bool)defaultConstructor);
+
+ NullableCSSValue nullPtrConstructor(nullptr);
+ EXPECT_EQ(false, (bool)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_EQ(false, (bool)nullCopyConstructor);
+
+ NullableCSSValue nullConstCopyConstructor(*const_cast<const NullableCSSValue*>(&nullPtrConstructor));
+ EXPECT_EQ(false, (bool)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

Powered by Google App Engine
This is Rietveld 408576698