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() { ...@@ -923,8 +923,13 @@ void BlinkTestRunner::CaptureDumpContinued() {
interfaces->TestRunner()->ShouldGeneratePixelResults() && interfaces->TestRunner()->ShouldGeneratePixelResults() &&
!interfaces->TestRunner()->ShouldDumpAsAudio()) { !interfaces->TestRunner()->ShouldDumpAsAudio()) {
CHECK(render_view()->GetWebView()->IsAcceleratedCompositingActive()); 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( interfaces->TestRunner()->DumpPixelsAsync(
render_view()->GetWebView(), render_view()->GetWebView()->MainFrame()->ToWebLocalFrame(),
base::Bind(&BlinkTestRunner::OnPixelsDumpCompleted, base::Bind(&BlinkTestRunner::OnPixelsDumpCompleted,
base::Unretained(this))); base::Unretained(this)));
return; return;
......
This diff is collapsed.
...@@ -6,34 +6,43 @@ ...@@ -6,34 +6,43 @@
#define CONTENT_SHELL_TEST_RUNNER_PIXEL_DUMP_H_ #define CONTENT_SHELL_TEST_RUNNER_PIXEL_DUMP_H_
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "content/shell/test_runner/test_runner_export.h"
class SkBitmap; class SkBitmap;
namespace blink { namespace blink {
class WebView; class WebLocalFrame;
} // namespace blink } // namespace blink
namespace test_runner { namespace test_runner {
class LayoutTestRuntimeFlags; // Asks |web_frame|'s widget to dump its pixels and calls |callback| with the
// result.
// Dumps image snapshot of |web_view|. Exact dump mode depends on |flags| (i.e. void DumpPixelsAsync(blink::WebLocalFrame* web_frame,
// dump_selection_rect and/or is_printing). Caller needs to ensure that float device_scale_factor_for_test,
// |layout_test_runtime_flags| stays alive until |callback| gets called. base::OnceCallback<void(const SkBitmap&)> callback);
TEST_RUNNER_EXPORT void DumpPixelsAsync(
blink::WebView* web_view, // Asks |web_frame| to print itself and calls |callback| with the result.
const LayoutTestRuntimeFlags& layout_test_runtime_flags, void PrintFrameAsync(blink::WebLocalFrame* web_frame,
float device_scale_factor_for_test, base::OnceCallback<void(const SkBitmap&)> callback);
const base::Callback<void(const SkBitmap&)>& callback);
// Captures the current selection bounds rect of |web_frame| and creates a
// Copy to clipboard the image present at |x|, |y| coordinates in |web_view| // 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|. // and pass the captured image to |callback|.
void CopyImageAtAndCapturePixels( void CopyImageAtAndCapturePixels(
blink::WebView* web_view, blink::WebLocalFrame* web_frame,
int x, int x,
int y, int y,
const base::Callback<void(const SkBitmap&)>& callback); base::OnceCallback<void(const SkBitmap&)> callback);
} // namespace test_runner } // namespace test_runner
......
...@@ -1768,8 +1768,8 @@ std::string TestRunner::DumpLayout(blink::WebLocalFrame* frame) { ...@@ -1768,8 +1768,8 @@ std::string TestRunner::DumpLayout(blink::WebLocalFrame* frame) {
} }
void TestRunner::DumpPixelsAsync( void TestRunner::DumpPixelsAsync(
blink::WebView* web_view, blink::WebLocalFrame* frame,
const base::Callback<void(const SkBitmap&)>& callback) { base::OnceCallback<void(const SkBitmap&)> callback) {
if (layout_test_runtime_flags_.dump_drag_image()) { if (layout_test_runtime_flags_.dump_drag_image()) {
if (drag_image_.IsNull()) { if (drag_image_.IsNull()) {
// This means the test called dumpDragImage but did not initiate a drag. // This means the test called dumpDragImage but did not initiate a drag.
...@@ -1777,16 +1777,29 @@ void TestRunner::DumpPixelsAsync( ...@@ -1777,16 +1777,29 @@ void TestRunner::DumpPixelsAsync(
SkBitmap bitmap; SkBitmap bitmap;
bitmap.allocN32Pixels(1, 1); bitmap.allocN32Pixels(1, 1);
bitmap.eraseColor(0); bitmap.eraseColor(0);
callback.Run(bitmap); std::move(callback).Run(bitmap);
return; return;
} }
callback.Run(drag_image_.GetSkBitmap()); std::move(callback).Run(drag_image_.GetSkBitmap());
return; return;
} }
test_runner::DumpPixelsAsync(web_view, layout_test_runtime_flags_, // See if we need to draw the selection bounds rect on top of the snapshot.
delegate_->GetDeviceScaleFactor(), callback); 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( void TestRunner::ReplicateLayoutTestRuntimeFlagsChanges(
......
...@@ -93,8 +93,8 @@ class TestRunner : public WebTestRunner { ...@@ -93,8 +93,8 @@ class TestRunner : public WebTestRunner {
bool IsRecursiveLayoutDumpRequested() override; bool IsRecursiveLayoutDumpRequested() override;
std::string DumpLayout(blink::WebLocalFrame* frame) override; std::string DumpLayout(blink::WebLocalFrame* frame) override;
void DumpPixelsAsync( void DumpPixelsAsync(
blink::WebView* web_view, blink::WebLocalFrame* frame,
const base::Callback<void(const SkBitmap&)>& callback) override; base::OnceCallback<void(const SkBitmap&)> callback) override;
void ReplicateLayoutTestRuntimeFlagsChanges( void ReplicateLayoutTestRuntimeFlagsChanges(
const base::DictionaryValue& changed_values) override; const base::DictionaryValue& changed_values) override;
bool HasCustomTextDump(std::string* custom_text_dump) const override; bool HasCustomTextDump(std::string* custom_text_dump) const override;
......
...@@ -233,10 +233,14 @@ void TestRunnerForSpecificView::CapturePixelsAsyncThen( ...@@ -233,10 +233,14 @@ void TestRunnerForSpecificView::CapturePixelsAsyncThen(
v8::UniquePersistent<v8::Function> persistent_callback( v8::UniquePersistent<v8::Function> persistent_callback(
blink::MainThreadIsolate(), 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() web_view_test_proxy_base_->test_interfaces()
->GetTestRunner() ->GetTestRunner()
->DumpPixelsAsync( ->DumpPixelsAsync(
web_view(), web_view()->MainFrame()->ToWebLocalFrame(),
base::Bind(&TestRunnerForSpecificView::CapturePixelsCallback, base::Bind(&TestRunnerForSpecificView::CapturePixelsCallback,
weak_factory_.GetWeakPtr(), weak_factory_.GetWeakPtr(),
base::Passed(std::move(persistent_callback)))); base::Passed(std::move(persistent_callback))));
...@@ -289,8 +293,14 @@ void TestRunnerForSpecificView::CopyImageAtAndCapturePixelsAsyncThen( ...@@ -289,8 +293,14 @@ void TestRunnerForSpecificView::CopyImageAtAndCapturePixelsAsyncThen(
v8::UniquePersistent<v8::Function> persistent_callback( v8::UniquePersistent<v8::Function> persistent_callback(
blink::MainThreadIsolate(), 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( CopyImageAtAndCapturePixels(
web_view(), x, y, web_view()->MainFrame()->ToWebLocalFrame(), x, y,
base::Bind(&TestRunnerForSpecificView::CapturePixelsCallback, base::Bind(&TestRunnerForSpecificView::CapturePixelsCallback,
weak_factory_.GetWeakPtr(), weak_factory_.GetWeakPtr(),
base::Passed(std::move(persistent_callback)))); base::Passed(std::move(persistent_callback))));
......
...@@ -56,8 +56,8 @@ class WebTestRunner { ...@@ -56,8 +56,8 @@ class WebTestRunner {
// and calls |callback| with the result. Caller needs to ensure that // and calls |callback| with the result. Caller needs to ensure that
// |web_view| stays alive until |callback| is called. // |web_view| stays alive until |callback| is called.
virtual void DumpPixelsAsync( virtual void DumpPixelsAsync(
blink::WebView* web_view, blink::WebLocalFrame* frame,
const base::Callback<void(const SkBitmap&)>& callback) = 0; base::OnceCallback<void(const SkBitmap&)> callback) = 0;
// Replicates changes to layout test runtime flags // Replicates changes to layout test runtime flags
// (i.e. changes that happened in another renderer). // (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