Commit e225b922 authored by jochen@chromium.org's avatar jochen@chromium.org

[content shell] Add support for layout tests using content_shell on Android (first step).

Added support for dumping pixel results, and signalling the server that we're
ready.

BUG=111316
TEST=none


Review URL: https://chromiumcodereview.appspot.com/10824351

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152202 0039d316-1c4b-4281-b951-d872f2087c98
parent 875db755
......@@ -5,6 +5,7 @@
#include "content/shell/layout_test_controller.h"
#include "base/md5.h"
#include "base/memory/scoped_ptr.h"
#include "base/stringprintf.h"
#include "content/public/renderer/render_view.h"
#include "content/shell/shell_messages.h"
......@@ -188,13 +189,29 @@ void LayoutTestController::OnCaptureImageDump(
SkAutoLockPixels snapshot_lock(snapshot);
base::MD5Digest digest;
#if defined(OS_ANDROID)
// On Android, pixel layout is RGBA, however, other Chrome platforms use BGRA.
const uint8_t* raw_pixels =
reinterpret_cast<const uint8_t*>(snapshot.getPixels());
size_t snapshot_size = snapshot.getSize();
scoped_array<uint8_t> reordered_pixels(new uint8_t[snapshot_size]);
for (size_t i = 0; i < snapshot_size; i += 4) {
reordered_pixels[i] = raw_pixels[i + 2];
reordered_pixels[i + 1] = raw_pixels[i + 1];
reordered_pixels[i + 2] = raw_pixels[i];
reordered_pixels[i + 3] = raw_pixels[i + 3];
}
base::MD5Sum(reordered_pixels.get(), snapshot_size, &digest);
#else
base::MD5Sum(snapshot.getPixels(), snapshot.getSize(), &digest);
#endif
std::string actual_pixel_hash = base::MD5DigestToBase16(digest);
if (actual_pixel_hash == expected_pixel_hash) {
SkBitmap empty_image;
Send(new ShellViewHostMsg_ImageDump(
routing_id(), actual_pixel_hash, empty_image));
return;
}
Send(new ShellViewHostMsg_ImageDump(
routing_id(), actual_pixel_hash, snapshot));
......
......@@ -118,11 +118,6 @@ void LayoutTestControllerHost::OnTextDump(const std::string& dump) {
void LayoutTestControllerHost::OnImageDump(
const std::string& actual_pixel_hash,
const SkBitmap& image) {
#if !defined(OS_ANDROID)
// DumpRenderTree is not currently supported for Android. Also, on Android
// the required webkit_support methods are not defined, so this method just
// doesn't compile.
SkAutoLockPixels image_lock(image);
printf("\nActualHash: %s\n", actual_pixel_hash.c_str());
......@@ -141,14 +136,27 @@ void LayoutTestControllerHost::OnImageDump(
bool discard_transparency = true;
#endif
if (webkit_support::EncodeBGRAPNGWithChecksum(
bool success = false;
#if defined(OS_ANDROID)
success = webkit_support::EncodeRGBAPNGWithChecksum(
reinterpret_cast<const unsigned char*>(image.getPixels()),
image.width(),
image.height(),
static_cast<int>(image.rowBytes()),
discard_transparency,
actual_pixel_hash,
&png);
#else
success = webkit_support::EncodeBGRAPNGWithChecksum(
reinterpret_cast<const unsigned char*>(image.getPixels()),
image.width(),
image.height(),
static_cast<int>(image.rowBytes()),
discard_transparency,
actual_pixel_hash,
&png)) {
&png);
#endif
if (success) {
printf("Content-Type: image/png\n");
printf("Content-Length: %u\n", static_cast<unsigned>(png.size()));
fwrite(&png[0], 1, png.size(), stdout);
......@@ -156,7 +164,6 @@ void LayoutTestControllerHost::OnImageDump(
}
MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
#endif
}
void LayoutTestControllerHost::OnNotifyDone() {
......
......@@ -20,12 +20,6 @@ namespace {
GURL GetURLForLayoutTest(const char* test_name,
std::string* expected_pixel_hash) {
#if defined(OS_ANDROID)
// DumpRenderTree is not currently supported for Android using the content
// shell.
NOTIMPLEMENTED();
return GURL::EmptyGURL();
#else
std::string path_or_url = test_name;
std::string pixel_hash;
std::string::size_type separator_position = path_or_url.find('\'');
......@@ -42,7 +36,6 @@ GURL GetURLForLayoutTest(const char* test_name,
webkit_support::SetCurrentDirectoryForFileURL(test_url);
}
return test_url;
#endif
}
} // namespace
......@@ -71,6 +64,11 @@ int ShellBrowserMain(const content::MainFunctionParams& parameters) {
static_cast<content::ShellContentBrowserClient*>(
content::GetContentClient()->browser())->browser_context();
#if defined(OS_ANDROID)
puts("#READY");
fflush(stdout);
#endif
while (fgets(test_string, sizeof(test_string), stdin)) {
char *new_line_position = strchr(test_string, '\n');
if (new_line_position)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment