Chromium Code Reviews| Index: content/browser/browser_plugin/test_timeout_tracker.h |
| diff --git a/content/browser/browser_plugin/test_timeout_tracker.h b/content/browser/browser_plugin/test_timeout_tracker.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fa239ef9cac5934e0502c3c158461beefc844ea9 |
| --- /dev/null |
| +++ b/content/browser/browser_plugin/test_timeout_tracker.h |
| @@ -0,0 +1,54 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
jam
2012/09/17 17:47:53
are you sure you really want this class? this alre
lazyboy
2012/09/17 20:22:24
Albert, can you comment on this one.
I guess we do
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_BROWSER_PLUGIN_TEST_TIMEOUT_TRACKER_H_ |
| +#define CONTENT_BROWSER_BROWSER_PLUGIN_TEST_TIMEOUT_TRACKER_H_ |
| + |
| +#include "base/bind.h" |
| +#include "base/callback_forward.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/test/test_timeouts.h" |
| +#include "content/public/test/test_utils.h" |
| + |
| +namespace content { |
| + |
| +// A class that tracks if |OnTimeout| callback has been called on it. |
| +// |
| +// This class also provides a utility method to run a MessageLoopRunner for |
| +// a specific timeout (TestTimeouts::action_timeout()) time. |
| +class TestTimeoutTracker { |
| + public: |
| + TestTimeoutTracker() : timed_out_(false) {} |
| + virtual ~TestTimeoutTracker() {} |
| + |
| + void OnTimeout(const base::Closure& done) { |
| + LOG(INFO) << "Timer timed out"; |
| + timed_out_ = true; |
| + done.Run(); |
| + } |
| + |
| + bool timed_out() { return timed_out_; } |
| + |
| + // Runs |message_loop_runner| for TestTimeouts::action_timeout(). |
| + static bool RunInActionTimeout(MessageLoopRunner* message_loop_runner) { |
| + TestTimeoutTracker timeout_tracker; |
| + // So the task cancels on function exit. |
| + base::WeakPtrFactory<TestTimeoutTracker> cb_weak_factory(&timeout_tracker); |
| + MessageLoop::current()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&TestTimeoutTracker::OnTimeout, |
| + cb_weak_factory.GetWeakPtr(), |
| + message_loop_runner->QuitClosure()), |
| + TestTimeouts::action_timeout()); |
| + message_loop_runner->Run(); |
| + return !timeout_tracker.timed_out(); |
| + } |
| + |
| + private: |
| + bool timed_out_; |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_BROWSER_PLUGIN_TEST_TIMEOUT_TRACKER_H_ |