summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-26 23:17:56 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-26 23:17:56 +0000
commit02bf7f27abb24a349f178d2faa2bdee635913f28 (patch)
treee34cc0a3035f9652e5d718bb47de323cc1ea5ba6 /base
parentd36540e90a608afc57b600d0981b906d6c94ab8f (diff)
downloadchromium_src-02bf7f27abb24a349f178d2faa2bdee635913f28.zip
chromium_src-02bf7f27abb24a349f178d2faa2bdee635913f28.tar.gz
chromium_src-02bf7f27abb24a349f178d2faa2bdee635913f28.tar.bz2
Add a test to DelayTimer ensure that the callback is never
made once the DelayTimer has been destroyed. Review URL: http://codereview.chromium.org/27234 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10520 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/timer.h3
-rw-r--r--base/timer_unittest.cc31
2 files changed, 34 insertions, 0 deletions
diff --git a/base/timer.h b/base/timer.h
index eb00486..706551f 100644
--- a/base/timer.h
+++ b/base/timer.h
@@ -206,6 +206,9 @@ class RepeatingTimer : public BaseTimer<Receiver, true> {};
// Once created, it is inactive until Reset is called. Once |delay| seconds have
// passed since the last call to Reset, the callback is made. Once the callback
// has been made, it's inactive until Reset is called again.
+//
+// If destroyed, the timeout is canceled and will not occur even if already
+// inflight.
template <class Receiver>
class DelayTimer {
public:
diff --git a/base/timer_unittest.cc b/base/timer_unittest.cc
index b48c774..4349245f 100644
--- a/base/timer_unittest.cc
+++ b/base/timer_unittest.cc
@@ -243,6 +243,31 @@ void RunTest_DelayTimer_Reset(MessageLoop::Type message_loop_type) {
ASSERT_TRUE(target.signaled());
}
+class DelayTimerFatalTarget {
+ public:
+ void Signal() {
+ ASSERT_TRUE(false);
+ }
+};
+
+
+void RunTest_DelayTimer_Deleted(MessageLoop::Type message_loop_type) {
+ MessageLoop loop(message_loop_type);
+
+ DelayTimerFatalTarget target;
+
+ {
+ base::DelayTimer<DelayTimerFatalTarget> timer(
+ TimeDelta::FromMilliseconds(50), &target,
+ &DelayTimerFatalTarget::Signal);
+ timer.Reset();
+ }
+
+ // When the timer is deleted, the DelayTimerFatalTarget should never be
+ // called.
+ PlatformThread::Sleep(100);
+}
+
} // namespace
//-----------------------------------------------------------------------------
@@ -299,6 +324,12 @@ TEST(TimerTest, DelayTimer_Reset) {
RunTest_DelayTimer_Reset(MessageLoop::TYPE_IO);
}
+TEST(TimerTest, DelayTimer_Deleted) {
+ RunTest_DelayTimer_Deleted(MessageLoop::TYPE_DEFAULT);
+ RunTest_DelayTimer_Deleted(MessageLoop::TYPE_UI);
+ RunTest_DelayTimer_Deleted(MessageLoop::TYPE_IO);
+}
+
TEST(TimerTest, MessageLoopShutdown) {
// This test is designed to verify that shutdown of the
// message loop does not cause crashes if there were pending