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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 21 matching lines...) Expand all
32 MHTMLGenerationTest() : has_mhtml_callback_run_(false), file_size_(0) {} 32 MHTMLGenerationTest() : has_mhtml_callback_run_(false), file_size_(0) {}
33 33
34 protected: 34 protected:
35 void SetUp() override { 35 void SetUp() override {
36 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 36 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
37 ASSERT_TRUE(embedded_test_server()->Start()); 37 ASSERT_TRUE(embedded_test_server()->Start());
38 ContentBrowserTest::SetUp(); 38 ContentBrowserTest::SetUp();
39 } 39 }
40 40
41 void GenerateMHTML(const base::FilePath& path, const GURL& url) { 41 void GenerateMHTML(const base::FilePath& path, const GURL& url) {
42 GenerateMHTML(path, url, false);
43 }
44
45 void GenerateMHTML(const base::FilePath& path,
46 const GURL& url,
47 bool use_binary_encoding) {
42 NavigateToURL(shell(), url); 48 NavigateToURL(shell(), url);
43 49
44 base::RunLoop run_loop; 50 base::RunLoop run_loop;
45 shell()->web_contents()->GenerateMHTML( 51 shell()->web_contents()->GenerateMHTML(
46 path, base::Bind(&MHTMLGenerationTest::MHTMLGenerated, this, 52 path, use_binary_encoding,
47 run_loop.QuitClosure())); 53 base::Bind(&MHTMLGenerationTest::MHTMLGenerated, this,
54 run_loop.QuitClosure()));
48 55
49 // Block until the MHTML is generated. 56 // Block until the MHTML is generated.
50 run_loop.Run(); 57 run_loop.Run();
51 58
52 EXPECT_TRUE(has_mhtml_callback_run()); 59 EXPECT_TRUE(has_mhtml_callback_run());
53 } 60 }
54 61
55 bool has_mhtml_callback_run() const { return has_mhtml_callback_run_; } 62 bool has_mhtml_callback_run() const { return has_mhtml_callback_run_; }
56 int64_t file_size() const { return file_size_; } 63 int64_t file_size() const { return file_size_; }
57 64
(...skipping 19 matching lines...) Expand all
77 path = path.Append(FILE_PATH_LITERAL("test.mht")); 84 path = path.Append(FILE_PATH_LITERAL("test.mht"));
78 85
79 GenerateMHTML(path, embedded_test_server()->GetURL("/simple_page.html")); 86 GenerateMHTML(path, embedded_test_server()->GetURL("/simple_page.html"));
80 ASSERT_FALSE(HasFailure()); 87 ASSERT_FALSE(HasFailure());
81 88
82 // Make sure the actual generated file has some contents. 89 // Make sure the actual generated file has some contents.
83 EXPECT_GT(file_size(), 0); // Verify the size reported by the callback. 90 EXPECT_GT(file_size(), 0); // Verify the size reported by the callback.
84 int64_t file_size; 91 int64_t file_size;
85 ASSERT_TRUE(base::GetFileSize(path, &file_size)); 92 ASSERT_TRUE(base::GetFileSize(path, &file_size));
86 EXPECT_GT(file_size, 100); // Verify the actual file size. 93 EXPECT_GT(file_size, 100); // Verify the actual file size.
94
95 std::string mhtml;
96 ASSERT_TRUE(base::ReadFileToString(path, &mhtml));
97 EXPECT_THAT(mhtml,
98 ContainsRegex("Content-Transfer-Encoding: quoted-printable"));
87 } 99 }
88 100
89 IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, InvalidPath) { 101 IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, InvalidPath) {
90 base::FilePath path(FILE_PATH_LITERAL("/invalid/file/path")); 102 base::FilePath path(FILE_PATH_LITERAL("/invalid/file/path"));
91 103
92 GenerateMHTML(path, embedded_test_server()->GetURL( 104 GenerateMHTML(path, embedded_test_server()->GetURL(
93 "/download/local-about-blank-subframes.html")); 105 "/download/local-about-blank-subframes.html"));
94 ASSERT_FALSE(HasFailure()); // No failures with the invocation itself? 106 ASSERT_FALSE(HasFailure()); // No failures with the invocation itself?
95 107
96 EXPECT_EQ(file_size(), -1); // Expecting that the callback reported failure. 108 EXPECT_EQ(file_size(), -1); // Expecting that the callback reported failure.
97 } 109 }
98 110
111 IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateNonBinaryMHTMLWithImage) {
112 base::FilePath path(temp_dir_.path());
113 path = path.Append(FILE_PATH_LITERAL("test_binary.mht"));
114
115 GURL url(embedded_test_server()->GetURL("/page_with_image.html"));
116 GenerateMHTML(path, url, false);
117 ASSERT_FALSE(HasFailure());
118 EXPECT_NE(file_size(), -1);
119
120 std::string mhtml;
121 ASSERT_TRUE(base::ReadFileToString(path, &mhtml));
122 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.
123 EXPECT_THAT(mhtml, Not(ContainsRegex("Content-Transfer-Encoding: binary")));
124 EXPECT_THAT(mhtml, ContainsRegex("Content-Location:.*blank.jpg"));
125 }
126
127 IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateBinaryMHTML) {
128 base::FilePath path(temp_dir_.path());
129 path = path.Append(FILE_PATH_LITERAL("test_binary.mht"));
130
131 GURL url(embedded_test_server()->GetURL("/page_with_image.html"));
132 GenerateMHTML(path, url, true);
133 ASSERT_FALSE(HasFailure());
134 EXPECT_NE(file_size(), -1);
135
136 std::string mhtml;
137 ASSERT_TRUE(base::ReadFileToString(path, &mhtml));
138 EXPECT_THAT(mhtml, ContainsRegex("Content-Transfer-Encoding: binary"));
139 EXPECT_THAT(mhtml, Not(ContainsRegex("Content-Transfer-Encoding: base64")));
140 EXPECT_THAT(mhtml, ContainsRegex("Content-Location:.*blank.jpg"));
141 }
142
99 // Test suite that allows testing --site-per-process against cross-site frames. 143 // Test suite that allows testing --site-per-process against cross-site frames.
100 // See http://dev.chromium.org/developers/design-documents/site-isolation. 144 // See http://dev.chromium.org/developers/design-documents/site-isolation.
101 class MHTMLGenerationSitePerProcessTest : public MHTMLGenerationTest { 145 class MHTMLGenerationSitePerProcessTest : public MHTMLGenerationTest {
102 public: 146 public:
103 MHTMLGenerationSitePerProcessTest() {} 147 MHTMLGenerationSitePerProcessTest() {}
104 148
105 protected: 149 protected:
106 void SetUpCommandLine(base::CommandLine* command_line) override { 150 void SetUpCommandLine(base::CommandLine* command_line) override {
107 MHTMLGenerationTest::SetUpCommandLine(command_line); 151 MHTMLGenerationTest::SetUpCommandLine(command_line);
108 152
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 188
145 // Make sure that URLs of both frames are present 189 // Make sure that URLs of both frames are present
146 // (note that these are single-line regexes). 190 // (note that these are single-line regexes).
147 EXPECT_THAT( 191 EXPECT_THAT(
148 mhtml, 192 mhtml,
149 ContainsRegex("Content-Location:.*/frame_tree/page_with_one_frame.html")); 193 ContainsRegex("Content-Location:.*/frame_tree/page_with_one_frame.html"));
150 EXPECT_THAT(mhtml, ContainsRegex("Content-Location:.*/title1.html")); 194 EXPECT_THAT(mhtml, ContainsRegex("Content-Location:.*/title1.html"));
151 } 195 }
152 196
153 } // namespace content 197 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/page_capture/page_capture_api.cc ('k') | content/browser/download/mhtml_generation_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698