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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // WebViewClient methods 123 // WebViewClient methods
124 virtual void didAutoResize(const WebSize& newSize) { m_testData.setSize(newS ize); } 124 virtual void didAutoResize(const WebSize& newSize) { m_testData.setSize(newS ize); }
125 125
126 // Local methods 126 // Local methods
127 TestData& testData() { return m_testData; } 127 TestData& testData() { return m_testData; }
128 128
129 private: 129 private:
130 TestData m_testData; 130 TestData m_testData;
131 }; 131 };
132 132
133 class SaveImageFromDataURLWebViewClient : public FrameTestHelpers::TestWebViewCl ient {
134 public:
135 // WebViewClient methods
136 virtual void saveImageFromDataURL(const WebString& dataURL) { m_dataURL = da taURL; }
137
138 // Local methods
139 const WebString& result() const { return m_dataURL; }
140 void reset() { m_dataURL = WebString(); }
141
142 private:
143 WebString m_dataURL;
144 };
145
133 class TapHandlingWebViewClient : public FrameTestHelpers::TestWebViewClient { 146 class TapHandlingWebViewClient : public FrameTestHelpers::TestWebViewClient {
134 public: 147 public:
135 // WebViewClient methods 148 // WebViewClient methods
136 virtual void didHandleGestureEvent(const WebGestureEvent& event, bool eventC ancelled) 149 virtual void didHandleGestureEvent(const WebGestureEvent& event, bool eventC ancelled)
137 { 150 {
138 if (event.type == WebInputEvent::GestureTap) { 151 if (event.type == WebInputEvent::GestureTap) {
139 m_tapX = event.x; 152 m_tapX = event.x;
140 m_tapY = event.y; 153 m_tapY = event.y;
141 } else if (event.type == WebInputEvent::GestureLongPress) { 154 } else if (event.type == WebInputEvent::GestureLongPress) {
142 m_longpressX = event.x; 155 m_longpressX = event.x;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 HorizontalScrollbarState expectedHorizontalState, Vertic alScrollbarState expectedVerticalState); 225 HorizontalScrollbarState expectedHorizontalState, Vertic alScrollbarState expectedVerticalState);
213 226
214 void testTextInputType(WebTextInputType expectedType, const std::string& htm lFile); 227 void testTextInputType(WebTextInputType expectedType, const std::string& htm lFile);
215 void testInputMode(const WebString& expectedInputMode, const std::string& ht mlFile); 228 void testInputMode(const WebString& expectedInputMode, const std::string& ht mlFile);
216 void testSelectionRootBounds(const char* htmlFile, float pageScaleFactor); 229 void testSelectionRootBounds(const char* htmlFile, float pageScaleFactor);
217 230
218 std::string m_baseURL; 231 std::string m_baseURL;
219 FrameTestHelpers::WebViewHelper m_webViewHelper; 232 FrameTestHelpers::WebViewHelper m_webViewHelper;
220 }; 233 };
221 234
235 TEST_F(WebViewTest, SaveImageAt)
236 {
237 SaveImageFromDataURLWebViewClient client;
238
239 std::string url = m_baseURL + "image-with-data-url.html";
240 URLTestHelpers::registerMockedURLLoad(toKURL(url), "image-with-data-url.html ");
241 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0, &client);
242 webView->resize(WebSize(400, 400));
243
244 client.reset();
245 webView->saveImageAt(WebPoint(1, 1));
246 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64"
247 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result());
248
249 client.reset();
250 webView->saveImageAt(WebPoint(1, 2));
251 EXPECT_EQ(WebString(), client.result());
252
253 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
254 };
255
222 TEST_F(WebViewTest, CopyImageAt) 256 TEST_F(WebViewTest, CopyImageAt)
223 { 257 {
224 std::string url = m_baseURL + "canvas-copy-image.html"; 258 std::string url = m_baseURL + "canvas-copy-image.html";
225 URLTestHelpers::registerMockedURLLoad(toKURL(url), "canvas-copy-image.html") ; 259 URLTestHelpers::registerMockedURLLoad(toKURL(url), "canvas-copy-image.html") ;
226 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0); 260 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0);
227 webView->resize(WebSize(400, 400)); 261 webView->resize(WebSize(400, 400));
228 webView->copyImageAt(WebPoint(50, 50)); 262 webView->copyImageAt(WebPoint(50, 50));
229 263
230 blink::WebData data = blink::Platform::current()->clipboard()->readImage(bli nk::WebClipboard::Buffer()); 264 blink::WebData data = blink::Platform::current()->clipboard()->readImage(bli nk::WebClipboard::Buffer());
231 blink::WebImage image = blink::WebImage::fromData(data, WebSize()); 265 blink::WebImage image = blink::WebImage::fromData(data, WebSize());
(...skipping 1947 matching lines...) Expand 10 before | Expand all | Expand 10 after
2179 loadFrame(webView->mainFrame(), url); 2213 loadFrame(webView->mainFrame(), url);
2180 2214
2181 blink::FrameView* frameView = m_webViewHelper.webViewImpl()->mainFrameImpl() ->frameView(); 2215 blink::FrameView* frameView = m_webViewHelper.webViewImpl()->mainFrameImpl() ->frameView();
2182 2216
2183 // Auto-resizing used to ASSERT(needsLayout()) in RenderBlockFlow::layout. T his EXPECT is 2217 // Auto-resizing used to ASSERT(needsLayout()) in RenderBlockFlow::layout. T his EXPECT is
2184 // merely a dummy. The real test is that we don't trigger asserts in debug b uilds. 2218 // merely a dummy. The real test is that we don't trigger asserts in debug b uilds.
2185 EXPECT_FALSE(frameView->needsLayout()); 2219 EXPECT_FALSE(frameView->needsLayout());
2186 }; 2220 };
2187 2221
2188 } // namespace 2222 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698