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

Side by Side Diff: cc/scheduler/begin_frame_source_unittest.cc

Issue 1136123009: Remove "mixin" from BeginFrameSource/Observer base classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated comments 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 unified diff | Download patch
« no previous file with comments | « cc/scheduler/begin_frame_source.cc ('k') | cc/scheduler/scheduler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 <deque> 5 #include <deque>
6 #include <string> 6 #include <string>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/gtest_prod_util.h" 9 #include "base/gtest_prod_util.h"
10 #include "base/test/test_simple_task_runner.h" 10 #include "base/test/test_simple_task_runner.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 #ifdef NDEBUG 163 #ifdef NDEBUG
164 nullptr, 164 nullptr,
165 #else 165 #else
166 FROM_HERE_WITH_EXPLICIT_FUNCTION( 166 FROM_HERE_WITH_EXPLICIT_FUNCTION(
167 "MockBeginFrameObserver::kDefaultBeginFrameArgs"), 167 "MockBeginFrameObserver::kDefaultBeginFrameArgs"),
168 #endif 168 #endif
169 -1, 169 -1,
170 -1, 170 -1,
171 -1); 171 -1);
172 172
173 // BeginFrameObserverMixIn testing --------------------------------------- 173 // BeginFrameObserverBase testing ---------------------------------------
174 class MockMinimalBeginFrameObserverMixIn : public BeginFrameObserverMixIn { 174 class MockMinimalBeginFrameObserverBase : public BeginFrameObserverBase {
175 public: 175 public:
176 MOCK_METHOD1(OnBeginFrameMixInDelegate, bool(const BeginFrameArgs&)); 176 MOCK_METHOD1(OnBeginFrameDerivedImpl, bool(const BeginFrameArgs&));
177 int64_t dropped_begin_frame_args() const { return dropped_begin_frame_args_; } 177 int64_t dropped_begin_frame_args() const { return dropped_begin_frame_args_; }
178 }; 178 };
179 179
180 TEST(BeginFrameObserverMixInTest, OnBeginFrameImplementation) { 180 TEST(BeginFrameObserverBaseTest, OnBeginFrameImplementation) {
181 using ::testing::Return; 181 using ::testing::Return;
182 MockMinimalBeginFrameObserverMixIn obs; 182 MockMinimalBeginFrameObserverBase obs;
183 ::testing::InSequence ordered; // These calls should be ordered 183 ::testing::InSequence ordered; // These calls should be ordered
184 184
185 // Initial conditions 185 // Initial conditions
186 EXPECT_EQ(BeginFrameArgs(), obs.LastUsedBeginFrameArgs()); 186 EXPECT_EQ(BeginFrameArgs(), obs.LastUsedBeginFrameArgs());
187 EXPECT_EQ(0, obs.dropped_begin_frame_args()); 187 EXPECT_EQ(0, obs.dropped_begin_frame_args());
188 188
189 #ifndef NDEBUG 189 #ifndef NDEBUG
190 EXPECT_DEATH({ obs.OnBeginFrame(BeginFrameArgs()); }, ""); 190 EXPECT_DEATH({ obs.OnBeginFrame(BeginFrameArgs()); }, "");
191 #endif 191 #endif
192 192
193 BeginFrameArgs args1 = 193 BeginFrameArgs args1 =
194 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 100, 200, 300); 194 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 100, 200, 300);
195 EXPECT_CALL(obs, OnBeginFrameMixInDelegate(args1)).WillOnce(Return(true)); 195 EXPECT_CALL(obs, OnBeginFrameDerivedImpl(args1)).WillOnce(Return(true));
196 obs.OnBeginFrame(args1); 196 obs.OnBeginFrame(args1);
197 EXPECT_EQ(args1, obs.LastUsedBeginFrameArgs()); 197 EXPECT_EQ(args1, obs.LastUsedBeginFrameArgs());
198 EXPECT_EQ(0, obs.dropped_begin_frame_args()); 198 EXPECT_EQ(0, obs.dropped_begin_frame_args());
199 199
200 #ifndef NDEBUG 200 #ifndef NDEBUG
201 EXPECT_DEATH({ 201 EXPECT_DEATH({
202 obs.OnBeginFrame(CreateBeginFrameArgsForTesting( 202 obs.OnBeginFrame(CreateBeginFrameArgsForTesting(
203 BEGINFRAME_FROM_HERE, 50, 200, 300)); 203 BEGINFRAME_FROM_HERE, 50, 200, 300));
204 }, 204 },
205 ""); 205 "");
206 #endif 206 #endif
207 207
208 // Returning false shouldn't update the LastUsedBeginFrameArgs value. 208 // Returning false shouldn't update the LastUsedBeginFrameArgs value.
209 BeginFrameArgs args2 = 209 BeginFrameArgs args2 =
210 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 200, 300, 400); 210 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 200, 300, 400);
211 EXPECT_CALL(obs, OnBeginFrameMixInDelegate(args2)).WillOnce(Return(false)); 211 EXPECT_CALL(obs, OnBeginFrameDerivedImpl(args2)).WillOnce(Return(false));
212 obs.OnBeginFrame(args2); 212 obs.OnBeginFrame(args2);
213 EXPECT_EQ(args1, obs.LastUsedBeginFrameArgs()); 213 EXPECT_EQ(args1, obs.LastUsedBeginFrameArgs());
214 EXPECT_EQ(1, obs.dropped_begin_frame_args()); 214 EXPECT_EQ(1, obs.dropped_begin_frame_args());
215 215
216 BeginFrameArgs args3 = 216 BeginFrameArgs args3 =
217 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 150, 300, 400); 217 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 150, 300, 400);
218 EXPECT_CALL(obs, OnBeginFrameMixInDelegate(args3)).WillOnce(Return(true)); 218 EXPECT_CALL(obs, OnBeginFrameDerivedImpl(args3)).WillOnce(Return(true));
219 obs.OnBeginFrame(args3); 219 obs.OnBeginFrame(args3);
220 EXPECT_EQ(args3, obs.LastUsedBeginFrameArgs()); 220 EXPECT_EQ(args3, obs.LastUsedBeginFrameArgs());
221 EXPECT_EQ(1, obs.dropped_begin_frame_args()); 221 EXPECT_EQ(1, obs.dropped_begin_frame_args());
222 } 222 }
223 223
224 // BeginFrameSource testing ---------------------------------------------- 224 // BeginFrameSource testing ----------------------------------------------
225 TEST(BeginFrameSourceMixInTest, ObserverManipulation) { 225 TEST(BeginFrameSourceBaseTest, ObserverManipulation) {
226 MockBeginFrameObserver obs; 226 MockBeginFrameObserver obs;
227 MockBeginFrameObserver otherObs; 227 MockBeginFrameObserver otherObs;
228 FakeBeginFrameSource source; 228 FakeBeginFrameSource source;
229 229
230 source.AddObserver(&obs); 230 source.AddObserver(&obs);
231 EXPECT_EQ(&obs, source.GetObserver()); 231 EXPECT_EQ(&obs, source.GetObserver());
232 232
233 #ifndef NDEBUG 233 #ifndef NDEBUG
234 // Adding an observer when an observer already exists should DCHECK fail. 234 // Adding an observer when an observer already exists should DCHECK fail.
235 EXPECT_DEATH({ source.AddObserver(&otherObs); }, ""); 235 EXPECT_DEATH({ source.AddObserver(&otherObs); }, "");
236 236
237 // Removing wrong observer should DCHECK fail. 237 // Removing wrong observer should DCHECK fail.
238 EXPECT_DEATH({ source.RemoveObserver(&otherObs); }, ""); 238 EXPECT_DEATH({ source.RemoveObserver(&otherObs); }, "");
239 239
240 // Removing an observer when there is no observer should DCHECK fail. 240 // Removing an observer when there is no observer should DCHECK fail.
241 EXPECT_DEATH({ 241 EXPECT_DEATH({
242 source.RemoveObserver(&obs); 242 source.RemoveObserver(&obs);
243 source.RemoveObserver(&obs); 243 source.RemoveObserver(&obs);
244 }, 244 },
245 ""); 245 "");
246 #endif 246 #endif
247 source.RemoveObserver(&obs); 247 source.RemoveObserver(&obs);
248 248
249 source.AddObserver(&otherObs); 249 source.AddObserver(&otherObs);
250 EXPECT_EQ(&otherObs, source.GetObserver()); 250 EXPECT_EQ(&otherObs, source.GetObserver());
251 source.RemoveObserver(&otherObs); 251 source.RemoveObserver(&otherObs);
252 } 252 }
253 253
254 TEST(BeginFrameSourceMixInTest, Observer) { 254 TEST(BeginFrameSourceBaseTest, Observer) {
255 FakeBeginFrameSource source; 255 FakeBeginFrameSource source;
256 MockBeginFrameObserver obs; 256 MockBeginFrameObserver obs;
257 source.AddObserver(&obs); 257 source.AddObserver(&obs);
258 EXPECT_BEGIN_FRAME_USED(obs, 100, 200, 300); 258 EXPECT_BEGIN_FRAME_USED(obs, 100, 200, 300);
259 EXPECT_BEGIN_FRAME_DROP(obs, 400, 600, 300); 259 EXPECT_BEGIN_FRAME_DROP(obs, 400, 600, 300);
260 EXPECT_BEGIN_FRAME_DROP(obs, 450, 650, 300); 260 EXPECT_BEGIN_FRAME_DROP(obs, 450, 650, 300);
261 EXPECT_BEGIN_FRAME_USED(obs, 700, 900, 300); 261 EXPECT_BEGIN_FRAME_USED(obs, 700, 900, 300);
262 262
263 SEND_BEGIN_FRAME_USED(source, 100, 200, 300); 263 SEND_BEGIN_FRAME_USED(source, 100, 200, 300);
264 SEND_BEGIN_FRAME_DROP(source, 400, 600, 300); 264 SEND_BEGIN_FRAME_DROP(source, 400, 600, 300);
265 SEND_BEGIN_FRAME_DROP(source, 450, 650, 300); 265 SEND_BEGIN_FRAME_DROP(source, 450, 650, 300);
266 SEND_BEGIN_FRAME_USED(source, 700, 900, 300); 266 SEND_BEGIN_FRAME_USED(source, 700, 900, 300);
267 } 267 }
268 268
269 TEST(BeginFrameSourceMixInTest, NoObserver) { 269 TEST(BeginFrameSourceBaseTest, NoObserver) {
270 FakeBeginFrameSource source; 270 FakeBeginFrameSource source;
271 SEND_BEGIN_FRAME_DROP(source, 100, 200, 300); 271 SEND_BEGIN_FRAME_DROP(source, 100, 200, 300);
272 } 272 }
273 273
274 TEST(BeginFrameSourceMixInTest, NeedsBeginFrames) { 274 TEST(BeginFrameSourceBaseTest, NeedsBeginFrames) {
275 FakeBeginFrameSource source; 275 FakeBeginFrameSource source;
276 EXPECT_FALSE(source.NeedsBeginFrames()); 276 EXPECT_FALSE(source.NeedsBeginFrames());
277 source.SetNeedsBeginFrames(true); 277 source.SetNeedsBeginFrames(true);
278 EXPECT_TRUE(source.NeedsBeginFrames()); 278 EXPECT_TRUE(source.NeedsBeginFrames());
279 source.SetNeedsBeginFrames(false); 279 source.SetNeedsBeginFrames(false);
280 EXPECT_FALSE(source.NeedsBeginFrames()); 280 EXPECT_FALSE(source.NeedsBeginFrames());
281 } 281 }
282 282
283 class LoopingBeginFrameObserver : public BeginFrameObserverMixIn { 283 class LoopingBeginFrameObserver : public BeginFrameObserverBase {
284 public: 284 public:
285 BeginFrameSource* source_; 285 BeginFrameSource* source_;
286 286
287 void AsValueInto(base::trace_event::TracedValue* dict) const override { 287 void AsValueInto(base::trace_event::TracedValue* dict) const override {
288 dict->SetString("type", "LoopingBeginFrameObserver"); 288 dict->SetString("type", "LoopingBeginFrameObserver");
289 dict->BeginDictionary("source"); 289 dict->BeginDictionary("source");
290 source_->AsValueInto(dict); 290 source_->AsValueInto(dict);
291 dict->EndDictionary(); 291 dict->EndDictionary();
292 } 292 }
293 293
294 protected: 294 protected:
295 // BeginFrameObserverMixIn 295 // BeginFrameObserverBase
296 bool OnBeginFrameMixInDelegate(const BeginFrameArgs& args) override { 296 bool OnBeginFrameDerivedImpl(const BeginFrameArgs& args) override {
297 return true; 297 return true;
298 } 298 }
299 }; 299 };
300 300
301 TEST(BeginFrameSourceMixInTest, DetectAsValueIntoLoop) { 301 TEST(BeginFrameSourceBaseTest, DetectAsValueIntoLoop) {
302 LoopingBeginFrameObserver obs; 302 LoopingBeginFrameObserver obs;
303 FakeBeginFrameSource source; 303 FakeBeginFrameSource source;
304 304
305 obs.source_ = &source; 305 obs.source_ = &source;
306 source.AddObserver(&obs); 306 source.AddObserver(&obs);
307 307
308 scoped_refptr<base::trace_event::TracedValue> state = 308 scoped_refptr<base::trace_event::TracedValue> state =
309 new base::trace_event::TracedValue(); 309 new base::trace_event::TracedValue();
310 source.AsValueInto(state.get()); 310 source.AsValueInto(state.get());
311 } 311 }
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 mux_->SetActiveSource(source2_); 766 mux_->SetActiveSource(source2_);
767 SEND_BEGIN_FRAME_DROP(*source2_, 750, 1050, 300); 767 SEND_BEGIN_FRAME_DROP(*source2_, 750, 1050, 300);
768 SEND_BEGIN_FRAME_USED(*source2_, 1050, 1250, 300); 768 SEND_BEGIN_FRAME_USED(*source2_, 1050, 1250, 300);
769 769
770 mux_->SetActiveSource(source1_); 770 mux_->SetActiveSource(source1_);
771 SEND_BEGIN_FRAME_DROP(*source2_, 1100, 1400, 300); 771 SEND_BEGIN_FRAME_DROP(*source2_, 1100, 1400, 300);
772 } 772 }
773 773
774 } // namespace 774 } // namespace
775 } // namespace cc 775 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/begin_frame_source.cc ('k') | cc/scheduler/scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698