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

Side by Side Diff: ui/views/attributes_unittest.cc

Issue 2230913003: Experimental alignment layout manager using a property on the views Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed AlignAttribute and associated types to FillAttribute Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « ui/views/attributes.cc ('k') | ui/views/examples/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/attributes.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 using AttributesTest = testing::Test;
10
11 namespace views {
12
13 namespace {
14
15 class SpecialContent {
16 public:
17 SpecialContent() {}
18 SpecialContent(int data) : attr_data_(data) {}
19 int GetAttrData() { return attr_data_; }
20
21 private:
22 int attr_data_;
23 };
24
25 class OtherContent : public SpecialContent {
26 public:
27 OtherContent() {}
28 OtherContent(int data, double double_data)
29 : SpecialContent(data), double_data_(double_data) {}
30 double GetDoubleData() { return double_data_; }
31
32 private:
33 double double_data_;
34 };
35
36 } // namespace
37
38 using SpecialAttribute = CustomAttribute<SpecialContent>;
39 using OtherAttribute = CustomAttribute<OtherContent, SpecialAttribute>;
40 REGISTER_ATTRIBUTE_ID(SpecialAttribute);
41 REGISTER_ATTRIBUTE_ID(OtherAttribute);
42
43 TEST_F(AttributesTest, InsertTest) {
44 AttributeContainer container(nullptr);
45 EXPECT_TRUE(container.Add(
46 base::WrapUnique(new SpecialAttribute(SpecialContent(10)))));
47 EXPECT_FALSE(container.Add(
48 base::WrapUnique(new SpecialAttribute(SpecialContent(20)))));
49 }
50
51 TEST_F(AttributesTest, RemoveTest) {
52 AttributeContainer container(nullptr);
53 EXPECT_TRUE(container.Add(
54 base::WrapUnique(new SpecialAttribute(SpecialContent(10)))));
55 EXPECT_TRUE(container.Remove(GetAttributeId<SpecialAttribute>()));
56 EXPECT_FALSE(container.Remove(GetAttributeId<SpecialAttribute>()));
57 }
58
59 TEST_F(AttributesTest, FindTest) {
60 AttributeContainer container(nullptr);
61 SpecialAttribute* sa;
62 EXPECT_TRUE(container.Add(
63 base::WrapUnique(new SpecialAttribute(SpecialContent(10)))));
64 EXPECT_TRUE(container.Find(sa));
65 EXPECT_EQ(sa->GetContent().GetAttrData(), 10);
66 EXPECT_TRUE(container.Remove(GetAttributeId<SpecialAttribute>()));
67 EXPECT_FALSE(container.Find(sa));
68 }
69
70 TEST_F(AttributesTest, FindTest2) {
71 AttributeContainer container(nullptr);
72 OtherAttribute* oa;
73 SpecialAttribute* sa;
74 EXPECT_TRUE(container.Add(
75 base::WrapUnique(new OtherAttribute(OtherContent(20, 3.14)))));
76 EXPECT_TRUE(container.Add(
77 base::WrapUnique(new SpecialAttribute(SpecialContent(10)))));
78 EXPECT_TRUE(container.Find(oa));
79 EXPECT_EQ(oa->GetContent().GetDoubleData(), 3.14);
80 EXPECT_EQ(oa->GetContent().GetAttrData(), 20);
81 EXPECT_TRUE(container.Find(sa));
82 EXPECT_EQ(sa->GetContent().GetAttrData(), 10);
83 }
84
85 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/attributes.cc ('k') | ui/views/examples/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698