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 10 matching lines...) Expand all Loading... |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "public/web/WebPageSerializer.h" | 31 #include "public/web/WebFrameSerializer.h" |
32 | 32 |
33 #include "platform/testing/URLTestHelpers.h" | 33 #include "platform/testing/URLTestHelpers.h" |
34 #include "platform/weborigin/KURL.h" | 34 #include "platform/weborigin/KURL.h" |
35 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
36 #include "public/platform/WebString.h" | 36 #include "public/platform/WebString.h" |
37 #include "public/platform/WebURL.h" | 37 #include "public/platform/WebURL.h" |
38 #include "public/platform/WebUnitTestSupport.h" | 38 #include "public/platform/WebUnitTestSupport.h" |
39 #include "public/web/WebPageSerializerClient.h" | 39 #include "public/web/WebFrameSerializerClient.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
41 #include "web/WebLocalFrameImpl.h" | 41 #include "web/WebLocalFrameImpl.h" |
42 #include "web/WebViewImpl.h" | 42 #include "web/WebViewImpl.h" |
43 #include "web/tests/FrameTestHelpers.h" | 43 #include "web/tests/FrameTestHelpers.h" |
44 #include "wtf/text/StringBuilder.h" | 44 #include "wtf/text/StringBuilder.h" |
45 | 45 |
46 namespace blink { | 46 namespace blink { |
47 | 47 |
48 namespace { | 48 namespace { |
49 class SimpleWebPageSerializerClient final : public WebPageSerializerClient { | 49 class SimpleWebFrameSerializerClient final : public WebFrameSerializerClient { |
50 public: | 50 public: |
51 String toString() { return m_builder.toString(); } | 51 String toString() { return m_builder.toString(); } |
52 | 52 |
53 private: | 53 private: |
54 void didSerializeDataForFrame(const WebCString& data, PageSerializationStatu
s) final | 54 void didSerializeDataForFrame(const WebCString& data, FrameSerializationStat
us) final |
55 { | 55 { |
56 m_builder.append(data.data(), data.length()); | 56 m_builder.append(data.data(), data.length()); |
57 } | 57 } |
58 | 58 |
59 StringBuilder m_builder; | 59 StringBuilder m_builder; |
60 }; | 60 }; |
61 | 61 |
62 } // namespace | 62 } // namespace |
63 | 63 |
64 class WebPageSerializerTest : public testing::Test { | 64 class WebFrameSerializerTest : public testing::Test { |
65 protected: | 65 protected: |
66 WebPageSerializerTest() | 66 WebFrameSerializerTest() |
67 { | 67 { |
68 m_helper.initialize(); | 68 m_helper.initialize(); |
69 } | 69 } |
70 | 70 |
71 ~WebPageSerializerTest() override | 71 ~WebFrameSerializerTest() override |
72 { | 72 { |
73 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 73 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
74 } | 74 } |
75 | 75 |
76 void registerMockedImageURL(const String& url) | 76 void registerMockedImageURL(const String& url) |
77 { | 77 { |
78 // Image resources need to be mocked, but irrelevant here what image the
y map to. | 78 // Image resources need to be mocked, but irrelevant here what image the
y map to. |
79 URLTestHelpers::registerMockedURLLoad(KURL(ParsedURLString, url), "pages
erialization/awesome.png"); | 79 URLTestHelpers::registerMockedURLLoad(KURL(ParsedURLString, url), "frame
serialization/awesome.png"); |
80 } | 80 } |
81 | 81 |
82 String serializeFile(const String& url, const String& fileName) | 82 String serializeFile(const String& url, const String& fileName) |
83 { | 83 { |
84 KURL parsedURL(ParsedURLString, url); | 84 KURL parsedURL(ParsedURLString, url); |
85 URLTestHelpers::registerMockedURLLoad(parsedURL, fileName, "pageserializ
ation/", "text/html"); | 85 URLTestHelpers::registerMockedURLLoad(parsedURL, fileName, "frameseriali
zation/", "text/html"); |
86 FrameTestHelpers::loadFrame(mainFrameImpl(), url.utf8().data()); | 86 FrameTestHelpers::loadFrame(mainFrameImpl(), url.utf8().data()); |
87 std::vector<std::pair<WebURL, WebString>> urlsToLocalPaths; | 87 std::vector<std::pair<WebURL, WebString>> urlsToLocalPaths; |
88 urlsToLocalPaths.push_back(std::make_pair(parsedURL, WebString("local"))
); | 88 urlsToLocalPaths.push_back(std::make_pair(parsedURL, WebString("local"))
); |
89 SimpleWebPageSerializerClient serializerClient; | 89 SimpleWebFrameSerializerClient serializerClient; |
90 WebPageSerializer::serialize(mainFrameImpl(), &serializerClient, urlsToL
ocalPaths); | 90 WebFrameSerializer::serialize(mainFrameImpl(), &serializerClient, urlsTo
LocalPaths); |
91 return serializerClient.toString(); | 91 return serializerClient.toString(); |
92 } | 92 } |
93 | 93 |
94 WebLocalFrameImpl* mainFrameImpl() | 94 WebLocalFrameImpl* mainFrameImpl() |
95 { | 95 { |
96 return m_helper.webViewImpl()->mainFrameImpl(); | 96 return m_helper.webViewImpl()->mainFrameImpl(); |
97 } | 97 } |
98 | 98 |
99 private: | 99 private: |
100 FrameTestHelpers::WebViewHelper m_helper; | 100 FrameTestHelpers::WebViewHelper m_helper; |
101 }; | 101 }; |
102 | 102 |
103 TEST_F(WebPageSerializerTest, URLAttributeValues) | 103 TEST_F(WebFrameSerializerTest, URLAttributeValues) |
104 { | 104 { |
105 registerMockedImageURL("javascript:\""); | 105 registerMockedImageURL("javascript:\""); |
106 | 106 |
107 const char* expectedHTML = | 107 const char* expectedHTML = |
108 "\n<!-- saved from url=(0020)http://www.test.com/ -->\n" | 108 "\n<!-- saved from url=(0020)http://www.test.com/ -->\n" |
109 "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; char
set=UTF-8\">\n" | 109 "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; char
set=UTF-8\">\n" |
110 "</head><body><img src=\"javascript:"\">\n" | 110 "</head><body><img src=\"javascript:"\">\n" |
111 "<a href=\"http://www.test.com/local#"\">local</a>\n" | 111 "<a href=\"http://www.test.com/local#"\">local</a>\n" |
112 "<a href=\"http://www.example.com/#"><script>alert(0)</
script>\">external</a>\n" | 112 "<a href=\"http://www.example.com/#"><script>alert(0)</
script>\">external</a>\n" |
113 "</body></html>"; | 113 "</body></html>"; |
114 String actualHTML = serializeFile("http://www.test.com", "url_attribute_valu
es.html"); | 114 String actualHTML = serializeFile("http://www.test.com", "url_attribute_valu
es.html"); |
115 EXPECT_EQ(expectedHTML, actualHTML); | 115 EXPECT_EQ(expectedHTML, actualHTML); |
116 } | 116 } |
117 | 117 |
118 TEST_F(WebPageSerializerTest, EncodingAndNormalization) | 118 TEST_F(WebFrameSerializerTest, EncodingAndNormalization) |
119 { | 119 { |
120 const char* expectedHTML = | 120 const char* expectedHTML = |
121 "<!DOCTYPE html>\n" | 121 "<!DOCTYPE html>\n" |
122 "<!-- saved from url=(0020)http://www.test.com/ -->\n" | 122 "<!-- saved from url=(0020)http://www.test.com/ -->\n" |
123 "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; char
set=EUC-KR\">\n" | 123 "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; char
set=EUC-KR\">\n" |
124 "<title>Ensure NFC normalization is not performed by page serializer</ti
tle>\n" | 124 "<title>Ensure NFC normalization is not performed by frame serializer</t
itle>\n" |
125 "</head><body>\n" | 125 "</head><body>\n" |
126 "\xe4\xc5\xd1\xe2\n" | 126 "\xe4\xc5\xd1\xe2\n" |
127 "\n</body></html>"; | 127 "\n</body></html>"; |
128 String actualHTML = serializeFile("http://www.test.com", "encoding_normaliza
tion.html"); | 128 String actualHTML = serializeFile("http://www.test.com", "encoding_normaliza
tion.html"); |
129 EXPECT_EQ(expectedHTML, actualHTML); | 129 EXPECT_EQ(expectedHTML, actualHTML); |
130 } | 130 } |
131 | 131 |
132 TEST_F(WebPageSerializerTest, FromUrlWithMinusMinus) | 132 TEST_F(WebFrameSerializerTest, FromUrlWithMinusMinus) |
133 { | 133 { |
134 String actualHTML = serializeFile("http://www.test.com?--x--", "text_only_pa
ge.html"); | 134 String actualHTML = serializeFile("http://www.test.com?--x--", "text_only_pa
ge.html"); |
135 EXPECT_EQ("<!-- saved from url=(0030)http://www.test.com/?-%2Dx-%2D -->", ac
tualHTML.substring(1, 60)); | 135 EXPECT_EQ("<!-- saved from url=(0030)http://www.test.com/?-%2Dx-%2D -->", ac
tualHTML.substring(1, 60)); |
136 } | 136 } |
137 | 137 |
138 } // namespace blink | 138 } // namespace blink |
OLD | NEW |