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

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
« no previous file with comments | « content/shell/renderer/test_runner/web_test_proxy.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..cf8a288fb667aa71aab14838c0db9dcad9a807da 100644
--- a/content/shell/renderer/test_runner/web_test_proxy.cc
+++ b/content/shell/renderer/test_runner/web_test_proxy.cc
@@ -34,6 +34,7 @@
#include "third_party/WebKit/public/platform/Platform.h"
#include "third_party/WebKit/public/platform/WebCString.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/WebURLRequest.h"
#include "third_party/WebKit/public/platform/WebURLResponse.h"
@@ -48,16 +49,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 +354,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 +478,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 +534,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 +580,23 @@ void WebTestProxyBase::CapturePixelsAsync(
return;
}
- composite_and_readback_callbacks_.push_back(callback);
- web_widget_->compositeAndReadbackAsync(this);
+ CaptureCallback* capture_callback = new CaptureCallback(base::Bind(
+ &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);
keishi 2014/09/18 09:14:17 I forgot to call DrawSelectionRect in my previous
+ if (!callback.is_null())
+ callback.Run(bitmap);
}
void WebTestProxyBase::SetLogConsoleOutput(bool enabled) {
« no previous file with comments | « content/shell/renderer/test_runner/web_test_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698