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 7a3b00fe319fdbde3899a37e2c2b32e0f5d09c2a..4ec5ea9b348344493fda1b2a8a8e4bb7a3b3d75e 100644 |
--- a/content/browser/download/mhtml_generation_browsertest.cc |
+++ b/content/browser/download/mhtml_generation_browsertest.cc |
@@ -39,12 +39,19 @@ class MHTMLGenerationTest : public ContentBrowserTest { |
} |
void GenerateMHTML(const base::FilePath& path, const GURL& url) { |
+ GenerateMHTML(path, url, false); |
+ } |
+ |
+ void GenerateMHTML(const base::FilePath& path, |
+ const GURL& url, |
+ bool use_binary_encoding) { |
NavigateToURL(shell(), url); |
base::RunLoop run_loop; |
shell()->web_contents()->GenerateMHTML( |
- path, base::Bind(&MHTMLGenerationTest::MHTMLGenerated, this, |
- run_loop.QuitClosure())); |
+ path, use_binary_encoding, |
+ base::Bind(&MHTMLGenerationTest::MHTMLGenerated, this, |
+ run_loop.QuitClosure())); |
// Block until the MHTML is generated. |
run_loop.Run(); |
@@ -84,6 +91,11 @@ IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateMHTML) { |
int64_t file_size; |
ASSERT_TRUE(base::GetFileSize(path, &file_size)); |
EXPECT_GT(file_size, 100); // Verify the actual file size. |
+ |
+ std::string mhtml; |
+ ASSERT_TRUE(base::ReadFileToString(path, &mhtml)); |
+ EXPECT_THAT(mhtml, |
+ ContainsRegex("Content-Transfer-Encoding: quoted-printable")); |
} |
IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, InvalidPath) { |
@@ -96,6 +108,38 @@ IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, InvalidPath) { |
EXPECT_EQ(file_size(), -1); // Expecting that the callback reported failure. |
} |
+IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateNonBinaryMHTMLWithImage) { |
+ base::FilePath path(temp_dir_.path()); |
+ path = path.Append(FILE_PATH_LITERAL("test_binary.mht")); |
+ |
+ GURL url(embedded_test_server()->GetURL("/page_with_image.html")); |
+ GenerateMHTML(path, url, false); |
+ ASSERT_FALSE(HasFailure()); |
+ EXPECT_NE(file_size(), -1); |
+ |
+ std::string mhtml; |
+ ASSERT_TRUE(base::ReadFileToString(path, &mhtml)); |
+ EXPECT_THAT(mhtml, ContainsRegex("Content-Transfer-Encoding: base64")); |
Dmitry Titov
2016/04/19 22:45:46
Is there a matcher that can just check if a string
dewittj
2016/04/19 23:24:39
Done.
|
+ EXPECT_THAT(mhtml, Not(ContainsRegex("Content-Transfer-Encoding: binary"))); |
+ EXPECT_THAT(mhtml, ContainsRegex("Content-Location:.*blank.jpg")); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateBinaryMHTML) { |
+ base::FilePath path(temp_dir_.path()); |
+ path = path.Append(FILE_PATH_LITERAL("test_binary.mht")); |
+ |
+ GURL url(embedded_test_server()->GetURL("/page_with_image.html")); |
+ GenerateMHTML(path, url, true); |
+ ASSERT_FALSE(HasFailure()); |
+ EXPECT_NE(file_size(), -1); |
+ |
+ std::string mhtml; |
+ ASSERT_TRUE(base::ReadFileToString(path, &mhtml)); |
+ EXPECT_THAT(mhtml, ContainsRegex("Content-Transfer-Encoding: binary")); |
+ EXPECT_THAT(mhtml, Not(ContainsRegex("Content-Transfer-Encoding: base64"))); |
+ EXPECT_THAT(mhtml, ContainsRegex("Content-Location:.*blank.jpg")); |
+} |
+ |
// Test suite that allows testing --site-per-process against cross-site frames. |
// See http://dev.chromium.org/developers/design-documents/site-isolation. |
class MHTMLGenerationSitePerProcessTest : public MHTMLGenerationTest { |