Chromium Code Reviews| Index: content/shell/renderer/test_runner/web_test_proxy.cc |
| diff --git a/content/shell/renderer/test_runner/web_test_proxy.cc b/content/shell/renderer/test_runner/web_test_proxy.cc |
| index b299810c7fb4872e31b2313ad953fb16a7286d5a..1d0b5af88cbf6ee721f2c718a233f3665f281420 100644 |
| --- a/content/shell/renderer/test_runner/web_test_proxy.cc |
| +++ b/content/shell/renderer/test_runner/web_test_proxy.cc |
| @@ -47,16 +47,36 @@ |
| #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| #include "third_party/WebKit/public/web/WebMIDIClientMock.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/WebPrintParams.h" |
| #include "third_party/WebKit/public/web/WebRange.h" |
| #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| #include "third_party/WebKit/public/web/WebView.h" |
| +#include "third_party/WebKit/public/web/WebWidgetClient.h" |
| namespace content { |
| 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(gfx::Point position) { popup_position_ = position; } |
|
tkent
2014/09/18 05:30:40
gfx::Point -> const gfx::Point&
keishi
2014/09/18 05:54:20
Done.
|
| + |
| + // 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> { |
| public: |
| typedef void (WebTestProxyBase::*CallbackMethodType)(); |
| @@ -332,7 +352,7 @@ WebTestProxyBase::~WebTestProxyBase() { |
| 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()); |
| + //CHECK_EQ(0u, composite_and_readback_callbacks_.size()); |
|
tkent
2014/09/18 05:30:40
Remove this line and the above comment.
keishi
2014/09/18 05:54:20
Done.
|
| } |
| void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) { |
| @@ -457,20 +477,6 @@ void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) { |
| canvas->drawIRect(rect, paint); |
| } |
| -void WebTestProxyBase::didCompositeAndReadback(const SkBitmap& bitmap) { |
| - TRACE_EVENT2("shell", |
|
tkent
2014/09/18 05:30:41
Can you move the TRACE_EVENT2 to CaptureCallback::
keishi
2014/09/18 05:54:20
Done.
|
| - "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) { |
| bool notify = accept_languages_ != accept_languages; |
| accept_languages_ = accept_languages; |
| @@ -527,6 +533,30 @@ void WebTestProxyBase::CapturePixelsForPrinting( |
| 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) { |
| + 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( |
| const base::Callback<void(const SkBitmap&)>& callback) { |
| TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); |
| @@ -543,8 +573,15 @@ void WebTestProxyBase::CapturePixelsAsync( |
| return; |
| } |
| - composite_and_readback_callbacks_.push_back(callback); |
| - web_widget_->compositeAndReadbackAsync(this); |
| + CaptureCallback* capture_callback = new CaptureCallback(callback); |
| + web_widget_->compositeAndReadbackAsync(capture_callback); |
| + if (blink::WebPagePopup* popup = web_widget_->pagePopup()) { |
| + capture_callback->set_wait_for_popup(true); |
| + blink::WebPoint popup_position = popup->positionRelativeToOwner(); |
| + capture_callback->set_popup_position( |
|
tkent
2014/09/18 05:30:40
I think we can write this like:
capture_callba
|
| + gfx::Point(popup_position.x, popup_position.y)); |
| + popup->compositeAndReadbackAsync(capture_callback); |
| + } |
| } |
| void WebTestProxyBase::SetLogConsoleOutput(bool enabled) { |