OLD | NEW |
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // WebViewClient methods | 143 // WebViewClient methods |
144 void didAutoResize(const WebSize& newSize) override { m_testData.setSize(new
Size); } | 144 void didAutoResize(const WebSize& newSize) override { m_testData.setSize(new
Size); } |
145 | 145 |
146 // Local methods | 146 // Local methods |
147 TestData& testData() { return m_testData; } | 147 TestData& testData() { return m_testData; } |
148 | 148 |
149 private: | 149 private: |
150 TestData m_testData; | 150 TestData m_testData; |
151 }; | 151 }; |
152 | 152 |
153 class SaveImageFromDataURLWebViewClient : public FrameTestHelpers::TestWebViewCl
ient { | |
154 public: | |
155 // WebViewClient methods | |
156 void saveImageFromDataURL(const WebString& dataURL) override { m_dataURL = d
ataURL; } | |
157 | |
158 // Local methods | |
159 const WebString& result() const { return m_dataURL; } | |
160 void reset() { m_dataURL = WebString(); } | |
161 | |
162 private: | |
163 WebString m_dataURL; | |
164 }; | |
165 | |
166 class TapHandlingWebViewClient : public FrameTestHelpers::TestWebViewClient { | 153 class TapHandlingWebViewClient : public FrameTestHelpers::TestWebViewClient { |
167 public: | 154 public: |
168 // WebViewClient methods | 155 // WebViewClient methods |
169 void didHandleGestureEvent(const WebGestureEvent& event, bool eventCancelled
) override | 156 void didHandleGestureEvent(const WebGestureEvent& event, bool eventCancelled
) override |
170 { | 157 { |
171 if (event.type == WebInputEvent::GestureTap) { | 158 if (event.type == WebInputEvent::GestureTap) { |
172 m_tapX = event.x; | 159 m_tapX = event.x; |
173 m_tapY = event.y; | 160 m_tapY = event.y; |
174 } else if (event.type == WebInputEvent::GestureLongPress) { | 161 } else if (event.type == WebInputEvent::GestureLongPress) { |
175 m_longpressX = event.x; | 162 m_longpressX = event.x; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 234 |
248 void testTextInputType(WebTextInputType expectedType, const std::string& htm
lFile); | 235 void testTextInputType(WebTextInputType expectedType, const std::string& htm
lFile); |
249 void testInputMode(const WebString& expectedInputMode, const std::string& ht
mlFile); | 236 void testInputMode(const WebString& expectedInputMode, const std::string& ht
mlFile); |
250 bool tapElement(WebInputEvent::Type, Element*); | 237 bool tapElement(WebInputEvent::Type, Element*); |
251 bool tapElementById(WebInputEvent::Type, const WebString& id); | 238 bool tapElementById(WebInputEvent::Type, const WebString& id); |
252 | 239 |
253 std::string m_baseURL; | 240 std::string m_baseURL; |
254 FrameTestHelpers::WebViewHelper m_webViewHelper; | 241 FrameTestHelpers::WebViewHelper m_webViewHelper; |
255 }; | 242 }; |
256 | 243 |
257 TEST_F(WebViewTest, SaveImageAt) | |
258 { | |
259 SaveImageFromDataURLWebViewClient client; | |
260 | |
261 std::string url = m_baseURL + "image-with-data-url.html"; | |
262 URLTestHelpers::registerMockedURLLoad(toKURL(url), "image-with-data-url.html
"); | |
263 URLTestHelpers::registerMockedURLLoad(toKURL("http://test"), "white-1x1.png"
); | |
264 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(url, true, 0, &clie
nt); | |
265 webView->resize(WebSize(400, 400)); | |
266 webView->updateAllLifecyclePhases(); | |
267 | |
268 client.reset(); | |
269 webView->saveImageAt(WebPoint(1, 1)); | |
270 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" | |
271 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); | |
272 | |
273 client.reset(); | |
274 webView->saveImageAt(WebPoint(1, 2)); | |
275 EXPECT_EQ(WebString(), client.result()); | |
276 | |
277 webView->setPageScaleFactor(4); | |
278 webView->setVisualViewportOffset(WebFloatPoint(1, 1)); | |
279 | |
280 client.reset(); | |
281 webView->saveImageAt(WebPoint(3, 3)); | |
282 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" | |
283 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); | |
284 | |
285 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. | |
286 }; | |
287 | |
288 TEST_F(WebViewTest, SaveImageWithImageMap) | |
289 { | |
290 SaveImageFromDataURLWebViewClient client; | |
291 | |
292 std::string url = m_baseURL + "image-map.html"; | |
293 URLTestHelpers::registerMockedURLLoad(toKURL(url), "image-map.html"); | |
294 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0, &client); | |
295 webView->resize(WebSize(400, 400)); | |
296 | |
297 client.reset(); | |
298 webView->saveImageAt(WebPoint(25, 25)); | |
299 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" | |
300 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); | |
301 | |
302 client.reset(); | |
303 webView->saveImageAt(WebPoint(75, 25)); | |
304 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" | |
305 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); | |
306 | |
307 client.reset(); | |
308 webView->saveImageAt(WebPoint(125, 25)); | |
309 EXPECT_EQ(WebString(), client.result()); | |
310 | |
311 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. | |
312 } | |
313 | |
314 TEST_F(WebViewTest, CopyImageAt) | |
315 { | |
316 std::string url = m_baseURL + "canvas-copy-image.html"; | |
317 URLTestHelpers::registerMockedURLLoad(toKURL(url), "canvas-copy-image.html")
; | |
318 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0); | |
319 webView->resize(WebSize(400, 400)); | |
320 | |
321 uint64_t sequence = Platform::current()->clipboard()->sequenceNumber(WebClip
board::BufferStandard); | |
322 | |
323 webView->copyImageAt(WebPoint(50, 50)); | |
324 | |
325 EXPECT_NE(sequence, Platform::current()->clipboard()->sequenceNumber(WebClip
board::BufferStandard)); | |
326 | |
327 WebImage image = static_cast<WebMockClipboard*>(Platform::current()->clipboa
rd())->readRawImage(WebClipboard::Buffer()); | |
328 | |
329 SkAutoLockPixels autoLock(image.getSkBitmap()); | |
330 EXPECT_EQ(SkColorSetARGB(255, 255, 0, 0), image.getSkBitmap().getColor(0, 0)
); | |
331 }; | |
332 | |
333 TEST_F(WebViewTest, CopyImageAtWithPinchZoom) | |
334 { | |
335 std::string url = m_baseURL + "canvas-copy-image.html"; | |
336 URLTestHelpers::registerMockedURLLoad(toKURL(url), "canvas-copy-image.html")
; | |
337 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(url, true, 0); | |
338 webView->resize(WebSize(400, 400)); | |
339 webView->updateAllLifecyclePhases(); | |
340 webView->setPageScaleFactor(2); | |
341 webView->setVisualViewportOffset(WebFloatPoint(200, 200)); | |
342 | |
343 uint64_t sequence = Platform::current()->clipboard()->sequenceNumber(WebClip
board::BufferStandard); | |
344 | |
345 webView->copyImageAt(WebPoint(0, 0)); | |
346 | |
347 EXPECT_NE(sequence, Platform::current()->clipboard()->sequenceNumber(WebClip
board::BufferStandard)); | |
348 | |
349 WebImage image = static_cast<WebMockClipboard*>(Platform::current()->clipboa
rd())->readRawImage(WebClipboard::Buffer()); | |
350 | |
351 SkAutoLockPixels autoLock(image.getSkBitmap()); | |
352 EXPECT_EQ(SkColorSetARGB(255, 255, 0, 0), image.getSkBitmap().getColor(0, 0)
); | |
353 }; | |
354 | |
355 TEST_F(WebViewTest, CopyImageWithImageMap) | |
356 { | |
357 SaveImageFromDataURLWebViewClient client; | |
358 | |
359 std::string url = m_baseURL + "image-map.html"; | |
360 URLTestHelpers::registerMockedURLLoad(toKURL(url), "image-map.html"); | |
361 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0, &client); | |
362 webView->resize(WebSize(400, 400)); | |
363 | |
364 client.reset(); | |
365 webView->saveImageAt(WebPoint(25, 25)); | |
366 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" | |
367 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); | |
368 | |
369 client.reset(); | |
370 webView->saveImageAt(WebPoint(75, 25)); | |
371 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" | |
372 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); | |
373 | |
374 client.reset(); | |
375 webView->saveImageAt(WebPoint(125, 25)); | |
376 EXPECT_EQ(WebString(), client.result()); | |
377 | |
378 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. | |
379 } | |
380 | |
381 static bool hitTestIsContentEditable(WebView* view, int x, int y) | 244 static bool hitTestIsContentEditable(WebView* view, int x, int y) |
382 { | 245 { |
383 WebPoint hitPoint(x, y); | 246 WebPoint hitPoint(x, y); |
384 WebHitTestResult hitTestResult = view->hitTestResultAt(hitPoint); | 247 WebHitTestResult hitTestResult = view->hitTestResultAt(hitPoint); |
385 return hitTestResult.isContentEditable(); | 248 return hitTestResult.isContentEditable(); |
386 } | 249 } |
387 | 250 |
388 static std::string hitTestElementId(WebView* view, int x, int y) | 251 static std::string hitTestElementId(WebView* view, int x, int y) |
389 { | 252 { |
390 WebPoint hitPoint(x, y); | 253 WebPoint hitPoint(x, y); |
(...skipping 2786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3177 frame->setAutofillClient(&client); | 3040 frame->setAutofillClient(&client); |
3178 webView->setInitialFocus(false); | 3041 webView->setInitialFocus(false); |
3179 | 3042 |
3180 EXPECT_TRUE(webView->confirmComposition(WebString::fromUTF8(std::string("hel
lo").c_str()))); | 3043 EXPECT_TRUE(webView->confirmComposition(WebString::fromUTF8(std::string("hel
lo").c_str()))); |
3181 EXPECT_EQ(1, client.textChangesFromUserGesture()); | 3044 EXPECT_EQ(1, client.textChangesFromUserGesture()); |
3182 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); | 3045 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); |
3183 frame->setAutofillClient(0); | 3046 frame->setAutofillClient(0); |
3184 } | 3047 } |
3185 | 3048 |
3186 } // namespace blink | 3049 } // namespace blink |
OLD | NEW |