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 |
| 123 serializer.setRewriteURLFolder(m_rewriteFolder); |
| 124 for (const auto& rewriteURL: m_rewriteURLs) |
| 125 serializer.registerRewriteURL(rewriteURL.key, rewriteURL.value); |
| 126 |
112 serializer.serialize(m_helper.webViewImpl()->mainFrameImpl()->frame()->p
age()); | 127 serializer.serialize(m_helper.webViewImpl()->mainFrameImpl()->frame()->p
age()); |
113 } | 128 } |
114 | 129 |
115 Vector<SerializedResource>& getResources() | 130 Vector<SerializedResource>& getResources() |
116 { | 131 { |
117 return m_resources; | 132 return m_resources; |
118 } | 133 } |
119 | 134 |
120 | 135 |
121 const SerializedResource* getResource(const char* url, const char* mimeType) | 136 const SerializedResource* getResource(const char* url, const char* mimeType) |
(...skipping 27 matching lines...) Expand all Loading... |
149 { | 164 { |
150 settings->setImagesEnabled(true); | 165 settings->setImagesEnabled(true); |
151 settings->setLoadsImagesAutomatically(true); | 166 settings->setLoadsImagesAutomatically(true); |
152 settings->setJavaScriptEnabled(true); | 167 settings->setJavaScriptEnabled(true); |
153 } | 168 } |
154 | 169 |
155 FrameTestHelpers::WebViewHelper m_helper; | 170 FrameTestHelpers::WebViewHelper m_helper; |
156 WebString m_folder; | 171 WebString m_folder; |
157 KURL m_baseUrl; | 172 KURL m_baseUrl; |
158 Vector<SerializedResource> m_resources; | 173 Vector<SerializedResource> m_resources; |
| 174 HashMap<String, String> m_rewriteURLs; |
| 175 String m_rewriteFolder; |
159 }; | 176 }; |
160 | 177 |
161 TEST_F(PageSerializerTest, HTMLElements) | 178 TEST_F(PageSerializerTest, HTMLElements) |
162 { | 179 { |
163 setBaseFolder("pageserializer/elements/"); | 180 setBaseFolder("pageserializer/elements/"); |
164 | 181 |
165 registerURL("elements.html", "text/html"); | 182 registerURL("elements.html", "text/html"); |
166 registerURL("style.css", "style.css", "text/css"); | 183 registerURL("style.css", "style.css", "text/css"); |
167 registerURL("copyright.html", "text.txt", "text/html"); | 184 registerURL("copyright.html", "text.txt", "text/html"); |
168 registerURL("script.js", "text.txt", "text/javascript"); | 185 registerURL("script.js", "text.txt", "text/javascript"); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 setBaseFolder("pageserializer/datauri/"); | 401 setBaseFolder("pageserializer/datauri/"); |
385 | 402 |
386 registerURL("page_with_morphing_data.html", "text/html"); | 403 registerURL("page_with_morphing_data.html", "text/html"); |
387 | 404 |
388 serialize("page_with_morphing_data.html"); | 405 serialize("page_with_morphing_data.html"); |
389 | 406 |
390 EXPECT_EQ(2U, getResources().size()); | 407 EXPECT_EQ(2U, getResources().size()); |
391 EXPECT_TRUE(isSerialized("page_with_morphing_data.html", "text/html")); | 408 EXPECT_TRUE(isSerialized("page_with_morphing_data.html", "text/html")); |
392 } | 409 } |
393 | 410 |
| 411 TEST_F(PageSerializerTest, RewriteLinksSimple) |
| 412 { |
| 413 setBaseFolder("pageserializer/rewritelinks/"); |
| 414 setRewriteURLFolder("folder"); |
| 415 |
| 416 registerURL("rewritelinks_simple.html", "text/html"); |
| 417 registerURL("absolute.png", "image.png", "image/png"); |
| 418 registerURL("relative.png", "image.png", "image/png"); |
| 419 registerRewriteURL("http://www.test.com/absolute.png", "a.png"); |
| 420 registerRewriteURL("http://www.test.com/relative.png", "b.png"); |
| 421 |
| 422 serialize("rewritelinks_simple.html"); |
| 423 |
| 424 EXPECT_EQ(3U, getResources().size()); |
| 425 EXPECT_NE(getSerializedData("rewritelinks_simple.html", "text/html").find(".
/folder/a.png"), kNotFound); |
| 426 EXPECT_NE(getSerializedData("rewritelinks_simple.html", "text/html").find(".
/folder/b.png"), kNotFound); |
| 427 } |
| 428 |
| 429 TEST_F(PageSerializerTest, RewriteLinksBase) |
| 430 { |
| 431 setBaseFolder("pageserializer/rewritelinks/"); |
| 432 setRewriteURLFolder("folder"); |
| 433 |
| 434 registerURL("rewritelinks_base.html", "text/html"); |
| 435 registerURL("images/here/image.png", "image.png", "image/png"); |
| 436 registerURL("images/here/or/in/here/image.png", "image.png", "image/png"); |
| 437 registerURL("or/absolute.png", "image.png", "image/png"); |
| 438 registerRewriteURL("http://www.test.com/images/here/image.png", "a.png"); |
| 439 registerRewriteURL("http://www.test.com/images/here/or/in/here/image.png", "
b.png"); |
| 440 registerRewriteURL("http://www.test.com/or/absolute.png", "c.png"); |
| 441 |
| 442 serialize("rewritelinks_base.html"); |
| 443 |
| 444 EXPECT_EQ(4U, getResources().size()); |
| 445 EXPECT_NE(getSerializedData("rewritelinks_base.html", "text/html").find("./f
older/a.png"), kNotFound); |
| 446 EXPECT_NE(getSerializedData("rewritelinks_base.html", "text/html").find("./f
older/b.png"), kNotFound); |
| 447 EXPECT_NE(getSerializedData("rewritelinks_base.html", "text/html").find("./f
older/c.png"), kNotFound); |
| 448 } |
| 449 |
394 // Test that we don't regress https://bugs.webkit.org/show_bug.cgi?id=99105 | 450 // Test that we don't regress https://bugs.webkit.org/show_bug.cgi?id=99105 |
395 TEST_F(PageSerializerTest, SVGImageDontCrash) | 451 TEST_F(PageSerializerTest, SVGImageDontCrash) |
396 { | 452 { |
397 setBaseFolder("pageserializer/svg/"); | 453 setBaseFolder("pageserializer/svg/"); |
398 | 454 |
399 registerURL("page_with_svg_image.html", "text/html"); | 455 registerURL("page_with_svg_image.html", "text/html"); |
400 registerURL("green_rectangle.svg", "image/svg+xml"); | 456 registerURL("green_rectangle.svg", "image/svg+xml"); |
401 | 457 |
402 serialize("page_with_svg_image.html"); | 458 serialize("page_with_svg_image.html"); |
403 | 459 |
(...skipping 24 matching lines...) Expand all Loading... |
428 registerURL("namespace_element.html", "text/html"); | 484 registerURL("namespace_element.html", "text/html"); |
429 | 485 |
430 serialize("namespace_element.html"); | 486 serialize("namespace_element.html"); |
431 | 487 |
432 EXPECT_EQ(1U, getResources().size()); | 488 EXPECT_EQ(1U, getResources().size()); |
433 EXPECT_TRUE(isSerialized("namespace_element.html", "text/html")); | 489 EXPECT_TRUE(isSerialized("namespace_element.html", "text/html")); |
434 EXPECT_GT(getSerializedData("namespace_element.html", "text/html").length(),
0U); | 490 EXPECT_GT(getSerializedData("namespace_element.html", "text/html").length(),
0U); |
435 } | 491 } |
436 | 492 |
437 } | 493 } |
OLD | NEW |