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

Unified Diff: chrome/test/interactive_ui/view_event_test_base.cc

Issue 355024: Addin a time-out to view base tests to prevent them from... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
« no previous file with comments | « chrome/test/interactive_ui/view_event_test_base.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/interactive_ui/view_event_test_base.cc
===================================================================
--- chrome/test/interactive_ui/view_event_test_base.cc (revision 30896)
+++ chrome/test/interactive_ui/view_event_test_base.cc (working copy)
@@ -8,13 +8,18 @@
#include <ole2.h>
#endif
+#include "base/compiler_specific.h"
#include "base/message_loop.h"
+#include "base/string_util.h"
#include "chrome/browser/automation/ui_controls.h"
#include "views/view.h"
#include "views/window/window.h"
namespace {
+// Default delay for the time-out at which we stop message loop.
+const int kTimeoutInMS = 20000;
+
// View subclass that allows you to specify the preferred size.
class TestView : public views::View {
public:
@@ -47,9 +52,16 @@
} // namespace
-ViewEventTestBase::ViewEventTestBase() : window_(NULL), content_view_(NULL) { }
+ViewEventTestBase::ViewEventTestBase()
+ : window_(NULL),
+ content_view_(NULL),
+ ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
+}
void ViewEventTestBase::Done() {
+ // Cancel the pending time-out.
+ method_factory_.RevokeAll();
+
MessageLoop::current()->Quit();
#if defined(OS_WIN)
@@ -60,8 +72,7 @@
// If we're in a nested message loop, as is the case with menus, we need
// to quit twice. The second quit does that for us.
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE, new MessageLoop::QuitTask(), 0);
+ MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
}
void ViewEventTestBase::SetUp() {
@@ -110,10 +121,15 @@
// Schedule a task that starts the test. Need to do this as we're going to
// run the message loop.
- MessageLoop::current()->PostDelayedTask(
+ MessageLoop::current()->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &ViewEventTestBase::DoTestOnMessageLoop), 0);
+ NewRunnableMethod(this, &ViewEventTestBase::DoTestOnMessageLoop));
+ // Start the timeout timer to prevent hangs.
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ method_factory_.NewRunnableMethod(&ViewEventTestBase::TimedOut),
+ kTimeoutInMS);
+
MessageLoop::current()->Run();
}
@@ -143,3 +159,13 @@
if (HasFatalFailure())
Done();
}
+
+void ViewEventTestBase::TimedOut() {
+ std::string error_message = "Test timed out. Each test runs for a max of ";
+ error_message += IntToString(kTimeoutInMS);
+ error_message += " ms (kTimeoutInMS).";
+
+ GTEST_NONFATAL_FAILURE_(error_message.c_str());
+
+ Done();
+}
« no previous file with comments | « chrome/test/interactive_ui/view_event_test_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698