summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-26 18:54:31 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-26 18:54:31 +0000
commit198c609745206de5fbf0f04ff9ec595823718caf (patch)
treed44ef0e1f9122b5eb7b08b52c3a4a6bec35063b1 /content
parent92df8a3f3c9352498d1064ddf507a84d758deddd (diff)
downloadchromium_src-198c609745206de5fbf0f04ff9ec595823718caf.zip
chromium_src-198c609745206de5fbf0f04ff9ec595823718caf.tar.gz
chromium_src-198c609745206de5fbf0f04ff9ec595823718caf.tar.bz2
Add a timeout watchdog to content shell for layout tests
BUG=111316 TEST=run on a HTML file like <script>layoutTestController.waitUntilDone()</script>, should time out after ~30s Review URL: https://chromiumcodereview.appspot.com/10662051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144222 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/shell/layout_test_controller_host.cc27
-rw-r--r--content/shell/layout_test_controller_host.h6
2 files changed, 33 insertions, 0 deletions
diff --git a/content/shell/layout_test_controller_host.cc b/content/shell/layout_test_controller_host.cc
index 94b534c..ade2c98 100644
--- a/content/shell/layout_test_controller_host.cc
+++ b/content/shell/layout_test_controller_host.cc
@@ -12,6 +12,10 @@
namespace content {
+namespace {
+const int kTestTimeoutMilliseconds = 30 * 1000;
+} // namespace
+
std::map<RenderViewHost*, LayoutTestControllerHost*>
LayoutTestControllerHost::controllers_;
@@ -28,6 +32,7 @@ LayoutTestControllerHost* LayoutTestControllerHost::FromRenderViewHost(
LayoutTestControllerHost::LayoutTestControllerHost(
RenderViewHost* render_view_host)
: RenderViewHostObserver(render_view_host),
+ captured_dump_(false),
dump_as_text_(false),
dump_child_frames_(false),
is_printing_(false),
@@ -38,9 +43,14 @@ LayoutTestControllerHost::LayoutTestControllerHost(
LayoutTestControllerHost::~LayoutTestControllerHost() {
controllers_.erase(render_view_host());
+ watchdog_.Cancel();
}
void LayoutTestControllerHost::CaptureDump() {
+ if (captured_dump_)
+ return;
+ captured_dump_ = true;
+
render_view_host()->Send(
new ShellViewMsg_CaptureTextDump(render_view_host()->GetRoutingID(),
dump_as_text_,
@@ -48,6 +58,12 @@ void LayoutTestControllerHost::CaptureDump() {
dump_child_frames_));
}
+void LayoutTestControllerHost::TimeoutHandler() {
+ std::cout << "FAIL: Timed out waiting for notifyDone to be called\n";
+ std::cerr << "FAIL: Timed out waiting for notifyDone to be called\n";
+ CaptureDump();
+}
+
bool LayoutTestControllerHost::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
@@ -85,6 +101,9 @@ void LayoutTestControllerHost::OnTextDump(const std::string& dump) {
}
void LayoutTestControllerHost::OnNotifyDone() {
+ if (!wait_until_done_)
+ return;
+ watchdog_.Cancel();
CaptureDump();
}
@@ -106,6 +125,14 @@ void LayoutTestControllerHost::OnDumpChildFramesAsText() {
}
void LayoutTestControllerHost::OnWaitUntilDone() {
+ if (wait_until_done_)
+ return;
+ watchdog_.Reset(base::Bind(&LayoutTestControllerHost::TimeoutHandler,
+ base::Unretained(this)));
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ watchdog_.callback(),
+ base::TimeDelta::FromMilliseconds(kTestTimeoutMilliseconds));
wait_until_done_ = true;
}
diff --git a/content/shell/layout_test_controller_host.h b/content/shell/layout_test_controller_host.h
index 733dfc9..7ff3d45 100644
--- a/content/shell/layout_test_controller_host.h
+++ b/content/shell/layout_test_controller_host.h
@@ -9,6 +9,7 @@
#include <map>
#include <string>
+#include "base/cancelable_callback.h"
#include "content/public/browser/render_view_host_observer.h"
namespace content {
@@ -30,6 +31,7 @@ class LayoutTestControllerHost : public RenderViewHostObserver {
private:
void CaptureDump();
+ void TimeoutHandler();
// Message handlers.
void OnDidFinishLoad();
@@ -45,12 +47,16 @@ class LayoutTestControllerHost : public RenderViewHostObserver {
static std::map<RenderViewHost*, LayoutTestControllerHost*> controllers_;
+ bool captured_dump_;
+
bool dump_as_text_;
bool dump_child_frames_;
bool is_printing_;
bool should_stay_on_page_after_handling_before_unload_;
bool wait_until_done_;
+ base::CancelableClosure watchdog_;
+
DISALLOW_COPY_AND_ASSIGN(LayoutTestControllerHost);
};