 Chromium Code Reviews
 Chromium Code Reviews Issue 1899803002:
  Offline Pages: Use 'binary encoding' to create MHTML, instead of base64.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1899803002:
  Offline Pages: Use 'binary encoding' to create MHTML, instead of base64.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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..ba15a4cc856d1485f400beb1413d20ea9731f74d 100644 | 
| --- a/content/browser/download/mhtml_generation_browsertest.cc | 
| +++ b/content/browser/download/mhtml_generation_browsertest.cc | 
| @@ -24,6 +24,7 @@ | 
| using testing::ContainsRegex; | 
| using testing::HasSubstr; | 
| +using testing::Not; | 
| namespace content { | 
| @@ -39,12 +40,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 +92,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, | 
| + HasSubstr("Content-Transfer-Encoding: quoted-printable")); | 
| } | 
| IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, InvalidPath) { | 
| @@ -96,6 +109,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) { | 
| 
nasko
2016/04/20 17:01:15
Please add a comment describing what this case is
 
dewittj
2016/04/20 20:20:59
Done.
 | 
| + 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)); | 
| 
nasko
2016/04/20 17:01:15
Can we also check file size? It is done in other t
 
dewittj
2016/04/20 20:20:59
Done.
 | 
| + EXPECT_THAT(mhtml, HasSubstr("Content-Transfer-Encoding: base64")); | 
| + EXPECT_THAT(mhtml, Not(HasSubstr("Content-Transfer-Encoding: binary"))); | 
| + EXPECT_THAT(mhtml, ContainsRegex("Content-Location:.*blank.jpg")); | 
| +} | 
| + | 
| +IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateBinaryMHTML) { | 
| 
nasko
2016/04/20 17:01:15
Be consistent with naming. If the previous test ca
 
nasko
2016/04/20 17:01:15
Add a comment here too.
 
dewittj
2016/04/20 20:20:59
Done.
 | 
| + 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, HasSubstr("Content-Transfer-Encoding: binary")); | 
| + EXPECT_THAT(mhtml, Not(HasSubstr("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 { |