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

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

Issue 2683493002: Get signals working in the EXTRA_DATA section of MHTML (Closed)
Patch Set: Dimich CR fixes Created 3 years, 9 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 #include <memory> 6 #include <memory>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/test/histogram_tester.h" 16 #include "base/test/histogram_tester.h"
17 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
18 #include "content/browser/download/mhtml_generation_manager.h"
18 #include "content/browser/renderer_host/render_process_host_impl.h" 19 #include "content/browser/renderer_host/render_process_host_impl.h"
19 #include "content/common/frame_messages.h" 20 #include "content/common/frame_messages.h"
20 #include "content/public/browser/render_process_host.h" 21 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/mhtml_generation_params.h" 23 #include "content/public/common/mhtml_generation_params.h"
23 #include "content/public/test/browser_test_utils.h" 24 #include "content/public/test/browser_test_utils.h"
24 #include "content/public/test/content_browser_test.h" 25 #include "content/public/test/content_browser_test.h"
25 #include "content/public/test/content_browser_test_utils.h" 26 #include "content/public/test/content_browser_test_utils.h"
26 #include "content/public/test/test_utils.h" 27 #include "content/public/test/test_utils.h"
27 #include "content/shell/browser/shell.h" 28 #include "content/shell/browser/shell.h"
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 { 666 {
666 base::ThreadRestrictions::ScopedAllowIO allow_io_for_content_verification; 667 base::ThreadRestrictions::ScopedAllowIO allow_io_for_content_verification;
667 ASSERT_TRUE(base::ReadFileToString(path, &mhtml)); 668 ASSERT_TRUE(base::ReadFileToString(path, &mhtml));
668 } 669 }
669 670
670 // Make sure the overlay is removed. 671 // Make sure the overlay is removed.
671 EXPECT_THAT(mhtml, Not(HasSubstr("class=3D\"overlay"))); 672 EXPECT_THAT(mhtml, Not(HasSubstr("class=3D\"overlay")));
672 EXPECT_THAT(mhtml, Not(HasSubstr("class=3D\"modal"))); 673 EXPECT_THAT(mhtml, Not(HasSubstr("class=3D\"modal")));
673 } 674 }
674 675
676 IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, GenerateMHTMLWithExtraData) {
677 const char kFakeSignalData1[] = "FakeSignalData1";
678 const char kFakeSignalData2[] = "OtherMockDataForSignals";
679 const char kFakeContentType[] = "text/plain";
680 const char kFakeContentLocation[] =
681 "cid:signal-data-62691-645341c4-62b3-478e-a8c5-e0dfccc3ca02@mhtml.blink";
682 base::FilePath path(temp_dir_.GetPath());
683 path = path.Append(FILE_PATH_LITERAL("test.mht"));
684 GURL url(embedded_test_server()->GetURL("/page_with_image.html"));
685 MHTMLGenerationParams params(path);
686
687 // Place the extra data we need into the web contents user data.
688 std::string signal_data1(kFakeSignalData1);
689 std::string signal_data2(kFakeSignalData2);
690 std::string content_type(kFakeContentType);
691 std::string content_location(kFakeContentLocation);
692 content::MHTMLGenerationManager::MHTMLExtraPart part1;
693 part1.body = signal_data1;
694 part1.content_type = content_type;
695 part1.content_location = content_location;
696 content::MHTMLGenerationManager::MHTMLExtraPart part2;
697 part2.body = signal_data2;
698 part2.content_type = content_type;
699 part2.content_location = content_location;
700
701 // Add two extra data parts to the MHTML.
702 MHTMLGenerationManager::MHTMLExtraData::AddPartToWebContents(
703 shell()->web_contents(), part1);
704 MHTMLGenerationManager::MHTMLExtraData::AddPartToWebContents(
705 shell()->web_contents(), part2);
706 GenerateMHTML(params, url);
707
708 EXPECT_TRUE(has_mhtml_callback_run());
709
710 std::string mhtml;
711 {
712 base::ThreadRestrictions::ScopedAllowIO allow_io_for_content_verification;
713 ASSERT_TRUE(base::ReadFileToString(path, &mhtml));
714 }
715
716 // Make sure that both extra data parts made it into the mhtml.
717 EXPECT_THAT(mhtml, HasSubstr(kFakeSignalData1));
718 EXPECT_THAT(mhtml, HasSubstr(kFakeSignalData2));
719 }
720
675 } // namespace content 721 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698