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

Unified Diff: content/shell/webkit_test_runner_host.cc

Issue 10941011: Rewrite layout_browsertests to use content_shell --dump-render-tree to execute layout tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates 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/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 b7d625bba3f8da654bca7842f0671df64f05fa54..f909f4cfb3307349d29a671924457854b98ec8d8 100644
--- a/content/shell/webkit_test_runner_host.cc
+++ b/content/shell/webkit_test_runner_host.cc
@@ -4,6 +4,8 @@
#include "content/shell/webkit_test_runner_host.h"
+#include <iostream>
+
#include "base/command_line.h"
#include "base/message_loop.h"
#include "base/run_loop.h"
@@ -25,8 +27,12 @@ const int kTestTimeoutMilliseconds = 30 * 1000;
// WebKitTestResultPrinter ----------------------------------------------------
-WebKitTestResultPrinter::WebKitTestResultPrinter()
- : state_(BEFORE_TEST) {
+WebKitTestResultPrinter::WebKitTestResultPrinter(
+ std::ostream* output, std::ostream* error)
+ : state_(BEFORE_TEST),
+ capture_text_only_(false),
+ output_(output),
+ error_(error) {
}
WebKitTestResultPrinter::~WebKitTestResultPrinter() {
@@ -34,60 +40,70 @@ WebKitTestResultPrinter::~WebKitTestResultPrinter() {
void WebKitTestResultPrinter::PrintTextHeader() {
DCHECK_EQ(state_, BEFORE_TEST);
- printf("Content-Type: text/plain\n");
+ if (!capture_text_only_)
+ *output_ << "Content-Type: text/plain\n";
state_ = IN_TEXT_BLOCK;
}
void WebKitTestResultPrinter::PrintTextBlock(const std::string& block) {
DCHECK_EQ(state_, IN_TEXT_BLOCK);
- printf("%s", block.c_str());
+ *output_ << block;
}
void WebKitTestResultPrinter::PrintTextFooter() {
if (state_ != IN_TEXT_BLOCK)
return;
- printf("#EOF\n");
- fprintf(stderr, "#EOF\n");
+ if (!capture_text_only_) {
+ *output_ << "#EOF\n";
+ *error_ << "#EOF\n";
+ output_->flush();
+ error_->flush();
+ }
state_ = IN_IMAGE_BLOCK;
}
void WebKitTestResultPrinter::PrintImageHeader(
const std::string& actual_hash,
const std::string& expected_hash) {
- if (state_ != IN_IMAGE_BLOCK)
+ if (state_ != IN_IMAGE_BLOCK || capture_text_only_)
return;
- printf("\nActualHash: %s\n", actual_hash.c_str());
+ *output_ << "\nActualHash: " << actual_hash << "%s\n";
if (!expected_hash.empty())
- printf("\nExpectedHash: %s\n", expected_hash.c_str());
+ *output_ << "\nExpectedHash: " << expected_hash << "%s\n";
}
void WebKitTestResultPrinter::PrintImageBlock(
const std::vector<unsigned char>& png_image) {
- if (state_ != IN_IMAGE_BLOCK)
+ if (state_ != IN_IMAGE_BLOCK || capture_text_only_)
return;
- printf("Content-Type: image/png\n");
- printf("Content-Length: %u\n", static_cast<unsigned>(png_image.size()));
- fwrite(&png_image[0], 1, png_image.size(), stdout);
+ *output_ << "Content-Type: image/png\n";
+ *output_ << "Content-Length: " << png_image.size() << "\n";
+ output_->write(
+ reinterpret_cast<const char*>(&png_image[0]), png_image.size());
}
void WebKitTestResultPrinter::PrintImageFooter() {
if (state_ != IN_IMAGE_BLOCK)
return;
- printf("#EOF\n");
+ if (!capture_text_only_) {
+ *output_ << "#EOF\n";
+ output_->flush();
+ }
state_ = AFTER_TEST;
}
void WebKitTestResultPrinter::AddMessage(const std::string& message) {
if (state_ != IN_TEXT_BLOCK)
return;
- printf("%s\n", message.c_str());
+ *output_ << message << "\n";
}
void WebKitTestResultPrinter::AddErrorMessage(const std::string& message) {
if (state_ != IN_TEXT_BLOCK)
return;
- printf("%s\n", message.c_str());
- fprintf(stderr, "%s\n", message.c_str());
+ *output_ << message << "\n";
+ if (!capture_text_only_)
+ *error_ << message << "\n";
PrintTextFooter();
PrintImageFooter();
MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
@@ -106,6 +122,7 @@ WebKitTestController* WebKitTestController::Get() {
WebKitTestController::WebKitTestController() {
CHECK(!instance_);
instance_ = this;
+ printer_.reset(new WebKitTestResultPrinter(&std::cout, &std::cerr));
content::ShellBrowserContext* browser_context =
static_cast<content::ShellContentBrowserClient*>(
@@ -137,16 +154,16 @@ bool WebKitTestController::PrepareForLayoutTest(
return false;
enable_pixel_dumping_ = enable_pixel_dumping;
expected_pixel_hash_ = expected_pixel_hash;
- printer_.reset();
- printer_.PrintTextHeader();
+ printer_->reset();
+ printer_->PrintTextHeader();
main_window_->LoadURL(test_url);
return true;
}
bool WebKitTestController::ResetAfterLayoutTest() {
DCHECK(CalledOnValidThread());
- printer_.PrintTextFooter();
- printer_.PrintImageFooter();
+ printer_->PrintTextFooter();
+ printer_->PrintImageFooter();
pumping_messages_ = false;
enable_pixel_dumping_ = false;
expected_pixel_hash_.clear();
@@ -174,7 +191,7 @@ bool WebKitTestController::ResetAfterLayoutTest() {
}
void WebKitTestController::RendererUnresponsive() {
- printer_.AddErrorMessage("#PROCESS UNRESPONSIVE - renderer");
+ printer_->AddErrorMessage("#PROCESS UNRESPONSIVE - renderer");
}
void WebKitTestController::NotifyDone() {
@@ -201,7 +218,7 @@ void WebKitTestController::WaitUntilDone() {
void WebKitTestController::NotImplemented(
const std::string& object_name,
const std::string& property_name) {
- printer_.AddErrorMessage(
+ printer_->AddErrorMessage(
std::string("FAIL: NOT IMPLEMENTED: ") +
object_name + "." + property_name);
}
@@ -219,21 +236,21 @@ bool WebKitTestController::OnMessageReceived(const IPC::Message& message) {
}
void WebKitTestController::PluginCrashed(const FilePath& plugin_path) {
- printer_.AddErrorMessage("#CRASHED - plugin");
+ printer_->AddErrorMessage("#CRASHED - plugin");
}
void WebKitTestController::RenderViewGone(base::TerminationStatus status) {
renderer_crashed_ = true;
- printer_.AddErrorMessage("#CRASHED - renderer");
+ printer_->AddErrorMessage("#CRASHED - renderer");
}
void WebKitTestController::WebContentsDestroyed(WebContents* web_contents) {
main_window_ = NULL;
- printer_.AddErrorMessage("FAIL: main window was destroyed");
+ printer_->AddErrorMessage("FAIL: main window was destroyed");
}
void WebKitTestController::CaptureDump() {
- if (captured_dump_ || !main_window_ || !printer_.in_text_block())
+ if (captured_dump_ || !main_window_ || !printer_->in_text_block())
return;
captured_dump_ = true;
@@ -253,7 +270,7 @@ void WebKitTestController::CaptureDump() {
}
void WebKitTestController::TimeoutHandler() {
- printer_.AddErrorMessage(
+ printer_->AddErrorMessage(
"FAIL: Timed out waiting for notifyDone to be called");
}
@@ -272,7 +289,7 @@ void WebKitTestController::OnImageDump(
const SkBitmap& image) {
SkAutoLockPixels image_lock(image);
- printer_.PrintImageHeader(actual_pixel_hash, expected_pixel_hash_);
+ printer_->PrintImageHeader(actual_pixel_hash, expected_pixel_hash_);
// Only encode and dump the png if the hashes don't match. Encoding the
// image is really expensive.
@@ -307,17 +324,17 @@ void WebKitTestController::OnImageDump(
&png);
#endif
if (success)
- printer_.PrintImageBlock(png);
+ printer_->PrintImageBlock(png);
}
- printer_.PrintImageFooter();
+ printer_->PrintImageFooter();
MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
}
void WebKitTestController::OnTextDump(const std::string& dump) {
- printer_.PrintTextBlock(dump);
- printer_.PrintTextFooter();
+ printer_->PrintTextBlock(dump);
+ printer_->PrintTextFooter();
if (dump_as_text_ || !enable_pixel_dumping_) {
- printer_.PrintImageFooter();
+ printer_->PrintImageFooter();
MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
}
}

Powered by Google App Engine
This is Rietveld 408576698