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

Side by Side Diff: content/browser/download/mhtml_generation_browsertest.cc

Issue 1977303003: Adds a feature to MHTML serialization that omits subframes and subresources marked no-store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no-store
Patch Set: Adds an image subresource to the test. Created 4 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 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // We expect that there was an error (file size -1 indicates an error.) 192 // We expect that there was an error (file size -1 indicates an error.)
193 EXPECT_EQ(-1, file_size()); 193 EXPECT_EQ(-1, file_size());
194 194
195 std::string mhtml; 195 std::string mhtml;
196 ASSERT_TRUE(base::ReadFileToString(path, &mhtml)); 196 ASSERT_TRUE(base::ReadFileToString(path, &mhtml));
197 197
198 // Make sure the contents are missing. 198 // Make sure the contents are missing.
199 EXPECT_THAT(mhtml, Not(HasSubstr("test body"))); 199 EXPECT_THAT(mhtml, Not(HasSubstr("test body")));
200 } 200 }
201 201
202 IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest,
Łukasz Anforowicz 2016/05/18 17:27:25 Could you please also add a test that tries to ope
dewittj 2016/05/19 04:13:17 Done.
Łukasz Anforowicz 2016/05/19 17:00:13 Thanks for checking. Since right now the no-store
dewittj 2016/05/19 18:18:35 Acknowledged.
203 GenerateMHTMLIgnoreNoStoreSubFrame) {
204 base::FilePath path(temp_dir_.path());
205 path = path.Append(FILE_PATH_LITERAL("test.mht"));
206
207 GURL url(embedded_test_server()->GetURL("/page_with_nostore_iframe.html"));
208
209 // Generate MHTML, specifying the FAIL_FOR_NO_STORE_MAIN_FRAME policy.
210 MHTMLGenerationParams params(path);
211 params.cache_control_policy =
212 content::MHTMLCacheControlPolicy::FAIL_FOR_NO_STORE_MAIN_FRAME;
213
214 GenerateMHTML(params, url);
215 // We expect that there was no error (file size -1 indicates an error.)
216 EXPECT_LT(0, file_size());
217
218 std::string mhtml;
219 ASSERT_TRUE(base::ReadFileToString(path, &mhtml));
220
221 // Make sure that no-store subresources exist in this mode.
222 EXPECT_THAT(mhtml, HasSubstr("no-store test body"));
223 EXPECT_THAT(mhtml, ContainsRegex("Content-Location:.*nostore.jpg"));
224 }
225
226 IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateMHTMLObeyNoStoreSubFrame) {
227 base::FilePath path(temp_dir_.path());
228 path = path.Append(FILE_PATH_LITERAL("test.mht"));
229
230 GURL url(embedded_test_server()->GetURL("/page_with_nostore_iframe.html"));
231
232 // Generate MHTML, specifying the FAIL_FOR_NO_STORE_MAIN_FRAME policy.
233 MHTMLGenerationParams params(path);
234 params.cache_control_policy = content::MHTMLCacheControlPolicy::
235 SKIP_ANY_FRAME_OR_RESOURCE_MARKED_NO_STORE;
236
237 GenerateMHTML(params, url);
238 // We expect that there was no error (file size -1 indicates an error.)
239 EXPECT_LT(0, file_size());
240
241 std::string mhtml;
242 ASSERT_TRUE(base::ReadFileToString(path, &mhtml));
243
244 // Make sure the contents are missing.
245 EXPECT_THAT(mhtml, Not(HasSubstr("no-store test body")));
246 // This image comes from a resource marked no-store.
247 EXPECT_THAT(mhtml, ContainsRegex("Content-Location:.*nostore.jpg"));
248 }
249
202 // Test suite that allows testing --site-per-process against cross-site frames. 250 // Test suite that allows testing --site-per-process against cross-site frames.
203 // See http://dev.chromium.org/developers/design-documents/site-isolation. 251 // See http://dev.chromium.org/developers/design-documents/site-isolation.
204 class MHTMLGenerationSitePerProcessTest : public MHTMLGenerationTest { 252 class MHTMLGenerationSitePerProcessTest : public MHTMLGenerationTest {
205 public: 253 public:
206 MHTMLGenerationSitePerProcessTest() {} 254 MHTMLGenerationSitePerProcessTest() {}
207 255
208 protected: 256 protected:
209 void SetUpCommandLine(base::CommandLine* command_line) override { 257 void SetUpCommandLine(base::CommandLine* command_line) override {
210 MHTMLGenerationTest::SetUpCommandLine(command_line); 258 MHTMLGenerationTest::SetUpCommandLine(command_line);
211 259
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 292
245 // Make sure that URLs of both frames are present 293 // Make sure that URLs of both frames are present
246 // (note that these are single-line regexes). 294 // (note that these are single-line regexes).
247 EXPECT_THAT( 295 EXPECT_THAT(
248 mhtml, 296 mhtml,
249 ContainsRegex("Content-Location:.*/frame_tree/page_with_one_frame.html")); 297 ContainsRegex("Content-Location:.*/frame_tree/page_with_one_frame.html"));
250 EXPECT_THAT(mhtml, ContainsRegex("Content-Location:.*/title1.html")); 298 EXPECT_THAT(mhtml, ContainsRegex("Content-Location:.*/title1.html"));
251 } 299 }
252 300
253 } // namespace content 301 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698