Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: trunk/Source/web/tests/PageSerializerTest.cpp

Issue 73673003: Revert 162155 "This review merges the two existing page serializ..." (Closed) Base URL: svn://svn.chromium.org/blink/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/Source/web/tests/MHTMLTest.cpp ('k') | trunk/Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 void setBaseUrl(const char* url) 98 void setBaseUrl(const char* url)
99 { 99 {
100 m_baseUrl = toKURL(url); 100 m_baseUrl = toKURL(url);
101 } 101 }
102 102
103 void setBaseFolder(const char* folder) 103 void setBaseFolder(const char* folder)
104 { 104 {
105 m_folder = WebString::fromUTF8(folder); 105 m_folder = WebString::fromUTF8(folder);
106 } 106 }
107 107
108 void setRewriteURLFolder(const char* folder)
109 {
110 m_rewriteFolder = folder;
111 }
112
113 void registerURL(const char* url, const char* file, const char* mimeType)
114 {
115 registerMockedURLLoad(KURL(m_baseUrl, url), WebString::fromUTF8(file), m _folder, WebString::fromUTF8(mimeType));
116 }
117
118 void registerURL(const char* file, const char* mimeType) 108 void registerURL(const char* file, const char* mimeType)
119 { 109 {
120 registerURL(file, file, mimeType); 110 registerMockedURLLoad(KURL(m_baseUrl, file), WebString::fromUTF8(file), m_folder, WebString::fromUTF8(mimeType));
121 } 111 }
122 112
123 void registerErrorURL(const char* file, int statusCode) 113 void registerErrorURL(const char* file, int statusCode)
124 { 114 {
125 WebURLError error; 115 WebURLError error;
126 error.reason = 0xdead + statusCode; 116 error.reason = 0xdead + statusCode;
127 error.domain = "PageSerializerTest"; 117 error.domain = "PageSerializerTest";
128 118
129 WebURLResponse response; 119 WebURLResponse response;
130 response.initialize(); 120 response.initialize();
131 response.setMIMEType("text/html"); 121 response.setMIMEType("text/html");
132 response.setHTTPStatusCode(statusCode); 122 response.setHTTPStatusCode(statusCode);
133 123
134 Platform::current()->unitTestSupport()->registerMockedErrorURL(KURL(m_ba seUrl, file), response, error); 124 Platform::current()->unitTestSupport()->registerMockedErrorURL(KURL(m_ba seUrl, file), response, error);
135 } 125 }
136 126
137 void registerRewriteURL(const char* fromURL, const char* toURL)
138 {
139 m_rewriteURLs.add(fromURL, toURL);
140 }
141
142 void serialize(const char* url) 127 void serialize(const char* url)
143 { 128 {
144 WebURLRequest urlRequest; 129 WebURLRequest urlRequest;
145 urlRequest.initialize(); 130 urlRequest.initialize();
146 urlRequest.setURL(KURL(m_baseUrl, url)); 131 urlRequest.setURL(KURL(m_baseUrl, url));
147 m_webViewImpl->mainFrame()->loadRequest(urlRequest); 132 m_webViewImpl->mainFrame()->loadRequest(urlRequest);
148 // Make sure any pending request get served. 133 // Make sure any pending request get served.
149 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests( ); 134 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests( );
150 // Some requests get delayed, run the timer. 135 // Some requests get delayed, run the timer.
151 runPendingTasks(); 136 runPendingTasks();
152 // Server the delayed resources. 137 // Server the delayed resources.
153 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests( ); 138 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests( );
154 139
155 PageSerializer serializer(&m_resources, 140 PageSerializer serializer(&m_resources);
156 m_rewriteURLs.isEmpty() ? 0: &m_rewriteURLs, m_rewriteFolder);
157 serializer.serialize(m_webViewImpl->mainFrameImpl()->frame()->page()); 141 serializer.serialize(m_webViewImpl->mainFrameImpl()->frame()->page());
158 } 142 }
159 143
160 Vector<SerializedResource>& getResources() 144 Vector<SerializedResource>& getResources()
161 { 145 {
162 return m_resources; 146 return m_resources;
163 } 147 }
164 148
165 149
166 const SerializedResource* getResource(const char* url, const char* mimeType) 150 const SerializedResource* getResource(const char* url, const char* mimeType)
(...skipping 15 matching lines...) Expand all
182 } 166 }
183 167
184 String getSerializedData(const char* url, const char* mimeType = 0) 168 String getSerializedData(const char* url, const char* mimeType = 0)
185 { 169 {
186 const SerializedResource* resource = getResource(url, mimeType); 170 const SerializedResource* resource = getResource(url, mimeType);
187 if (resource) 171 if (resource)
188 return String(resource->data->data(), resource->data->size()); 172 return String(resource->data->data(), resource->data->size());
189 return String(); 173 return String();
190 } 174 }
191 175
192 // For debugging
193 void printResources()
194 {
195 printf("Printing resources (%zu resources in total)\n", m_resources.size ());
196 for (size_t i = 0; i < m_resources.size(); ++i) {
197 printf("%zu. '%s', '%s'\n", i, m_resources[i].url.string().utf8().da ta(),
198 m_resources[i].mimeType.utf8().data());
199 }
200 }
201
202 WebViewImpl* m_webViewImpl; 176 WebViewImpl* m_webViewImpl;
203 177
204 private: 178 private:
205 TestWebFrameClient m_webFrameClient; 179 TestWebFrameClient m_webFrameClient;
206 WebFrame* m_mainFrame; 180 WebFrame* m_mainFrame;
207 WebString m_folder; 181 WebString m_folder;
208 KURL m_baseUrl; 182 KURL m_baseUrl;
209 Vector<SerializedResource> m_resources; 183 Vector<SerializedResource> m_resources;
210 LinkLocalPathMap m_rewriteURLs;
211 String m_rewriteFolder;
212 }; 184 };
213 185
214 TEST_F(PageSerializerTest, HTMLElements) 186
187 TEST_F(PageSerializerTest, InputImage)
215 { 188 {
216 setBaseFolder("pageserializer/elements/"); 189 setBaseFolder("pageserializer/input-image/");
217 190
218 registerURL("elements.html", "text/html"); 191 registerURL("input-image.html", "text/html");
219 registerURL("style.css", "style.css", "text/css"); 192 registerURL("button.png", "image/png");
220 registerURL("copyright.html", "text.txt", "text/html"); 193 registerErrorURL("non-existing-button.png", 404);
221 registerURL("script.js", "text.txt", "text/javascript");
222 194
223 registerURL("bodyBackground.png", "image.png", "image/png"); 195 serialize("input-image.html");
224 196
225 registerURL("imageSrc.png", "image.png", "image/png"); 197 EXPECT_TRUE(isSerialized("button.png", "image/png"));
226 198 EXPECT_FALSE(isSerialized("non-existing-button.png", "image/png"));
227 registerURL("inputImage.png", "image.png", "image/png");
228
229 registerURL("tableBackground.png", "image.png", "image/png");
230 registerURL("trBackground.png", "image.png", "image/png");
231 registerURL("tdBackground.png", "image.png", "image/png");
232
233 registerURL("blockquoteCite.html", "text.txt", "text/html");
234 registerURL("qCite.html", "text.txt", "text/html");
235 registerURL("delCite.html", "text.txt", "text/html");
236 registerURL("insCite.html", "text.txt", "text/html");
237
238 registerErrorURL("nonExisting.png", 404);
239
240 serialize("elements.html");
241
242 EXPECT_EQ(8U, getResources().size());
243
244 EXPECT_TRUE(isSerialized("elements.html", "text/html"));
245 EXPECT_TRUE(isSerialized("style.css", "text/css"));
246 EXPECT_TRUE(isSerialized("bodyBackground.png", "image/png"));
247 EXPECT_TRUE(isSerialized("imageSrc.png", "image/png"));
248 EXPECT_TRUE(isSerialized("inputImage.png", "image/png"));
249 EXPECT_TRUE(isSerialized("tableBackground.png", "image/png"));
250 EXPECT_TRUE(isSerialized("trBackground.png", "image/png"));
251 EXPECT_TRUE(isSerialized("tdBackground.png", "image/png"));
252 EXPECT_FALSE(isSerialized("nonExisting.png", "image/png"));
253 }
254
255 TEST_F(PageSerializerTest, Frames)
256 {
257 setBaseFolder("pageserializer/frames/");
258
259 registerURL("simple_frames.html", "text/html");
260 registerURL("simple_frames_top.html", "text/html");
261 registerURL("simple_frames_1.html", "text/html");
262 registerURL("simple_frames_3.html", "text/html");
263
264 registerURL("frame_1.png", "image.png", "image/png");
265 registerURL("frame_2.png", "image.png", "image/png");
266 registerURL("frame_3.png", "image.png", "image/png");
267 registerURL("frame_4.png", "image.png", "image/png");
268
269 serialize("simple_frames.html");
270
271 EXPECT_EQ(8U, getResources().size());
272
273 EXPECT_TRUE(isSerialized("simple_frames.html", "text/html"));
274 EXPECT_TRUE(isSerialized("simple_frames_top.html", "text/html"));
275 EXPECT_TRUE(isSerialized("simple_frames_1.html", "text/html"));
276 EXPECT_TRUE(isSerialized("simple_frames_3.html", "text/html"));
277
278 EXPECT_TRUE(isSerialized("frame_1.png", "image/png"));
279 EXPECT_TRUE(isSerialized("frame_2.png", "image/png"));
280 EXPECT_TRUE(isSerialized("frame_3.png", "image/png"));
281 EXPECT_TRUE(isSerialized("frame_4.png", "image/png"));
282 }
283
284 TEST_F(PageSerializerTest, IFrames)
285 {
286 setBaseFolder("pageserializer/frames/");
287
288 registerURL("top_frame.html", "text/html");
289 registerURL("simple_iframe.html", "text/html");
290 registerURL("object_iframe.html", "text/html");
291 registerURL("embed_iframe.html", "text/html");
292
293 registerURL("top.png", "image.png", "image/png");
294 registerURL("simple.png", "image.png", "image/png");
295 registerURL("object.png", "image.png", "image/png");
296 registerURL("embed.png", "image.png", "image/png");
297
298 serialize("top_frame.html");
299
300 EXPECT_EQ(8U, getResources().size());
301
302 EXPECT_TRUE(isSerialized("top_frame.html", "text/html"));
303 EXPECT_TRUE(isSerialized("simple_iframe.html", "text/html"));
304 EXPECT_TRUE(isSerialized("object_iframe.html", "text/html"));
305 EXPECT_TRUE(isSerialized("embed_iframe.html", "text/html"));
306
307 EXPECT_TRUE(isSerialized("top.png", "image/png"));
308 EXPECT_TRUE(isSerialized("simple.png", "image/png"));
309 EXPECT_TRUE(isSerialized("object.png", "image/png"));
310 EXPECT_TRUE(isSerialized("embed.png", "image/png"));
311 }
312
313 // Tests that when serializing a page with blank frames these are reported with their resources.
314 TEST_F(PageSerializerTest, BlankFrames)
315 {
316 setBaseFolder("pageserializer/frames/");
317
318 registerURL("blank_frames.html", "text/html");
319 registerURL("red_background.png", "image.png", "image/png");
320 registerURL("orange_background.png", "image.png", "image/png");
321 registerURL("blue_background.png", "image.png", "image/png");
322
323 serialize("blank_frames.html");
324
325 EXPECT_EQ(7U, getResources().size());
326
327 EXPECT_TRUE(isSerialized("http://www.test.com/red_background.png", "image/pn g"));
328 EXPECT_TRUE(isSerialized("http://www.test.com/orange_background.png", "image /png"));
329 EXPECT_TRUE(isSerialized("http://www.test.com/blue_background.png", "image/p ng"));
330 // The blank frames should have got a magic URL.
331 EXPECT_TRUE(isSerialized("wyciwyg://frame/0", "text/html"));
332 EXPECT_TRUE(isSerialized("wyciwyg://frame/1", "text/html"));
333 EXPECT_TRUE(isSerialized("wyciwyg://frame/2", "text/html"));
334 }
335
336 TEST_F(PageSerializerTest, CSS)
337 {
338 setBaseFolder("pageserializer/css/");
339
340 registerURL("css_test_page.html", "text/html");
341 registerURL("link_styles.css", "text/css");
342 registerURL("import_style_from_link.css", "text/css");
343 registerURL("import_styles.css", "text/css");
344 registerURL("red_background.png", "image.png", "image/png");
345 registerURL("orange_background.png", "image.png", "image/png");
346 registerURL("yellow_background.png", "image.png", "image/png");
347 registerURL("green_background.png", "image.png", "image/png");
348 registerURL("blue_background.png", "image.png", "image/png");
349 registerURL("purple_background.png", "image.png", "image/png");
350 registerURL("ul-dot.png", "image.png", "image/png");
351 registerURL("ol-dot.png", "image.png", "image/png");
352
353 serialize("css_test_page.html");
354
355 EXPECT_EQ(12U, getResources().size());
356
357 EXPECT_TRUE(isSerialized("css_test_page.html", "text/html"));
358 EXPECT_TRUE(isSerialized("link_styles.css", "text/css"));
359 EXPECT_TRUE(isSerialized("import_styles.css", "text/css"));
360 EXPECT_TRUE(isSerialized("import_style_from_link.css", "text/css"));
361 EXPECT_TRUE(isSerialized("red_background.png", "image/png"));
362 EXPECT_TRUE(isSerialized("orange_background.png", "image/png"));
363 EXPECT_TRUE(isSerialized("yellow_background.png", "image/png"));
364 EXPECT_TRUE(isSerialized("green_background.png", "image/png"));
365 EXPECT_TRUE(isSerialized("blue_background.png", "image/png"));
366 EXPECT_TRUE(isSerialized("purple_background.png", "image/png"));
367 EXPECT_TRUE(isSerialized("ul-dot.png", "image/png"));
368 EXPECT_TRUE(isSerialized("ol-dot.png", "image/png"));
369 } 199 }
370 200
371 TEST_F(PageSerializerTest, XMLDeclaration) 201 TEST_F(PageSerializerTest, XMLDeclaration)
372 { 202 {
373 setBaseFolder("pageserializer/xml/"); 203 setBaseFolder("pageserializer/xmldecl/");
374 204
375 registerURL("xmldecl.xml", "text/xml"); 205 registerURL("xmldecl.xml", "text/xml");
376 serialize("xmldecl.xml"); 206 serialize("xmldecl.xml");
377 207
378 String expectedStart("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 208 String expectedStart("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
379 EXPECT_TRUE(getSerializedData("xmldecl.xml").startsWith(expectedStart)); 209 EXPECT_TRUE(getSerializedData("xmldecl.xml").startsWith(expectedStart));
380 } 210 }
381 211
382 TEST_F(PageSerializerTest, DTD) 212 TEST_F(PageSerializerTest, DTD)
383 { 213 {
384 setBaseFolder("pageserializer/dtd/"); 214 setBaseFolder("pageserializer/dtd/");
385 215
386 registerURL("html5.html", "text/html"); 216 registerURL("dtd.html", "text/html");
387 serialize("html5.html"); 217 serialize("dtd.html");
388 218
389 String expectedStart("<!DOCTYPE html>"); 219 String expectedStart("<!DOCTYPE html>");
390 EXPECT_TRUE(getSerializedData("html5.html").startsWith(expectedStart)); 220 EXPECT_TRUE(getSerializedData("dtd.html").startsWith(expectedStart));
391 } 221 }
392 222
393 TEST_F(PageSerializerTest, Font) 223 TEST_F(PageSerializerTest, Font)
394 { 224 {
395 setBaseFolder("pageserializer/font/"); 225 setBaseFolder("pageserializer/font/");
396 226
397 registerURL("font.html", "text/html"); 227 registerURL("font.html", "text/html");
398 registerURL("font.ttf", "application/octet-stream"); 228 registerURL("font.ttf", "application/octet-stream");
399 229
400 serialize("font.html"); 230 serialize("font.html");
401 231
402 EXPECT_TRUE(isSerialized("font.ttf", "application/octet-stream")); 232 EXPECT_TRUE(isSerialized("font.ttf", "application/octet-stream"));
403 } 233 }
404 234
405 TEST_F(PageSerializerTest, DataURI)
406 {
407 setBaseFolder("pageserializer/datauri/");
408
409 registerURL("page_with_data.html", "text/html");
410
411 serialize("page_with_data.html");
412
413 EXPECT_EQ(1U, getResources().size());
414 EXPECT_TRUE(isSerialized("page_with_data.html", "text/html"));
415 } 235 }
416
417 TEST_F(PageSerializerTest, DataURIMorphing)
418 {
419 setBaseFolder("pageserializer/datauri/");
420
421 registerURL("page_with_morphing_data.html", "text/html");
422
423 serialize("page_with_morphing_data.html");
424
425 EXPECT_EQ(2U, getResources().size());
426 EXPECT_TRUE(isSerialized("page_with_morphing_data.html", "text/html"));
427 }
428
429 TEST_F(PageSerializerTest, RewriteLinksSimple)
430 {
431 setBaseFolder("pageserializer/rewritelinks/");
432 setRewriteURLFolder("folder");
433
434 registerURL("rewritelinks_simple.html", "text/html");
435 registerURL("absolute.png", "image.png", "image/png");
436 registerURL("relative.png", "image.png", "image/png");
437 registerRewriteURL("http://www.test.com/absolute.png", "a.png");
438 registerRewriteURL("http://www.test.com/relative.png", "b.png");
439
440 serialize("rewritelinks_simple.html");
441
442 EXPECT_EQ(3U, getResources().size());
443 EXPECT_NE(getSerializedData("rewritelinks_simple.html", "text/html").find(". /folder/a.png"), kNotFound);
444 EXPECT_NE(getSerializedData("rewritelinks_simple.html", "text/html").find(". /folder/b.png"), kNotFound);
445 }
446
447 TEST_F(PageSerializerTest, RewriteLinksBase)
448 {
449 setBaseFolder("pageserializer/rewritelinks/");
450 setRewriteURLFolder("folder");
451
452 registerURL("rewritelinks_base.html", "text/html");
453 registerURL("images/here/image.png", "image.png", "image/png");
454 registerURL("images/here/or/in/here/image.png", "image.png", "image/png");
455 registerURL("or/absolute.png", "image.png", "image/png");
456 registerRewriteURL("http://www.test.com/images/here/image.png", "a.png");
457 registerRewriteURL("http://www.test.com/images/here/or/in/here/image.png", " b.png");
458 registerRewriteURL("http://www.test.com/or/absolute.png", "c.png");
459
460 serialize("rewritelinks_base.html");
461
462 EXPECT_EQ(4U, getResources().size());
463 EXPECT_NE(getSerializedData("rewritelinks_base.html", "text/html").find("./f older/a.png"), kNotFound);
464 EXPECT_NE(getSerializedData("rewritelinks_base.html", "text/html").find("./f older/b.png"), kNotFound);
465 EXPECT_NE(getSerializedData("rewritelinks_base.html", "text/html").find("./f older/c.png"), kNotFound);
466 }
467
468 // Test that we don't regress https://bugs.webkit.org/show_bug.cgi?id=99105
469 TEST_F(PageSerializerTest, SVGImageDontCrash)
470 {
471 setBaseFolder("pageserializer/svg/");
472
473 registerURL("page_with_svg_image.html", "text/html");
474 registerURL("green_rectangle.svg", "image/svg+xml");
475
476 serialize("page_with_svg_image.html");
477
478 EXPECT_EQ(2U, getResources().size());
479
480 EXPECT_TRUE(isSerialized("green_rectangle.svg", "image/svg+xml"));
481 EXPECT_GT(getSerializedData("green_rectangle.svg", "image/svg+xml").length() , 250U);
482 }
483
484 TEST_F(PageSerializerTest, NamespaceElementsDontCrash)
485 {
486 setBaseFolder("pageserializer/namespace/");
487
488 registerURL("namespace_element.html", "text/html");
489
490 serialize("namespace_element.html");
491
492 EXPECT_EQ(1U, getResources().size());
493 EXPECT_TRUE(isSerialized("namespace_element.html", "text/html"));
494 EXPECT_GT(getSerializedData("namespace_element.html", "text/html").length(), 0U);
495 }
496
497 }
OLDNEW
« no previous file with comments | « trunk/Source/web/tests/MHTMLTest.cpp ('k') | trunk/Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698