| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. | 2 * Copyright (c) 2013, Opera Software ASA. 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | 21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 28 * OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/page/PageSerializer.h" | 31 #include "core/frame/FrameSerializer.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/V8Binding.h" | 33 #include "bindings/core/v8/V8Binding.h" |
| 34 #include "bindings/core/v8/V8BindingForTesting.h" | 34 #include "bindings/core/v8/V8BindingForTesting.h" |
| 35 #include "core/page/Page.h" | |
| 36 #include "platform/SerializedResource.h" | 35 #include "platform/SerializedResource.h" |
| 37 #include "platform/testing/URLTestHelpers.h" | 36 #include "platform/testing/URLTestHelpers.h" |
| 38 #include "public/platform/Platform.h" | 37 #include "public/platform/Platform.h" |
| 39 #include "public/platform/WebString.h" | 38 #include "public/platform/WebString.h" |
| 40 #include "public/platform/WebThread.h" | 39 #include "public/platform/WebThread.h" |
| 41 #include "public/platform/WebURL.h" | 40 #include "public/platform/WebURL.h" |
| 42 #include "public/platform/WebURLRequest.h" | 41 #include "public/platform/WebURLRequest.h" |
| 43 #include "public/platform/WebURLResponse.h" | 42 #include "public/platform/WebURLResponse.h" |
| 44 #include "public/platform/WebUnitTestSupport.h" | 43 #include "public/platform/WebUnitTestSupport.h" |
| 45 #include "public/web/WebSettings.h" | 44 #include "public/web/WebSettings.h" |
| 46 #include "testing/gtest/include/gtest/gtest.h" | 45 #include "testing/gtest/include/gtest/gtest.h" |
| 47 #include "web/WebLocalFrameImpl.h" | 46 #include "web/WebLocalFrameImpl.h" |
| 48 #include "web/WebViewImpl.h" | 47 #include "web/WebViewImpl.h" |
| 49 #include "web/tests/FrameTestHelpers.h" | 48 #include "web/tests/FrameTestHelpers.h" |
| 50 #include "wtf/Assertions.h" | 49 #include "wtf/Assertions.h" |
| 51 #include "wtf/Vector.h" | 50 #include "wtf/Vector.h" |
| 52 | 51 |
| 53 using blink::URLTestHelpers::toKURL; | 52 using blink::URLTestHelpers::toKURL; |
| 54 using blink::URLTestHelpers::registerMockedURLLoad; | 53 using blink::URLTestHelpers::registerMockedURLLoad; |
| 55 | 54 |
| 56 namespace blink { | 55 namespace blink { |
| 57 | 56 |
| 58 class PageSerializerTest | 57 class FrameSerializerTest |
| 59 : public testing::Test | 58 : public testing::Test |
| 60 , public PageSerializer::Delegate { | 59 , public FrameSerializer::Delegate { |
| 61 public: | 60 public: |
| 62 PageSerializerTest() | 61 FrameSerializerTest() |
| 63 : m_folder(WebString::fromUTF8("pageserializer/")) | 62 : m_folder(WebString::fromUTF8("frameserializer/")) |
| 64 , m_baseUrl(toKURL("http://www.test.com")) | 63 , m_baseUrl(toKURL("http://www.test.com")) |
| 65 { | 64 { |
| 66 } | 65 } |
| 67 | 66 |
| 68 protected: | 67 protected: |
| 69 void SetUp() override | 68 void SetUp() override |
| 70 { | 69 { |
| 71 // We want the images to load and JavaScript to be on. | 70 // We want the images to load and JavaScript to be on. |
| 72 m_helper.initialize(true, 0, 0, &configureSettings); | 71 m_helper.initialize(true, 0, 0, &configureSettings); |
| 73 } | 72 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 94 | 93 |
| 95 void registerURL(const char* file, const char* mimeType) | 94 void registerURL(const char* file, const char* mimeType) |
| 96 { | 95 { |
| 97 registerURL(file, file, mimeType); | 96 registerURL(file, file, mimeType); |
| 98 } | 97 } |
| 99 | 98 |
| 100 void registerErrorURL(const char* file, int statusCode) | 99 void registerErrorURL(const char* file, int statusCode) |
| 101 { | 100 { |
| 102 WebURLError error; | 101 WebURLError error; |
| 103 error.reason = 0xdead + statusCode; | 102 error.reason = 0xdead + statusCode; |
| 104 error.domain = "PageSerializerTest"; | 103 error.domain = "FrameSerializerTest"; |
| 105 | 104 |
| 106 WebURLResponse response; | 105 WebURLResponse response; |
| 107 response.initialize(); | 106 response.initialize(); |
| 108 response.setMIMEType("text/html"); | 107 response.setMIMEType("text/html"); |
| 109 response.setHTTPStatusCode(statusCode); | 108 response.setHTTPStatusCode(statusCode); |
| 110 | 109 |
| 111 Platform::current()->unitTestSupport()->registerMockedErrorURL(KURL(m_ba
seUrl, file), response, error); | 110 Platform::current()->unitTestSupport()->registerMockedErrorURL(KURL(m_ba
seUrl, file), response, error); |
| 112 } | 111 } |
| 113 | 112 |
| 114 void registerRewriteURL(const char* fromURL, const char* toURL) | 113 void registerRewriteURL(const char* fromURL, const char* toURL) |
| 115 { | 114 { |
| 116 m_rewriteURLs.add(fromURL, toURL); | 115 m_rewriteURLs.add(fromURL, toURL); |
| 117 } | 116 } |
| 118 | 117 |
| 119 void serialize(const char* url) | 118 void serialize(const char* url) |
| 120 { | 119 { |
| 121 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), KURL(m_base
Url, url).string().utf8().data()); | 120 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), KURL(m_base
Url, url).string().utf8().data()); |
| 122 PageSerializer serializer(m_resources, *this); | 121 FrameSerializer serializer(m_resources, *this); |
| 123 Frame* frame = m_helper.webViewImpl()->mainFrameImpl()->frame(); | 122 Frame* frame = m_helper.webViewImpl()->mainFrameImpl()->frame(); |
| 124 for (; frame; frame = frame->tree().traverseNext()) { | 123 for (; frame; frame = frame->tree().traverseNext()) { |
| 125 // This is safe, because tests do not do cross-site navigation | 124 // This is safe, because tests do not do cross-site navigation |
| 126 // (and therefore don't have remote frames). | 125 // (and therefore don't have remote frames). |
| 127 serializer.serializeFrame(*toLocalFrame(frame)); | 126 serializer.serializeFrame(*toLocalFrame(frame)); |
| 128 } | 127 } |
| 129 } | 128 } |
| 130 | 129 |
| 131 Vector<SerializedResource>& getResources() | 130 Vector<SerializedResource>& getResources() |
| 132 { | 131 { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 160 } | 159 } |
| 161 | 160 |
| 162 private: | 161 private: |
| 163 static void configureSettings(WebSettings* settings) | 162 static void configureSettings(WebSettings* settings) |
| 164 { | 163 { |
| 165 settings->setImagesEnabled(true); | 164 settings->setImagesEnabled(true); |
| 166 settings->setLoadsImagesAutomatically(true); | 165 settings->setLoadsImagesAutomatically(true); |
| 167 settings->setJavaScriptEnabled(true); | 166 settings->setJavaScriptEnabled(true); |
| 168 } | 167 } |
| 169 | 168 |
| 170 // PageSerializer::Delegate implementation. | 169 // FrameSerializer::Delegate implementation. |
| 171 bool rewriteLink(const Element& element, String& rewrittenLink) | 170 bool rewriteLink(const Element& element, String& rewrittenLink) |
| 172 { | 171 { |
| 173 String completeURL; | 172 String completeURL; |
| 174 for (const auto& attribute : element.attributes()) { | 173 for (const auto& attribute : element.attributes()) { |
| 175 if (element.hasLegalLinkAttribute(attribute.name())) { | 174 if (element.hasLegalLinkAttribute(attribute.name())) { |
| 176 completeURL = element.document().completeURL(attribute.value()); | 175 completeURL = element.document().completeURL(attribute.value()); |
| 177 break; | 176 break; |
| 178 } | 177 } |
| 179 } | 178 } |
| 180 | 179 |
| 181 if (completeURL.isNull() || !m_rewriteURLs.contains(completeURL)) | 180 if (completeURL.isNull() || !m_rewriteURLs.contains(completeURL)) |
| 182 return false; | 181 return false; |
| 183 | 182 |
| 184 StringBuilder uriBuilder; | 183 StringBuilder uriBuilder; |
| 185 uriBuilder.append(m_rewriteFolder); | 184 uriBuilder.append(m_rewriteFolder); |
| 186 uriBuilder.appendLiteral("/"); | 185 uriBuilder.appendLiteral("/"); |
| 187 uriBuilder.append(m_rewriteURLs.get(completeURL)); | 186 uriBuilder.append(m_rewriteURLs.get(completeURL)); |
| 188 rewrittenLink = uriBuilder.toString(); | 187 rewrittenLink = uriBuilder.toString(); |
| 189 return true; | 188 return true; |
| 190 } | 189 } |
| 191 | 190 |
| 192 FrameTestHelpers::WebViewHelper m_helper; | 191 FrameTestHelpers::WebViewHelper m_helper; |
| 193 WebString m_folder; | 192 WebString m_folder; |
| 194 KURL m_baseUrl; | 193 KURL m_baseUrl; |
| 195 Vector<SerializedResource> m_resources; | 194 Vector<SerializedResource> m_resources; |
| 196 HashMap<String, String> m_rewriteURLs; | 195 HashMap<String, String> m_rewriteURLs; |
| 197 String m_rewriteFolder; | 196 String m_rewriteFolder; |
| 198 }; | 197 }; |
| 199 | 198 |
| 200 TEST_F(PageSerializerTest, HTMLElements) | 199 TEST_F(FrameSerializerTest, HTMLElements) |
| 201 { | 200 { |
| 202 setBaseFolder("pageserializer/elements/"); | 201 setBaseFolder("frameserializer/elements/"); |
| 203 | 202 |
| 204 registerURL("elements.html", "text/html"); | 203 registerURL("elements.html", "text/html"); |
| 205 registerURL("style.css", "style.css", "text/css"); | 204 registerURL("style.css", "style.css", "text/css"); |
| 206 registerURL("copyright.html", "empty.txt", "text/html"); | 205 registerURL("copyright.html", "empty.txt", "text/html"); |
| 207 registerURL("script.js", "empty.txt", "text/javascript"); | 206 registerURL("script.js", "empty.txt", "text/javascript"); |
| 208 | 207 |
| 209 registerURL("bodyBackground.png", "image.png", "image/png"); | 208 registerURL("bodyBackground.png", "image.png", "image/png"); |
| 210 | 209 |
| 211 registerURL("imageSrc.png", "image.png", "image/png"); | 210 registerURL("imageSrc.png", "image.png", "image/png"); |
| 212 | 211 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 231 EXPECT_TRUE(isSerialized("style.css", "text/css")); | 230 EXPECT_TRUE(isSerialized("style.css", "text/css")); |
| 232 EXPECT_TRUE(isSerialized("bodyBackground.png", "image/png")); | 231 EXPECT_TRUE(isSerialized("bodyBackground.png", "image/png")); |
| 233 EXPECT_TRUE(isSerialized("imageSrc.png", "image/png")); | 232 EXPECT_TRUE(isSerialized("imageSrc.png", "image/png")); |
| 234 EXPECT_TRUE(isSerialized("inputImage.png", "image/png")); | 233 EXPECT_TRUE(isSerialized("inputImage.png", "image/png")); |
| 235 EXPECT_TRUE(isSerialized("tableBackground.png", "image/png")); | 234 EXPECT_TRUE(isSerialized("tableBackground.png", "image/png")); |
| 236 EXPECT_TRUE(isSerialized("trBackground.png", "image/png")); | 235 EXPECT_TRUE(isSerialized("trBackground.png", "image/png")); |
| 237 EXPECT_TRUE(isSerialized("tdBackground.png", "image/png")); | 236 EXPECT_TRUE(isSerialized("tdBackground.png", "image/png")); |
| 238 EXPECT_FALSE(isSerialized("nonExisting.png", "image/png")); | 237 EXPECT_FALSE(isSerialized("nonExisting.png", "image/png")); |
| 239 } | 238 } |
| 240 | 239 |
| 241 TEST_F(PageSerializerTest, Frames) | 240 TEST_F(FrameSerializerTest, Frames) |
| 242 { | 241 { |
| 243 setBaseFolder("pageserializer/frames/"); | 242 setBaseFolder("frameserializer/frames/"); |
| 244 | 243 |
| 245 registerURL("simple_frames.html", "text/html"); | 244 registerURL("simple_frames.html", "text/html"); |
| 246 registerURL("simple_frames_top.html", "text/html"); | 245 registerURL("simple_frames_top.html", "text/html"); |
| 247 registerURL("simple_frames_1.html", "text/html"); | 246 registerURL("simple_frames_1.html", "text/html"); |
| 248 registerURL("simple_frames_3.html", "text/html"); | 247 registerURL("simple_frames_3.html", "text/html"); |
| 249 | 248 |
| 250 registerURL("frame_1.png", "image.png", "image/png"); | 249 registerURL("frame_1.png", "image.png", "image/png"); |
| 251 registerURL("frame_2.png", "image.png", "image/png"); | 250 registerURL("frame_2.png", "image.png", "image/png"); |
| 252 registerURL("frame_3.png", "image.png", "image/png"); | 251 registerURL("frame_3.png", "image.png", "image/png"); |
| 253 registerURL("frame_4.png", "image.png", "image/png"); | 252 registerURL("frame_4.png", "image.png", "image/png"); |
| 254 | 253 |
| 255 serialize("simple_frames.html"); | 254 serialize("simple_frames.html"); |
| 256 | 255 |
| 257 EXPECT_EQ(8U, getResources().size()); | 256 EXPECT_EQ(8U, getResources().size()); |
| 258 | 257 |
| 259 EXPECT_TRUE(isSerialized("simple_frames.html", "text/html")); | 258 EXPECT_TRUE(isSerialized("simple_frames.html", "text/html")); |
| 260 EXPECT_TRUE(isSerialized("simple_frames_top.html", "text/html")); | 259 EXPECT_TRUE(isSerialized("simple_frames_top.html", "text/html")); |
| 261 EXPECT_TRUE(isSerialized("simple_frames_1.html", "text/html")); | 260 EXPECT_TRUE(isSerialized("simple_frames_1.html", "text/html")); |
| 262 EXPECT_TRUE(isSerialized("simple_frames_3.html", "text/html")); | 261 EXPECT_TRUE(isSerialized("simple_frames_3.html", "text/html")); |
| 263 | 262 |
| 264 EXPECT_TRUE(isSerialized("frame_1.png", "image/png")); | 263 EXPECT_TRUE(isSerialized("frame_1.png", "image/png")); |
| 265 EXPECT_TRUE(isSerialized("frame_2.png", "image/png")); | 264 EXPECT_TRUE(isSerialized("frame_2.png", "image/png")); |
| 266 EXPECT_TRUE(isSerialized("frame_3.png", "image/png")); | 265 EXPECT_TRUE(isSerialized("frame_3.png", "image/png")); |
| 267 EXPECT_TRUE(isSerialized("frame_4.png", "image/png")); | 266 EXPECT_TRUE(isSerialized("frame_4.png", "image/png")); |
| 268 } | 267 } |
| 269 | 268 |
| 270 TEST_F(PageSerializerTest, IFrames) | 269 TEST_F(FrameSerializerTest, IFrames) |
| 271 { | 270 { |
| 272 setBaseFolder("pageserializer/frames/"); | 271 setBaseFolder("frameserializer/frames/"); |
| 273 | 272 |
| 274 registerURL("top_frame.html", "text/html"); | 273 registerURL("top_frame.html", "text/html"); |
| 275 registerURL("simple_iframe.html", "text/html"); | 274 registerURL("simple_iframe.html", "text/html"); |
| 276 registerURL("object_iframe.html", "text/html"); | 275 registerURL("object_iframe.html", "text/html"); |
| 277 registerURL("embed_iframe.html", "text/html"); | 276 registerURL("embed_iframe.html", "text/html"); |
| 278 registerURL("encoded_iframe.html", "text/html"); | 277 registerURL("encoded_iframe.html", "text/html"); |
| 279 | 278 |
| 280 registerURL("top.png", "image.png", "image/png"); | 279 registerURL("top.png", "image.png", "image/png"); |
| 281 registerURL("simple.png", "image.png", "image/png"); | 280 registerURL("simple.png", "image.png", "image/png"); |
| 282 registerURL("object.png", "image.png", "image/png"); | 281 registerURL("object.png", "image.png", "image/png"); |
| 283 registerURL("embed.png", "image.png", "image/png"); | 282 registerURL("embed.png", "image.png", "image/png"); |
| 284 | 283 |
| 285 serialize("top_frame.html"); | 284 serialize("top_frame.html"); |
| 286 | 285 |
| 287 EXPECT_EQ(10U, getResources().size()); | 286 EXPECT_EQ(10U, getResources().size()); |
| 288 | 287 |
| 289 EXPECT_TRUE(isSerialized("top_frame.html", "text/html")); | 288 EXPECT_TRUE(isSerialized("top_frame.html", "text/html")); |
| 290 EXPECT_TRUE(isSerialized("simple_iframe.html", "text/html")); // Twice. | 289 EXPECT_TRUE(isSerialized("simple_iframe.html", "text/html")); // Twice. |
| 291 EXPECT_TRUE(isSerialized("object_iframe.html", "text/html")); | 290 EXPECT_TRUE(isSerialized("object_iframe.html", "text/html")); |
| 292 EXPECT_TRUE(isSerialized("embed_iframe.html", "text/html")); | 291 EXPECT_TRUE(isSerialized("embed_iframe.html", "text/html")); |
| 293 EXPECT_TRUE(isSerialized("encoded_iframe.html", "text/html")); | 292 EXPECT_TRUE(isSerialized("encoded_iframe.html", "text/html")); |
| 294 | 293 |
| 295 EXPECT_TRUE(isSerialized("top.png", "image/png")); | 294 EXPECT_TRUE(isSerialized("top.png", "image/png")); |
| 296 EXPECT_TRUE(isSerialized("simple.png", "image/png")); | 295 EXPECT_TRUE(isSerialized("simple.png", "image/png")); |
| 297 EXPECT_TRUE(isSerialized("object.png", "image/png")); | 296 EXPECT_TRUE(isSerialized("object.png", "image/png")); |
| 298 EXPECT_TRUE(isSerialized("embed.png", "image/png")); | 297 EXPECT_TRUE(isSerialized("embed.png", "image/png")); |
| 299 | 298 |
| 300 // Ensure that page contents are not NFC-normalized before encoding. | 299 // Ensure that frame contents are not NFC-normalized before encoding. |
| 301 String expectedMetaCharset = "<meta http-equiv=\"Content-Type\" content=\"te
xt/html; charset=EUC-KR\">"; | 300 String expectedMetaCharset = "<meta http-equiv=\"Content-Type\" content=\"te
xt/html; charset=EUC-KR\">"; |
| 302 EXPECT_TRUE(getSerializedData("encoded_iframe.html", "text/html").contains(e
xpectedMetaCharset)); | 301 EXPECT_TRUE(getSerializedData("encoded_iframe.html", "text/html").contains(e
xpectedMetaCharset)); |
| 303 EXPECT_TRUE(getSerializedData("encoded_iframe.html", "text/html").contains("
\xE4\xC5\xD1\xE2")); | 302 EXPECT_TRUE(getSerializedData("encoded_iframe.html", "text/html").contains("
\xE4\xC5\xD1\xE2")); |
| 304 EXPECT_FALSE(getSerializedData("encoded_iframe.html", "text/html").contains(
"\xE4\xC5\xE4\xC5")); | 303 EXPECT_FALSE(getSerializedData("encoded_iframe.html", "text/html").contains(
"\xE4\xC5\xE4\xC5")); |
| 305 } | 304 } |
| 306 | 305 |
| 307 // Tests that when serializing a page with blank frames these are reported with
their resources. | 306 // Tests that when serializing a page with blank frames these are reported with
their resources. |
| 308 TEST_F(PageSerializerTest, BlankFrames) | 307 TEST_F(FrameSerializerTest, BlankFrames) |
| 309 { | 308 { |
| 310 setBaseFolder("pageserializer/frames/"); | 309 setBaseFolder("frameserializer/frames/"); |
| 311 | 310 |
| 312 registerURL("blank_frames.html", "text/html"); | 311 registerURL("blank_frames.html", "text/html"); |
| 313 registerURL("red_background.png", "image.png", "image/png"); | 312 registerURL("red_background.png", "image.png", "image/png"); |
| 314 registerURL("orange_background.png", "image.png", "image/png"); | 313 registerURL("orange_background.png", "image.png", "image/png"); |
| 315 registerURL("blue_background.png", "image.png", "image/png"); | 314 registerURL("blue_background.png", "image.png", "image/png"); |
| 316 | 315 |
| 317 serialize("blank_frames.html"); | 316 serialize("blank_frames.html"); |
| 318 | 317 |
| 319 EXPECT_EQ(7U, getResources().size()); | 318 EXPECT_EQ(7U, getResources().size()); |
| 320 | 319 |
| 321 EXPECT_TRUE(isSerialized("http://www.test.com/red_background.png", "image/pn
g")); | 320 EXPECT_TRUE(isSerialized("http://www.test.com/red_background.png", "image/pn
g")); |
| 322 EXPECT_TRUE(isSerialized("http://www.test.com/orange_background.png", "image
/png")); | 321 EXPECT_TRUE(isSerialized("http://www.test.com/orange_background.png", "image
/png")); |
| 323 EXPECT_TRUE(isSerialized("http://www.test.com/blue_background.png", "image/p
ng")); | 322 EXPECT_TRUE(isSerialized("http://www.test.com/blue_background.png", "image/p
ng")); |
| 324 | 323 |
| 325 // The blank frames no longer get magic URL (i.e. wyciwyg://frame/0), so we | 324 // The blank frames no longer get magic URL (i.e. wyciwyg://frame/0), so we |
| 326 // can't really assert their presence via URL. We also can't use content-id | 325 // can't really assert their presence via URL. We also can't use content-id |
| 327 // in assertions (since it is not deterministic). Therefore we need to rely | 326 // in assertions (since it is not deterministic). Therefore we need to rely |
| 328 // on getResources().size() assertion above and on browser-level tests | 327 // on getResources().size() assertion above and on browser-level tests |
| 329 // (i.e. SavePageMultiFrameBrowserTest.AboutBlank). | 328 // (i.e. SavePageMultiFrameBrowserTest.AboutBlank). |
| 330 } | 329 } |
| 331 | 330 |
| 332 TEST_F(PageSerializerTest, CSS) | 331 TEST_F(FrameSerializerTest, CSS) |
| 333 { | 332 { |
| 334 setBaseFolder("pageserializer/css/"); | 333 setBaseFolder("frameserializer/css/"); |
| 335 | 334 |
| 336 registerURL("css_test_page.html", "text/html"); | 335 registerURL("css_test_page.html", "text/html"); |
| 337 registerURL("link_styles.css", "text/css"); | 336 registerURL("link_styles.css", "text/css"); |
| 338 registerURL("encoding.css", "text/css"); | 337 registerURL("encoding.css", "text/css"); |
| 339 registerURL("import_style_from_link.css", "text/css"); | 338 registerURL("import_style_from_link.css", "text/css"); |
| 340 registerURL("import_styles.css", "text/css"); | 339 registerURL("import_styles.css", "text/css"); |
| 341 registerURL("do_not_serialize.png", "image.png", "image/png"); | 340 registerURL("do_not_serialize.png", "image.png", "image/png"); |
| 342 registerURL("red_background.png", "image.png", "image/png"); | 341 registerURL("red_background.png", "image.png", "image/png"); |
| 343 registerURL("orange_background.png", "image.png", "image/png"); | 342 registerURL("orange_background.png", "image.png", "image/png"); |
| 344 registerURL("yellow_background.png", "image.png", "image/png"); | 343 registerURL("yellow_background.png", "image.png", "image/png"); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 EXPECT_TRUE(getSerializedData("link_styles.css", "text/css").startsWith("@ch
arset")); | 375 EXPECT_TRUE(getSerializedData("link_styles.css", "text/css").startsWith("@ch
arset")); |
| 377 EXPECT_TRUE(getSerializedData("import_styles.css", "text/css").startsWith("@
charset")); | 376 EXPECT_TRUE(getSerializedData("import_styles.css", "text/css").startsWith("@
charset")); |
| 378 EXPECT_TRUE(getSerializedData("import_style_from_link.css", "text/css").star
tsWith("@charset")); | 377 EXPECT_TRUE(getSerializedData("import_style_from_link.css", "text/css").star
tsWith("@charset")); |
| 379 EXPECT_TRUE(getSerializedData("encoding.css", "text/css").startsWith("@chars
et \"euc-kr\";")); | 378 EXPECT_TRUE(getSerializedData("encoding.css", "text/css").startsWith("@chars
et \"euc-kr\";")); |
| 380 | 379 |
| 381 // Ensure that stylesheet contents are not NFC-normalized before encoding. | 380 // Ensure that stylesheet contents are not NFC-normalized before encoding. |
| 382 EXPECT_TRUE(getSerializedData("encoding.css", "text/css").contains("\xE4\xC5
\xD1\xE2")); | 381 EXPECT_TRUE(getSerializedData("encoding.css", "text/css").contains("\xE4\xC5
\xD1\xE2")); |
| 383 EXPECT_FALSE(getSerializedData("encoding.css", "text/css").contains("\xE4\xC
5\xE4\xC5")); | 382 EXPECT_FALSE(getSerializedData("encoding.css", "text/css").contains("\xE4\xC
5\xE4\xC5")); |
| 384 } | 383 } |
| 385 | 384 |
| 386 TEST_F(PageSerializerTest, CSSImport) | 385 TEST_F(FrameSerializerTest, CSSImport) |
| 387 { | 386 { |
| 388 setBaseFolder("pageserializer/css/"); | 387 setBaseFolder("frameserializer/css/"); |
| 389 | 388 |
| 390 registerURL("import.html", "text/html"); | 389 registerURL("import.html", "text/html"); |
| 391 registerURL("import/base.css", "text/css"); | 390 registerURL("import/base.css", "text/css"); |
| 392 registerURL("import/relative/red-background.css", "text/css"); | 391 registerURL("import/relative/red-background.css", "text/css"); |
| 393 registerURL("import/absolute/green-header.css", "text/css"); | 392 registerURL("import/absolute/green-header.css", "text/css"); |
| 394 | 393 |
| 395 serialize("import.html"); | 394 serialize("import.html"); |
| 396 | 395 |
| 397 EXPECT_TRUE(isSerialized("import.html", "text/html")); | 396 EXPECT_TRUE(isSerialized("import.html", "text/html")); |
| 398 EXPECT_TRUE(isSerialized("import/base.css", "text/css")); | 397 EXPECT_TRUE(isSerialized("import/base.css", "text/css")); |
| 399 EXPECT_TRUE(isSerialized("import/relative/red-background.css", "text/css")); | 398 EXPECT_TRUE(isSerialized("import/relative/red-background.css", "text/css")); |
| 400 EXPECT_TRUE(isSerialized("import/absolute/green-header.css", "text/css")); | 399 EXPECT_TRUE(isSerialized("import/absolute/green-header.css", "text/css")); |
| 401 } | 400 } |
| 402 | 401 |
| 403 TEST_F(PageSerializerTest, XMLDeclaration) | 402 TEST_F(FrameSerializerTest, XMLDeclaration) |
| 404 { | 403 { |
| 405 V8TestingScope scope(v8::Isolate::GetCurrent()); | 404 V8TestingScope scope(v8::Isolate::GetCurrent()); |
| 406 setBaseFolder("pageserializer/xml/"); | 405 setBaseFolder("frameserializer/xml/"); |
| 407 | 406 |
| 408 registerURL("xmldecl.xml", "text/xml"); | 407 registerURL("xmldecl.xml", "text/xml"); |
| 409 serialize("xmldecl.xml"); | 408 serialize("xmldecl.xml"); |
| 410 | 409 |
| 411 String expectedStart("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); | 410 String expectedStart("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
| 412 EXPECT_TRUE(getSerializedData("xmldecl.xml").startsWith(expectedStart)); | 411 EXPECT_TRUE(getSerializedData("xmldecl.xml").startsWith(expectedStart)); |
| 413 } | 412 } |
| 414 | 413 |
| 415 TEST_F(PageSerializerTest, DTD) | 414 TEST_F(FrameSerializerTest, DTD) |
| 416 { | 415 { |
| 417 setBaseFolder("pageserializer/dtd/"); | 416 setBaseFolder("frameserializer/dtd/"); |
| 418 | 417 |
| 419 registerURL("html5.html", "text/html"); | 418 registerURL("html5.html", "text/html"); |
| 420 serialize("html5.html"); | 419 serialize("html5.html"); |
| 421 | 420 |
| 422 String expectedStart("<!DOCTYPE html>"); | 421 String expectedStart("<!DOCTYPE html>"); |
| 423 EXPECT_TRUE(getSerializedData("html5.html").startsWith(expectedStart)); | 422 EXPECT_TRUE(getSerializedData("html5.html").startsWith(expectedStart)); |
| 424 } | 423 } |
| 425 | 424 |
| 426 TEST_F(PageSerializerTest, Font) | 425 TEST_F(FrameSerializerTest, Font) |
| 427 { | 426 { |
| 428 setBaseFolder("pageserializer/font/"); | 427 setBaseFolder("frameserializer/font/"); |
| 429 | 428 |
| 430 registerURL("font.html", "text/html"); | 429 registerURL("font.html", "text/html"); |
| 431 registerURL("font.ttf", "application/octet-stream"); | 430 registerURL("font.ttf", "application/octet-stream"); |
| 432 | 431 |
| 433 serialize("font.html"); | 432 serialize("font.html"); |
| 434 | 433 |
| 435 EXPECT_TRUE(isSerialized("font.ttf", "application/octet-stream")); | 434 EXPECT_TRUE(isSerialized("font.ttf", "application/octet-stream")); |
| 436 } | 435 } |
| 437 | 436 |
| 438 TEST_F(PageSerializerTest, DataURI) | 437 TEST_F(FrameSerializerTest, DataURI) |
| 439 { | 438 { |
| 440 setBaseFolder("pageserializer/datauri/"); | 439 setBaseFolder("frameserializer/datauri/"); |
| 441 | 440 |
| 442 registerURL("page_with_data.html", "text/html"); | 441 registerURL("page_with_data.html", "text/html"); |
| 443 | 442 |
| 444 serialize("page_with_data.html"); | 443 serialize("page_with_data.html"); |
| 445 | 444 |
| 446 EXPECT_EQ(1U, getResources().size()); | 445 EXPECT_EQ(1U, getResources().size()); |
| 447 EXPECT_TRUE(isSerialized("page_with_data.html", "text/html")); | 446 EXPECT_TRUE(isSerialized("page_with_data.html", "text/html")); |
| 448 } | 447 } |
| 449 | 448 |
| 450 TEST_F(PageSerializerTest, DataURIMorphing) | 449 TEST_F(FrameSerializerTest, DataURIMorphing) |
| 451 { | 450 { |
| 452 setBaseFolder("pageserializer/datauri/"); | 451 setBaseFolder("frameserializer/datauri/"); |
| 453 | 452 |
| 454 registerURL("page_with_morphing_data.html", "text/html"); | 453 registerURL("page_with_morphing_data.html", "text/html"); |
| 455 | 454 |
| 456 serialize("page_with_morphing_data.html"); | 455 serialize("page_with_morphing_data.html"); |
| 457 | 456 |
| 458 EXPECT_EQ(2U, getResources().size()); | 457 EXPECT_EQ(2U, getResources().size()); |
| 459 EXPECT_TRUE(isSerialized("page_with_morphing_data.html", "text/html")); | 458 EXPECT_TRUE(isSerialized("page_with_morphing_data.html", "text/html")); |
| 460 } | 459 } |
| 461 | 460 |
| 462 TEST_F(PageSerializerTest, RewriteLinksSimple) | 461 TEST_F(FrameSerializerTest, RewriteLinksSimple) |
| 463 { | 462 { |
| 464 setBaseFolder("pageserializer/rewritelinks/"); | 463 setBaseFolder("frameserializer/rewritelinks/"); |
| 465 setRewriteURLFolder("folder"); | 464 setRewriteURLFolder("folder"); |
| 466 | 465 |
| 467 registerURL("rewritelinks_simple.html", "text/html"); | 466 registerURL("rewritelinks_simple.html", "text/html"); |
| 468 registerURL("absolute.png", "image.png", "image/png"); | 467 registerURL("absolute.png", "image.png", "image/png"); |
| 469 registerURL("relative.png", "image.png", "image/png"); | 468 registerURL("relative.png", "image.png", "image/png"); |
| 470 registerRewriteURL("http://www.test.com/absolute.png", "a.png"); | 469 registerRewriteURL("http://www.test.com/absolute.png", "a.png"); |
| 471 registerRewriteURL("http://www.test.com/relative.png", "b.png"); | 470 registerRewriteURL("http://www.test.com/relative.png", "b.png"); |
| 472 | 471 |
| 473 serialize("rewritelinks_simple.html"); | 472 serialize("rewritelinks_simple.html"); |
| 474 | 473 |
| 475 EXPECT_EQ(3U, getResources().size()); | 474 EXPECT_EQ(3U, getResources().size()); |
| 476 EXPECT_NE(getSerializedData("rewritelinks_simple.html", "text/html").find("\
"folder/a.png\""), kNotFound); | 475 EXPECT_NE(getSerializedData("rewritelinks_simple.html", "text/html").find("\
"folder/a.png\""), kNotFound); |
| 477 EXPECT_NE(getSerializedData("rewritelinks_simple.html", "text/html").find("\
"folder/b.png\""), kNotFound); | 476 EXPECT_NE(getSerializedData("rewritelinks_simple.html", "text/html").find("\
"folder/b.png\""), kNotFound); |
| 478 } | 477 } |
| 479 | 478 |
| 480 // Test that we don't regress https://bugs.webkit.org/show_bug.cgi?id=99105 | 479 // Test that we don't regress https://bugs.webkit.org/show_bug.cgi?id=99105 |
| 481 TEST_F(PageSerializerTest, SVGImageDontCrash) | 480 TEST_F(FrameSerializerTest, SVGImageDontCrash) |
| 482 { | 481 { |
| 483 setBaseFolder("pageserializer/svg/"); | 482 setBaseFolder("frameserializer/svg/"); |
| 484 | 483 |
| 485 registerURL("page_with_svg_image.html", "text/html"); | 484 registerURL("page_with_svg_image.html", "text/html"); |
| 486 registerURL("green_rectangle.svg", "image/svg+xml"); | 485 registerURL("green_rectangle.svg", "image/svg+xml"); |
| 487 | 486 |
| 488 serialize("page_with_svg_image.html"); | 487 serialize("page_with_svg_image.html"); |
| 489 | 488 |
| 490 EXPECT_EQ(2U, getResources().size()); | 489 EXPECT_EQ(2U, getResources().size()); |
| 491 | 490 |
| 492 EXPECT_TRUE(isSerialized("green_rectangle.svg", "image/svg+xml")); | 491 EXPECT_TRUE(isSerialized("green_rectangle.svg", "image/svg+xml")); |
| 493 EXPECT_GT(getSerializedData("green_rectangle.svg", "image/svg+xml").length()
, 250U); | 492 EXPECT_GT(getSerializedData("green_rectangle.svg", "image/svg+xml").length()
, 250U); |
| 494 } | 493 } |
| 495 | 494 |
| 496 TEST_F(PageSerializerTest, DontIncludeErrorImage) | 495 TEST_F(FrameSerializerTest, DontIncludeErrorImage) |
| 497 { | 496 { |
| 498 setBaseFolder("pageserializer/image/"); | 497 setBaseFolder("frameserializer/image/"); |
| 499 | 498 |
| 500 registerURL("page_with_img_error.html", "text/html"); | 499 registerURL("page_with_img_error.html", "text/html"); |
| 501 registerURL("error_image.png", "image/png"); | 500 registerURL("error_image.png", "image/png"); |
| 502 | 501 |
| 503 serialize("page_with_img_error.html"); | 502 serialize("page_with_img_error.html"); |
| 504 | 503 |
| 505 EXPECT_EQ(1U, getResources().size()); | 504 EXPECT_EQ(1U, getResources().size()); |
| 506 EXPECT_TRUE(isSerialized("page_with_img_error.html", "text/html")); | 505 EXPECT_TRUE(isSerialized("page_with_img_error.html", "text/html")); |
| 507 EXPECT_FALSE(isSerialized("error_image.png", "image/png")); | 506 EXPECT_FALSE(isSerialized("error_image.png", "image/png")); |
| 508 } | 507 } |
| 509 | 508 |
| 510 TEST_F(PageSerializerTest, NamespaceElementsDontCrash) | 509 TEST_F(FrameSerializerTest, NamespaceElementsDontCrash) |
| 511 { | 510 { |
| 512 setBaseFolder("pageserializer/namespace/"); | 511 setBaseFolder("frameserializer/namespace/"); |
| 513 | 512 |
| 514 registerURL("namespace_element.html", "text/html"); | 513 registerURL("namespace_element.html", "text/html"); |
| 515 | 514 |
| 516 serialize("namespace_element.html"); | 515 serialize("namespace_element.html"); |
| 517 | 516 |
| 518 EXPECT_EQ(1U, getResources().size()); | 517 EXPECT_EQ(1U, getResources().size()); |
| 519 EXPECT_TRUE(isSerialized("namespace_element.html", "text/html")); | 518 EXPECT_TRUE(isSerialized("namespace_element.html", "text/html")); |
| 520 EXPECT_GT(getSerializedData("namespace_element.html", "text/html").length(),
0U); | 519 EXPECT_GT(getSerializedData("namespace_element.html", "text/html").length(),
0U); |
| 521 } | 520 } |
| 522 | 521 |
| 523 TEST_F(PageSerializerTest, markOfTheWebDeclaration) | 522 TEST_F(FrameSerializerTest, markOfTheWebDeclaration) |
| 524 { | 523 { |
| 525 EXPECT_EQ("saved from url=(0015)http://foo.com/", PageSerializer::markOfTheW
ebDeclaration(KURL(ParsedURLString, "http://foo.com"))); | 524 EXPECT_EQ("saved from url=(0015)http://foo.com/", FrameSerializer::markOfThe
WebDeclaration(KURL(ParsedURLString, "http://foo.com"))); |
| 526 EXPECT_EQ("saved from url=(0015)http://f-o.com/", PageSerializer::markOfTheW
ebDeclaration(KURL(ParsedURLString, "http://f-o.com"))); | 525 EXPECT_EQ("saved from url=(0015)http://f-o.com/", FrameSerializer::markOfThe
WebDeclaration(KURL(ParsedURLString, "http://f-o.com"))); |
| 527 EXPECT_EQ("saved from url=(0019)http://foo.com-%2D/", PageSerializer::markOf
TheWebDeclaration(KURL(ParsedURLString, "http://foo.com--"))); | 526 EXPECT_EQ("saved from url=(0019)http://foo.com-%2D/", FrameSerializer::markO
fTheWebDeclaration(KURL(ParsedURLString, "http://foo.com--"))); |
| 528 EXPECT_EQ("saved from url=(0024)http://f-%2D.com-%2D%3E/", PageSerializer::m
arkOfTheWebDeclaration(KURL(ParsedURLString, "http://f--.com-->"))); | 527 EXPECT_EQ("saved from url=(0024)http://f-%2D.com-%2D%3E/", FrameSerializer::
markOfTheWebDeclaration(KURL(ParsedURLString, "http://f--.com-->"))); |
| 529 EXPECT_EQ("saved from url=(0020)http://foo.com/?-%2D", PageSerializer::markO
fTheWebDeclaration(KURL(ParsedURLString, "http://foo.com?--"))); | 528 EXPECT_EQ("saved from url=(0020)http://foo.com/?-%2D", FrameSerializer::mark
OfTheWebDeclaration(KURL(ParsedURLString, "http://foo.com?--"))); |
| 530 EXPECT_EQ("saved from url=(0020)http://foo.com/#-%2D", PageSerializer::markO
fTheWebDeclaration(KURL(ParsedURLString, "http://foo.com#--"))); | 529 EXPECT_EQ("saved from url=(0020)http://foo.com/#-%2D", FrameSerializer::mark
OfTheWebDeclaration(KURL(ParsedURLString, "http://foo.com#--"))); |
| 531 EXPECT_EQ("saved from url=(0026)http://foo.com/#bar-%2Dbaz", PageSerializer:
:markOfTheWebDeclaration(KURL(ParsedURLString, "http://foo.com#bar--baz"))); | 530 EXPECT_EQ("saved from url=(0026)http://foo.com/#bar-%2Dbaz", FrameSerializer
::markOfTheWebDeclaration(KURL(ParsedURLString, "http://foo.com#bar--baz"))); |
| 532 } | 531 } |
| 533 | 532 |
| 534 } // namespace blink | 533 } // namespace blink |
| OLD | NEW |