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

Side by Side Diff: third_party/WebKit/Source/web/tests/MHTMLTest.cpp

Issue 2841483007: MHTMLTest::TestMHTMLEncoding checks generated MTHML is well formed. (Closed)
Patch Set: Move validation into GenerateMHTMLData. Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "core/dom/Document.h" 31 #include "core/dom/Document.h"
32 #include "core/frame/LocalFrame.h" 32 #include "core/frame/LocalFrame.h"
33 #include "core/frame/Location.h" 33 #include "core/frame/Location.h"
34 #include "core/page/Page.h" 34 #include "core/page/Page.h"
35 #include "platform/SerializedResource.h" 35 #include "platform/SerializedResource.h"
36 #include "platform/SharedBuffer.h" 36 #include "platform/SharedBuffer.h"
37 #include "platform/mhtml/MHTMLArchive.h" 37 #include "platform/mhtml/MHTMLArchive.h"
38 #include "platform/mhtml/MHTMLParser.h"
38 #include "platform/testing/URLTestHelpers.h" 39 #include "platform/testing/URLTestHelpers.h"
39 #include "platform/testing/UnitTestHelpers.h" 40 #include "platform/testing/UnitTestHelpers.h"
40 #include "platform/weborigin/KURL.h" 41 #include "platform/weborigin/KURL.h"
41 #include "platform/weborigin/SchemeRegistry.h" 42 #include "platform/weborigin/SchemeRegistry.h"
42 #include "public/platform/Platform.h" 43 #include "public/platform/Platform.h"
43 #include "public/platform/WebString.h" 44 #include "public/platform/WebString.h"
44 #include "public/platform/WebURL.h" 45 #include "public/platform/WebURL.h"
45 #include "public/platform/WebURLLoaderMockFactory.h" 46 #include "public/platform/WebURLLoaderMockFactory.h"
46 #include "public/platform/WebURLRequest.h" 47 #include "public/platform/WebURLRequest.h"
47 #include "public/platform/WebURLResponse.h" 48 #include "public/platform/WebURLResponse.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 155
155 RefPtr<RawData> mhtml_data = RawData::Create(); 156 RefPtr<RawData> mhtml_data = RawData::Create();
156 MHTMLArchive::GenerateMHTMLHeader(boundary, title, mime_type, 157 MHTMLArchive::GenerateMHTMLHeader(boundary, title, mime_type,
157 *mhtml_data->MutableData()); 158 *mhtml_data->MutableData());
158 for (const auto& resource : resources) { 159 for (const auto& resource : resources) {
159 MHTMLArchive::GenerateMHTMLPart(boundary, String(), encoding_policy, 160 MHTMLArchive::GenerateMHTMLPart(boundary, String(), encoding_policy,
160 resource, *mhtml_data->MutableData()); 161 resource, *mhtml_data->MutableData());
161 } 162 }
162 MHTMLArchive::GenerateMHTMLFooterForTesting(boundary, 163 MHTMLArchive::GenerateMHTMLFooterForTesting(boundary,
163 *mhtml_data->MutableData()); 164 *mhtml_data->MutableData());
165
166 // Validate the generated MHTML.
167 MHTMLParser parser(
168 SharedBuffer::Create(mhtml_data->data(), mhtml_data->length()));
169 if (parser.ParseArchive().IsEmpty())
170 return RawData::Create();
Łukasz Anforowicz 2017/04/25 20:00:45 Would it be okay if the above said: if (parse
carlosk 2017/04/25 20:18:15 Done.
171
164 return mhtml_data.Release(); 172 return mhtml_data.Release();
165 } 173 }
166 174
167 PassRefPtr<RawData> Serialize(const char* title, 175 PassRefPtr<RawData> Serialize(const char* title,
168 const char* mime, 176 const char* mime,
169 MHTMLArchive::EncodingPolicy encoding_policy) { 177 MHTMLArchive::EncodingPolicy encoding_policy) {
170 return GenerateMHTMLData(resources_, encoding_policy, title, mime); 178 return GenerateMHTMLData(resources_, encoding_policy, title, mime);
171 } 179 }
172 180
173 private: 181 private:
(...skipping 25 matching lines...) Expand all
199 EXPECT_STREQ(kFileURL, frame->DomWindow()->location()->href().Ascii().data()); 207 EXPECT_STREQ(kFileURL, frame->DomWindow()->location()->href().Ascii().data());
200 208
201 SecurityOrigin* origin = document->GetSecurityOrigin(); 209 SecurityOrigin* origin = document->GetSecurityOrigin();
202 EXPECT_STRNE("localhost", origin->Domain().Ascii().data()); 210 EXPECT_STRNE("localhost", origin->Domain().Ascii().data());
203 } 211 }
204 212
205 TEST_F(MHTMLTest, TestMHTMLEncoding) { 213 TEST_F(MHTMLTest, TestMHTMLEncoding) {
206 AddTestResources(); 214 AddTestResources();
207 RefPtr<RawData> data = Serialize("Test Serialization", "text/html", 215 RefPtr<RawData> data = Serialize("Test Serialization", "text/html",
208 MHTMLArchive::kUseDefaultEncoding); 216 MHTMLArchive::kUseDefaultEncoding);
217 ASSERT_GT(data->length(), 0u) << "Invalid MHTML";
209 218
210 // Read the MHTML data line per line and do some pseudo-parsing to make sure 219 // Read the MHTML data line per line and do some pseudo-parsing to make sure
211 // the right encoding is used for the different sections. 220 // the right encoding is used for the different sections.
212 LineReader line_reader(std::string(data->data(), data->length())); 221 LineReader line_reader(std::string(data->data(), data->length()));
213 int section_checked_count = 0; 222 int section_checked_count = 0;
214 const char* expected_encoding = 0; 223 const char* expected_encoding = 0;
215 std::string line; 224 std::string line;
216 while (line_reader.GetNextLine(&line)) { 225 while (line_reader.GetNextLine(&line)) {
217 if (line.compare(0, 13, "Content-Type:") == 0) { 226 if (line.compare(0, 13, "Content-Type:") == 0) {
218 ASSERT_FALSE(expected_encoding); 227 ASSERT_FALSE(expected_encoding);
(...skipping 16 matching lines...) Expand all
235 section_checked_count++; 244 section_checked_count++;
236 } 245 }
237 } 246 }
238 EXPECT_EQ(12, section_checked_count); 247 EXPECT_EQ(12, section_checked_count);
239 } 248 }
240 249
241 TEST_F(MHTMLTest, MHTMLFromScheme) { 250 TEST_F(MHTMLTest, MHTMLFromScheme) {
242 AddTestResources(); 251 AddTestResources();
243 RefPtr<RawData> raw_data = Serialize("Test Serialization", "text/html", 252 RefPtr<RawData> raw_data = Serialize("Test Serialization", "text/html",
244 MHTMLArchive::kUseDefaultEncoding); 253 MHTMLArchive::kUseDefaultEncoding);
254 ASSERT_GT(raw_data->length(), 0u) << "Invalid MHTML";
255
245 RefPtr<SharedBuffer> data = 256 RefPtr<SharedBuffer> data =
246 SharedBuffer::Create(raw_data->data(), raw_data->length()); 257 SharedBuffer::Create(raw_data->data(), raw_data->length());
247 KURL http_url = ToKURL("http://www.example.com"); 258 KURL http_url = ToKURL("http://www.example.com");
248 KURL content_url = ToKURL("content://foo"); 259 KURL content_url = ToKURL("content://foo");
249 KURL file_url = ToKURL("file://foo"); 260 KURL file_url = ToKURL("file://foo");
250 KURL special_scheme_url = ToKURL("fooscheme://bar"); 261 KURL special_scheme_url = ToKURL("fooscheme://bar");
251 262
252 // MHTMLArchives can only be initialized from local schemes, http/https 263 // MHTMLArchives can only be initialized from local schemes, http/https
253 // schemes, and content scheme(Android specific). 264 // schemes, and content scheme(Android specific).
254 EXPECT_NE(nullptr, MHTMLArchive::Create(http_url, data.Get())); 265 EXPECT_NE(nullptr, MHTMLArchive::Create(http_url, data.Get()));
(...skipping 24 matching lines...) Expand all
279 // Full sandboxing should be turned on. 290 // Full sandboxing should be turned on.
280 EXPECT_TRUE(document->IsSandboxed(kSandboxAll)); 291 EXPECT_TRUE(document->IsSandboxed(kSandboxAll));
281 292
282 // MHTML document should be loaded into unique origin. 293 // MHTML document should be loaded into unique origin.
283 EXPECT_TRUE(document->GetSecurityOrigin()->IsUnique()); 294 EXPECT_TRUE(document->GetSecurityOrigin()->IsUnique());
284 // Script execution should be disabled. 295 // Script execution should be disabled.
285 EXPECT_FALSE(document->CanExecuteScripts(kNotAboutToExecuteScript)); 296 EXPECT_FALSE(document->CanExecuteScripts(kNotAboutToExecuteScript));
286 } 297 }
287 298
288 } // namespace blink 299 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698