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

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

Issue 2379823003: Move MHTML file writing out of the renderer main thread. (Closed)
Patch Set: Removed unneeded std::move calls that clang was complaining about. Created 4 years, 2 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
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 addResource("http://www.test.com/green_background.png", "image/png", 139 addResource("http://www.test.com/green_background.png", "image/png",
140 "green_background.png"); 140 "green_background.png");
141 addResource("http://www.test.com/blue_background.png", "image/png", 141 addResource("http://www.test.com/blue_background.png", "image/png",
142 "blue_background.png"); 142 "blue_background.png");
143 addResource("http://www.test.com/purple_background.png", "image/png", 143 addResource("http://www.test.com/purple_background.png", "image/png",
144 "purple_background.png"); 144 "purple_background.png");
145 addResource("http://www.test.com/ul-dot.png", "image/png", "ul-dot.png"); 145 addResource("http://www.test.com/ul-dot.png", "image/png", "ul-dot.png");
146 addResource("http://www.test.com/ol-dot.png", "image/png", "ol-dot.png"); 146 addResource("http://www.test.com/ol-dot.png", "image/png", "ol-dot.png");
147 } 147 }
148 148
149 static PassRefPtr<SharedBuffer> generateMHTMLData( 149 static std::vector<char> generateMHTMLData(
150 const Vector<SerializedResource>& resources, 150 const Vector<SerializedResource>& resources,
151 MHTMLArchive::EncodingPolicy encodingPolicy, 151 MHTMLArchive::EncodingPolicy encodingPolicy,
152 const String& title, 152 const String& title,
153 const String& mimeType) { 153 const String& mimeType) {
154 // This boundary is as good as any other. Plus it gets used in almost 154 // This boundary is as good as any other. Plus it gets used in almost
155 // all the examples in the MHTML spec - RFC 2557. 155 // all the examples in the MHTML spec - RFC 2557.
156 String boundary = String::fromUTF8("boundary-example"); 156 String boundary = String::fromUTF8("boundary-example");
157 157
158 RefPtr<SharedBuffer> mhtmlData = SharedBuffer::create(); 158 std::vector<char> mhtmlData;
159 MHTMLArchive::generateMHTMLHeader(boundary, title, mimeType, *mhtmlData); 159 MHTMLArchive::generateMHTMLHeader(boundary, title, mimeType, mhtmlData);
160 for (const auto& resource : resources) { 160 for (const auto& resource : resources) {
161 MHTMLArchive::generateMHTMLPart(boundary, String(), encodingPolicy, 161 MHTMLArchive::generateMHTMLPart(boundary, String(), encodingPolicy,
162 resource, *mhtmlData); 162 resource, mhtmlData);
163 } 163 }
164 MHTMLArchive::generateMHTMLFooter(boundary, *mhtmlData); 164 MHTMLArchive::generateMHTMLFooter(boundary, mhtmlData);
165 return mhtmlData.release(); 165 return mhtmlData;
166 } 166 }
167 167
168 PassRefPtr<SharedBuffer> serialize( 168 std::vector<char> serialize(const char* title,
169 const char* title, 169 const char* mime,
170 const char* mime, 170 MHTMLArchive::EncodingPolicy encodingPolicy) {
171 MHTMLArchive::EncodingPolicy encodingPolicy) {
172 return generateMHTMLData(m_resources, encodingPolicy, title, mime); 171 return generateMHTMLData(m_resources, encodingPolicy, title, mime);
173 } 172 }
174 173
175 private: 174 private:
176 PassRefPtr<SharedBuffer> readFile(const char* fileName) { 175 PassRefPtr<SharedBuffer> readFile(const char* fileName) {
177 String filePath = m_filePath + fileName; 176 String filePath = m_filePath + fileName;
178 return testing::readFromFile(filePath); 177 return testing::readFromFile(filePath);
179 } 178 }
180 179
181 String m_filePath; 180 String m_filePath;
(...skipping 17 matching lines...) Expand all
199 ASSERT_TRUE(document); 198 ASSERT_TRUE(document);
200 199
201 EXPECT_STREQ(kFileURL, frame->domWindow()->location()->href().ascii().data()); 200 EXPECT_STREQ(kFileURL, frame->domWindow()->location()->href().ascii().data());
202 201
203 SecurityOrigin* origin = document->getSecurityOrigin(); 202 SecurityOrigin* origin = document->getSecurityOrigin();
204 EXPECT_STRNE("localhost", origin->domain().ascii().data()); 203 EXPECT_STRNE("localhost", origin->domain().ascii().data());
205 } 204 }
206 205
207 TEST_F(MHTMLTest, TestMHTMLEncoding) { 206 TEST_F(MHTMLTest, TestMHTMLEncoding) {
208 addTestResources(); 207 addTestResources();
209 RefPtr<SharedBuffer> data = serialize("Test Serialization", "text/html", 208 std::vector<char> data = serialize("Test Serialization", "text/html",
210 MHTMLArchive::UseDefaultEncoding); 209 MHTMLArchive::UseDefaultEncoding);
211 210
212 // Read the MHTML data line per line and do some pseudo-parsing to make sure 211 // Read the MHTML data line per line and do some pseudo-parsing to make sure
213 // the right encoding is used for the different sections. 212 // the right encoding is used for the different sections.
214 LineReader lineReader(std::string(data->data(), data->size())); 213 LineReader lineReader(std::string(&data.front(), data.size()));
215 int sectionCheckedCount = 0; 214 int sectionCheckedCount = 0;
216 const char* expectedEncoding = 0; 215 const char* expectedEncoding = 0;
217 std::string line; 216 std::string line;
218 while (lineReader.getNextLine(&line)) { 217 while (lineReader.getNextLine(&line)) {
219 if (line.compare(0, 13, "Content-Type:") == 0) { 218 if (line.compare(0, 13, "Content-Type:") == 0) {
220 ASSERT_FALSE(expectedEncoding); 219 ASSERT_FALSE(expectedEncoding);
221 if (line.find("multipart/related;") != std::string::npos) { 220 if (line.find("multipart/related;") != std::string::npos) {
222 // Skip this one, it's part of the MHTML header. 221 // Skip this one, it's part of the MHTML header.
223 continue; 222 continue;
224 } 223 }
(...skipping 10 matching lines...) Expand all
235 EXPECT_NE(line.find(expectedEncoding), std::string::npos); 234 EXPECT_NE(line.find(expectedEncoding), std::string::npos);
236 expectedEncoding = 0; 235 expectedEncoding = 0;
237 sectionCheckedCount++; 236 sectionCheckedCount++;
238 } 237 }
239 } 238 }
240 EXPECT_EQ(12, sectionCheckedCount); 239 EXPECT_EQ(12, sectionCheckedCount);
241 } 240 }
242 241
243 TEST_F(MHTMLTest, MHTMLFromScheme) { 242 TEST_F(MHTMLTest, MHTMLFromScheme) {
244 addTestResources(); 243 addTestResources();
245 RefPtr<SharedBuffer> data = serialize("Test Serialization", "text/html", 244 std::vector<char> dataVector = serialize("Test Serialization", "text/html",
246 MHTMLArchive::UseDefaultEncoding); 245 MHTMLArchive::UseDefaultEncoding);
246 RefPtr<SharedBuffer> data =
247 SharedBuffer::create(&dataVector.front(), dataVector.size());
247 KURL httpURL = toKURL("http://www.example.com"); 248 KURL httpURL = toKURL("http://www.example.com");
248 KURL contentURL = toKURL("content://foo"); 249 KURL contentURL = toKURL("content://foo");
249 KURL fileURL = toKURL("file://foo"); 250 KURL fileURL = toKURL("file://foo");
250 KURL specialSchemeURL = toKURL("fooscheme://bar"); 251 KURL specialSchemeURL = toKURL("fooscheme://bar");
251 252
252 // MHTMLArchives can only be initialized from local schemes, http/https 253 // MHTMLArchives can only be initialized from local schemes, http/https
253 // schemes, and content scheme(Android specific). 254 // schemes, and content scheme(Android specific).
254 EXPECT_NE(nullptr, MHTMLArchive::create(httpURL, data.get())); 255 EXPECT_NE(nullptr, MHTMLArchive::create(httpURL, data.get()));
255 #if OS(ANDROID) 256 #if OS(ANDROID)
256 EXPECT_NE(nullptr, MHTMLArchive::create(contentURL, data.get())); 257 EXPECT_NE(nullptr, MHTMLArchive::create(contentURL, data.get()));
(...skipping 22 matching lines...) Expand all
279 // Full sandboxing should be turned on. 280 // Full sandboxing should be turned on.
280 EXPECT_TRUE(document->isSandboxed(SandboxAll)); 281 EXPECT_TRUE(document->isSandboxed(SandboxAll));
281 282
282 // MHTML document should be loaded into unique origin. 283 // MHTML document should be loaded into unique origin.
283 EXPECT_TRUE(document->getSecurityOrigin()->isUnique()); 284 EXPECT_TRUE(document->getSecurityOrigin()->isUnique());
284 // Script execution should be disabled. 285 // Script execution should be disabled.
285 EXPECT_FALSE(frame->script().canExecuteScripts(NotAboutToExecuteScript)); 286 EXPECT_FALSE(frame->script().canExecuteScripts(NotAboutToExecuteScript));
286 } 287 }
287 288
288 } // namespace blink 289 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698