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

Side by Side Diff: Source/web/tests/WebPageNewSerializerTest.cpp

Issue 177243005: [SavePage] Do not save images with errors (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed the unused variable. Created 6 years, 9 months 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
OLDNEW
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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 registerMockedURLLoad(pageUrl, WebString::fromUTF8("page_with_svg_image.html "), WebString::fromUTF8("pageserializer/"), htmlMimeType()); 360 registerMockedURLLoad(pageUrl, WebString::fromUTF8("page_with_svg_image.html "), WebString::fromUTF8("pageserializer/"), htmlMimeType());
361 registerMockedURLLoad(imageUrl, WebString::fromUTF8("green_rectangle.svg"), WebString::fromUTF8("pageserializer/"), svgMimeType()); 361 registerMockedURLLoad(imageUrl, WebString::fromUTF8("green_rectangle.svg"), WebString::fromUTF8("pageserializer/"), svgMimeType());
362 362
363 loadURLInTopFrame(pageUrl); 363 loadURLInTopFrame(pageUrl);
364 364
365 WebCString mhtml = WebPageSerializer::serializeToMHTML(webView()); 365 WebCString mhtml = WebPageSerializer::serializeToMHTML(webView());
366 // We expect some data to be generated. 366 // We expect some data to be generated.
367 EXPECT_GT(mhtml.length(), 50U); 367 EXPECT_GT(mhtml.length(), 50U);
368 } 368 }
369 369
370
371 TEST_F(WebPageNewSerializeTest, DontIncludeErrorImage)
372 {
373 WebURL pageUrl = toKURL("http://www.test.com");
374 WebURL imageUrl = toKURL("http://www.test.com/error_image.png");
375
376 registerMockedURLLoad(pageUrl, WebString::fromUTF8("page_with_img_error.html "), WebString::fromUTF8("pageserializer/"), htmlMimeType());
377 registerMockedURLLoad(imageUrl, WebString::fromUTF8("error_image.png"), WebS tring::fromUTF8("pageserializer/"), pngMimeType());
378
379 loadURLInTopFrame(pageUrl);
380
381 WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
382 ASSERT_FALSE(mhtmlData.isEmpty());
383
384 // Sniff the MHTML data to make sure image content is excluded.
385 LineReader lineReader(std::string(mhtmlData.data()));
386 std::string line;
387 while (lineReader.getNextLine(&line)) {
388 if (line.find("image/") != std::string::npos)
389 FAIL() << "Error Image was not excluded " << line;
390 }
391 }
392
393
370 TEST_F(WebPageNewSerializeTest, NamespaceElementsDontCrash) 394 TEST_F(WebPageNewSerializeTest, NamespaceElementsDontCrash)
371 { 395 {
372 WebURL pageUrl = toKURL("http://www.test.com"); 396 WebURL pageUrl = toKURL("http://www.test.com");
373 registerMockedURLLoad(pageUrl, WebString::fromUTF8("namespace_element.html") , WebString::fromUTF8("pageserializer/"), htmlMimeType()); 397 registerMockedURLLoad(pageUrl, WebString::fromUTF8("namespace_element.html") , WebString::fromUTF8("pageserializer/"), htmlMimeType());
374 398
375 loadURLInTopFrame(pageUrl); 399 loadURLInTopFrame(pageUrl);
376 400
377 WebVector<WebURL> localLinks(static_cast<size_t>(1)); 401 WebVector<WebURL> localLinks(static_cast<size_t>(1));
378 WebVector<WebString> localPaths(static_cast<size_t>(1)); 402 WebVector<WebString> localPaths(static_cast<size_t>(1));
379 localLinks[0] = pageUrl; 403 localLinks[0] = pageUrl;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 // exactly two times. 453 // exactly two times.
430 size_t nbDataURLs = 0; 454 size_t nbDataURLs = 0;
431 LineReader lineReader(std::string(mhtmlData.data())); 455 LineReader lineReader(std::string(mhtmlData.data()));
432 std::string line; 456 std::string line;
433 while (lineReader.getNextLine(&line)) { 457 while (lineReader.getNextLine(&line)) {
434 if (line.find("data:text") != std::string::npos) 458 if (line.find("data:text") != std::string::npos)
435 nbDataURLs++; 459 nbDataURLs++;
436 } 460 }
437 EXPECT_EQ(2u, nbDataURLs); 461 EXPECT_EQ(2u, nbDataURLs);
438 } 462 }
OLDNEW
« no previous file with comments | « Source/core/page/PageSerializer.cpp ('k') | Source/web/tests/data/pageserializer/error_image.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698