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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 m_string += data; | 61 m_string += data; |
62 } | 62 } |
63 | 63 |
64 std::string m_string; | 64 std::string m_string; |
65 }; | 65 }; |
66 | 66 |
67 } // namespace | 67 } // namespace |
68 | 68 |
69 class WebPageSerializerTest : public testing::Test { | 69 class WebPageSerializerTest : public testing::Test { |
70 public: | 70 public: |
71 WebPageSerializerTest() : m_supportedSchemes(static_cast<size_t>(3)) | 71 WebPageSerializerTest() |
| 72 : m_supportedSchemes(static_cast<size_t>(3)) |
72 { | 73 { |
73 m_supportedSchemes[0] = "http"; | 74 m_supportedSchemes[0] = "http"; |
74 m_supportedSchemes[1] = "https"; | 75 m_supportedSchemes[1] = "https"; |
75 m_supportedSchemes[2] = "file"; | 76 m_supportedSchemes[2] = "file"; |
| 77 |
| 78 registerMockedImageURL("http://www.test.com/awesome.png"); |
76 } | 79 } |
77 | 80 |
78 protected: | 81 protected: |
79 void SetUp() override | 82 void SetUp() override |
80 { | 83 { |
81 m_helper.initialize(); | 84 m_helper.initialize(); |
82 } | 85 } |
83 | 86 |
84 void TearDown() override | 87 void TearDown() override |
85 { | 88 { |
86 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 89 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
87 } | 90 } |
88 | 91 |
89 void registerMockedURLLoad(const std::string& url, const WebString& fileName
) | 92 void registerMockedURLLoad(const std::string& url, const WebString& fileName
) |
90 { | 93 { |
91 URLTestHelpers::registerMockedURLLoad(toKURL(url), fileName, WebString::
fromUTF8("pageserialization/"), WebString::fromUTF8("text/html")); | 94 URLTestHelpers::registerMockedURLLoad(toKURL(url), fileName, WebString::
fromUTF8("pageserialization/"), WebString::fromUTF8("text/html")); |
92 } | 95 } |
93 | 96 |
| 97 void registerMockedImageURL(const std::string& url) |
| 98 { |
| 99 // Image resources need to be mocked, but irrelevant here what image the
y map to. |
| 100 URLTestHelpers::registerMockedURLLoad(toKURL(url), "pageserialization/aw
esome.png"); |
| 101 } |
| 102 |
94 void loadURLInTopFrame(const WebURL& url) | 103 void loadURLInTopFrame(const WebURL& url) |
95 { | 104 { |
96 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), url.string(
).utf8()); | 105 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), url.string(
).utf8()); |
97 } | 106 } |
98 | 107 |
99 static bool webVectorContains(const WebVector<WebURL>& vector, const char* u
rl) | 108 static bool webVectorContains(const WebVector<WebURL>& vector, const char* u
rl) |
100 { | 109 { |
101 return vector.contains(WebURL(toKURL(std::string(url)))); | 110 return vector.contains(WebURL(toKURL(std::string(url)))); |
102 } | 111 } |
103 | 112 |
(...skipping 11 matching lines...) Expand all Loading... |
115 private: | 124 private: |
116 FrameTestHelpers::WebViewHelper m_helper; | 125 FrameTestHelpers::WebViewHelper m_helper; |
117 }; | 126 }; |
118 | 127 |
119 TEST_F(WebPageSerializerTest, HTMLNodes) | 128 TEST_F(WebPageSerializerTest, HTMLNodes) |
120 { | 129 { |
121 // Register the mocked frame and load it. | 130 // Register the mocked frame and load it. |
122 WebURL topFrameURL = toKURL("http://www.test.com"); | 131 WebURL topFrameURL = toKURL("http://www.test.com"); |
123 registerMockedURLLoad("http://www.test.com", WebString::fromUTF8("simple_pag
e.html")); | 132 registerMockedURLLoad("http://www.test.com", WebString::fromUTF8("simple_pag
e.html")); |
124 registerMockedURLLoad("http://www.example.com/beautifull.css", WebString::fr
omUTF8("beautifull.css")); | 133 registerMockedURLLoad("http://www.example.com/beautifull.css", WebString::fr
omUTF8("beautifull.css")); |
| 134 |
| 135 registerMockedImageURL("http://www.test.com/imageButton.png"); |
| 136 registerMockedImageURL("http://www.test.com/tableBackground.png"); |
| 137 registerMockedImageURL("http://www.test.com/trBackground.png"); |
| 138 registerMockedImageURL("http://www.test.com/tdBackground.png"); |
| 139 registerMockedImageURL("http://www.test.com/innerFrame.png"); |
| 140 registerMockedImageURL("http://www.test.com/bodyBackground.jpg"); |
| 141 registerMockedImageURL("https://www.secure.com/https.gif"); |
| 142 registerMockedImageURL("ftp://ftp.com/ftp.gif"); |
| 143 registerMockedImageURL("unknown://unkown.com/unknown.gif"); |
| 144 |
125 loadURLInTopFrame(topFrameURL); | 145 loadURLInTopFrame(topFrameURL); |
126 | 146 |
127 // Retrieve all resources. | 147 // Retrieve all resources. |
128 WebVector<WebURL> frames; | 148 WebVector<WebURL> frames; |
129 WebVector<WebURL> resources; | 149 WebVector<WebURL> resources; |
130 ASSERT_TRUE(WebPageSerializer::retrieveAllResources( | 150 ASSERT_TRUE(WebPageSerializer::retrieveAllResources( |
131 webView(), m_supportedSchemes, &resources, &frames)); | 151 webView(), m_supportedSchemes, &resources, &frames)); |
132 | 152 |
133 // Tests that all resources from the frame have been retrieved. | 153 // Tests that all resources from the frame have been retrieved. |
134 EXPECT_EQ(1U, frames.size()); // There should be no duplicates. | 154 EXPECT_EQ(1U, frames.size()); // There should be no duplicates. |
(...skipping 13 matching lines...) Expand all Loading... |
148 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/why_deleted.ht
ml")); | 168 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/why_deleted.ht
ml")); |
149 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/why_inserted.h
tml")); | 169 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/why_inserted.h
tml")); |
150 EXPECT_TRUE(webVectorContains(resources, "https://www.secure.com/https.gif")
); | 170 EXPECT_TRUE(webVectorContains(resources, "https://www.secure.com/https.gif")
); |
151 EXPECT_TRUE(webVectorContains(resources, "file://c/my_folder/file.gif")); | 171 EXPECT_TRUE(webVectorContains(resources, "file://c/my_folder/file.gif")); |
152 } | 172 } |
153 | 173 |
154 TEST_F(WebPageSerializerTest, URLAttributeValues) | 174 TEST_F(WebPageSerializerTest, URLAttributeValues) |
155 { | 175 { |
156 WebURL topFrameURL = toKURL("http://www.test.com"); | 176 WebURL topFrameURL = toKURL("http://www.test.com"); |
157 registerMockedURLLoad(topFrameURL.spec(), WebString::fromUTF8("url_attribute
_values.html")); | 177 registerMockedURLLoad(topFrameURL.spec(), WebString::fromUTF8("url_attribute
_values.html")); |
| 178 registerMockedImageURL("javascript:\""); |
| 179 |
158 loadURLInTopFrame(topFrameURL); | 180 loadURLInTopFrame(topFrameURL); |
159 | 181 |
160 SimpleWebPageSerializerClient serializerClient; | 182 SimpleWebPageSerializerClient serializerClient; |
161 WebVector<WebURL> links(&topFrameURL, 1); | 183 WebVector<WebURL> links(&topFrameURL, 1); |
162 WebVector<WebString> localPaths(&"local", 1); | 184 WebVector<WebString> localPaths(&"local", 1); |
163 WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), &ser
ializerClient, links, localPaths, ""); | 185 WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), &ser
ializerClient, links, localPaths, ""); |
164 | 186 |
165 const char* expectedHTML = | 187 const char* expectedHTML = |
166 "\n<!-- saved from url=(0020)http://www.test.com/ -->\n" | 188 "\n<!-- saved from url=(0020)http://www.test.com/ -->\n" |
167 "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; char
set=UTF-8\"><meta charset=\"utf8\">\n" | 189 "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; char
set=UTF-8\"><meta charset=\"utf8\">\n" |
(...skipping 22 matching lines...) Expand all Loading... |
190 { | 212 { |
191 // Register the mocked frames. | 213 // Register the mocked frames. |
192 WebURL topFrameURL = toKURL("http://www.test.com"); | 214 WebURL topFrameURL = toKURL("http://www.test.com"); |
193 registerMockedURLLoad("http://www.test.com", WebString::fromUTF8("top_frame.
html")); | 215 registerMockedURLLoad("http://www.test.com", WebString::fromUTF8("top_frame.
html")); |
194 registerMockedURLLoad("http://www.test.com/simple_iframe.html", | 216 registerMockedURLLoad("http://www.test.com/simple_iframe.html", |
195 WebString::fromUTF8("simple_iframe.html")); | 217 WebString::fromUTF8("simple_iframe.html")); |
196 registerMockedURLLoad("http://www.test.com/object_iframe.html", | 218 registerMockedURLLoad("http://www.test.com/object_iframe.html", |
197 WebString::fromUTF8("object_iframe.html")); | 219 WebString::fromUTF8("object_iframe.html")); |
198 registerMockedURLLoad("http://www.test.com/embed_iframe.html", | 220 registerMockedURLLoad("http://www.test.com/embed_iframe.html", |
199 WebString::fromUTF8("embed_iframe.html")); | 221 WebString::fromUTF8("embed_iframe.html")); |
200 // If we don't register a mocked resource for awesome.png, it causes the | 222 registerMockedImageURL("http://www.test.com/innerFrame.png"); |
201 // document loader of the iframe that has it as its src to assert on close, | 223 registerMockedImageURL("http://www.test.com/embed.png"); |
202 // not sure why. | 224 registerMockedImageURL("http://www.test.com/object.png"); |
203 registerMockedURLLoad("http://www.test.com/awesome.png", | |
204 WebString::fromUTF8("awesome.png")); | |
205 | 225 |
206 loadURLInTopFrame(topFrameURL); | 226 loadURLInTopFrame(topFrameURL); |
207 | 227 |
208 // Retrieve all resources. | 228 // Retrieve all resources. |
209 WebVector<WebURL> frames; | 229 WebVector<WebURL> frames; |
210 WebVector<WebURL> resources; | 230 WebVector<WebURL> resources; |
211 ASSERT_TRUE(WebPageSerializer::retrieveAllResources( | 231 ASSERT_TRUE(WebPageSerializer::retrieveAllResources( |
212 webView(), m_supportedSchemes, &resources, &frames)); | 232 webView(), m_supportedSchemes, &resources, &frames)); |
213 | 233 |
214 // Tests that all resources from the frame have been retrieved. | 234 // Tests that all resources from the frame have been retrieved. |
215 EXPECT_EQ(4U, frames.size()); // There should be no duplicates. | 235 EXPECT_EQ(4U, frames.size()); // There should be no duplicates. |
216 EXPECT_TRUE(webVectorContains(frames, "http://www.test.com")); | 236 EXPECT_TRUE(webVectorContains(frames, "http://www.test.com")); |
217 EXPECT_TRUE(webVectorContains(frames, "http://www.test.com/simple_iframe.htm
l")); | 237 EXPECT_TRUE(webVectorContains(frames, "http://www.test.com/simple_iframe.htm
l")); |
218 EXPECT_TRUE(webVectorContains(frames, "http://www.test.com/object_iframe.htm
l")); | 238 EXPECT_TRUE(webVectorContains(frames, "http://www.test.com/object_iframe.htm
l")); |
219 EXPECT_TRUE(webVectorContains(frames, "http://www.test.com/embed_iframe.html
")); | 239 EXPECT_TRUE(webVectorContains(frames, "http://www.test.com/embed_iframe.html
")); |
220 | 240 |
221 EXPECT_EQ(5U, resources.size()); // There should be no duplicates. | 241 EXPECT_EQ(5U, resources.size()); // There should be no duplicates. |
222 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/awesome.png"))
; | 242 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/awesome.png"))
; |
223 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/innerFrame.png
")); | 243 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/innerFrame.png
")); |
224 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/flash.swf")); | 244 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/flash.swf")); |
225 // FIXME: for some reason the following resources is missing on one of the b
ot | 245 // FIXME: for some reason the following resources is missing on one of the b
ot |
226 // causing the test to fail. Probably a plugin issue. | 246 // causing the test to fail. Probably a plugin issue. |
227 // EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/music.mid")
); | 247 // EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/music.mid")
); |
228 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/object.png")); | 248 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/object.png")); |
229 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/embed.png")); | 249 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/embed.png")); |
230 } | 250 } |
231 | 251 |
232 } // namespace blink | 252 } // namespace blink |
OLD | NEW |