| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 addResource("http://www.test.com/red_background.png", "image/png", "red_
background.png"); | 136 addResource("http://www.test.com/red_background.png", "image/png", "red_
background.png"); |
| 137 addResource("http://www.test.com/orange_background.png", "image/png", "o
range_background.png"); | 137 addResource("http://www.test.com/orange_background.png", "image/png", "o
range_background.png"); |
| 138 addResource("http://www.test.com/yellow_background.png", "image/png", "y
ellow_background.png"); | 138 addResource("http://www.test.com/yellow_background.png", "image/png", "y
ellow_background.png"); |
| 139 addResource("http://www.test.com/green_background.png", "image/png", "gr
een_background.png"); | 139 addResource("http://www.test.com/green_background.png", "image/png", "gr
een_background.png"); |
| 140 addResource("http://www.test.com/blue_background.png", "image/png", "blu
e_background.png"); | 140 addResource("http://www.test.com/blue_background.png", "image/png", "blu
e_background.png"); |
| 141 addResource("http://www.test.com/purple_background.png", "image/png", "p
urple_background.png"); | 141 addResource("http://www.test.com/purple_background.png", "image/png", "p
urple_background.png"); |
| 142 addResource("http://www.test.com/ul-dot.png", "image/png", "ul-dot.png")
; | 142 addResource("http://www.test.com/ul-dot.png", "image/png", "ul-dot.png")
; |
| 143 addResource("http://www.test.com/ol-dot.png", "image/png", "ol-dot.png")
; | 143 addResource("http://www.test.com/ol-dot.png", "image/png", "ol-dot.png")
; |
| 144 } | 144 } |
| 145 | 145 |
| 146 static PassRefPtr<SharedBuffer> generateMHTMLData( | 146 static std::vector<char> generateMHTMLData( |
| 147 const Vector<SerializedResource>& resources, | 147 const Vector<SerializedResource>& resources, |
| 148 MHTMLArchive::EncodingPolicy encodingPolicy, | 148 MHTMLArchive::EncodingPolicy encodingPolicy, |
| 149 const String& title, const String& mimeType) | 149 const String& title, const String& mimeType) |
| 150 { | 150 { |
| 151 // This boundary is as good as any other. Plus it gets used in almost | 151 // This boundary is as good as any other. Plus it gets used in almost |
| 152 // all the examples in the MHTML spec - RFC 2557. | 152 // all the examples in the MHTML spec - RFC 2557. |
| 153 String boundary = String::fromUTF8("boundary-example"); | 153 String boundary = String::fromUTF8("boundary-example"); |
| 154 | 154 |
| 155 RefPtr<SharedBuffer> mhtmlData = SharedBuffer::create(); | 155 std::vector<char> mhtmlData; |
| 156 MHTMLArchive::generateMHTMLHeader(boundary, title, mimeType, *mhtmlData)
; | 156 MHTMLArchive::generateMHTMLHeader(boundary, title, mimeType, mhtmlData); |
| 157 for (const auto& resource : resources) { | 157 for (const auto& resource : resources) { |
| 158 MHTMLArchive::generateMHTMLPart( | 158 MHTMLArchive::generateMHTMLPart( |
| 159 boundary, String(), encodingPolicy, resource, *mhtmlData); | 159 boundary, String(), encodingPolicy, resource, mhtmlData); |
| 160 } | 160 } |
| 161 MHTMLArchive::generateMHTMLFooter(boundary, *mhtmlData); | 161 MHTMLArchive::generateMHTMLFooter(boundary, mhtmlData); |
| 162 return mhtmlData.release(); | 162 return std::move(mhtmlData); |
| 163 } | 163 } |
| 164 | 164 |
| 165 PassRefPtr<SharedBuffer> serialize(const char *title, const char *mime, MHT
MLArchive::EncodingPolicy encodingPolicy) | 165 std::vector<char> serialize(const char *title, const char *mime, MHTMLArchi
ve::EncodingPolicy encodingPolicy) |
| 166 { | 166 { |
| 167 return generateMHTMLData(m_resources, encodingPolicy, title, mime); | 167 return std::move(generateMHTMLData(m_resources, encodingPolicy, title, m
ime)); |
| 168 } | 168 } |
| 169 | 169 |
| 170 private: | 170 private: |
| 171 PassRefPtr<SharedBuffer> readFile(const char* fileName) | 171 PassRefPtr<SharedBuffer> readFile(const char* fileName) |
| 172 { | 172 { |
| 173 String filePath = m_filePath + fileName; | 173 String filePath = m_filePath + fileName; |
| 174 return testing::readFromFile(filePath); | 174 return testing::readFromFile(filePath); |
| 175 } | 175 } |
| 176 | 176 |
| 177 String m_filePath; | 177 String m_filePath; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 197 | 197 |
| 198 EXPECT_STREQ(kFileURL, frame->domWindow()->location()->href().ascii().data()
); | 198 EXPECT_STREQ(kFileURL, frame->domWindow()->location()->href().ascii().data()
); |
| 199 | 199 |
| 200 SecurityOrigin* origin = document->getSecurityOrigin(); | 200 SecurityOrigin* origin = document->getSecurityOrigin(); |
| 201 EXPECT_STRNE("localhost", origin->domain().ascii().data()); | 201 EXPECT_STRNE("localhost", origin->domain().ascii().data()); |
| 202 } | 202 } |
| 203 | 203 |
| 204 TEST_F(MHTMLTest, TestMHTMLEncoding) | 204 TEST_F(MHTMLTest, TestMHTMLEncoding) |
| 205 { | 205 { |
| 206 addTestResources(); | 206 addTestResources(); |
| 207 RefPtr<SharedBuffer> data = serialize("Test Serialization", "text/html", MH
TMLArchive::UseDefaultEncoding); | 207 std::vector<char> data = serialize("Test Serialization", "text/html", MHTMLA
rchive::UseDefaultEncoding); |
| 208 | 208 |
| 209 // Read the MHTML data line per line and do some pseudo-parsing to make sure
the right encoding is used for the different sections. | 209 // Read the MHTML data line per line and do some pseudo-parsing to make sure
the right encoding is used for the different sections. |
| 210 LineReader lineReader(std::string(data->data(), data->size())); | 210 LineReader lineReader(std::string(&data.front(), data.size())); |
| 211 int sectionCheckedCount = 0; | 211 int sectionCheckedCount = 0; |
| 212 const char* expectedEncoding = 0; | 212 const char* expectedEncoding = 0; |
| 213 std::string line; | 213 std::string line; |
| 214 while (lineReader.getNextLine(&line)) { | 214 while (lineReader.getNextLine(&line)) { |
| 215 if (line.compare(0, 13, "Content-Type:") == 0) { | 215 if (line.compare(0, 13, "Content-Type:") == 0) { |
| 216 ASSERT_FALSE(expectedEncoding); | 216 ASSERT_FALSE(expectedEncoding); |
| 217 if (line.find("multipart/related;") != std::string::npos) { | 217 if (line.find("multipart/related;") != std::string::npos) { |
| 218 // Skip this one, it's part of the MHTML header. | 218 // Skip this one, it's part of the MHTML header. |
| 219 continue; | 219 continue; |
| 220 } | 220 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 232 expectedEncoding = 0; | 232 expectedEncoding = 0; |
| 233 sectionCheckedCount++; | 233 sectionCheckedCount++; |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 EXPECT_EQ(12, sectionCheckedCount); | 236 EXPECT_EQ(12, sectionCheckedCount); |
| 237 } | 237 } |
| 238 | 238 |
| 239 TEST_F(MHTMLTest, MHTMLFromScheme) | 239 TEST_F(MHTMLTest, MHTMLFromScheme) |
| 240 { | 240 { |
| 241 addTestResources(); | 241 addTestResources(); |
| 242 RefPtr<SharedBuffer> data = serialize("Test Serialization", "text/html", MHT
MLArchive::UseDefaultEncoding); | 242 std::vector<char> dataVector = serialize("Test Serialization", "text/html",
MHTMLArchive::UseDefaultEncoding); |
| 243 RefPtr<SharedBuffer> data = SharedBuffer::create(&dataVector.front(), dataVe
ctor.size()); |
| 243 KURL httpURL = toKURL("http://www.example.com"); | 244 KURL httpURL = toKURL("http://www.example.com"); |
| 244 KURL contentURL = toKURL("content://foo"); | 245 KURL contentURL = toKURL("content://foo"); |
| 245 KURL fileURL = toKURL("file://foo"); | 246 KURL fileURL = toKURL("file://foo"); |
| 246 KURL specialSchemeURL = toKURL("fooscheme://bar"); | 247 KURL specialSchemeURL = toKURL("fooscheme://bar"); |
| 247 | 248 |
| 248 // MHTMLArchives can only be initialized from local schemes, http/https sche
mes, and content scheme(Android specific). | 249 // MHTMLArchives can only be initialized from local schemes, http/https sche
mes, and content scheme(Android specific). |
| 249 EXPECT_NE(nullptr, MHTMLArchive::create(httpURL, data.get())); | 250 EXPECT_NE(nullptr, MHTMLArchive::create(httpURL, data.get())); |
| 250 #if OS(ANDROID) | 251 #if OS(ANDROID) |
| 251 EXPECT_NE(nullptr, MHTMLArchive::create(contentURL, data.get())); | 252 EXPECT_NE(nullptr, MHTMLArchive::create(contentURL, data.get())); |
| 252 #else | 253 #else |
| (...skipping 23 matching lines...) Expand all Loading... |
| 276 EXPECT_TRUE(document->isSandboxed(SandboxAll)); | 277 EXPECT_TRUE(document->isSandboxed(SandboxAll)); |
| 277 | 278 |
| 278 // MHTML document should be loaded into unique origin. | 279 // MHTML document should be loaded into unique origin. |
| 279 EXPECT_TRUE(document->getSecurityOrigin()->isUnique()); | 280 EXPECT_TRUE(document->getSecurityOrigin()->isUnique()); |
| 280 // Script execution should be disabled. | 281 // Script execution should be disabled. |
| 281 EXPECT_FALSE(frame->script().canExecuteScripts(NotAboutToExecuteScript)); | 282 EXPECT_FALSE(frame->script().canExecuteScripts(NotAboutToExecuteScript)); |
| 282 } | 283 } |
| 283 | 284 |
| 284 | 285 |
| 285 } // namespace blink | 286 } // namespace blink |
| OLD | NEW |