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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 void TearDown() override | 73 void TearDown() override |
74 { | 74 { |
75 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 75 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
76 } | 76 } |
77 | 77 |
78 void setBaseFolder(const char* folder) | 78 void setBaseFolder(const char* folder) |
79 { | 79 { |
80 m_folder = WebString::fromUTF8(folder); | 80 m_folder = WebString::fromUTF8(folder); |
81 } | 81 } |
82 | 82 |
| 83 void setRewriteURLFolder(const char* folder) |
| 84 { |
| 85 m_rewriteFolder = folder; |
| 86 } |
| 87 |
83 void registerURL(const char* url, const char* file, const char* mimeType) | 88 void registerURL(const char* url, const char* file, const char* mimeType) |
84 { | 89 { |
85 registerMockedURLLoad(KURL(m_baseUrl, url), WebString::fromUTF8(file), m
_folder, WebString::fromUTF8(mimeType)); | 90 registerMockedURLLoad(KURL(m_baseUrl, url), WebString::fromUTF8(file), m
_folder, WebString::fromUTF8(mimeType)); |
86 } | 91 } |
87 | 92 |
88 void registerURL(const char* file, const char* mimeType) | 93 void registerURL(const char* file, const char* mimeType) |
89 { | 94 { |
90 registerURL(file, file, mimeType); | 95 registerURL(file, file, mimeType); |
91 } | 96 } |
92 | 97 |
93 void registerErrorURL(const char* file, int statusCode) | 98 void registerErrorURL(const char* file, int statusCode) |
94 { | 99 { |
95 WebURLError error; | 100 WebURLError error; |
96 error.reason = 0xdead + statusCode; | 101 error.reason = 0xdead + statusCode; |
97 error.domain = "PageSerializerTest"; | 102 error.domain = "PageSerializerTest"; |
98 | 103 |
99 WebURLResponse response; | 104 WebURLResponse response; |
100 response.initialize(); | 105 response.initialize(); |
101 response.setMIMEType("text/html"); | 106 response.setMIMEType("text/html"); |
102 response.setHTTPStatusCode(statusCode); | 107 response.setHTTPStatusCode(statusCode); |
103 | 108 |
104 Platform::current()->unitTestSupport()->registerMockedErrorURL(KURL(m_ba
seUrl, file), response, error); | 109 Platform::current()->unitTestSupport()->registerMockedErrorURL(KURL(m_ba
seUrl, file), response, error); |
105 } | 110 } |
106 | 111 |
| 112 void registerRewriteURL(const char* fromURL, const char* toURL) |
| 113 { |
| 114 m_rewriteURLs.add(fromURL, toURL); |
| 115 } |
| 116 |
107 void serialize(const char* url) | 117 void serialize(const char* url) |
108 { | 118 { |
109 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), KURL(m_base
Url, url).string().utf8().data()); | 119 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), KURL(m_base
Url, url).string().utf8().data()); |
110 PageSerializer serializer(&m_resources, nullptr); | 120 PageSerializer serializer(&m_resources, nullptr); |
| 121 |
| 122 serializer.setRewriteURLFolder(m_rewriteFolder); |
| 123 for (const auto& rewriteURL: m_rewriteURLs) |
| 124 serializer.registerRewriteURL(rewriteURL.key, rewriteURL.value); |
| 125 |
111 serializer.serialize(m_helper.webViewImpl()->mainFrameImpl()->frame()->p
age()); | 126 serializer.serialize(m_helper.webViewImpl()->mainFrameImpl()->frame()->p
age()); |
112 } | 127 } |
113 | 128 |
114 Vector<SerializedResource>& getResources() | 129 Vector<SerializedResource>& getResources() |
115 { | 130 { |
116 return m_resources; | 131 return m_resources; |
117 } | 132 } |
118 | 133 |
119 | 134 |
120 const SerializedResource* getResource(const char* url, const char* mimeType) | 135 const SerializedResource* getResource(const char* url, const char* mimeType) |
(...skipping 27 matching lines...) Expand all Loading... |
148 { | 163 { |
149 settings->setImagesEnabled(true); | 164 settings->setImagesEnabled(true); |
150 settings->setLoadsImagesAutomatically(true); | 165 settings->setLoadsImagesAutomatically(true); |
151 settings->setJavaScriptEnabled(true); | 166 settings->setJavaScriptEnabled(true); |
152 } | 167 } |
153 | 168 |
154 FrameTestHelpers::WebViewHelper m_helper; | 169 FrameTestHelpers::WebViewHelper m_helper; |
155 WebString m_folder; | 170 WebString m_folder; |
156 KURL m_baseUrl; | 171 KURL m_baseUrl; |
157 Vector<SerializedResource> m_resources; | 172 Vector<SerializedResource> m_resources; |
| 173 HashMap<String, String> m_rewriteURLs; |
| 174 String m_rewriteFolder; |
158 }; | 175 }; |
159 | 176 |
160 TEST_F(PageSerializerTest, HTMLElements) | 177 TEST_F(PageSerializerTest, HTMLElements) |
161 { | 178 { |
162 setBaseFolder("pageserializer/elements/"); | 179 setBaseFolder("pageserializer/elements/"); |
163 | 180 |
164 registerURL("elements.html", "text/html"); | 181 registerURL("elements.html", "text/html"); |
165 registerURL("style.css", "style.css", "text/css"); | 182 registerURL("style.css", "style.css", "text/css"); |
166 registerURL("copyright.html", "empty.txt", "text/html"); | 183 registerURL("copyright.html", "empty.txt", "text/html"); |
167 registerURL("script.js", "empty.txt", "text/javascript"); | 184 registerURL("script.js", "empty.txt", "text/javascript"); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 setBaseFolder("pageserializer/datauri/"); | 407 setBaseFolder("pageserializer/datauri/"); |
391 | 408 |
392 registerURL("page_with_morphing_data.html", "text/html"); | 409 registerURL("page_with_morphing_data.html", "text/html"); |
393 | 410 |
394 serialize("page_with_morphing_data.html"); | 411 serialize("page_with_morphing_data.html"); |
395 | 412 |
396 EXPECT_EQ(2U, getResources().size()); | 413 EXPECT_EQ(2U, getResources().size()); |
397 EXPECT_TRUE(isSerialized("page_with_morphing_data.html", "text/html")); | 414 EXPECT_TRUE(isSerialized("page_with_morphing_data.html", "text/html")); |
398 } | 415 } |
399 | 416 |
| 417 TEST_F(PageSerializerTest, RewriteLinksSimple) |
| 418 { |
| 419 setBaseFolder("pageserializer/rewritelinks/"); |
| 420 setRewriteURLFolder("folder"); |
| 421 |
| 422 registerURL("rewritelinks_simple.html", "text/html"); |
| 423 registerURL("absolute.png", "image.png", "image/png"); |
| 424 registerURL("relative.png", "image.png", "image/png"); |
| 425 registerRewriteURL("http://www.test.com/absolute.png", "a.png"); |
| 426 registerRewriteURL("http://www.test.com/relative.png", "b.png"); |
| 427 |
| 428 serialize("rewritelinks_simple.html"); |
| 429 |
| 430 EXPECT_EQ(3U, getResources().size()); |
| 431 EXPECT_NE(getSerializedData("rewritelinks_simple.html", "text/html").find("\
"folder/a.png\""), kNotFound); |
| 432 EXPECT_NE(getSerializedData("rewritelinks_simple.html", "text/html").find("\
"folder/b.png\""), kNotFound); |
| 433 } |
| 434 |
| 435 TEST_F(PageSerializerTest, RewriteLinksBase) |
| 436 { |
| 437 setBaseFolder("pageserializer/rewritelinks/"); |
| 438 setRewriteURLFolder("folder"); |
| 439 |
| 440 registerURL("rewritelinks_base.html", "text/html"); |
| 441 registerURL("images/here/image.png", "image.png", "image/png"); |
| 442 registerURL("images/here/or/in/here/image.png", "image.png", "image/png"); |
| 443 registerURL("or/absolute.png", "image.png", "image/png"); |
| 444 registerRewriteURL("http://www.test.com/images/here/image.png", "a.png"); |
| 445 registerRewriteURL("http://www.test.com/images/here/or/in/here/image.png", "
b.png"); |
| 446 registerRewriteURL("http://www.test.com/or/absolute.png", "c.png"); |
| 447 |
| 448 serialize("rewritelinks_base.html"); |
| 449 |
| 450 EXPECT_EQ(4U, getResources().size()); |
| 451 EXPECT_NE(getSerializedData("rewritelinks_base.html", "text/html").find("\"f
older/a.png\""), kNotFound); |
| 452 EXPECT_NE(getSerializedData("rewritelinks_base.html", "text/html").find("\"f
older/b.png\""), kNotFound); |
| 453 EXPECT_NE(getSerializedData("rewritelinks_base.html", "text/html").find("\"f
older/c.png\""), kNotFound); |
| 454 } |
| 455 |
400 // Test that we don't regress https://bugs.webkit.org/show_bug.cgi?id=99105 | 456 // Test that we don't regress https://bugs.webkit.org/show_bug.cgi?id=99105 |
401 TEST_F(PageSerializerTest, SVGImageDontCrash) | 457 TEST_F(PageSerializerTest, SVGImageDontCrash) |
402 { | 458 { |
403 setBaseFolder("pageserializer/svg/"); | 459 setBaseFolder("pageserializer/svg/"); |
404 | 460 |
405 registerURL("page_with_svg_image.html", "text/html"); | 461 registerURL("page_with_svg_image.html", "text/html"); |
406 registerURL("green_rectangle.svg", "image/svg+xml"); | 462 registerURL("green_rectangle.svg", "image/svg+xml"); |
407 | 463 |
408 serialize("page_with_svg_image.html"); | 464 serialize("page_with_svg_image.html"); |
409 | 465 |
(...skipping 24 matching lines...) Expand all Loading... |
434 registerURL("namespace_element.html", "text/html"); | 490 registerURL("namespace_element.html", "text/html"); |
435 | 491 |
436 serialize("namespace_element.html"); | 492 serialize("namespace_element.html"); |
437 | 493 |
438 EXPECT_EQ(1U, getResources().size()); | 494 EXPECT_EQ(1U, getResources().size()); |
439 EXPECT_TRUE(isSerialized("namespace_element.html", "text/html")); | 495 EXPECT_TRUE(isSerialized("namespace_element.html", "text/html")); |
440 EXPECT_GT(getSerializedData("namespace_element.html", "text/html").length(),
0U); | 496 EXPECT_GT(getSerializedData("namespace_element.html", "text/html").length(),
0U); |
441 } | 497 } |
442 | 498 |
443 } // namespace blink | 499 } // namespace blink |
OLD | NEW |