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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 GenerateMHTML(path, embedded_test_server()->GetURL("/simple_page.html")); | 76 GenerateMHTML(path, embedded_test_server()->GetURL("/simple_page.html")); |
77 ASSERT_FALSE(HasFailure()); | 77 ASSERT_FALSE(HasFailure()); |
78 | 78 |
79 // Make sure the actual generated file has some contents. | 79 // Make sure the actual generated file has some contents. |
80 EXPECT_GT(file_size(), 0); // Verify the size reported by the callback. | 80 EXPECT_GT(file_size(), 0); // Verify the size reported by the callback. |
81 int64 file_size; | 81 int64 file_size; |
82 ASSERT_TRUE(base::GetFileSize(path, &file_size)); | 82 ASSERT_TRUE(base::GetFileSize(path, &file_size)); |
83 EXPECT_GT(file_size, 100); // Verify the actual file size. | 83 EXPECT_GT(file_size, 100); // Verify the actual file size. |
84 } | 84 } |
85 | 85 |
86 // This test verifies how MHTML serialization handles frames that have | |
87 // the same URI (especially about:blank URI) but different content. | |
88 // It should preserve contents of all the frames. | |
89 IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, LocalAboutBlankSubframes) { | |
90 base::FilePath path(temp_dir_.path()); | |
91 path = path.Append(FILE_PATH_LITERAL("test-local-about-blank-subframes.mht")); | |
92 | |
93 GenerateMHTML(path, embedded_test_server()->GetURL( | |
94 "/download/local-about-blank-subframes.html")); | |
95 ASSERT_FALSE(HasFailure()); | |
96 | |
97 std::string mhtml; | |
98 ASSERT_TRUE(base::ReadFileToString(path, &mhtml)); | |
99 | |
100 // Make sure the contents of all frames are present. | |
101 // 1. Check for contents (this is insufficient as it can also hit the contents | |
102 // in the iframe.srcdoc attribute). | |
103 EXPECT_THAT(mhtml, HasSubstr("main: acb0609d-eb10-4c26-83e2-ad8afb7b0ff3")); | |
104 EXPECT_THAT(mhtml, HasSubstr("sub1: b124df3a-d39f-47a1-ae04-5bb5d0bf549e")); | |
105 EXPECT_THAT(mhtml, HasSubstr("sub2: 07014068-604d-45ae-884f-a068cfe7bc0a")); | |
106 EXPECT_THAT(mhtml, HasSubstr("sub3: 06cc8fcc-c692-4a1a-a10f-1645b746e8f4")); | |
107 // 2. Count the number of text/html mhtml parts. | |
108 int count = 0; | |
109 size_t pos = 0; | |
110 for (;;) { | |
111 pos = mhtml.find("Content-Type: text/html", pos); | |
112 if (pos == std::string::npos) | |
113 break; | |
114 count++; | |
115 pos++; | |
116 } | |
117 EXPECT_EQ(4, count) << "Verify number of text/html parts in the mhtml output"; | |
118 } | |
119 | |
120 IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, InvalidPath) { | 86 IN_PROC_BROWSER_TEST_F(MHTMLGenerationTest, InvalidPath) { |
121 base::FilePath path(FILE_PATH_LITERAL("/invalid/file/path")); | 87 base::FilePath path(FILE_PATH_LITERAL("/invalid/file/path")); |
122 | 88 |
123 GenerateMHTML(path, embedded_test_server()->GetURL( | 89 GenerateMHTML(path, embedded_test_server()->GetURL( |
124 "/download/local-about-blank-subframes.html")); | 90 "/download/local-about-blank-subframes.html")); |
125 ASSERT_FALSE(HasFailure()); // No failures with the invocation itself? | 91 ASSERT_FALSE(HasFailure()); // No failures with the invocation itself? |
126 | 92 |
127 EXPECT_EQ(file_size(), -1); // Expecting that the callback reported failure. | 93 EXPECT_EQ(file_size(), -1); // Expecting that the callback reported failure. |
128 } | 94 } |
129 | 95 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 141 |
176 // Make sure that URLs of both frames are present | 142 // Make sure that URLs of both frames are present |
177 // (note that these are single-line regexes). | 143 // (note that these are single-line regexes). |
178 EXPECT_THAT( | 144 EXPECT_THAT( |
179 mhtml, | 145 mhtml, |
180 ContainsRegex("Content-Location:.*/frame_tree/page_with_one_frame.html")); | 146 ContainsRegex("Content-Location:.*/frame_tree/page_with_one_frame.html")); |
181 EXPECT_THAT(mhtml, ContainsRegex("Content-Location:.*/title1.html")); | 147 EXPECT_THAT(mhtml, ContainsRegex("Content-Location:.*/title1.html")); |
182 } | 148 } |
183 | 149 |
184 } // namespace content | 150 } // namespace content |
OLD | NEW |