OLD | NEW |
---|---|
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/renderer_host/render_process_host_impl.h" | 18 #include "content/browser/renderer_host/render_process_host_impl.h" |
19 #include "content/common/frame_messages.h" | 19 #include "content/common/frame_messages.h" |
20 #include "content/public/browser/mhtml_extra_parts.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" |
28 #include "net/base/filename_util.h" | 29 #include "net/base/filename_util.h" |
29 #include "net/dns/mock_host_resolver.h" | 30 #include "net/dns/mock_host_resolver.h" |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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); | |
David Trainor- moved to gerrit
2017/03/30 05:26:40
Do you need these?
Pete Williamson
2017/03/31 00:29:49
Removed
| |
689 std::string signal_data2(kFakeSignalData2); | |
690 std::string content_type(kFakeContentType); | |
691 std::string content_location(kFakeContentLocation); | |
692 | |
693 // Get the MHTMLExtraParts | |
694 MHTMLExtraParts* extra_parts = | |
695 MHTMLExtraParts::FromWebContents(shell()->web_contents()); | |
696 | |
697 // Add two extra data parts to the MHTML. | |
698 extra_parts->AddExtraMHTMLPart(content_type, content_location, signal_data1); | |
699 extra_parts->AddExtraMHTMLPart(content_type, content_location, signal_data2); | |
700 GenerateMHTML(params, url); | |
701 | |
702 EXPECT_TRUE(has_mhtml_callback_run()); | |
703 | |
704 std::string mhtml; | |
705 { | |
706 base::ThreadRestrictions::ScopedAllowIO allow_io_for_content_verification; | |
707 ASSERT_TRUE(base::ReadFileToString(path, &mhtml)); | |
708 } | |
709 | |
710 // Make sure that both extra data parts made it into the mhtml. | |
711 EXPECT_THAT(mhtml, HasSubstr(kFakeSignalData1)); | |
712 EXPECT_THAT(mhtml, HasSubstr(kFakeSignalData2)); | |
713 } | |
714 | |
675 } // namespace content | 715 } // namespace content |
OLD | NEW |