| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 URLTestHelpers::registerMockedURLLoad(parsedURL, fileName, | 136 URLTestHelpers::registerMockedURLLoad(parsedURL, fileName, |
| 137 "frameserialization/", "text/html"); | 137 "frameserialization/", "text/html"); |
| 138 FrameTestHelpers::loadFrame(mainFrameImpl(), url.utf8().data()); | 138 FrameTestHelpers::loadFrame(mainFrameImpl(), url.utf8().data()); |
| 139 SingleLinkRewritingDelegate delegate(parsedURL, WebString("local")); | 139 SingleLinkRewritingDelegate delegate(parsedURL, WebString("local")); |
| 140 SimpleWebFrameSerializerClient serializerClient; | 140 SimpleWebFrameSerializerClient serializerClient; |
| 141 WebFrameSerializer::serialize(mainFrameImpl(), &serializerClient, | 141 WebFrameSerializer::serialize(mainFrameImpl(), &serializerClient, |
| 142 &delegate); | 142 &delegate); |
| 143 return serializerClient.toString(); | 143 return serializerClient.toString(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 WebViewImpl* webView() { return m_helper.webView(); } |
| 147 |
| 146 WebLocalFrameImpl* mainFrameImpl() { | 148 WebLocalFrameImpl* mainFrameImpl() { |
| 147 return m_helper.webView()->mainFrameImpl(); | 149 return m_helper.webView()->mainFrameImpl(); |
| 148 } | 150 } |
| 149 | 151 |
| 150 private: | 152 private: |
| 151 FrameTestHelpers::WebViewHelper m_helper; | 153 FrameTestHelpers::WebViewHelper m_helper; |
| 152 }; | 154 }; |
| 153 | 155 |
| 154 TEST_F(WebFrameSerializerTest, URLAttributeValues) { | 156 TEST_F(WebFrameSerializerTest, URLAttributeValues) { |
| 155 registerMockedImageURL("javascript:\""); | 157 registerMockedImageURL("javascript:\""); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 279 } |
| 278 | 280 |
| 279 // Regression test for crbug.com/678893, where in some cases serializing an | 281 // Regression test for crbug.com/678893, where in some cases serializing an |
| 280 // image document could cause code to pick an element from an empty container. | 282 // image document could cause code to pick an element from an empty container. |
| 281 TEST_F(WebFrameSerializerSanitizationTest, FromBrokenImageDocument) { | 283 TEST_F(WebFrameSerializerSanitizationTest, FromBrokenImageDocument) { |
| 282 String mhtml = generateMHTMLParts("http://www.test.com", "broken-image.png", | 284 String mhtml = generateMHTMLParts("http://www.test.com", "broken-image.png", |
| 283 "image/png"); | 285 "image/png"); |
| 284 EXPECT_TRUE(mhtml.isEmpty()); | 286 EXPECT_TRUE(mhtml.isEmpty()); |
| 285 } | 287 } |
| 286 | 288 |
| 289 TEST_F(WebFrameSerializerSanitizationTest, ImageLoadedFromSrcsetForHiDPI) { |
| 290 URLTestHelpers::registerMockedURLLoad( |
| 291 KURL(ParsedURLString, "http://www.test.com/1x.png"), |
| 292 "frameserialization/1x.png"); |
| 293 URLTestHelpers::registerMockedURLLoad( |
| 294 KURL(ParsedURLString, "http://www.test.com/2x.png"), |
| 295 "frameserialization/2x.png"); |
| 296 |
| 297 // Set high DPR in order to load image from srcset, instead of src. |
| 298 webView()->setDeviceScaleFactor(2.0f); |
| 299 |
| 300 String mhtml = generateMHTMLParts("http://www.test.com", "img_srcset.html"); |
| 301 |
| 302 // srcset attribute should be skipped. |
| 303 EXPECT_EQ(WTF::kNotFound, mhtml.find("srcset=")); |
| 304 |
| 305 // Width and height attributes should be set when none is present in <img>. |
| 306 EXPECT_NE(WTF::kNotFound, |
| 307 mhtml.find("id=3D\"i1\" width=3D\"6\" height=3D\"6\">")); |
| 308 |
| 309 // Height attribute should not be set if width attribute is already present in |
| 310 // <img> |
| 311 EXPECT_NE(WTF::kNotFound, mhtml.find("id=3D\"i2\" width=3D\"8\">")); |
| 312 } |
| 313 |
| 314 TEST_F(WebFrameSerializerSanitizationTest, ImageLoadedFromSrcForNormalDPI) { |
| 315 URLTestHelpers::registerMockedURLLoad( |
| 316 KURL(ParsedURLString, "http://www.test.com/1x.png"), |
| 317 "frameserialization/1x.png"); |
| 318 URLTestHelpers::registerMockedURLLoad( |
| 319 KURL(ParsedURLString, "http://www.test.com/2x.png"), |
| 320 "frameserialization/2x.png"); |
| 321 |
| 322 String mhtml = generateMHTMLParts("http://www.test.com", "img_srcset.html"); |
| 323 |
| 324 // srcset attribute should be skipped. |
| 325 EXPECT_EQ(WTF::kNotFound, mhtml.find("srcset=")); |
| 326 |
| 327 // New width and height attributes should not be set. |
| 328 EXPECT_NE(WTF::kNotFound, mhtml.find("id=3D\"i1\">")); |
| 329 EXPECT_NE(WTF::kNotFound, mhtml.find("id=3D\"i2\" width=3D\"8\">")); |
| 330 } |
| 331 |
| 287 } // namespace blink | 332 } // namespace blink |
| OLD | NEW |