add a use_alsa gyp setting
[chromium-blink-merge.git] / cc / test / scheduler_test_common.h
blobbe13fbf5cd23447fd5a46ad55c820614401f1569
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
3 // found in the LICENSE file.
5 #ifndef CC_TEST_SCHEDULER_TEST_COMMON_H_
6 #define CC_TEST_SCHEDULER_TEST_COMMON_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "cc/delay_based_time_source.h"
10 #include "cc/frame_rate_controller.h"
11 #include "cc/thread.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace cc {
16 class FakeTimeSourceClient : public cc::TimeSourceClient {
17 public:
18 FakeTimeSourceClient() { reset(); }
19 void reset() { m_tickCalled = false; }
20 bool tickCalled() const { return m_tickCalled; }
22 virtual void onTimerTick() OVERRIDE;
24 protected:
25 bool m_tickCalled;
28 class FakeThread : public cc::Thread {
29 public:
30 FakeThread();
31 virtual ~FakeThread();
33 void reset()
35 m_pendingTaskDelay = 0;
36 m_pendingTask.reset();
37 m_runPendingTaskOnOverwrite = false;
40 void runPendingTaskOnOverwrite(bool enable)
42 m_runPendingTaskOnOverwrite = enable;
45 bool hasPendingTask() const { return m_pendingTask; }
46 void runPendingTask();
48 long long pendingDelayMs() const
50 EXPECT_TRUE(hasPendingTask());
51 return m_pendingTaskDelay;
54 virtual void postTask(base::Closure cb) OVERRIDE;
55 virtual void postDelayedTask(base::Closure cb, long long delay) OVERRIDE;
56 virtual bool belongsToCurrentThread() const OVERRIDE;
58 protected:
59 scoped_ptr<base::Closure> m_pendingTask;
60 long long m_pendingTaskDelay;
61 bool m_runPendingTaskOnOverwrite;
64 class FakeTimeSource : public cc::TimeSource {
65 public:
66 FakeTimeSource()
67 : m_active(false)
68 , m_client(0)
72 virtual void setClient(cc::TimeSourceClient* client) OVERRIDE;
73 virtual void setActive(bool b) OVERRIDE;
74 virtual bool active() const OVERRIDE;
75 virtual void setTimebaseAndInterval(base::TimeTicks timebase, base::TimeDelta interval) OVERRIDE { }
76 virtual base::TimeTicks lastTickTime() OVERRIDE;
77 virtual base::TimeTicks nextTickTime() OVERRIDE;
79 void tick()
81 ASSERT_TRUE(m_active);
82 if (m_client)
83 m_client->onTimerTick();
86 void setNextTickTime(base::TimeTicks nextTickTime) { m_nextTickTime = nextTickTime; }
88 protected:
89 virtual ~FakeTimeSource() { }
91 bool m_active;
92 base::TimeTicks m_nextTickTime;
93 cc::TimeSourceClient* m_client;
96 class FakeDelayBasedTimeSource : public cc::DelayBasedTimeSource {
97 public:
98 static scoped_refptr<FakeDelayBasedTimeSource> create(base::TimeDelta interval, cc::Thread* thread)
100 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval, thread));
103 void setNow(base::TimeTicks time) { m_now = time; }
104 virtual base::TimeTicks now() const OVERRIDE;
106 protected:
107 FakeDelayBasedTimeSource(base::TimeDelta interval, cc::Thread* thread)
108 : DelayBasedTimeSource(interval, thread)
111 virtual ~FakeDelayBasedTimeSource() { }
113 base::TimeTicks m_now;
116 class FakeFrameRateController : public cc::FrameRateController {
117 public:
118 FakeFrameRateController(scoped_refptr<cc::TimeSource> timer) : cc::FrameRateController(timer) { }
120 int numFramesPending() const { return m_numFramesPending; }
123 } // namespace cc
125 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_