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

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

Issue 1899803002: Offline Pages: Use 'binary encoding' to create MHTML, instead of base64. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nasko's comments Created 4 years, 8 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 7a3b00fe319fdbde3899a37e2c2b32e0f5d09c2a..ed893fee76b7f5eec4b678ac35802081c86c39c3 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();
@@ -52,6 +60,12 @@ class MHTMLGenerationTest : public ContentBrowserTest {
EXPECT_TRUE(has_mhtml_callback_run());
}
+ int64_t readFileSizeFromDisk(base::FilePath path) {
nasko 2016/04/20 22:22:38 Method name should start with Capital letter.
+ int64_t file_size;
+ if (!base::GetFileSize(path, &file_size)) return -1;
+ return file_size;
+ }
+
bool has_mhtml_callback_run() const { return has_mhtml_callback_run_; }
int64_t file_size() const { return file_size_; }
@@ -81,9 +95,12 @@ IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateMHTML) {
// Make sure the actual generated file has some contents.
EXPECT_GT(file_size(), 0); // Verify the size reported by the callback.
- int64_t file_size;
- ASSERT_TRUE(base::GetFileSize(path, &file_size));
- EXPECT_GT(file_size, 100); // Verify the actual file size.
+ EXPECT_GT(readFileSizeFromDisk(path), 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 +113,46 @@ IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, InvalidPath) {
EXPECT_EQ(file_size(), -1); // Expecting that the callback reported failure.
}
+// Tests that MHTML generated using the default 'quoted-printable' encoding does
+// not contain the 'binary' Content-Transfer-Encoding header, and generates
+// base64 encoding for the image part.
+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_GT(file_size(), 0); // Verify the size reported by the callback.
+ EXPECT_GT(readFileSizeFromDisk(path), 100); // Verify the actual file size.
+
+ std::string mhtml;
+ ASSERT_TRUE(base::ReadFileToString(path, &mhtml));
+ 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"));
+}
+
+// Tests that MHTML generated using the binary encoding contains the 'binary'
+// Content-Transfer-Encoding header, and does not contain any base64 encoded
+// parts.
+IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateBinaryMHTMLWithImage) {
+ 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_GT(file_size(), 0); // Verify the size reported by the callback.
+ EXPECT_GT(readFileSizeFromDisk(path), 100); // Verify the actual file size.
+
+ 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 {

Powered by Google App Engine
This is Rietveld 408576698