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

Unified Diff: Source/web/tests/WebViewTest.cpp

Issue 518043003: Add saveImageFromDataURL() and use it in saveImageAt(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add test 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
Index: Source/web/tests/WebViewTest.cpp
diff --git a/Source/web/tests/WebViewTest.cpp b/Source/web/tests/WebViewTest.cpp
index 4c2c66242524996fa67ee4ccb32934e21604f351..3090d24a8e117dd25b86b68aa81ae15216747e44 100644
--- a/Source/web/tests/WebViewTest.cpp
+++ b/Source/web/tests/WebViewTest.cpp
@@ -130,6 +130,19 @@ private:
TestData m_testData;
};
+class SaveImageFromDataURLWebViewClient : public FrameTestHelpers::TestWebViewClient {
+public:
+ // WebViewClient methods
+ virtual void saveImageFromDataURL(const WebString& dataURL) { m_dataURL = dataURL; }
+
+ // Local methods
+ const WebString& result() const { return m_dataURL; }
+ void reset() { m_dataURL = WebString(); }
+
+private:
+ WebString m_dataURL;
+};
+
class TapHandlingWebViewClient : public FrameTestHelpers::TestWebViewClient {
public:
// WebViewClient methods
@@ -219,6 +232,27 @@ protected:
FrameTestHelpers::WebViewHelper m_webViewHelper;
};
+TEST_F(WebViewTest, SaveImageAt)
+{
+ SaveImageFromDataURLWebViewClient client;
+
+ std::string url = m_baseURL + "image-with-data-url.html";
+ URLTestHelpers::registerMockedURLLoad(toKURL(url), "image-with-data-url.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0, &client);
+ webView->resize(WebSize(400, 400));
+
+ client.reset();
+ webView->saveImageAt(WebPoint(1, 1));
+ EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64"
+ ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result());
+
+ client.reset();
+ webView->saveImageAt(WebPoint(1, 2));
+ EXPECT_EQ(WebString(), client.result());
+
+ m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
+};
+
TEST_F(WebViewTest, CopyImageAt)
{
std::string url = m_baseURL + "canvas-copy-image.html";

Powered by Google App Engine
This is Rietveld 408576698