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

Unified Diff: content/shell/webkit_test_runner_host.cc

Issue 10832412: [content shell] create a central WebKitTestController object that manages the test cycle (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « content/shell/webkit_test_runner_host.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/shell/webkit_test_runner_host.cc
diff --git a/content/shell/webkit_test_runner_host.cc b/content/shell/webkit_test_runner_host.cc
index d301e30f95005fc5736b4bbae920ae5d8606694c..137c378a30feef71eaed53405781209a55b3072f 100644
--- a/content/shell/webkit_test_runner_host.cc
+++ b/content/shell/webkit_test_runner_host.cc
@@ -7,6 +7,10 @@
#include "base/command_line.h"
#include "base/message_loop.h"
#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+#include "content/shell/shell.h"
+#include "content/shell/shell_browser_context.h"
+#include "content/shell/shell_content_browser_client.h"
#include "content/shell/shell_messages.h"
#include "content/shell/shell_switches.h"
#include "webkit/support/webkit_support_gfx.h"
@@ -17,66 +21,145 @@ namespace {
const int kTestTimeoutMilliseconds = 30 * 1000;
} // namespace
-std::map<RenderViewHost*, WebKitTestRunnerHost*>
- WebKitTestRunnerHost::controllers_;
-std::string WebKitTestRunnerHost::expected_pixel_hash_;
+WebKitTestController* WebKitTestController::instance_ = NULL;
// static
-WebKitTestRunnerHost* WebKitTestRunnerHost::FromRenderViewHost(
- RenderViewHost* render_view_host) {
- const std::map<RenderViewHost*, WebKitTestRunnerHost*>::iterator it =
- controllers_.find(render_view_host);
- if (it == controllers_.end())
- return NULL;
- return it->second;
+WebKitTestController* WebKitTestController::Get() {
+ DCHECK(!instance_ || instance_->CalledOnValidThread());
+ return instance_;
}
-// static
-void WebKitTestRunnerHost::Init(const std::string& expected_pixel_hash) {
- // TODO(jochen): We should only dump the results for the "main window".
+WebKitTestController::WebKitTestController() {
+ CHECK(!instance_);
+ instance_ = this;
+
+ ResetAfterLayoutTest();
+
+ content::ShellBrowserContext* browser_context =
+ static_cast<content::ShellContentBrowserClient*>(
+ content::GetContentClient()->browser())->browser_context();
+ main_window_ = content::Shell::CreateNewWindow(
+ browser_context,
+ GURL("about:blank"),
+ NULL,
+ MSG_ROUTING_NONE,
+ NULL);
+ Observe(main_window_->web_contents());
+}
+
+WebKitTestController::~WebKitTestController() {
+ DCHECK(CalledOnValidThread());
+ CHECK(instance_ == this);
+ if (main_window_)
+ main_window_->Close();
+ instance_ = NULL;
+}
+
+void WebKitTestController::PrepareForLayoutTest(
+ const GURL& test_url, const std::string& expected_pixel_hash) {
+ DCHECK(CalledOnValidThread());
+ DCHECK(main_window_);
expected_pixel_hash_ = expected_pixel_hash;
+ main_window_->LoadURL(test_url);
}
-WebKitTestRunnerHost::WebKitTestRunnerHost(
- RenderViewHost* render_view_host)
- : RenderViewHostObserver(render_view_host),
- captured_dump_(false),
- dump_as_text_(false),
- dump_child_frames_(false),
- is_printing_(false),
- should_stay_on_page_after_handling_before_unload_(false),
- wait_until_done_(false) {
- controllers_[render_view_host] = this;
+bool WebKitTestController::ResetAfterLayoutTest() {
+ DCHECK(CalledOnValidThread());
+ expected_pixel_hash_.clear();
+ captured_dump_ = false;
+ dump_as_text_ = false;
+ dump_child_frames_ = false;
+ is_printing_ = false;
+ should_stay_on_page_after_handling_before_unload_ = false;
+ wait_until_done_ = false;
+ watchdog_.Cancel();
+ return main_window_ != NULL;
}
-WebKitTestRunnerHost::~WebKitTestRunnerHost() {
- controllers_.erase(render_view_host());
+void WebKitTestController::LoadFinished(Shell* window) {
+ if (wait_until_done_)
+ return;
+
+ if (window == main_window_)
+ CaptureDump();
+}
+
+void WebKitTestController::NotifyDone() {
+ if (!wait_until_done_)
+ return;
watchdog_.Cancel();
+ CaptureDump();
}
-void WebKitTestRunnerHost::CaptureDump() {
+void WebKitTestController::WaitUntilDone() {
+ if (wait_until_done_)
+ return;
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTimeout)) {
+ watchdog_.Reset(base::Bind(&WebKitTestController::TimeoutHandler,
+ base::Unretained(this)));
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ watchdog_.callback(),
+ base::TimeDelta::FromMilliseconds(kTestTimeoutMilliseconds));
+ }
+ wait_until_done_ = true;
+}
+
+void WebKitTestController::NotImplemented(
+ const std::string& object_name,
+ const std::string& property_name) {
if (captured_dump_)
return;
+ printf("FAIL: NOT IMPLEMENTED: %s.%s\n",
+ object_name.c_str(), property_name.c_str());
+ fprintf(stderr, "FAIL: NOT IMPLEMENTED: %s.%s\n",
+ object_name.c_str(), property_name.c_str());
+ watchdog_.Cancel();
+ CaptureDump();
+}
+
+void WebKitTestController::WebContentsDestroyed(WebContents* web_contents) {
+ main_window_ = NULL;
+ printf("FAIL: main window was destroyed\n");
+ fprintf(stderr, "FAIL: main window was destroyed\n");
+ watchdog_.Cancel();
+ MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
+}
+
+void WebKitTestController::CaptureDump() {
+ if (captured_dump_ || !main_window_)
+ return;
captured_dump_ = true;
- render_view_host()->Send(
- new ShellViewMsg_CaptureTextDump(render_view_host()->GetRoutingID(),
- dump_as_text_,
- is_printing_,
- dump_child_frames_));
+ RenderViewHost* render_view_host =
+ main_window_->web_contents()->GetRenderViewHost();
+
+ render_view_host->Send(new ShellViewMsg_CaptureTextDump(
+ render_view_host->GetRoutingID(),
+ dump_as_text_,
+ is_printing_,
+ dump_child_frames_));
if (!dump_as_text_) {
- render_view_host()->Send(
- new ShellViewMsg_CaptureImageDump(render_view_host()->GetRoutingID(),
- expected_pixel_hash_));
+ render_view_host->Send(new ShellViewMsg_CaptureImageDump(
+ render_view_host->GetRoutingID(),
+ expected_pixel_hash_));
}
}
-void WebKitTestRunnerHost::TimeoutHandler() {
+void WebKitTestController::TimeoutHandler() {
printf("FAIL: Timed out waiting for notifyDone to be called\n");
fprintf(stderr, "FAIL: Timed out waiting for notifyDone to be called\n");
CaptureDump();
}
+WebKitTestRunnerHost::WebKitTestRunnerHost(
+ RenderViewHost* render_view_host)
+ : RenderViewHostObserver(render_view_host) {
+}
+
+WebKitTestRunnerHost::~WebKitTestRunnerHost() {
+}
+
bool WebKitTestRunnerHost::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
@@ -101,17 +184,15 @@ bool WebKitTestRunnerHost::OnMessageReceived(
}
void WebKitTestRunnerHost::OnDidFinishLoad() {
- if (wait_until_done_)
- return;
-
- CaptureDump();
+ WebKitTestController::Get()->LoadFinished(
+ Shell::FromRenderViewHost(render_view_host()));
}
void WebKitTestRunnerHost::OnTextDump(const std::string& dump) {
printf("%s#EOF\n", dump.c_str());
fprintf(stderr, "#EOF\n");
- if (dump_as_text_)
+ if (WebKitTestController::Get()->dump_as_text())
MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
}
@@ -121,12 +202,14 @@ void WebKitTestRunnerHost::OnImageDump(
SkAutoLockPixels image_lock(image);
printf("\nActualHash: %s\n", actual_pixel_hash.c_str());
- if (!expected_pixel_hash_.empty())
- printf("\nExpectedHash: %s\n", expected_pixel_hash_.c_str());
+ std::string expected_pixel_hash =
+ WebKitTestController::Get()->expected_pixel_hash();
+ if (!expected_pixel_hash.empty())
+ printf("\nExpectedHash: %s\n", expected_pixel_hash.c_str());
// Only encode and dump the png if the hashes don't match. Encoding the
// image is really expensive.
- if (actual_pixel_hash != expected_pixel_hash_) {
+ if (actual_pixel_hash != expected_pixel_hash) {
std::vector<unsigned char> png;
// Only the expected PNGs for Mac have a valid alpha channel.
@@ -167,54 +250,36 @@ void WebKitTestRunnerHost::OnImageDump(
}
void WebKitTestRunnerHost::OnNotifyDone() {
- if (!wait_until_done_)
- return;
- watchdog_.Cancel();
- CaptureDump();
+ WebKitTestController::Get()->NotifyDone();
}
void WebKitTestRunnerHost::OnDumpAsText() {
- dump_as_text_ = true;
+ WebKitTestController::Get()->set_dump_as_text(true);
}
void WebKitTestRunnerHost::OnSetPrinting() {
- is_printing_ = true;
+ WebKitTestController::Get()->set_is_printing(true);
}
void WebKitTestRunnerHost::OnSetShouldStayOnPageAfterHandlingBeforeUnload(
bool should_stay_on_page) {
- should_stay_on_page_after_handling_before_unload_ = should_stay_on_page;
+ WebKitTestController* controller = WebKitTestController::Get();
+ controller->set_should_stay_on_page_after_handling_before_unload(
+ should_stay_on_page);
}
void WebKitTestRunnerHost::OnDumpChildFramesAsText() {
- dump_child_frames_ = true;
+ WebKitTestController::Get()->set_dump_child_frames(true);
}
void WebKitTestRunnerHost::OnWaitUntilDone() {
- if (wait_until_done_)
- return;
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTimeout)) {
- watchdog_.Reset(base::Bind(&WebKitTestRunnerHost::TimeoutHandler,
- base::Unretained(this)));
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- watchdog_.callback(),
- base::TimeDelta::FromMilliseconds(kTestTimeoutMilliseconds));
- }
- wait_until_done_ = true;
+ WebKitTestController::Get()->WaitUntilDone();
}
void WebKitTestRunnerHost::OnNotImplemented(
const std::string& object_name,
const std::string& property_name) {
- if (captured_dump_)
- return;
- printf("FAIL: NOT IMPLEMENTED: %s.%s\n",
- object_name.c_str(), property_name.c_str());
- fprintf(stderr, "FAIL: NOT IMPLEMENTED: %s.%s\n",
- object_name.c_str(), property_name.c_str());
- watchdog_.Cancel();
- CaptureDump();
+ WebKitTestController::Get()->NotImplemented(object_name, property_name);
}
} // namespace content
« no previous file with comments | « content/shell/webkit_test_runner_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698