OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/strings/string_split.h" | 5 #include "base/strings/string_split.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "net/base/mime_util.h" | 8 #include "net/base/mime_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 #else | 266 #else |
267 if (extensions[j] == tests[i].contained_result) | 267 if (extensions[j] == tests[i].contained_result) |
268 found = true; | 268 found = true; |
269 #endif | 269 #endif |
270 } | 270 } |
271 ASSERT_TRUE(found) << "Must find at least the contained result within " | 271 ASSERT_TRUE(found) << "Must find at least the contained result within " |
272 << tests[i].mime_type; | 272 << tests[i].mime_type; |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
| 276 TEST(MimeUtilTest, TestGenerateMimeMultipartBoundary) { |
| 277 std::string boundary1 = GenerateMimeMultipartBoundary(); |
| 278 std::string boundary2 = GenerateMimeMultipartBoundary(); |
| 279 |
| 280 // RFC 1341 says: the boundary parameter [...] consists of 1 to 70 characters. |
| 281 EXPECT_GE(70u, boundary1.size()); |
| 282 EXPECT_GE(70u, boundary2.size()); |
| 283 |
| 284 // RFC 1341 asks to: exercise care to choose a unique boundary. |
| 285 EXPECT_NE(boundary1, boundary2); |
| 286 ASSERT_LE(16u, boundary1.size()); |
| 287 ASSERT_LE(16u, boundary2.size()); |
| 288 |
| 289 // Expect that we don't pick '\0' character from the array/string |
| 290 // where we take the characters from. |
| 291 EXPECT_EQ(std::string::npos, boundary1.find('\0')); |
| 292 EXPECT_EQ(std::string::npos, boundary2.find('\0')); |
| 293 |
| 294 // Asserts below are not RFC 1341 requirements, but are here |
| 295 // to improve readability of generated MIME documents and to |
| 296 // try to preserve some aspects of the old boundary generation code. |
| 297 EXPECT_EQ("--", boundary1.substr(0, 2)); |
| 298 EXPECT_EQ("--", boundary2.substr(0, 2)); |
| 299 EXPECT_NE(std::string::npos, boundary1.find("MultipartBoundary")); |
| 300 EXPECT_NE(std::string::npos, boundary2.find("MultipartBoundary")); |
| 301 EXPECT_EQ("--", boundary1.substr(boundary1.size() - 2, 2)); |
| 302 EXPECT_EQ("--", boundary2.substr(boundary2.size() - 2, 2)); |
| 303 } |
276 | 304 |
277 TEST(MimeUtilTest, TestAddMultipartValueForUpload) { | 305 TEST(MimeUtilTest, TestAddMultipartValueForUpload) { |
278 const char ref_output[] = | 306 const char ref_output[] = |
279 "--boundary\r\nContent-Disposition: form-data;" | 307 "--boundary\r\nContent-Disposition: form-data;" |
280 " name=\"value name\"\r\nContent-Type: content type" | 308 " name=\"value name\"\r\nContent-Type: content type" |
281 "\r\n\r\nvalue\r\n" | 309 "\r\n\r\nvalue\r\n" |
282 "--boundary\r\nContent-Disposition: form-data;" | 310 "--boundary\r\nContent-Disposition: form-data;" |
283 " name=\"value name\"\r\n\r\nvalue\r\n" | 311 " name=\"value name\"\r\n\r\nvalue\r\n" |
284 "--boundary--\r\n"; | 312 "--boundary--\r\n"; |
285 std::string post_data; | 313 std::string post_data; |
286 AddMultipartValueForUpload("value name", "value", "boundary", | 314 AddMultipartValueForUpload("value name", "value", "boundary", |
287 "content type", &post_data); | 315 "content type", &post_data); |
288 AddMultipartValueForUpload("value name", "value", "boundary", | 316 AddMultipartValueForUpload("value name", "value", "boundary", |
289 "", &post_data); | 317 "", &post_data); |
290 AddMultipartFinalDelimiterForUpload("boundary", &post_data); | 318 AddMultipartFinalDelimiterForUpload("boundary", &post_data); |
291 EXPECT_STREQ(ref_output, post_data.c_str()); | 319 EXPECT_STREQ(ref_output, post_data.c_str()); |
292 } | 320 } |
293 | 321 |
294 } // namespace net | 322 } // namespace net |
OLD | NEW |