OLD | NEW |
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 Loading... |
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 PassRefPtr<RawData> 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 RefPtr<RawData> mhtmlData = RawData::create(); |
159 MHTMLArchive::generateMHTMLHeader(boundary, title, mimeType, *mhtmlData); | 159 MHTMLArchive::generateMHTMLHeader(boundary, title, mimeType, |
| 160 *mhtmlData->mutableData()); |
160 for (const auto& resource : resources) { | 161 for (const auto& resource : resources) { |
161 MHTMLArchive::generateMHTMLPart(boundary, String(), encodingPolicy, | 162 MHTMLArchive::generateMHTMLPart(boundary, String(), encodingPolicy, |
162 resource, *mhtmlData); | 163 resource, *mhtmlData->mutableData()); |
163 } | 164 } |
164 MHTMLArchive::generateMHTMLFooter(boundary, *mhtmlData); | 165 MHTMLArchive::generateMHTMLFooter(boundary, *mhtmlData->mutableData()); |
165 return mhtmlData.release(); | 166 return mhtmlData.release(); |
166 } | 167 } |
167 | 168 |
168 PassRefPtr<SharedBuffer> serialize( | 169 PassRefPtr<RawData> serialize(const char* title, |
169 const char* title, | 170 const char* mime, |
170 const char* mime, | 171 MHTMLArchive::EncodingPolicy encodingPolicy) { |
171 MHTMLArchive::EncodingPolicy encodingPolicy) { | |
172 return generateMHTMLData(m_resources, encodingPolicy, title, mime); | 172 return generateMHTMLData(m_resources, encodingPolicy, title, mime); |
173 } | 173 } |
174 | 174 |
175 private: | 175 private: |
176 PassRefPtr<SharedBuffer> readFile(const char* fileName) { | 176 PassRefPtr<SharedBuffer> readFile(const char* fileName) { |
177 String filePath = m_filePath + fileName; | 177 String filePath = m_filePath + fileName; |
178 return testing::readFromFile(filePath); | 178 return testing::readFromFile(filePath); |
179 } | 179 } |
180 | 180 |
181 String m_filePath; | 181 String m_filePath; |
(...skipping 17 matching lines...) Expand all Loading... |
199 ASSERT_TRUE(document); | 199 ASSERT_TRUE(document); |
200 | 200 |
201 EXPECT_STREQ(kFileURL, frame->domWindow()->location()->href().ascii().data()); | 201 EXPECT_STREQ(kFileURL, frame->domWindow()->location()->href().ascii().data()); |
202 | 202 |
203 SecurityOrigin* origin = document->getSecurityOrigin(); | 203 SecurityOrigin* origin = document->getSecurityOrigin(); |
204 EXPECT_STRNE("localhost", origin->domain().ascii().data()); | 204 EXPECT_STRNE("localhost", origin->domain().ascii().data()); |
205 } | 205 } |
206 | 206 |
207 TEST_F(MHTMLTest, TestMHTMLEncoding) { | 207 TEST_F(MHTMLTest, TestMHTMLEncoding) { |
208 addTestResources(); | 208 addTestResources(); |
209 RefPtr<SharedBuffer> data = serialize("Test Serialization", "text/html", | 209 RefPtr<RawData> data = serialize("Test Serialization", "text/html", |
210 MHTMLArchive::UseDefaultEncoding); | 210 MHTMLArchive::UseDefaultEncoding); |
211 | 211 |
212 // Read the MHTML data line per line and do some pseudo-parsing to make sure | 212 // 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. | 213 // the right encoding is used for the different sections. |
214 LineReader lineReader(std::string(data->data(), data->size())); | 214 LineReader lineReader(std::string(data->data(), data->length())); |
215 int sectionCheckedCount = 0; | 215 int sectionCheckedCount = 0; |
216 const char* expectedEncoding = 0; | 216 const char* expectedEncoding = 0; |
217 std::string line; | 217 std::string line; |
218 while (lineReader.getNextLine(&line)) { | 218 while (lineReader.getNextLine(&line)) { |
219 if (line.compare(0, 13, "Content-Type:") == 0) { | 219 if (line.compare(0, 13, "Content-Type:") == 0) { |
220 ASSERT_FALSE(expectedEncoding); | 220 ASSERT_FALSE(expectedEncoding); |
221 if (line.find("multipart/related;") != std::string::npos) { | 221 if (line.find("multipart/related;") != std::string::npos) { |
222 // Skip this one, it's part of the MHTML header. | 222 // Skip this one, it's part of the MHTML header. |
223 continue; | 223 continue; |
224 } | 224 } |
(...skipping 10 matching lines...) Expand all Loading... |
235 EXPECT_NE(line.find(expectedEncoding), std::string::npos); | 235 EXPECT_NE(line.find(expectedEncoding), std::string::npos); |
236 expectedEncoding = 0; | 236 expectedEncoding = 0; |
237 sectionCheckedCount++; | 237 sectionCheckedCount++; |
238 } | 238 } |
239 } | 239 } |
240 EXPECT_EQ(12, sectionCheckedCount); | 240 EXPECT_EQ(12, sectionCheckedCount); |
241 } | 241 } |
242 | 242 |
243 TEST_F(MHTMLTest, MHTMLFromScheme) { | 243 TEST_F(MHTMLTest, MHTMLFromScheme) { |
244 addTestResources(); | 244 addTestResources(); |
245 RefPtr<SharedBuffer> data = serialize("Test Serialization", "text/html", | 245 RefPtr<RawData> rawData = serialize("Test Serialization", "text/html", |
246 MHTMLArchive::UseDefaultEncoding); | 246 MHTMLArchive::UseDefaultEncoding); |
| 247 RefPtr<SharedBuffer> data = |
| 248 SharedBuffer::create(rawData->data(), rawData->length()); |
247 KURL httpURL = toKURL("http://www.example.com"); | 249 KURL httpURL = toKURL("http://www.example.com"); |
248 KURL contentURL = toKURL("content://foo"); | 250 KURL contentURL = toKURL("content://foo"); |
249 KURL fileURL = toKURL("file://foo"); | 251 KURL fileURL = toKURL("file://foo"); |
250 KURL specialSchemeURL = toKURL("fooscheme://bar"); | 252 KURL specialSchemeURL = toKURL("fooscheme://bar"); |
251 | 253 |
252 // MHTMLArchives can only be initialized from local schemes, http/https | 254 // MHTMLArchives can only be initialized from local schemes, http/https |
253 // schemes, and content scheme(Android specific). | 255 // schemes, and content scheme(Android specific). |
254 EXPECT_NE(nullptr, MHTMLArchive::create(httpURL, data.get())); | 256 EXPECT_NE(nullptr, MHTMLArchive::create(httpURL, data.get())); |
255 #if OS(ANDROID) | 257 #if OS(ANDROID) |
256 EXPECT_NE(nullptr, MHTMLArchive::create(contentURL, data.get())); | 258 EXPECT_NE(nullptr, MHTMLArchive::create(contentURL, data.get())); |
(...skipping 22 matching lines...) Expand all Loading... |
279 // Full sandboxing should be turned on. | 281 // Full sandboxing should be turned on. |
280 EXPECT_TRUE(document->isSandboxed(SandboxAll)); | 282 EXPECT_TRUE(document->isSandboxed(SandboxAll)); |
281 | 283 |
282 // MHTML document should be loaded into unique origin. | 284 // MHTML document should be loaded into unique origin. |
283 EXPECT_TRUE(document->getSecurityOrigin()->isUnique()); | 285 EXPECT_TRUE(document->getSecurityOrigin()->isUnique()); |
284 // Script execution should be disabled. | 286 // Script execution should be disabled. |
285 EXPECT_FALSE(frame->script().canExecuteScripts(NotAboutToExecuteScript)); | 287 EXPECT_FALSE(frame->script().canExecuteScripts(NotAboutToExecuteScript)); |
286 } | 288 } |
287 | 289 |
288 } // namespace blink | 290 } // namespace blink |
OLD | NEW |