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

Side by Side Diff: chrome/browser/extensions/api/declarative/deduping_factory_unittest.cc

Issue 16295003: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/declarative/deduping_factory.h" 5 #include "chrome/browser/extensions/api/declarative/deduping_factory.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace { 10 namespace {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 scoped_ptr<base::DictionaryValue> d4(CreateDictWithParameter(4)); 91 scoped_ptr<base::DictionaryValue> d4(CreateDictWithParameter(4));
92 92
93 std::string error; 93 std::string error;
94 bool bad_message = false; 94 bool bad_message = false;
95 95
96 // Fill factory with 2 different types. 96 // Fill factory with 2 different types.
97 scoped_refptr<const BaseClass> c1( 97 scoped_refptr<const BaseClass> c1(
98 factory.Instantiate(kTypeName, d1.get(), &error, &bad_message)); 98 factory.Instantiate(kTypeName, d1.get(), &error, &bad_message));
99 scoped_refptr<const BaseClass> c2( 99 scoped_refptr<const BaseClass> c2(
100 factory.Instantiate(kTypeName, d2.get(), &error, &bad_message)); 100 factory.Instantiate(kTypeName, d2.get(), &error, &bad_message));
101 ASSERT_TRUE(c1); 101 ASSERT_TRUE(c1.get());
102 ASSERT_TRUE(c2); 102 ASSERT_TRUE(c2.get());
103 EXPECT_EQ(1, static_cast<const Foo*>(c1.get())->parameter()); 103 EXPECT_EQ(1, static_cast<const Foo*>(c1.get())->parameter());
104 EXPECT_EQ(2, static_cast<const Foo*>(c2.get())->parameter()); 104 EXPECT_EQ(2, static_cast<const Foo*>(c2.get())->parameter());
105 105
106 // This one produces an overflow, now the cache contains [2, 3] 106 // This one produces an overflow, now the cache contains [2, 3]
107 scoped_refptr<const BaseClass> c3( 107 scoped_refptr<const BaseClass> c3(
108 factory.Instantiate(kTypeName, d3.get(), &error, &bad_message)); 108 factory.Instantiate(kTypeName, d3.get(), &error, &bad_message));
109 ASSERT_TRUE(c3); 109 ASSERT_TRUE(c3.get());
110 EXPECT_EQ(3, static_cast<const Foo*>(c3.get())->parameter()); 110 EXPECT_EQ(3, static_cast<const Foo*>(c3.get())->parameter());
111 111
112 // Reuse 2, this should give the same instance as c2. 112 // Reuse 2, this should give the same instance as c2.
113 scoped_refptr<const BaseClass> c2_b( 113 scoped_refptr<const BaseClass> c2_b(
114 factory.Instantiate(kTypeName, d2.get(), &error, &bad_message)); 114 factory.Instantiate(kTypeName, d2.get(), &error, &bad_message));
115 EXPECT_EQ(2, static_cast<const Foo*>(c2_b.get())->parameter()); 115 EXPECT_EQ(2, static_cast<const Foo*>(c2_b.get())->parameter());
116 EXPECT_EQ(c2, c2_b); 116 EXPECT_EQ(c2, c2_b);
117 117
118 // Also check that the reuse of 2 moved it to the end, so that the cache is 118 // Also check that the reuse of 2 moved it to the end, so that the cache is
119 // now [3, 2] and 3 is discarded before 2. 119 // now [3, 2] and 3 is discarded before 2.
(...skipping 17 matching lines...) Expand all
137 137
138 std::string error; 138 std::string error;
139 bool bad_message = false; 139 bool bad_message = false;
140 140
141 // We create two instances with different dictionaries but because the type is 141 // We create two instances with different dictionaries but because the type is
142 // declared to be not parameterized, we should get the same instance. 142 // declared to be not parameterized, we should get the same instance.
143 scoped_refptr<const BaseClass> c1( 143 scoped_refptr<const BaseClass> c1(
144 factory.Instantiate(kTypeName, d1.get(), &error, &bad_message)); 144 factory.Instantiate(kTypeName, d1.get(), &error, &bad_message));
145 scoped_refptr<const BaseClass> c2( 145 scoped_refptr<const BaseClass> c2(
146 factory.Instantiate(kTypeName, d2.get(), &error, &bad_message)); 146 factory.Instantiate(kTypeName, d2.get(), &error, &bad_message));
147 ASSERT_TRUE(c1); 147 ASSERT_TRUE(c1.get());
148 ASSERT_TRUE(c2); 148 ASSERT_TRUE(c2.get());
149 EXPECT_EQ(1, static_cast<const Foo*>(c1.get())->parameter()); 149 EXPECT_EQ(1, static_cast<const Foo*>(c1.get())->parameter());
150 EXPECT_EQ(1, static_cast<const Foo*>(c2.get())->parameter()); 150 EXPECT_EQ(1, static_cast<const Foo*>(c2.get())->parameter());
151 EXPECT_EQ(c1, c2); 151 EXPECT_EQ(c1, c2);
152 } 152 }
153 153
154 TEST(DedupingFactoryTest, TypeNames) { 154 TEST(DedupingFactoryTest, TypeNames) {
155 DedupingFactory<BaseClass> factory(2); 155 DedupingFactory<BaseClass> factory(2);
156 factory.RegisterFactoryMethod( 156 factory.RegisterFactoryMethod(
157 kTypeName, DedupingFactory<BaseClass>::IS_PARAMETERIZED, &CreateFoo); 157 kTypeName, DedupingFactory<BaseClass>::IS_PARAMETERIZED, &CreateFoo);
158 factory.RegisterFactoryMethod( 158 factory.RegisterFactoryMethod(
159 kTypeName2, DedupingFactory<BaseClass>::IS_PARAMETERIZED, &CreateFoo); 159 kTypeName2, DedupingFactory<BaseClass>::IS_PARAMETERIZED, &CreateFoo);
160 160
161 scoped_ptr<base::DictionaryValue> d1(CreateDictWithParameter(1)); 161 scoped_ptr<base::DictionaryValue> d1(CreateDictWithParameter(1));
162 162
163 std::string error; 163 std::string error;
164 bool bad_message = false; 164 bool bad_message = false;
165 165
166 scoped_refptr<const BaseClass> c1_a( 166 scoped_refptr<const BaseClass> c1_a(
167 factory.Instantiate(kTypeName, d1.get(), &error, &bad_message)); 167 factory.Instantiate(kTypeName, d1.get(), &error, &bad_message));
168 scoped_refptr<const BaseClass> c1_b( 168 scoped_refptr<const BaseClass> c1_b(
169 factory.Instantiate(kTypeName2, d1.get(), &error, &bad_message)); 169 factory.Instantiate(kTypeName2, d1.get(), &error, &bad_message));
170 170
171 ASSERT_TRUE(c1_a); 171 ASSERT_TRUE(c1_a.get());
172 ASSERT_TRUE(c1_b); 172 ASSERT_TRUE(c1_b.get());
173 EXPECT_NE(c1_a, c1_b); 173 EXPECT_NE(c1_a, c1_b);
174 } 174 }
175 175
176 TEST(DedupingFactoryTest, Clear) { 176 TEST(DedupingFactoryTest, Clear) {
177 DedupingFactory<BaseClass> factory(2); 177 DedupingFactory<BaseClass> factory(2);
178 factory.RegisterFactoryMethod( 178 factory.RegisterFactoryMethod(
179 kTypeName, DedupingFactory<BaseClass>::IS_PARAMETERIZED, &CreateFoo); 179 kTypeName, DedupingFactory<BaseClass>::IS_PARAMETERIZED, &CreateFoo);
180 180
181 scoped_ptr<base::DictionaryValue> d1(CreateDictWithParameter(1)); 181 scoped_ptr<base::DictionaryValue> d1(CreateDictWithParameter(1));
182 182
183 std::string error; 183 std::string error;
184 bool bad_message = false; 184 bool bad_message = false;
185 185
186 scoped_refptr<const BaseClass> c1_a( 186 scoped_refptr<const BaseClass> c1_a(
187 factory.Instantiate(kTypeName, d1.get(), &error, &bad_message)); 187 factory.Instantiate(kTypeName, d1.get(), &error, &bad_message));
188 188
189 factory.ClearPrototypes(); 189 factory.ClearPrototypes();
190 190
191 scoped_refptr<const BaseClass> c1_b( 191 scoped_refptr<const BaseClass> c1_b(
192 factory.Instantiate(kTypeName, d1.get(), &error, &bad_message)); 192 factory.Instantiate(kTypeName, d1.get(), &error, &bad_message));
193 193
194 ASSERT_TRUE(c1_a); 194 ASSERT_TRUE(c1_a.get());
195 ASSERT_TRUE(c1_b); 195 ASSERT_TRUE(c1_b.get());
196 EXPECT_NE(c1_a, c1_b); 196 EXPECT_NE(c1_a, c1_b);
197 } 197 }
198 198
199 } // namespace extensions 199 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698