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

Side by Side Diff: net/base/mime_util_unittest.cc

Issue 1547593002: Introducing a net::GenerateMimeMultipartBoundary helper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing... Created 4 years, 11 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
« google_apis/drive/base_requests.cc ('K') | « net/base/mime_util.cc ('k') | 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 // 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
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 // Asserts below are not RFC 1341 requirements, but are here
290 // to improve readability of generated MIME documents and to
291 // try to preserve some aspects of the old boundary generation code.
292 EXPECT_EQ("--", boundary1.substr(0, 2));
293 EXPECT_EQ("--", boundary2.substr(0, 2));
294 EXPECT_NE(std::string::npos, boundary1.find("MultipartBoundary"));
295 EXPECT_NE(std::string::npos, boundary2.find("MultipartBoundary"));
296 EXPECT_EQ("--", boundary1.substr(boundary1.size() - 2, 2));
297 EXPECT_EQ("--", boundary2.substr(boundary2.size() - 2, 2));
298 }
276 299
277 TEST(MimeUtilTest, TestAddMultipartValueForUpload) { 300 TEST(MimeUtilTest, TestAddMultipartValueForUpload) {
278 const char ref_output[] = 301 const char ref_output[] =
279 "--boundary\r\nContent-Disposition: form-data;" 302 "--boundary\r\nContent-Disposition: form-data;"
280 " name=\"value name\"\r\nContent-Type: content type" 303 " name=\"value name\"\r\nContent-Type: content type"
281 "\r\n\r\nvalue\r\n" 304 "\r\n\r\nvalue\r\n"
282 "--boundary\r\nContent-Disposition: form-data;" 305 "--boundary\r\nContent-Disposition: form-data;"
283 " name=\"value name\"\r\n\r\nvalue\r\n" 306 " name=\"value name\"\r\n\r\nvalue\r\n"
284 "--boundary--\r\n"; 307 "--boundary--\r\n";
285 std::string post_data; 308 std::string post_data;
286 AddMultipartValueForUpload("value name", "value", "boundary", 309 AddMultipartValueForUpload("value name", "value", "boundary",
287 "content type", &post_data); 310 "content type", &post_data);
288 AddMultipartValueForUpload("value name", "value", "boundary", 311 AddMultipartValueForUpload("value name", "value", "boundary",
289 "", &post_data); 312 "", &post_data);
290 AddMultipartFinalDelimiterForUpload("boundary", &post_data); 313 AddMultipartFinalDelimiterForUpload("boundary", &post_data);
291 EXPECT_STREQ(ref_output, post_data.c_str()); 314 EXPECT_STREQ(ref_output, post_data.c_str());
292 } 315 }
293 316
294 } // namespace net 317 } // namespace net
OLDNEW
« google_apis/drive/base_requests.cc ('K') | « net/base/mime_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698