Commit 20971a65 authored by lukasza's avatar lukasza Committed by Commit Bot

Split DumpPixelsAsync in pixel_dump.h into more granular functions.

Before this CL, test_runner/pixel_dump.h would expose a single function:

  void DumpPixelsAsync(
      blink::WebView* web_view,
      const LayoutTestRuntimeFlags& layout_test_runtime_flags,
      float device_scale_factor_for_test,
      const base::Callback<void(const SkBitmap&)>& callback);

After this CL, three more granular functions are exposed instead:

  void DumpPixelsAsync(blink::WebLocalFrame* web_frame,
                       float device_scale_factor_for_test,
                       base::OnceCallback<void(const SkBitmap&)> callback);

  void PrintFrameAsync(blink::WebLocalFrame* web_frame,
                       base::OnceCallback<void(const SkBitmap&)> callback);

  base::OnceCallback<void(const SkBitmap&)>
  CreateSelectionBoundsRectDrawingCallback(
      blink::WebLocalFrame* web_frame,
      base::OnceCallback<void(const SkBitmap&)> original_callback);

This change means that it is easier to replace only the new DumpPixelsAsync
part, while retaining the old behavior for PrintFrameAsync and
CreateSelectionDrawingCallback.  In particular, a future CL should attempt to
delegate DumpPixelsAsync to the browser, so that pixels belonging to OOPIFs are
also captured.

BUG=667551

Review-Url: https://codereview.chromium.org/2963593002
Cr-Commit-Position: refs/heads/master@{#485774}
parent dcbb1b6e
......@@ -923,8 +923,13 @@ void BlinkTestRunner::CaptureDumpContinued() {
interfaces->TestRunner()->ShouldGeneratePixelResults() &&
!interfaces->TestRunner()->ShouldDumpAsAudio()) {
CHECK(render_view()->GetWebView()->IsAcceleratedCompositingActive());
// Test finish should only be processed in the BlinkTestRunner associated
// with the current, non-swapped-out RenderView.
DCHECK(render_view()->GetWebView()->MainFrame()->IsWebLocalFrame());
interfaces->TestRunner()->DumpPixelsAsync(
render_view()->GetWebView(),
render_view()->GetWebView()->MainFrame()->ToWebLocalFrame(),
base::Bind(&BlinkTestRunner::OnPixelsDumpCompleted,
base::Unretained(this)));
return;
......
This diff is collapsed.
......@@ -6,34 +6,43 @@
#define CONTENT_SHELL_TEST_RUNNER_PIXEL_DUMP_H_
#include "base/callback_forward.h"
#include "content/shell/test_runner/test_runner_export.h"
class SkBitmap;
namespace blink {
class WebView;
class WebLocalFrame;
} // namespace blink
namespace test_runner {
class LayoutTestRuntimeFlags;
// Dumps image snapshot of |web_view|. Exact dump mode depends on |flags| (i.e.
// dump_selection_rect and/or is_printing). Caller needs to ensure that
// |layout_test_runtime_flags| stays alive until |callback| gets called.
TEST_RUNNER_EXPORT void DumpPixelsAsync(
blink::WebView* web_view,
const LayoutTestRuntimeFlags& layout_test_runtime_flags,
float device_scale_factor_for_test,
const base::Callback<void(const SkBitmap&)>& callback);
// Copy to clipboard the image present at |x|, |y| coordinates in |web_view|
// Asks |web_frame|'s widget to dump its pixels and calls |callback| with the
// result.
void DumpPixelsAsync(blink::WebLocalFrame* web_frame,
float device_scale_factor_for_test,
base::OnceCallback<void(const SkBitmap&)> callback);
// Asks |web_frame| to print itself and calls |callback| with the result.
void PrintFrameAsync(blink::WebLocalFrame* web_frame,
base::OnceCallback<void(const SkBitmap&)> callback);
// Captures the current selection bounds rect of |web_frame| and creates a
// callback that will draw the rect (if any) on top of the |original_bitmap|,
// before passing |bitmap_with_selection_bounds_rect| to the
// |original_callback|. Selection bounds rect is the rect enclosing the
// (possibly transformed) selection.
base::OnceCallback<void(const SkBitmap& original_bitmap)>
CreateSelectionBoundsRectDrawingCallback(
blink::WebLocalFrame* web_frame,
base::OnceCallback<void(const SkBitmap& bitmap_with_selection_bounds_rect)>
original_callback);
// Copy to clipboard the image present at |x|, |y| coordinates in |web_frame|
// and pass the captured image to |callback|.
void CopyImageAtAndCapturePixels(
blink::WebView* web_view,
blink::WebLocalFrame* web_frame,
int x,
int y,
const base::Callback<void(const SkBitmap&)>& callback);
base::OnceCallback<void(const SkBitmap&)> callback);
} // namespace test_runner
......
......@@ -1768,8 +1768,8 @@ std::string TestRunner::DumpLayout(blink::WebLocalFrame* frame) {
}
void TestRunner::DumpPixelsAsync(
blink::WebView* web_view,
const base::Callback<void(const SkBitmap&)>& callback) {
blink::WebLocalFrame* frame,
base::OnceCallback<void(const SkBitmap&)> callback) {
if (layout_test_runtime_flags_.dump_drag_image()) {
if (drag_image_.IsNull()) {
// This means the test called dumpDragImage but did not initiate a drag.
......@@ -1777,16 +1777,29 @@ void TestRunner::DumpPixelsAsync(
SkBitmap bitmap;
bitmap.allocN32Pixels(1, 1);
bitmap.eraseColor(0);
callback.Run(bitmap);
std::move(callback).Run(bitmap);
return;
}
callback.Run(drag_image_.GetSkBitmap());
std::move(callback).Run(drag_image_.GetSkBitmap());
return;
}
test_runner::DumpPixelsAsync(web_view, layout_test_runtime_flags_,
delegate_->GetDeviceScaleFactor(), callback);
// See if we need to draw the selection bounds rect on top of the snapshot.
if (layout_test_runtime_flags_.dump_selection_rect()) {
callback =
CreateSelectionBoundsRectDrawingCallback(frame, std::move(callback));
}
// Request appropriate kind of pixel dump.
if (layout_test_runtime_flags_.is_printing()) {
test_runner::PrintFrameAsync(frame, std::move(callback));
} else {
// TODO(lukasza): Ask the |delegate_| to capture the pixels in the browser
// process, so that OOPIF pixels are also captured.
test_runner::DumpPixelsAsync(frame, delegate_->GetDeviceScaleFactor(),
std::move(callback));
}
}
void TestRunner::ReplicateLayoutTestRuntimeFlagsChanges(
......
......@@ -93,8 +93,8 @@ class TestRunner : public WebTestRunner {
bool IsRecursiveLayoutDumpRequested() override;
std::string DumpLayout(blink::WebLocalFrame* frame) override;
void DumpPixelsAsync(
blink::WebView* web_view,
const base::Callback<void(const SkBitmap&)>& callback) override;
blink::WebLocalFrame* frame,
base::OnceCallback<void(const SkBitmap&)> callback) override;
void ReplicateLayoutTestRuntimeFlagsChanges(
const base::DictionaryValue& changed_values) override;
bool HasCustomTextDump(std::string* custom_text_dump) const override;
......
......@@ -233,10 +233,14 @@ void TestRunnerForSpecificView::CapturePixelsAsyncThen(
v8::UniquePersistent<v8::Function> persistent_callback(
blink::MainThreadIsolate(), callback);
CHECK(web_view()->MainFrame()->IsWebLocalFrame())
<< "Layout tests harness doesn't currently support running "
<< "testRuner.capturePixelsAsyncThen from an OOPIF";
web_view_test_proxy_base_->test_interfaces()
->GetTestRunner()
->DumpPixelsAsync(
web_view(),
web_view()->MainFrame()->ToWebLocalFrame(),
base::Bind(&TestRunnerForSpecificView::CapturePixelsCallback,
weak_factory_.GetWeakPtr(),
base::Passed(std::move(persistent_callback))));
......@@ -289,8 +293,14 @@ void TestRunnerForSpecificView::CopyImageAtAndCapturePixelsAsyncThen(
v8::UniquePersistent<v8::Function> persistent_callback(
blink::MainThreadIsolate(), callback);
// TODO(lukasza): Support image capture in OOPIFs for
// https://crbug.com/477150.
CHECK(web_view()->MainFrame()->IsWebLocalFrame())
<< "Layout tests harness doesn't support calling "
<< "testRunner.copyImageAtAndCapturePixelsAsyncThen from an OOPIF.";
CopyImageAtAndCapturePixels(
web_view(), x, y,
web_view()->MainFrame()->ToWebLocalFrame(), x, y,
base::Bind(&TestRunnerForSpecificView::CapturePixelsCallback,
weak_factory_.GetWeakPtr(),
base::Passed(std::move(persistent_callback))));
......
......@@ -56,8 +56,8 @@ class WebTestRunner {
// and calls |callback| with the result. Caller needs to ensure that
// |web_view| stays alive until |callback| is called.
virtual void DumpPixelsAsync(
blink::WebView* web_view,
const base::Callback<void(const SkBitmap&)>& callback) = 0;
blink::WebLocalFrame* frame,
base::OnceCallback<void(const SkBitmap&)> callback) = 0;
// Replicates changes to layout test runtime flags
// (i.e. changes that happened in another renderer).
......
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