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