summaryrefslogtreecommitdiffstats
path: root/chrome/test/interactive_ui
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-04 18:37:35 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-04 18:37:35 +0000
commit5cee161e7452b717ece661d194b28dff1513290d (patch)
tree2d0afb767372ed0222e0e2d0792d56ec30d3526e /chrome/test/interactive_ui
parent630947caffc803a4cc96e3754af45aeedc957c0c (diff)
downloadchromium_src-5cee161e7452b717ece661d194b28dff1513290d.zip
chromium_src-5cee161e7452b717ece661d194b28dff1513290d.tar.gz
chromium_src-5cee161e7452b717ece661d194b28dff1513290d.tar.bz2
Addin a time-out to view base tests to prevent them from
potentially hanging the interactive ui tests. BUG=None TEST=Run the interactive ui tests. R=sky Review URL: http://codereview.chromium.org/355024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30972 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/interactive_ui')
-rw-r--r--chrome/test/interactive_ui/view_event_test_base.cc36
-rw-r--r--chrome/test/interactive_ui/view_event_test_base.h7
2 files changed, 38 insertions, 5 deletions
diff --git a/chrome/test/interactive_ui/view_event_test_base.cc b/chrome/test/interactive_ui/view_event_test_base.cc
index 24db9c5..e971954 100644
--- a/chrome/test/interactive_ui/view_event_test_base.cc
+++ b/chrome/test/interactive_ui/view_event_test_base.cc
@@ -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 @@ const int kMouseMoveDelayMS = 200;
} // 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 @@ void ViewEventTestBase::Done() {
// 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,9 +121,14 @@ void ViewEventTestBase::StartMessageLoopAndRunTest() {
// 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 @@ void ViewEventTestBase::RunTestMethod(Task* task) {
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();
+}
diff --git a/chrome/test/interactive_ui/view_event_test_base.h b/chrome/test/interactive_ui/view_event_test_base.h
index 456cefc..31606dd 100644
--- a/chrome/test/interactive_ui/view_event_test_base.h
+++ b/chrome/test/interactive_ui/view_event_test_base.h
@@ -6,6 +6,7 @@
#define CHROME_TEST_INTERACTIVE_UI_VIEW_EVENT_TEST_BASE_H_
#include "base/message_loop.h"
+#include "base/task.h"
#include "base/thread.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "views/window/window_delegate.h"
@@ -119,6 +120,9 @@ class ViewEventTestBase : public views::WindowDelegate,
// supplied task and if there are failures invokes Done.
void RunTestMethod(Task* task);
+ // Called when the test has been running for longer than expected.
+ void TimedOut();
+
// The content of the Window.
views::View* content_view_;
@@ -127,6 +131,9 @@ class ViewEventTestBase : public views::WindowDelegate,
MessageLoopForUI message_loop_;
+ // Method factory used for time-outs.
+ ScopedRunnableMethodFactory<ViewEventTestBase> method_factory_;
+
DISALLOW_COPY_AND_ASSIGN(ViewEventTestBase);
};