summaryrefslogtreecommitdiffstats
path: root/webkit/tools/test_shell
diff options
context:
space:
mode:
authordcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-07 22:15:40 +0000
committerdcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-07 22:15:40 +0000
commit316d6c6b8c65f182af6f04bc68fbcd281cd43b28 (patch)
tree3e870ab03087e12a8da04f340afec8ea7da75340 /webkit/tools/test_shell
parentf4812211951630ac47b96a1b7b78f3a3dcc2b9b9 (diff)
downloadchromium_src-316d6c6b8c65f182af6f04bc68fbcd281cd43b28.zip
chromium_src-316d6c6b8c65f182af6f04bc68fbcd281cd43b28.tar.gz
chromium_src-316d6c6b8c65f182af6f04bc68fbcd281cd43b28.tar.bz2
Implement mock Clipboard::readImage() for WebKit layout tests.
BUG=75237 TEST=none Review URL: http://codereview.chromium.org/6691043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80852 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools/test_shell')
-rw-r--r--webkit/tools/test_shell/mock_webclipboard_impl.cc48
-rw-r--r--webkit/tools/test_shell/mock_webclipboard_impl.h9
2 files changed, 53 insertions, 4 deletions
diff --git a/webkit/tools/test_shell/mock_webclipboard_impl.cc b/webkit/tools/test_shell/mock_webclipboard_impl.cc
index 1e00f70..f7c19d9 100644
--- a/webkit/tools/test_shell/mock_webclipboard_impl.cc
+++ b/webkit/tools/test_shell/mock_webclipboard_impl.cc
@@ -1,16 +1,24 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/tools/test_shell/mock_webclipboard_impl.h"
#include "base/logging.h"
+#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "net/base/escape.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebCommon.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
#include "webkit/glue/webclipboard_impl.h"
#include "webkit/glue/webkit_glue.h"
+#include "webkit/support/webkit_support_gfx.h"
+
+#if WEBKIT_USING_CG
+#include <ApplicationServices/ApplicationServices.h>
+#include <CoreFoundation/CoreFoundation.h>
+#endif
using WebKit::WebString;
using WebKit::WebURL;
@@ -58,17 +66,50 @@ WebKit::WebString MockWebClipboardImpl::readHTML(
return m_htmlText;
}
+WebKit::WebData MockWebClipboardImpl::readImage(
+ WebKit::WebClipboard::Buffer buffer) {
+ std::string data;
+ std::vector<unsigned char> encoded_image;
+ // TODO(dcheng): Verify that we can assume the image is ARGB8888. Note that
+ // for endianess reasons, it will be BGRA8888 on Windows.
+#if WEBKIT_USING_SKIA
+ const SkBitmap& bitmap = m_image.getSkBitmap();
+ SkAutoLockPixels lock(bitmap);
+ webkit_support::EncodeBGRAPNG(static_cast<unsigned char*>(bitmap.getPixels()),
+ bitmap.width(),
+ bitmap.height(),
+ bitmap.rowBytes(),
+ false,
+ &encoded_image);
+#elif WEBKIT_USING_CG
+ CGImageRef image = m_image.getCGImageRef();
+ CFDataRef image_data_ref =
+ CGDataProviderCopyData(CGImageGetDataProvider(image));
+ webkit_support::EncodeRGBAPNG(CFDataGetBytePtr(image_data_ref),
+ CGImageGetWidth(image),
+ CGImageGetHeight(image),
+ CGImageGetBytesPerRow(image),
+ &encoded_image);
+ CFRelease(image_data_ref);
+#endif
+ data.assign(reinterpret_cast<char*>(vector_as_array(&encoded_image)),
+ encoded_image.size());
+ return data;
+}
+
void MockWebClipboardImpl::writeHTML(
const WebKit::WebString& htmlText, const WebKit::WebURL& url,
const WebKit::WebString& plainText, bool writeSmartPaste) {
m_htmlText = htmlText;
m_plainText = plainText;
+ m_image.reset();
m_writeSmartPaste = writeSmartPaste;
}
void MockWebClipboardImpl::writePlainText(const WebKit::WebString& plain_text) {
m_htmlText = WebKit::WebString();
m_plainText = plain_text;
+ m_image.reset();
m_writeSmartPaste = false;
}
@@ -77,6 +118,7 @@ void MockWebClipboardImpl::writeURL(
m_htmlText = WebString::fromUTF8(
webkit_glue::WebClipboardImpl::URLToMarkup(url, title));
m_plainText = url.spec().utf16();
+ m_image.reset();
m_writeSmartPaste = false;
}
@@ -86,6 +128,7 @@ void MockWebClipboardImpl::writeImage(const WebKit::WebImage& image,
m_htmlText = WebString::fromUTF8(
webkit_glue::WebClipboardImpl::URLToImageMarkup(url, title));
m_plainText = m_htmlText;
+ m_image = image;
m_writeSmartPaste = false;
}
}
@@ -100,5 +143,8 @@ WebVector<WebString> MockWebClipboardImpl::readAvailableTypes(
if (!m_htmlText.isEmpty()) {
results.push_back(WebString("text/html"));
}
+ if (!m_image.isNull()) {
+ results.push_back(WebString("image/png"));
+ }
return results;
}
diff --git a/webkit/tools/test_shell/mock_webclipboard_impl.h b/webkit/tools/test_shell/mock_webclipboard_impl.h
index 2cf4f2b..fa58109 100644
--- a/webkit/tools/test_shell/mock_webclipboard_impl.h
+++ b/webkit/tools/test_shell/mock_webclipboard_impl.h
@@ -1,6 +1,6 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
//
// This file mocks out just enough of the WebClipboard API for running the
// webkit tests. This is so we can run webkit tests without them sharing a
@@ -11,6 +11,7 @@
#define WEBKIT_TOOLS_TEST_SHELL_MOCK_WEBCLIPBOARD_IMPL_H_
#include "third_party/WebKit/Source/WebKit/chromium/public/WebClipboard.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
class MockWebClipboardImpl : public WebKit::WebClipboard {
public:
@@ -20,6 +21,7 @@ class MockWebClipboardImpl : public WebKit::WebClipboard {
virtual WebKit::WebString readPlainText(WebKit::WebClipboard::Buffer);
virtual WebKit::WebString readHTML(WebKit::WebClipboard::Buffer,
WebKit::WebURL*);
+ virtual WebKit::WebData readImage(WebKit::WebClipboard::Buffer);
virtual void writePlainText(const WebKit::WebString& plain_text);
virtual void writeHTML(
@@ -37,6 +39,7 @@ class MockWebClipboardImpl : public WebKit::WebClipboard {
private:
WebKit::WebString m_plainText;
WebKit::WebString m_htmlText;
+ WebKit::WebImage m_image;
bool m_writeSmartPaste;
};