Add testRunner.copyAtAndCapturePixelsAsyncThen() method

Added method to allow "copy image" menu tests for elements that
need capturePixels to verify test results.

BUG=392765

Review URL: https://codereview.chromium.org/396953002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284098 0039d316-1c4b-4281-b951-d872f2087c98
parent b63f1d6d
...@@ -281,6 +281,9 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> { ...@@ -281,6 +281,9 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
void DisplayAsync(); void DisplayAsync();
void DisplayAsyncThen(v8::Handle<v8::Function> callback); void DisplayAsyncThen(v8::Handle<v8::Function> callback);
void CapturePixelsAsyncThen(v8::Handle<v8::Function> callback); void CapturePixelsAsyncThen(v8::Handle<v8::Function> callback);
void CopyImageAtAndCapturePixelsAsyncThen(int x,
int y,
v8::Handle<v8::Function> callback);
void SetCustomTextOutput(std::string output); void SetCustomTextOutput(std::string output);
void SetViewSourceForFrame(const std::string& name, bool enabled); void SetViewSourceForFrame(const std::string& name, bool enabled);
void SetMockPushClientSuccess(const std::string& endpoint, void SetMockPushClientSuccess(const std::string& endpoint,
...@@ -528,6 +531,8 @@ gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder( ...@@ -528,6 +531,8 @@ gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
.SetMethod("displayAsyncThen", &TestRunnerBindings::DisplayAsyncThen) .SetMethod("displayAsyncThen", &TestRunnerBindings::DisplayAsyncThen)
.SetMethod("capturePixelsAsyncThen", .SetMethod("capturePixelsAsyncThen",
&TestRunnerBindings::CapturePixelsAsyncThen) &TestRunnerBindings::CapturePixelsAsyncThen)
.SetMethod("copyImageAtAndCapturePixelsAsyncThen",
&TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen)
.SetMethod("setCustomTextOutput", .SetMethod("setCustomTextOutput",
&TestRunnerBindings::SetCustomTextOutput) &TestRunnerBindings::SetCustomTextOutput)
.SetMethod("setViewSourceForFrame", .SetMethod("setViewSourceForFrame",
...@@ -1350,6 +1355,12 @@ void TestRunnerBindings::CapturePixelsAsyncThen( ...@@ -1350,6 +1355,12 @@ void TestRunnerBindings::CapturePixelsAsyncThen(
runner_->CapturePixelsAsyncThen(callback); runner_->CapturePixelsAsyncThen(callback);
} }
void TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen(
int x, int y, v8::Handle<v8::Function> callback) {
if (runner_)
runner_->CopyImageAtAndCapturePixelsAsyncThen(x, y, callback);
}
void TestRunnerBindings::SetCustomTextOutput(std::string output) { void TestRunnerBindings::SetCustomTextOutput(std::string output) {
runner_->setCustomTextOutput(output); runner_->setCustomTextOutput(output);
} }
...@@ -2789,6 +2800,16 @@ void TestRunner::CapturePixelsAsyncThen(v8::Handle<v8::Function> callback) { ...@@ -2789,6 +2800,16 @@ void TestRunner::CapturePixelsAsyncThen(v8::Handle<v8::Function> callback) {
base::Passed(&task))); base::Passed(&task)));
} }
void TestRunner::CopyImageAtAndCapturePixelsAsyncThen(
int x, int y, v8::Handle<v8::Function> callback) {
scoped_ptr<InvokeCallbackTask> task(
new InvokeCallbackTask(this, callback));
proxy_->CopyImageAtAndCapturePixels(
x, y, base::Bind(&TestRunner::CapturePixelsCallback,
base::Unretained(this),
base::Passed(&task)));
}
void TestRunner::CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task, void TestRunner::CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task,
const SkBitmap& snapshot) { const SkBitmap& snapshot) {
v8::Isolate* isolate = blink::mainThreadIsolate(); v8::Isolate* isolate = blink::mainThreadIsolate();
...@@ -2803,12 +2824,12 @@ void TestRunner::CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task, ...@@ -2803,12 +2824,12 @@ void TestRunner::CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task,
v8::Handle<v8::Value> argv[3]; v8::Handle<v8::Value> argv[3];
SkAutoLockPixels snapshot_lock(snapshot); SkAutoLockPixels snapshot_lock(snapshot);
// Size can be 0 for cases where copyImageAt was called on position
// that doesn't have an image.
int width = snapshot.info().fWidth; int width = snapshot.info().fWidth;
DCHECK_NE(0, width);
argv[0] = v8::Number::New(isolate, width); argv[0] = v8::Number::New(isolate, width);
int height = snapshot.info().fHeight; int height = snapshot.info().fHeight;
DCHECK_NE(0, height);
argv[1] = v8::Number::New(isolate, height); argv[1] = v8::Number::New(isolate, height);
blink::WebArrayBuffer buffer = blink::WebArrayBuffer buffer =
......
...@@ -542,6 +542,12 @@ class TestRunner : public WebTestRunner, ...@@ -542,6 +542,12 @@ class TestRunner : public WebTestRunner,
// snapshot (width, height, snapshot) to the callback. The snapshot is in // snapshot (width, height, snapshot) to the callback. The snapshot is in
// uint8 RGBA format. // uint8 RGBA format.
void CapturePixelsAsyncThen(v8::Handle<v8::Function> callback); void CapturePixelsAsyncThen(v8::Handle<v8::Function> callback);
// Similar to CapturePixelsAsyncThen(). Copies to the clipboard the image
// located at a particular point in the WebView (if there is such an image),
// reads back its pixels, and provides the snapshot to the callback. If there
// is no image at that point, calls the callback with (0, 0, empty_snapshot).
void CopyImageAtAndCapturePixelsAsyncThen(
int x, int y, const v8::Handle<v8::Function> callback);
void SetMockPushClientSuccess(const std::string& endpoint, void SetMockPushClientSuccess(const std::string& endpoint,
const std::string& registration_id); const std::string& registration_id);
......
...@@ -26,7 +26,9 @@ ...@@ -26,7 +26,9 @@
#include "content/shell/renderer/test_runner/web_test_runner.h" #include "content/shell/renderer/test_runner/web_test_runner.h"
// FIXME: Including platform_canvas.h here is a layering violation. // FIXME: Including platform_canvas.h here is a layering violation.
#include "skia/ext/platform_canvas.h" #include "skia/ext/platform_canvas.h"
#include "third_party/WebKit/public/platform/Platform.h"
#include "third_party/WebKit/public/platform/WebCString.h" #include "third_party/WebKit/public/platform/WebCString.h"
#include "third_party/WebKit/public/platform/WebClipboard.h"
#include "third_party/WebKit/public/platform/WebURLError.h" #include "third_party/WebKit/public/platform/WebURLError.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h" #include "third_party/WebKit/public/platform/WebURLRequest.h"
#include "third_party/WebKit/public/platform/WebURLResponse.h" #include "third_party/WebKit/public/platform/WebURLResponse.h"
...@@ -468,6 +470,28 @@ void WebTestProxyBase::SetAcceptLanguages(const std::string& accept_languages) { ...@@ -468,6 +470,28 @@ void WebTestProxyBase::SetAcceptLanguages(const std::string& accept_languages) {
GetWebView()->acceptLanguagesChanged(); GetWebView()->acceptLanguagesChanged();
} }
void WebTestProxyBase::CopyImageAtAndCapturePixels(
int x, int y, const base::Callback<void(const SkBitmap&)>& callback) {
DCHECK(web_widget_->isAcceleratedCompositingActive());
DCHECK(!callback.is_null());
uint64_t sequence_number = blink::Platform::current()->clipboard()->
sequenceNumber(blink::WebClipboard::Buffer());
GetWebView()->copyImageAt(blink::WebPoint(x, y));
if (sequence_number == blink::Platform::current()->clipboard()->
sequenceNumber(blink::WebClipboard::Buffer())) {
SkBitmap emptyBitmap;
callback.Run(emptyBitmap);
return;
}
blink::WebData data = blink::Platform::current()->clipboard()->readImage(
blink::WebClipboard::Buffer());
blink::WebImage image = blink::WebImage::fromData(data, blink::WebSize());
const SkBitmap& bitmap = image.getSkBitmap();
SkAutoLockPixels autoLock(bitmap);
callback.Run(bitmap);
}
void WebTestProxyBase::CapturePixelsForPrinting( void WebTestProxyBase::CapturePixelsForPrinting(
const base::Callback<void(const SkBitmap&)>& callback) { const base::Callback<void(const SkBitmap&)>& callback) {
web_widget_->layout(); web_widget_->layout();
......
...@@ -116,6 +116,8 @@ class WebTestProxyBase : public blink::WebCompositeAndReadbackAsyncCallback { ...@@ -116,6 +116,8 @@ class WebTestProxyBase : public blink::WebCompositeAndReadbackAsyncCallback {
std::string CaptureTree(bool debug_render_tree); std::string CaptureTree(bool debug_render_tree);
void CapturePixelsForPrinting( void CapturePixelsForPrinting(
const base::Callback<void(const SkBitmap&)>& callback); const base::Callback<void(const SkBitmap&)>& callback);
void CopyImageAtAndCapturePixels(
int x, int y, const base::Callback<void(const SkBitmap&)>& callback);
void CapturePixelsAsync( void CapturePixelsAsync(
const base::Callback<void(const SkBitmap&)>& callback); const base::Callback<void(const SkBitmap&)>& callback);
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <algorithm> #include <algorithm>
#include "base/logging.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -26,10 +25,16 @@ using blink::WebVector; ...@@ -26,10 +25,16 @@ using blink::WebVector;
namespace content { namespace content {
MockWebClipboardImpl::MockWebClipboardImpl() {} MockWebClipboardImpl::MockWebClipboardImpl()
: m_sequenceNumber(0),
m_writeSmartPaste(false) {}
MockWebClipboardImpl::~MockWebClipboardImpl() {} MockWebClipboardImpl::~MockWebClipboardImpl() {}
uint64_t MockWebClipboardImpl::sequenceNumber(Buffer) {
return m_sequenceNumber;
}
bool MockWebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { bool MockWebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) {
switch (format) { switch (format) {
case FormatPlainText: case FormatPlainText:
...@@ -130,12 +135,14 @@ void MockWebClipboardImpl::writeHTML(const blink::WebString& htmlText, ...@@ -130,12 +135,14 @@ void MockWebClipboardImpl::writeHTML(const blink::WebString& htmlText,
m_htmlText = htmlText; m_htmlText = htmlText;
m_plainText = plainText; m_plainText = plainText;
m_writeSmartPaste = writeSmartPaste; m_writeSmartPaste = writeSmartPaste;
++m_sequenceNumber;
} }
void MockWebClipboardImpl::writePlainText(const blink::WebString& plain_text) { void MockWebClipboardImpl::writePlainText(const blink::WebString& plain_text) {
clear(); clear();
m_plainText = plain_text; m_plainText = plain_text;
++m_sequenceNumber;
} }
void MockWebClipboardImpl::writeURL(const blink::WebURL& url, void MockWebClipboardImpl::writeURL(const blink::WebURL& url,
...@@ -144,6 +151,7 @@ void MockWebClipboardImpl::writeURL(const blink::WebURL& url, ...@@ -144,6 +151,7 @@ void MockWebClipboardImpl::writeURL(const blink::WebURL& url,
m_htmlText = WebString::fromUTF8(URLToMarkup(url, title)); m_htmlText = WebString::fromUTF8(URLToMarkup(url, title));
m_plainText = url.spec().utf16(); m_plainText = url.spec().utf16();
++m_sequenceNumber;
} }
void MockWebClipboardImpl::writeImage(const blink::WebImage& image, void MockWebClipboardImpl::writeImage(const blink::WebImage& image,
...@@ -155,6 +163,7 @@ void MockWebClipboardImpl::writeImage(const blink::WebImage& image, ...@@ -155,6 +163,7 @@ void MockWebClipboardImpl::writeImage(const blink::WebImage& image,
m_plainText = m_htmlText; m_plainText = m_htmlText;
m_htmlText = WebString::fromUTF8(URLToImageMarkup(url, title)); m_htmlText = WebString::fromUTF8(URLToImageMarkup(url, title));
m_image = image; m_image = image;
++m_sequenceNumber;
} }
} }
...@@ -166,6 +175,7 @@ void MockWebClipboardImpl::writeDataObject(const WebDragData& data) { ...@@ -166,6 +175,7 @@ void MockWebClipboardImpl::writeDataObject(const WebDragData& data) {
const WebDragData::Item& item = itemList[i]; const WebDragData::Item& item = itemList[i];
switch (item.storageType) { switch (item.storageType) {
case WebDragData::Item::StorageTypeString: { case WebDragData::Item::StorageTypeString: {
++m_sequenceNumber;
if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) { if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) {
m_plainText = item.stringData; m_plainText = item.stringData;
continue; continue;
......
...@@ -25,6 +25,7 @@ class MockWebClipboardImpl : public blink::WebClipboard { ...@@ -25,6 +25,7 @@ class MockWebClipboardImpl : public blink::WebClipboard {
MockWebClipboardImpl(); MockWebClipboardImpl();
virtual ~MockWebClipboardImpl(); virtual ~MockWebClipboardImpl();
virtual uint64_t sequenceNumber(Buffer);
virtual bool isFormatAvailable(blink::WebClipboard::Format format, virtual bool isFormatAvailable(blink::WebClipboard::Format format,
blink::WebClipboard::Buffer buffer); blink::WebClipboard::Buffer buffer);
virtual blink::WebVector<blink::WebString> readAvailableTypes( virtual blink::WebVector<blink::WebString> readAvailableTypes(
...@@ -53,6 +54,7 @@ class MockWebClipboardImpl : public blink::WebClipboard { ...@@ -53,6 +54,7 @@ class MockWebClipboardImpl : public blink::WebClipboard {
private: private:
void clear(); void clear();
uint64_t m_sequenceNumber;
base::NullableString16 m_plainText; base::NullableString16 m_plainText;
base::NullableString16 m_htmlText; base::NullableString16 m_htmlText;
blink::WebImage m_image; blink::WebImage m_image;
......
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