diff options
author | peter@chromium.org <peter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-17 11:54:43 +0000 |
---|---|---|
committer | peter@chromium.org <peter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-17 11:54:43 +0000 |
commit | a543c0acd1c9f50693b941254cdbf33dd70954b8 (patch) | |
tree | 1f8dfa034497bd533a1536a375e0086fdb9eac67 /content/shell/webkit_test_controller.cc | |
parent | 2422af4f66861389da1a1d3f0d36f8872a0d7b4b (diff) | |
download | chromium_src-a543c0acd1c9f50693b941254cdbf33dd70954b8.zip chromium_src-a543c0acd1c9f50693b941254cdbf33dd70954b8.tar.gz chromium_src-a543c0acd1c9f50693b941254cdbf33dd70954b8.tar.bz2 |
content_shell: allow binary layout test data to be encoded with base64.
This patch implements a new command line option, --encode-binary, which
tells the WebKitTestResultPrinter to encode binary layout test result
data (such as images and audio) with base64 prior to outputting it.
Android needs this because of the FIFOs being used. This functionality
was already part of DumpRenderTree.
BUG=232044
Review URL: https://chromiumcodereview.appspot.com/17033006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206705 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/shell/webkit_test_controller.cc')
-rw-r--r-- | content/shell/webkit_test_controller.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/content/shell/webkit_test_controller.cc b/content/shell/webkit_test_controller.cc index 62ca29e..b756a84 100644 --- a/content/shell/webkit_test_controller.cc +++ b/content/shell/webkit_test_controller.cc @@ -6,6 +6,7 @@ #include <iostream> +#include "base/base64.h" #include "base/command_line.h" #include "base/message_loop.h" #include "base/process_util.h" @@ -42,6 +43,7 @@ WebKitTestResultPrinter::WebKitTestResultPrinter( std::ostream* output, std::ostream* error) : state_(DURING_TEST), capture_text_only_(false), + encode_binary_data_(false), output_(output), error_(error) { } @@ -88,6 +90,11 @@ void WebKitTestResultPrinter::PrintImageBlock( if (state_ != IN_IMAGE_BLOCK || capture_text_only_) return; *output_ << "Content-Type: image/png\n"; + if (encode_binary_data_) { + PrintEncodedBinaryData(png_image); + return; + } + *output_ << "Content-Length: " << png_image.size() << "\n"; output_->write( reinterpret_cast<const char*>(&png_image[0]), png_image.size()); @@ -116,6 +123,11 @@ void WebKitTestResultPrinter::PrintAudioBlock( const std::vector<unsigned char>& audio_data) { if (state_ != IN_AUDIO_BLOCK || capture_text_only_) return; + if (encode_binary_data_) { + PrintEncodedBinaryData(audio_data); + return; + } + *output_ << "Content-Length: " << audio_data.size() << "\n"; output_->write( reinterpret_cast<const char*>(&audio_data[0]), audio_data.size()); @@ -154,6 +166,20 @@ void WebKitTestResultPrinter::AddErrorMessage(const std::string& message) { PrintImageFooter(); } +void WebKitTestResultPrinter::PrintEncodedBinaryData( + const std::vector<unsigned char>& data) { + *output_ << "Content-Transfer-Encoding: base64\n"; + + std::string data_base64; + DCHECK(base::Base64Encode( + base::StringPiece(reinterpret_cast<const char*>(&data[0]), data.size()), + &data_base64)); + + *output_ << "Content-Length: " << data_base64.length() << "\n"; + output_->write(data_base64.c_str(), data_base64.length()); +} + + // WebKitTestController ------------------------------------------------------- WebKitTestController* WebKitTestController::instance_ = NULL; @@ -170,6 +196,8 @@ WebKitTestController::WebKitTestController() CHECK(!instance_); instance_ = this; printer_.reset(new WebKitTestResultPrinter(&std::cout, &std::cerr)); + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEncodeBinary)) + printer_->set_encode_binary_data(true); registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CREATED, NotificationService::AllSources()); |