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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 std::string m_baseURL; | 235 std::string m_baseURL; |
236 FrameTestHelpers::WebViewHelper m_webViewHelper; | 236 FrameTestHelpers::WebViewHelper m_webViewHelper; |
237 }; | 237 }; |
238 | 238 |
239 TEST_F(WebViewTest, SaveImageAt) | 239 TEST_F(WebViewTest, SaveImageAt) |
240 { | 240 { |
241 SaveImageFromDataURLWebViewClient client; | 241 SaveImageFromDataURLWebViewClient client; |
242 | 242 |
243 std::string url = m_baseURL + "image-with-data-url.html"; | 243 std::string url = m_baseURL + "image-with-data-url.html"; |
244 URLTestHelpers::registerMockedURLLoad(toKURL(url), "image-with-data-url.html
"); | 244 URLTestHelpers::registerMockedURLLoad(toKURL(url), "image-with-data-url.html
"); |
245 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0, &client); | 245 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(url, true, 0, &clie
nt); |
246 webView->resize(WebSize(400, 400)); | 246 webView->resize(WebSize(400, 400)); |
| 247 webView->layout(); |
247 | 248 |
248 client.reset(); | 249 client.reset(); |
249 webView->saveImageAt(WebPoint(1, 1)); | 250 webView->saveImageAt(WebPoint(1, 1)); |
250 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" | 251 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" |
251 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); | 252 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); |
252 | 253 |
253 client.reset(); | 254 client.reset(); |
254 webView->saveImageAt(WebPoint(1, 2)); | 255 webView->saveImageAt(WebPoint(1, 2)); |
255 EXPECT_EQ(WebString(), client.result()); | 256 EXPECT_EQ(WebString(), client.result()); |
256 | 257 |
| 258 webView->setPageScaleFactor(4); |
| 259 webView->setPinchViewportOffset(WebFloatPoint(1, 1)); |
| 260 |
| 261 client.reset(); |
| 262 webView->saveImageAt(WebPoint(3, 3)); |
| 263 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" |
| 264 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); |
| 265 |
257 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. | 266 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. |
258 }; | 267 }; |
259 | 268 |
260 TEST_F(WebViewTest, CopyImageAt) | 269 TEST_F(WebViewTest, CopyImageAt) |
261 { | 270 { |
262 std::string url = m_baseURL + "canvas-copy-image.html"; | 271 std::string url = m_baseURL + "canvas-copy-image.html"; |
263 URLTestHelpers::registerMockedURLLoad(toKURL(url), "canvas-copy-image.html")
; | 272 URLTestHelpers::registerMockedURLLoad(toKURL(url), "canvas-copy-image.html")
; |
264 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0); | 273 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0); |
265 webView->resize(WebSize(400, 400)); | 274 webView->resize(WebSize(400, 400)); |
| 275 |
| 276 uint64_t sequence = Platform::current()->clipboard()->sequenceNumber(WebClip
board::BufferStandard); |
| 277 |
266 webView->copyImageAt(WebPoint(50, 50)); | 278 webView->copyImageAt(WebPoint(50, 50)); |
267 | 279 |
| 280 EXPECT_NE(sequence, Platform::current()->clipboard()->sequenceNumber(WebClip
board::BufferStandard)); |
| 281 |
268 WebData data = Platform::current()->clipboard()->readImage(WebClipboard::Buf
fer()); | 282 WebData data = Platform::current()->clipboard()->readImage(WebClipboard::Buf
fer()); |
269 WebImage image = WebImage::fromData(data, WebSize()); | 283 WebImage image = WebImage::fromData(data, WebSize()); |
270 | 284 |
| 285 SkAutoLockPixels autoLock(image.getSkBitmap()); |
| 286 EXPECT_EQ(SkColorSetARGB(255, 255, 0, 0), image.getSkBitmap().getColor(0, 0)
); |
| 287 }; |
| 288 |
| 289 TEST_F(WebViewTest, CopyImageAtWithPinchZoom) |
| 290 { |
| 291 std::string url = m_baseURL + "canvas-copy-image.html"; |
| 292 URLTestHelpers::registerMockedURLLoad(toKURL(url), "canvas-copy-image.html")
; |
| 293 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(url, true, 0); |
| 294 webView->resize(WebSize(400, 400)); |
| 295 webView->layout(); |
| 296 webView->setPageScaleFactor(2); |
| 297 webView->setPinchViewportOffset(WebFloatPoint(200, 200)); |
| 298 |
| 299 uint64_t sequence = Platform::current()->clipboard()->sequenceNumber(WebClip
board::BufferStandard); |
| 300 |
| 301 webView->copyImageAt(WebPoint(0, 0)); |
| 302 |
| 303 EXPECT_NE(sequence, Platform::current()->clipboard()->sequenceNumber(WebClip
board::BufferStandard)); |
| 304 |
| 305 WebData data = Platform::current()->clipboard()->readImage(WebClipboard::Buf
fer()); |
| 306 WebImage image = WebImage::fromData(data, WebSize()); |
| 307 |
271 SkAutoLockPixels autoLock(image.getSkBitmap()); | 308 SkAutoLockPixels autoLock(image.getSkBitmap()); |
272 EXPECT_EQ(SkColorSetARGB(255, 255, 0, 0), image.getSkBitmap().getColor(0, 0)
); | 309 EXPECT_EQ(SkColorSetARGB(255, 255, 0, 0), image.getSkBitmap().getColor(0, 0)
); |
273 }; | 310 }; |
274 | 311 |
275 TEST_F(WebViewTest, SetBaseBackgroundColor) | 312 TEST_F(WebViewTest, SetBaseBackgroundColor) |
276 { | 313 { |
277 const WebColor kWhite = 0xFFFFFFFF; | 314 const WebColor kWhite = 0xFFFFFFFF; |
278 const WebColor kBlue = 0xFF0000FF; | 315 const WebColor kBlue = 0xFF0000FF; |
279 const WebColor kDarkCyan = 0xFF227788; | 316 const WebColor kDarkCyan = 0xFF227788; |
280 const WebColor kTranslucentPutty = 0x80BFB196; | 317 const WebColor kTranslucentPutty = 0x80BFB196; |
(...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1813 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("smartclip.html")); | 1850 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("smartclip.html")); |
1814 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "smartclip.
html"); | 1851 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "smartclip.
html"); |
1815 webView->resize(WebSize(500, 500)); | 1852 webView->resize(WebSize(500, 500)); |
1816 webView->layout(); | 1853 webView->layout(); |
1817 WebRect cropRect(300, 125, 152, 50); | 1854 WebRect cropRect(300, 125, 152, 50); |
1818 webView->extractSmartClipData(cropRect, clipText, clipHtml, clipRect); | 1855 webView->extractSmartClipData(cropRect, clipText, clipHtml, clipRect); |
1819 EXPECT_STREQ(kExpectedClipText, clipText.utf8().c_str()); | 1856 EXPECT_STREQ(kExpectedClipText, clipText.utf8().c_str()); |
1820 EXPECT_STREQ(kExpectedClipHtml, clipHtml.utf8().c_str()); | 1857 EXPECT_STREQ(kExpectedClipHtml, clipHtml.utf8().c_str()); |
1821 } | 1858 } |
1822 | 1859 |
| 1860 TEST_F(WebViewTest, SmartClipDataWithPinchZoom) |
| 1861 { |
| 1862 static const char* kExpectedClipText = "\nPrice 10,000,000won"; |
| 1863 static const char* kExpectedClipHtml = |
| 1864 "<div id=\"div4\" style=\"padding: 10px; margin: 10px; border: 2px " |
| 1865 "solid rgb(135, 206, 235); float: left; width: 190px; height: 30px; " |
| 1866 "color: rgb(0, 0, 0); font-family: myahem; font-size: 8px; font-style: " |
| 1867 "normal; font-variant: normal; font-weight: normal; letter-spacing: " |
| 1868 "normal; line-height: normal; orphans: auto; text-align: start; " |
| 1869 "text-indent: 0px; text-transform: none; white-space: normal; widows: " |
| 1870 "1; word-spacing: 0px; -webkit-text-stroke-width: 0px;\">Air " |
| 1871 "conditioner</div><div id=\"div5\" style=\"padding: 10px; margin: " |
| 1872 "10px; border: 2px solid rgb(135, 206, 235); float: left; width: " |
| 1873 "190px; height: 30px; color: rgb(0, 0, 0); font-family: myahem; " |
| 1874 "font-size: 8px; font-style: normal; font-variant: normal; " |
| 1875 "font-weight: normal; letter-spacing: normal; line-height: normal; " |
| 1876 "orphans: auto; text-align: start; text-indent: 0px; text-transform: " |
| 1877 "none; white-space: normal; widows: 1; word-spacing: 0px; " |
| 1878 "-webkit-text-stroke-width: 0px;\">Price 10,000,000won</div>"; |
| 1879 WebString clipText; |
| 1880 WebString clipHtml; |
| 1881 WebRect clipRect; |
| 1882 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("Ahem.ttf")); |
| 1883 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("smartclip.html")); |
| 1884 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "smartclip.
html"); |
| 1885 webView->resize(WebSize(500, 500)); |
| 1886 webView->layout(); |
| 1887 webView->setPageScaleFactor(1.5); |
| 1888 webView->setPinchViewportOffset(WebFloatPoint(167, 100)); |
| 1889 WebRect cropRect(200, 38, 228, 75); |
| 1890 webView->extractSmartClipData(cropRect, clipText, clipHtml, clipRect); |
| 1891 EXPECT_STREQ(kExpectedClipText, clipText.utf8().c_str()); |
| 1892 EXPECT_STREQ(kExpectedClipHtml, clipHtml.utf8().c_str()); |
| 1893 } |
| 1894 |
1823 TEST_F(WebViewTest, SmartClipReturnsEmptyStringsWhenUserSelectIsNone) | 1895 TEST_F(WebViewTest, SmartClipReturnsEmptyStringsWhenUserSelectIsNone) |
1824 { | 1896 { |
1825 WebString clipText; | 1897 WebString clipText; |
1826 WebString clipHtml; | 1898 WebString clipHtml; |
1827 WebRect clipRect; | 1899 WebRect clipRect; |
1828 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("Ahem.ttf")); | 1900 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("Ahem.ttf")); |
1829 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("smartclip_user_select_none.html")); | 1901 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("smartclip_user_select_none.html")); |
1830 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "smartclip_
user_select_none.html"); | 1902 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "smartclip_
user_select_none.html"); |
1831 webView->resize(WebSize(500, 500)); | 1903 webView->resize(WebSize(500, 500)); |
1832 webView->layout(); | 1904 webView->layout(); |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2521 // Test without any preventDefault. | 2593 // Test without any preventDefault. |
2522 client.reset(); | 2594 client.reset(); |
2523 frame->executeScript(WebScriptSource("setTest('none');")); | 2595 frame->executeScript(WebScriptSource("setTest('none');")); |
2524 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr
omUTF8("target"))); | 2596 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr
omUTF8("target"))); |
2525 EXPECT_TRUE(client.getWasCalled()); | 2597 EXPECT_TRUE(client.getWasCalled()); |
2526 | 2598 |
2527 m_webViewHelper.reset(); // Remove dependency on locally scoped client. | 2599 m_webViewHelper.reset(); // Remove dependency on locally scoped client. |
2528 } | 2600 } |
2529 | 2601 |
2530 } // namespace | 2602 } // namespace |
OLD | NEW |