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

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 Created 5 years, 5 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/css/CSSValuePool.cpp ('k') | Source/core/css/CSSValueTestHelper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « Source/core/css/CSSValuePool.cpp ('k') | Source/core/css/CSSValueTestHelper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698