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

Unified Diff: content/browser/download/mhtml_generation_browsertest.cc

Issue 2866873002: Validate generated MHTML in mhtml_generation_browsertest.cc tests. (Closed)
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/download/mhtml_generation_browsertest.cc
diff --git a/content/browser/download/mhtml_generation_browsertest.cc b/content/browser/download/mhtml_generation_browsertest.cc
index 3f99ffb7157b7993c5bc5880510704afe19cc3ae..d4b5bf53f4a8200f402b321ebcec3cfa0957ce82 100644
--- a/content/browser/download/mhtml_generation_browsertest.cc
+++ b/content/browser/download/mhtml_generation_browsertest.cc
@@ -18,6 +18,7 @@
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/common/frame_messages.h"
#include "content/public/browser/mhtml_extra_parts.h"
+#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/mhtml_generation_params.h"
@@ -124,7 +125,20 @@ class MHTMLGenerationTest : public ContentBrowserTest {
// Block until the MHTML is generated.
run_loop.Run();
- EXPECT_TRUE(has_mhtml_callback_run());
+ ASSERT_TRUE(has_mhtml_callback_run())
+ << "An error occurred while generating the MHTML file";
+
+ // Loads the generated file to check if it is well formed.
+ WebContentsDelegate* old_delegate = shell()->web_contents()->GetDelegate();
+ ConsoleObserverDelegate console_delegate(shell()->web_contents(),
+ "Malformed multipart archive: *");
+ shell()->web_contents()->SetDelegate(&console_delegate);
+
+ NavigateToURL(shell(), net::FilePathToFileURL(params.file_path));
nasko 2017/05/08 17:16:58 EXPECT_TRUE, otherwise failure to load, such as fi
carlosk 2017/05/16 20:56:08 Done.
+ EXPECT_EQ(0U, console_delegate.message().length())
+ << "The generated MHTML file is malformed";
+
+ shell()->web_contents()->SetDelegate(old_delegate);
}
int64_t ReadFileSizeFromDisk(base::FilePath path) {
@@ -153,7 +167,6 @@ class MHTMLGenerationTest : public ContentBrowserTest {
}
GenerateMHTML(params, url);
- ASSERT_FALSE(HasFailure());
// Stop the test server (to make sure the locally saved page
// is self-contained / won't try to open original resources).
@@ -223,7 +236,6 @@ IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateMHTML) {
path = path.Append(FILE_PATH_LITERAL("test.mht"));
GenerateMHTML(path, embedded_test_server()->GetURL("/simple_page.html"));
- ASSERT_FALSE(HasFailure());
// Make sure the actual generated file has some contents.
EXPECT_GT(file_size(), 0); // Verify the size reported by the callback.
@@ -363,7 +375,6 @@ IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, InvalidPath) {
GenerateMHTML(path, embedded_test_server()->GetURL(
"/download/local-about-blank-subframes.html"));
- ASSERT_FALSE(HasFailure()); // No failures with the invocation itself?
EXPECT_EQ(file_size(), -1); // Expecting that the callback reported failure.
@@ -382,7 +393,6 @@ IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateNonBinaryMHTMLWithImage) {
GURL url(embedded_test_server()->GetURL("/page_with_image.html"));
GenerateMHTML(path, url);
- ASSERT_FALSE(HasFailure());
EXPECT_GT(file_size(), 0); // Verify the size reported by the callback.
EXPECT_GT(ReadFileSizeFromDisk(path), 100); // Verify the actual file size.
@@ -408,7 +418,6 @@ IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateBinaryMHTMLWithImage) {
params.use_binary_encoding = true;
GenerateMHTML(params, url);
- ASSERT_FALSE(HasFailure());
EXPECT_GT(file_size(), 0); // Verify the size reported by the callback.
EXPECT_GT(ReadFileSizeFromDisk(path), 100); // Verify the actual file size.
@@ -431,9 +440,6 @@ IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateMHTMLIgnoreNoStore) {
// Generate MHTML without specifying the FailForNoStoreMainFrame policy.
GenerateMHTML(path, url);
- // We expect that there wasn't an error (file size -1 indicates an error.)
- ASSERT_FALSE(HasFailure());
-
std::string mhtml;
{
base::ThreadRestrictions::ScopedAllowIO allow_io_for_content_verification;
@@ -630,7 +636,6 @@ IN_PROC_BROWSER_TEST_F(MHTMLGenerationSitePerProcessTest, GenerateMHTML) {
GURL url(embedded_test_server()->GetURL(
"a.com", "/frame_tree/page_with_one_frame.html"));
GenerateMHTML(path, url);
- ASSERT_FALSE(HasFailure());
std::string mhtml;
{
@@ -660,7 +665,6 @@ IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, RemovePopupOverlay) {
params.remove_popup_overlay = true;
GenerateMHTML(params, url);
- ASSERT_FALSE(HasFailure());
std::string mhtml;
{

Powered by Google App Engine
This is Rietveld 408576698