| Index: ui/views/attributes_unittest.cc
|
| diff --git a/ui/views/attributes_unittest.cc b/ui/views/attributes_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..24cd34075ccb47f9c5f8d8f4fc3e2ed696e80b40
|
| --- /dev/null
|
| +++ b/ui/views/attributes_unittest.cc
|
| @@ -0,0 +1,85 @@
|
| +// Copyright (c) 2016 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 "ui/views/attributes.h"
|
| +
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +using AttributesTest = testing::Test;
|
| +
|
| +namespace views {
|
| +
|
| +namespace {
|
| +
|
| +class SpecialContent {
|
| + public:
|
| + SpecialContent() {}
|
| + SpecialContent(int data) : attr_data_(data) {}
|
| + int GetAttrData() { return attr_data_; }
|
| +
|
| + private:
|
| + int attr_data_;
|
| +};
|
| +
|
| +class OtherContent : public SpecialContent {
|
| + public:
|
| + OtherContent() {}
|
| + OtherContent(int data, double double_data)
|
| + : SpecialContent(data), double_data_(double_data) {}
|
| + double GetDoubleData() { return double_data_; }
|
| +
|
| + private:
|
| + double double_data_;
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +using SpecialAttribute = CustomAttribute<SpecialContent>;
|
| +using OtherAttribute = CustomAttribute<OtherContent, SpecialAttribute>;
|
| +REGISTER_ATTRIBUTE_ID(SpecialAttribute);
|
| +REGISTER_ATTRIBUTE_ID(OtherAttribute);
|
| +
|
| +TEST_F(AttributesTest, InsertTest) {
|
| + AttributeContainer container(nullptr);
|
| + EXPECT_TRUE(container.Add(
|
| + base::WrapUnique(new SpecialAttribute(SpecialContent(10)))));
|
| + EXPECT_FALSE(container.Add(
|
| + base::WrapUnique(new SpecialAttribute(SpecialContent(20)))));
|
| +}
|
| +
|
| +TEST_F(AttributesTest, RemoveTest) {
|
| + AttributeContainer container(nullptr);
|
| + EXPECT_TRUE(container.Add(
|
| + base::WrapUnique(new SpecialAttribute(SpecialContent(10)))));
|
| + EXPECT_TRUE(container.Remove(GetAttributeId<SpecialAttribute>()));
|
| + EXPECT_FALSE(container.Remove(GetAttributeId<SpecialAttribute>()));
|
| +}
|
| +
|
| +TEST_F(AttributesTest, FindTest) {
|
| + AttributeContainer container(nullptr);
|
| + SpecialAttribute* sa;
|
| + EXPECT_TRUE(container.Add(
|
| + base::WrapUnique(new SpecialAttribute(SpecialContent(10)))));
|
| + EXPECT_TRUE(container.Find(sa));
|
| + EXPECT_EQ(sa->GetContent().GetAttrData(), 10);
|
| + EXPECT_TRUE(container.Remove(GetAttributeId<SpecialAttribute>()));
|
| + EXPECT_FALSE(container.Find(sa));
|
| +}
|
| +
|
| +TEST_F(AttributesTest, FindTest2) {
|
| + AttributeContainer container(nullptr);
|
| + OtherAttribute* oa;
|
| + SpecialAttribute* sa;
|
| + EXPECT_TRUE(container.Add(
|
| + base::WrapUnique(new OtherAttribute(OtherContent(20, 3.14)))));
|
| + EXPECT_TRUE(container.Add(
|
| + base::WrapUnique(new SpecialAttribute(SpecialContent(10)))));
|
| + EXPECT_TRUE(container.Find(oa));
|
| + EXPECT_EQ(oa->GetContent().GetDoubleData(), 3.14);
|
| + EXPECT_EQ(oa->GetContent().GetAttrData(), 20);
|
| + EXPECT_TRUE(container.Find(sa));
|
| + EXPECT_EQ(sa->GetContent().GetAttrData(), 10);
|
| +}
|
| +
|
| +} // namespace views
|
|
|