Commit 9b51e6b4 authored by keishi's avatar keishi Committed by Commit bot

Draw page popups in layout tests

BUG=409503

Review URL: https://codereview.chromium.org/508063002

Cr-Commit-Position: refs/heads/master@{#295454}
parent 288942a7
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "third_party/WebKit/public/platform/Platform.h" #include "third_party/WebKit/public/platform/Platform.h"
#include "third_party/WebKit/public/platform/WebCString.h" #include "third_party/WebKit/public/platform/WebCString.h"
#include "third_party/WebKit/public/platform/WebClipboard.h" #include "third_party/WebKit/public/platform/WebClipboard.h"
#include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallback.h"
#include "third_party/WebKit/public/platform/WebURLError.h" #include "third_party/WebKit/public/platform/WebURLError.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h" #include "third_party/WebKit/public/platform/WebURLRequest.h"
#include "third_party/WebKit/public/platform/WebURLResponse.h" #include "third_party/WebKit/public/platform/WebURLResponse.h"
...@@ -48,16 +49,38 @@ ...@@ -48,16 +49,38 @@
#include "third_party/WebKit/public/web/WebLocalFrame.h" #include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebMIDIClientMock.h" #include "third_party/WebKit/public/web/WebMIDIClientMock.h"
#include "third_party/WebKit/public/web/WebNode.h" #include "third_party/WebKit/public/web/WebNode.h"
#include "third_party/WebKit/public/web/WebPagePopup.h"
#include "third_party/WebKit/public/web/WebPluginParams.h" #include "third_party/WebKit/public/web/WebPluginParams.h"
#include "third_party/WebKit/public/web/WebPrintParams.h" #include "third_party/WebKit/public/web/WebPrintParams.h"
#include "third_party/WebKit/public/web/WebRange.h" #include "third_party/WebKit/public/web/WebRange.h"
#include "third_party/WebKit/public/web/WebUserGestureIndicator.h" #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
#include "third_party/WebKit/public/web/WebView.h" #include "third_party/WebKit/public/web/WebView.h"
#include "third_party/WebKit/public/web/WebWidgetClient.h"
namespace content { namespace content {
namespace { namespace {
class CaptureCallback : public blink::WebCompositeAndReadbackAsyncCallback {
public:
CaptureCallback(const base::Callback<void(const SkBitmap&)>& callback);
virtual ~CaptureCallback();
void set_wait_for_popup(bool wait) { wait_for_popup_ = wait; }
void set_popup_position(const gfx::Point& position) {
popup_position_ = position;
}
// WebCompositeAndReadbackAsyncCallback implementation.
virtual void didCompositeAndReadback(const SkBitmap& bitmap);
private:
base::Callback<void(const SkBitmap&)> callback_;
SkBitmap main_bitmap_;
bool wait_for_popup_;
gfx::Point popup_position_;
};
class HostMethodTask : public WebMethodTask<WebTestProxyBase> { class HostMethodTask : public WebMethodTask<WebTestProxyBase> {
public: public:
typedef void (WebTestProxyBase::*CallbackMethodType)(); typedef void (WebTestProxyBase::*CallbackMethodType)();
...@@ -331,9 +354,6 @@ WebTestProxyBase::WebTestProxyBase() ...@@ -331,9 +354,6 @@ WebTestProxyBase::WebTestProxyBase()
WebTestProxyBase::~WebTestProxyBase() { WebTestProxyBase::~WebTestProxyBase() {
test_interfaces_->WindowClosed(this); test_interfaces_->WindowClosed(this);
// Tests must wait for readback requests to finish before notifying that
// they are done.
CHECK_EQ(0u, composite_and_readback_callbacks_.size());
} }
void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) { void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) {
...@@ -458,20 +478,6 @@ void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) { ...@@ -458,20 +478,6 @@ void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) {
canvas->drawIRect(rect, paint); canvas->drawIRect(rect, paint);
} }
void WebTestProxyBase::didCompositeAndReadback(const SkBitmap& bitmap) {
TRACE_EVENT2("shell",
"WebTestProxyBase::didCompositeAndReadback",
"x",
bitmap.info().fWidth,
"y",
bitmap.info().fHeight);
SkCanvas canvas(bitmap);
DrawSelectionRect(&canvas);
DCHECK(!composite_and_readback_callbacks_.empty());
composite_and_readback_callbacks_.front().Run(bitmap);
composite_and_readback_callbacks_.pop_front();
}
void WebTestProxyBase::SetAcceptLanguages(const std::string& accept_languages) { void WebTestProxyBase::SetAcceptLanguages(const std::string& accept_languages) {
bool notify = accept_languages_ != accept_languages; bool notify = accept_languages_ != accept_languages;
accept_languages_ = accept_languages; accept_languages_ = accept_languages;
...@@ -528,6 +534,36 @@ void WebTestProxyBase::CapturePixelsForPrinting( ...@@ -528,6 +534,36 @@ void WebTestProxyBase::CapturePixelsForPrinting(
callback.Run(bitmap); callback.Run(bitmap);
} }
CaptureCallback::CaptureCallback(
const base::Callback<void(const SkBitmap&)>& callback)
: callback_(callback), wait_for_popup_(false) {
}
CaptureCallback::~CaptureCallback() {
}
void CaptureCallback::didCompositeAndReadback(const SkBitmap& bitmap) {
TRACE_EVENT2("shell",
"CaptureCallback::didCompositeAndReadback",
"x",
bitmap.info().fWidth,
"y",
bitmap.info().fHeight);
if (!wait_for_popup_) {
callback_.Run(bitmap);
delete this;
return;
}
if (main_bitmap_.isNull()) {
bitmap.deepCopyTo(&main_bitmap_);
return;
}
SkCanvas canvas(main_bitmap_);
canvas.drawBitmap(bitmap, popup_position_.x(), popup_position_.y());
callback_.Run(main_bitmap_);
delete this;
}
void WebTestProxyBase::CapturePixelsAsync( void WebTestProxyBase::CapturePixelsAsync(
const base::Callback<void(const SkBitmap&)>& callback) { const base::Callback<void(const SkBitmap&)>& callback) {
TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync");
...@@ -544,8 +580,23 @@ void WebTestProxyBase::CapturePixelsAsync( ...@@ -544,8 +580,23 @@ void WebTestProxyBase::CapturePixelsAsync(
return; return;
} }
composite_and_readback_callbacks_.push_back(callback); CaptureCallback* capture_callback = new CaptureCallback(base::Bind(
web_widget_->compositeAndReadbackAsync(this); &WebTestProxyBase::DidCapturePixelsAsync, base::Unretained(this),
callback));
web_widget_->compositeAndReadbackAsync(capture_callback);
if (blink::WebPagePopup* popup = web_widget_->pagePopup()) {
capture_callback->set_wait_for_popup(true);
capture_callback->set_popup_position(popup->positionRelativeToOwner());
popup->compositeAndReadbackAsync(capture_callback);
}
}
void WebTestProxyBase::DidCapturePixelsAsync(const base::Callback<void(const SkBitmap&)>& callback,
const SkBitmap& bitmap) {
SkCanvas canvas(bitmap);
DrawSelectionRect(&canvas);
if (!callback.is_null())
callback.Run(bitmap);
} }
void WebTestProxyBase::SetLogConsoleOutput(bool enabled) { void WebTestProxyBase::SetLogConsoleOutput(bool enabled) {
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "content/shell/renderer/test_runner/web_task.h" #include "content/shell/renderer/test_runner/web_task.h"
#include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallback.h"
#include "third_party/WebKit/public/platform/WebRect.h" #include "third_party/WebKit/public/platform/WebRect.h"
#include "third_party/WebKit/public/platform/WebScreenInfo.h" #include "third_party/WebKit/public/platform/WebScreenInfo.h"
#include "third_party/WebKit/public/platform/WebURLError.h" #include "third_party/WebKit/public/platform/WebURLError.h"
...@@ -32,6 +31,7 @@ ...@@ -32,6 +31,7 @@
#include "third_party/WebKit/public/web/WebTextAffinity.h" #include "third_party/WebKit/public/web/WebTextAffinity.h"
#include "third_party/WebKit/public/web/WebTextDirection.h" #include "third_party/WebKit/public/web/WebTextDirection.h"
class SkBitmap;
class SkCanvas; class SkCanvas;
namespace blink { namespace blink {
...@@ -93,7 +93,7 @@ class WebTestInterfaces; ...@@ -93,7 +93,7 @@ class WebTestInterfaces;
// when it requires a behavior to be different from the usual, it will call // when it requires a behavior to be different from the usual, it will call
// WebTestProxyBase that implements the expected behavior. // WebTestProxyBase that implements the expected behavior.
// See WebTestProxy class comments for more information. // See WebTestProxy class comments for more information.
class WebTestProxyBase : public blink::WebCompositeAndReadbackAsyncCallback { class WebTestProxyBase {
public: public:
void SetInterfaces(WebTestInterfaces* interfaces); void SetInterfaces(WebTestInterfaces* interfaces);
void SetDelegate(WebTestDelegate* delegate); void SetDelegate(WebTestDelegate* delegate);
...@@ -141,9 +141,6 @@ class WebTestProxyBase : public blink::WebCompositeAndReadbackAsyncCallback { ...@@ -141,9 +141,6 @@ class WebTestProxyBase : public blink::WebCompositeAndReadbackAsyncCallback {
void PostSpellCheckEvent(const blink::WebString& event_name); void PostSpellCheckEvent(const blink::WebString& event_name);
// WebCompositeAndReadbackAsyncCallback implementation.
virtual void didCompositeAndReadback(const SkBitmap& bitmap);
void SetAcceptLanguages(const std::string& accept_languages); void SetAcceptLanguages(const std::string& accept_languages);
MockWebPushClient* GetPushClientMock(); MockWebPushClient* GetPushClientMock();
...@@ -253,6 +250,7 @@ class WebTestProxyBase : public blink::WebCompositeAndReadbackAsyncCallback { ...@@ -253,6 +250,7 @@ class WebTestProxyBase : public blink::WebCompositeAndReadbackAsyncCallback {
void CheckDone(blink::WebLocalFrame* frame, CheckDoneReason reason); void CheckDone(blink::WebLocalFrame* frame, CheckDoneReason reason);
void AnimateNow(); void AnimateNow();
void DrawSelectionRect(SkCanvas* canvas); void DrawSelectionRect(SkCanvas* canvas);
void DidCapturePixelsAsync(const base::Callback<void(const SkBitmap&)>& callback, const SkBitmap& bitmap);
void DidDisplayAsync(const base::Closure& callback, const SkBitmap& bitmap); void DidDisplayAsync(const base::Closure& callback, const SkBitmap& bitmap);
blink::WebWidget* web_widget() const { return web_widget_; } blink::WebWidget* web_widget() const { return web_widget_; }
...@@ -268,8 +266,6 @@ class WebTestProxyBase : public blink::WebCompositeAndReadbackAsyncCallback { ...@@ -268,8 +266,6 @@ class WebTestProxyBase : public blink::WebCompositeAndReadbackAsyncCallback {
bool animate_scheduled_; bool animate_scheduled_;
std::map<unsigned, std::string> resource_identifier_map_; std::map<unsigned, std::string> resource_identifier_map_;
std::deque<base::Callback<void(const SkBitmap&)> >
composite_and_readback_callbacks_;
bool log_console_output_; bool log_console_output_;
int chooser_count_; int chooser_count_;
......
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