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

Unified Diff: Source/platform/Timer.h

Issue 112023010: Make EventHandler::ActiveIntervalTimer mockable. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years 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 side-by-side diff with in-line comments
Download patch
« Source/core/page/EventHandler.h ('K') | « Source/core/testing/TimerTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/Timer.h
diff --git a/Source/platform/Timer.h b/Source/platform/Timer.h
index 1f03cf11dc894643c79ec0b2ed0eda911cebf9fb..2ca6cce94d8d4144d9c023f9099896de2cc67624 100644
--- a/Source/platform/Timer.h
+++ b/Source/platform/Timer.h
@@ -105,8 +105,12 @@ private:
friend class TimerHeapReference;
};
+template <typename TimerFiredClass> class MockableTimer;
+
template <typename TimerFiredClass>
class Timer : public TimerBase {
+ friend class MockableTimer<TimerFiredClass>;
+
public:
typedef void (TimerFiredClass::*TimerFiredFunction)(Timer*);
@@ -120,6 +124,37 @@ private:
TimerFiredFunction m_function;
};
+// Just derive from TimerBase and skip the template-fu?
Zeeshan Qureshi 2013/12/13 02:05:58 Deriving from TimerBase might just be cleaner.
Rick Byers 2013/12/13 22:52:25 I like that you don't have to duplicate anything h
+template <typename TimerFiredClass>
+class MockableTimer : public Timer<TimerFiredClass> {
+public:
+ typedef typename Timer<TimerFiredClass>::TimerFiredFunction TimerFiredFunction;
+
+ MockableTimer(TimerFiredClass* o, TimerFiredFunction f)
+ : Timer<TimerFiredClass>(o, f)
+ , m_suspended(false)
+ {
+ }
+
+ bool isSuspended() { return m_suspended; }
+
+ void suspend() { m_suspended = true; }
Rick Byers 2013/12/13 22:52:25 I wonder if we should make these a little scarrier
Zeeshan Qureshi 2014/01/07 19:35:09 Yes!
+
+ void resume() { m_suspended = false; }
+
+ // Should this only work when timer is suspended?
Zeeshan Qureshi 2013/12/13 02:05:58 Not sure, maybe only allow this when m_suspended?
Rick Byers 2013/12/13 22:52:25 Yeah, probably a good idea to ASSERT(m_suspended)
Zeeshan Qureshi 2014/01/07 19:35:09 Done, it's a little tricky to reason about pending
+ void fire() { Timer<TimerFiredClass>::fired(); }
+
+private:
+ bool m_suspended;
+
+ virtual void fired()
+ {
+ if (!m_suspended)
+ Timer<TimerFiredClass>::fired();
+ }
+};
+
inline bool TimerBase::isActive() const
{
ASSERT(m_thread == currentThread());
« Source/core/page/EventHandler.h ('K') | « Source/core/testing/TimerTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698