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

Unified Diff: content/shell/renderer/test_runner/web_test_proxy.cc

Issue 508063002: Draw page popups in layout tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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/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 983c864de63e11ac90444219d6c8c377dd1f7606..c94e4c07547e8534563b246953cd13ca2b62ffb8 100644
--- a/content/shell/renderer/test_runner/web_test_proxy.cc
+++ b/content/shell/renderer/test_runner/web_test_proxy.cc
@@ -48,16 +48,38 @@
#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(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> {
public:
typedef void (WebTestProxyBase::*CallbackMethodType)();
@@ -331,9 +353,6 @@ WebTestProxyBase::WebTestProxyBase()
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());
}
void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) {
@@ -458,20 +477,6 @@ void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) {
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) {
bool notify = accept_languages_ != accept_languages;
accept_languages_ = accept_languages;
@@ -528,6 +533,36 @@ 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) {
+ 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(
const base::Callback<void(const SkBitmap&)>& callback) {
TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync");
@@ -544,8 +579,14 @@ 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);
+ capture_callback->set_popup_position(
+ popup->positionRelativeToOwner());
+ popup->compositeAndReadbackAsync(capture_callback);
+ }
}
void WebTestProxyBase::SetLogConsoleOutput(bool enabled) {

Powered by Google App Engine
This is Rietveld 408576698