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

Unified Diff: content/browser/browser_plugin/test_timeout_tracker.h

Issue 10868012: Browser Plugin: New Implementation (Browser Side) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master-trial-obrowser
Patch Set: @tott + Address comments + fix win_rel trybot flakiness Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698