| OLD | NEW |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 EXPECT_EQ(boundary + "--", *lines_it++); | 91 EXPECT_EQ(boundary + "--", *lines_it++); |
| 92 | 92 |
| 93 EXPECT_EQ(lines.end(), lines_it); | 93 EXPECT_EQ(lines.end(), lines_it); |
| 94 } | 94 } |
| 95 | 95 |
| 96 TEST(HTTPMultipartBuilder, ThreeFileAttachments) { | 96 TEST(HTTPMultipartBuilder, ThreeFileAttachments) { |
| 97 HTTPMultipartBuilder builder; | 97 HTTPMultipartBuilder builder; |
| 98 // TODO(rsesek): Use a more robust mechanism to locate testdata | 98 // TODO(rsesek): Use a more robust mechanism to locate testdata |
| 99 // <https://code.google.com/p/crashpad/issues/detail?id=4>. | 99 // <https://code.google.com/p/crashpad/issues/detail?id=4>. |
| 100 builder.SetFileAttachment("first", "minidump.dmp", | 100 builder.SetFileAttachment("first", |
| 101 base::FilePath("util/net/testdata/ascii_http_body.txt"), ""); | 101 "minidump.dmp", |
| 102 builder.SetFileAttachment("second", "minidump.dmp", | 102 base::FilePath(FILE_PATH_LITERAL( |
| 103 base::FilePath("util/net/testdata/ascii_http_body.txt"), "text/plain"); | 103 "util/net/testdata/ascii_http_body.txt")), |
| 104 builder.SetFileAttachment("\"third 50% silly\"", "test%foo.txt", | 104 ""); |
| 105 base::FilePath("util/net/testdata/ascii_http_body.txt"), "text/plain"); | 105 builder.SetFileAttachment("second", |
| 106 "minidump.dmp", |
| 107 base::FilePath(FILE_PATH_LITERAL( |
| 108 "util/net/testdata/ascii_http_body.txt")), |
| 109 "text/plain"); |
| 110 builder.SetFileAttachment("\"third 50% silly\"", |
| 111 "test%foo.txt", |
| 112 base::FilePath(FILE_PATH_LITERAL( |
| 113 "util/net/testdata/ascii_http_body.txt")), |
| 114 "text/plain"); |
| 106 | 115 |
| 107 const char kFileContents[] = "This is a test.\n"; | 116 const char kFileContents[] = "This is a test.\n"; |
| 108 | 117 |
| 109 scoped_ptr<HTTPBodyStream> body(builder.GetBodyStream()); | 118 scoped_ptr<HTTPBodyStream> body(builder.GetBodyStream()); |
| 110 ASSERT_TRUE(body.get()); | 119 ASSERT_TRUE(body.get()); |
| 111 std::string contents = ReadStreamToString(body.get()); | 120 std::string contents = ReadStreamToString(body.get()); |
| 112 auto lines = SplitCRLF(contents); | 121 auto lines = SplitCRLF(contents); |
| 113 ASSERT_EQ(16u, lines.size()); | 122 ASSERT_EQ(16u, lines.size()); |
| 114 auto lines_it = lines.begin(); | 123 auto lines_it = lines.begin(); |
| 115 | 124 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 EXPECT_EQ(boundary + "--", *lines_it++); | 177 EXPECT_EQ(boundary + "--", *lines_it++); |
| 169 EXPECT_EQ(lines.end(), lines_it); | 178 EXPECT_EQ(lines.end(), lines_it); |
| 170 } | 179 } |
| 171 | 180 |
| 172 TEST(HTTPMultipartBuilder, OverwriteFileAttachment) { | 181 TEST(HTTPMultipartBuilder, OverwriteFileAttachment) { |
| 173 HTTPMultipartBuilder builder; | 182 HTTPMultipartBuilder builder; |
| 174 const char kValue[] = "1 2 3 test"; | 183 const char kValue[] = "1 2 3 test"; |
| 175 builder.SetFormData("a key", kValue); | 184 builder.SetFormData("a key", kValue); |
| 176 // TODO(rsesek): Use a more robust mechanism to locate testdata | 185 // TODO(rsesek): Use a more robust mechanism to locate testdata |
| 177 // <https://code.google.com/p/crashpad/issues/detail?id=4>. | 186 // <https://code.google.com/p/crashpad/issues/detail?id=4>. |
| 178 builder.SetFileAttachment("minidump", "minidump.dmp", | 187 builder.SetFileAttachment("minidump", |
| 179 base::FilePath("util/net/testdata/binary_http_body.dat"), ""); | 188 "minidump.dmp", |
| 180 builder.SetFileAttachment("minidump2", "minidump.dmp", | 189 base::FilePath(FILE_PATH_LITERAL( |
| 181 base::FilePath("util/net/testdata/binary_http_body.dat"), ""); | 190 "util/net/testdata/binary_http_body.dat")), |
| 182 builder.SetFileAttachment("minidump", "minidump.dmp", | 191 ""); |
| 183 base::FilePath("util/net/testdata/ascii_http_body.txt"), "text/plain"); | 192 builder.SetFileAttachment("minidump2", |
| 193 "minidump.dmp", |
| 194 base::FilePath(FILE_PATH_LITERAL( |
| 195 "util/net/testdata/binary_http_body.dat")), |
| 196 ""); |
| 197 builder.SetFileAttachment("minidump", |
| 198 "minidump.dmp", |
| 199 base::FilePath(FILE_PATH_LITERAL( |
| 200 "util/net/testdata/ascii_http_body.txt")), |
| 201 "text/plain"); |
| 184 scoped_ptr<HTTPBodyStream> body(builder.GetBodyStream()); | 202 scoped_ptr<HTTPBodyStream> body(builder.GetBodyStream()); |
| 185 ASSERT_TRUE(body.get()); | 203 ASSERT_TRUE(body.get()); |
| 186 std::string contents = ReadStreamToString(body.get()); | 204 std::string contents = ReadStreamToString(body.get()); |
| 187 auto lines = SplitCRLF(contents); | 205 auto lines = SplitCRLF(contents); |
| 188 ASSERT_EQ(15u, lines.size()); | 206 ASSERT_EQ(15u, lines.size()); |
| 189 auto lines_it = lines.begin(); | 207 auto lines_it = lines.begin(); |
| 190 | 208 |
| 191 const std::string& boundary = *lines_it++; | 209 const std::string& boundary = *lines_it++; |
| 192 EXPECT_GE(boundary.length(), 1u); | 210 EXPECT_GE(boundary.length(), 1u); |
| 193 EXPECT_LE(boundary.length(), 70u); | 211 EXPECT_LE(boundary.length(), 70u); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 214 | 232 |
| 215 EXPECT_EQ(boundary + "--", *lines_it++); | 233 EXPECT_EQ(boundary + "--", *lines_it++); |
| 216 | 234 |
| 217 EXPECT_EQ(lines.end(), lines_it); | 235 EXPECT_EQ(lines.end(), lines_it); |
| 218 } | 236 } |
| 219 | 237 |
| 220 TEST(HTTPMultipartBuilder, SharedFormDataAndAttachmentKeyNamespace) { | 238 TEST(HTTPMultipartBuilder, SharedFormDataAndAttachmentKeyNamespace) { |
| 221 HTTPMultipartBuilder builder; | 239 HTTPMultipartBuilder builder; |
| 222 const char kValue1[] = "11111"; | 240 const char kValue1[] = "11111"; |
| 223 builder.SetFormData("one", kValue1); | 241 builder.SetFormData("one", kValue1); |
| 224 builder.SetFileAttachment("minidump", "minidump.dmp", | 242 builder.SetFileAttachment("minidump", |
| 225 base::FilePath("util/net/testdata/ascii_http_body.txt"), ""); | 243 "minidump.dmp", |
| 244 base::FilePath(FILE_PATH_LITERAL( |
| 245 "util/net/testdata/ascii_http_body.txt")), |
| 246 ""); |
| 226 const char kValue2[] = "this is not a file"; | 247 const char kValue2[] = "this is not a file"; |
| 227 builder.SetFormData("minidump", kValue2); | 248 builder.SetFormData("minidump", kValue2); |
| 228 | 249 |
| 229 scoped_ptr<HTTPBodyStream> body(builder.GetBodyStream()); | 250 scoped_ptr<HTTPBodyStream> body(builder.GetBodyStream()); |
| 230 ASSERT_TRUE(body.get()); | 251 ASSERT_TRUE(body.get()); |
| 231 std::string contents = ReadStreamToString(body.get()); | 252 std::string contents = ReadStreamToString(body.get()); |
| 232 auto lines = SplitCRLF(contents); | 253 auto lines = SplitCRLF(contents); |
| 233 auto lines_it = lines.begin(); | 254 auto lines_it = lines.begin(); |
| 234 | 255 |
| 235 const std::string& boundary = *lines_it++; | 256 const std::string& boundary = *lines_it++; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 259 ASSERT_DEATH(builder.SetFileAttachment("", "", base::FilePath(), "<>"), ""); | 280 ASSERT_DEATH(builder.SetFileAttachment("", "", base::FilePath(), "<>"), ""); |
| 260 // Invalid but safe: | 281 // Invalid but safe: |
| 261 builder.SetFileAttachment("", "", base::FilePath(), "0/totally/-invalid.pdf"); | 282 builder.SetFileAttachment("", "", base::FilePath(), "0/totally/-invalid.pdf"); |
| 262 // Valid and safe: | 283 // Valid and safe: |
| 263 builder.SetFileAttachment("", "", base::FilePath(), "application/xml+xhtml"); | 284 builder.SetFileAttachment("", "", base::FilePath(), "application/xml+xhtml"); |
| 264 } | 285 } |
| 265 | 286 |
| 266 } // namespace | 287 } // namespace |
| 267 } // namespace test | 288 } // namespace test |
| 268 } // namespace crashpad | 289 } // namespace crashpad |
| OLD | NEW |