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

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: 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 201
201 SecurityOrigin* origin = document->GetSecurityOrigin(); 202 SecurityOrigin* origin = document->GetSecurityOrigin();
202 EXPECT_STRNE("localhost", origin->Domain().Ascii().data()); 203 EXPECT_STRNE("localhost", origin->Domain().Ascii().data());
203 } 204 }
204 205
205 TEST_F(MHTMLTest, TestMHTMLEncoding) { 206 TEST_F(MHTMLTest, TestMHTMLEncoding) {
206 AddTestResources(); 207 AddTestResources();
207 RefPtr<RawData> data = Serialize("Test Serialization", "text/html", 208 RefPtr<RawData> data = Serialize("Test Serialization", "text/html",
208 MHTMLArchive::kUseDefaultEncoding); 209 MHTMLArchive::kUseDefaultEncoding);
209 210
211 // Validate the generated MHTML.
212 MHTMLParser parser(SharedBuffer::Create(data->data(), data->length()));
213 ASSERT_FALSE(parser.ParseArchive().IsEmpty()) << "Invalid MHTML";
Łukasz Anforowicz 2017/04/25 19:01:24 Would it be possible to increase the coverage of t
carlosk 2017/04/25 19:49:30 Done.
214
210 // Read the MHTML data line per line and do some pseudo-parsing to make sure 215 // 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. 216 // the right encoding is used for the different sections.
212 LineReader line_reader(std::string(data->data(), data->length())); 217 LineReader line_reader(std::string(data->data(), data->length()));
213 int section_checked_count = 0; 218 int section_checked_count = 0;
214 const char* expected_encoding = 0; 219 const char* expected_encoding = 0;
215 std::string line; 220 std::string line;
216 while (line_reader.GetNextLine(&line)) { 221 while (line_reader.GetNextLine(&line)) {
217 if (line.compare(0, 13, "Content-Type:") == 0) { 222 if (line.compare(0, 13, "Content-Type:") == 0) {
218 ASSERT_FALSE(expected_encoding); 223 ASSERT_FALSE(expected_encoding);
219 if (line.find("multipart/related;") != std::string::npos) { 224 if (line.find("multipart/related;") != std::string::npos) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 // Full sandboxing should be turned on. 284 // Full sandboxing should be turned on.
280 EXPECT_TRUE(document->IsSandboxed(kSandboxAll)); 285 EXPECT_TRUE(document->IsSandboxed(kSandboxAll));
281 286
282 // MHTML document should be loaded into unique origin. 287 // MHTML document should be loaded into unique origin.
283 EXPECT_TRUE(document->GetSecurityOrigin()->IsUnique()); 288 EXPECT_TRUE(document->GetSecurityOrigin()->IsUnique());
284 // Script execution should be disabled. 289 // Script execution should be disabled.
285 EXPECT_FALSE(document->CanExecuteScripts(kNotAboutToExecuteScript)); 290 EXPECT_FALSE(document->CanExecuteScripts(kNotAboutToExecuteScript));
286 } 291 }
287 292
288 } // namespace blink 293 } // 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