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 content_type(kFakeContentType); |
| 689 std::string content_location(kFakeContentLocation); |
| 690 |
| 691 // Get the MHTMLExtraParts |
| 692 MHTMLExtraParts* extra_parts = |
| 693 MHTMLExtraParts::FromWebContents(shell()->web_contents()); |
| 694 |
| 695 // Add two extra data parts to the MHTML. |
| 696 extra_parts->AddExtraMHTMLPart(content_type, content_location, |
| 697 kFakeSignalData1); |
| 698 extra_parts->AddExtraMHTMLPart(content_type, content_location, |
| 699 kFakeSignalData2); |
| 700 EXPECT_EQ(extra_parts->size(), 2); |
| 701 GenerateMHTML(params, url); |
| 702 |
| 703 EXPECT_TRUE(has_mhtml_callback_run()); |
| 704 |
| 705 std::string mhtml; |
| 706 { |
| 707 base::ThreadRestrictions::ScopedAllowIO allow_io_for_content_verification; |
| 708 ASSERT_TRUE(base::ReadFileToString(path, &mhtml)); |
| 709 } |
| 710 |
| 711 // Make sure that both extra data parts made it into the mhtml. |
| 712 EXPECT_THAT(mhtml, HasSubstr(kFakeSignalData1)); |
| 713 EXPECT_THAT(mhtml, HasSubstr(kFakeSignalData2)); |
| 714 } |
| 715 |
675 } // namespace content | 716 } // namespace content |
OLD | NEW |