| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 EXPECT_EQ(expected_lines, static_cast<int>(lines.size())); | 30 EXPECT_EQ(expected_lines, static_cast<int>(lines.size())); |
| 31 return expected_lines == static_cast<int>(lines.size()); | 31 return expected_lines == static_cast<int>(lines.size()); |
| 32 } | 32 } |
| 33 | 33 |
| 34 bool VerifyLastLineHasAllInfo() { | 34 bool VerifyLastLineHasAllInfo() { |
| 35 std::string last_line = GetLastLineFromListFile(); | 35 std::string last_line = GetLastLineFromListFile(); |
| 36 if (last_line.empty()) | 36 if (last_line.empty()) |
| 37 return false; | 37 return false; |
| 38 std::vector<std::string> line_parts = base::SplitString( | 38 std::vector<std::string> line_parts = base::SplitString( |
| 39 last_line, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 39 last_line, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 40 EXPECT_EQ(3u, line_parts.size()); | 40 EXPECT_EQ(4u, line_parts.size()); |
| 41 if (3u != line_parts.size()) | 41 if (4u != line_parts.size()) |
| 42 return false; | 42 return false; |
| 43 // The time (line_parts[0]) is the time when the info was written to the | 43 // The times (indices 0 and 3) is the time when the info was written to the |
| 44 // file which we don't know, so just verify that it's not empty. | 44 // file which we don't know, so just verify that it's not empty. |
| 45 EXPECT_FALSE(line_parts[0].empty()); | 45 EXPECT_FALSE(line_parts[0].empty()); |
| 46 EXPECT_STREQ(kTestReportId, line_parts[1].c_str()); | 46 EXPECT_STREQ(kTestReportId, line_parts[1].c_str()); |
| 47 EXPECT_STREQ(kTestLocalId, line_parts[2].c_str()); | 47 EXPECT_STREQ(kTestLocalId, line_parts[2].c_str()); |
| 48 EXPECT_FALSE(line_parts[3].empty()); |
| 48 return true; | 49 return true; |
| 49 } | 50 } |
| 50 | 51 |
| 51 bool VerifyLastLineHasLocalIdOnly() { | 52 // Verify that the last line contains the correct info for a local storage. |
| 53 bool VerifyLastLineHasLocalStorageInfoOnly() { |
| 52 std::string last_line = GetLastLineFromListFile(); | 54 std::string last_line = GetLastLineFromListFile(); |
| 53 if (last_line.empty()) | 55 if (last_line.empty()) |
| 54 return false; | 56 return false; |
| 55 std::vector<std::string> line_parts = base::SplitString( | 57 std::vector<std::string> line_parts = base::SplitString( |
| 56 last_line, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 58 last_line, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 57 EXPECT_EQ(3u, line_parts.size()); | 59 EXPECT_EQ(4u, line_parts.size()); |
| 58 if (3u != line_parts.size()) | 60 if (4u != line_parts.size()) |
| 59 return false; | 61 return false; |
| 60 EXPECT_TRUE(line_parts[0].empty()); | 62 EXPECT_TRUE(line_parts[0].empty()); |
| 61 EXPECT_TRUE(line_parts[1].empty()); | 63 EXPECT_TRUE(line_parts[1].empty()); |
| 62 EXPECT_STREQ(kTestLocalId, line_parts[2].c_str()); | 64 EXPECT_STREQ(kTestLocalId, line_parts[2].c_str()); |
| 65 EXPECT_FALSE(line_parts[3].empty()); |
| 63 return true; | 66 return true; |
| 64 } | 67 } |
| 65 | 68 |
| 66 bool VerifyLastLineHasUploadTimeAndIdOnly() { | 69 // Verify that the last line contains the correct info for an upload. |
| 70 bool VerifyLastLineHasUploadInfoOnly() { |
| 67 std::string last_line = GetLastLineFromListFile(); | 71 std::string last_line = GetLastLineFromListFile(); |
| 68 if (last_line.empty()) | 72 if (last_line.empty()) |
| 69 return false; | 73 return false; |
| 70 std::vector<std::string> line_parts = base::SplitString( | 74 std::vector<std::string> line_parts = base::SplitString( |
| 71 last_line, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 75 last_line, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 72 EXPECT_EQ(3u, line_parts.size()); | 76 EXPECT_EQ(4u, line_parts.size()); |
| 73 if (3u != line_parts.size()) | 77 if (4u != line_parts.size()) |
| 74 return false; | 78 return false; |
| 75 EXPECT_FALSE(line_parts[0].empty()); | 79 EXPECT_FALSE(line_parts[0].empty()); |
| 76 EXPECT_STREQ(kTestReportId, line_parts[1].c_str()); | 80 EXPECT_STREQ(kTestReportId, line_parts[1].c_str()); |
| 77 EXPECT_TRUE(line_parts[2].empty()); | 81 EXPECT_TRUE(line_parts[2].empty()); |
| 82 EXPECT_FALSE(line_parts[3].empty()); |
| 78 return true; | 83 return true; |
| 79 } | 84 } |
| 80 | 85 |
| 81 bool AddLinesToTestFile(int number_of_lines) { | 86 bool AddLinesToTestFile(int number_of_lines) { |
| 82 base::File test_list_file(test_list_path_, | 87 base::File test_list_file(test_list_path_, |
| 83 base::File::FLAG_OPEN | base::File::FLAG_APPEND); | 88 base::File::FLAG_OPEN | base::File::FLAG_APPEND); |
| 84 EXPECT_TRUE(test_list_file.IsValid()); | 89 EXPECT_TRUE(test_list_file.IsValid()); |
| 85 if (!test_list_file.IsValid()) | 90 if (!test_list_file.IsValid()) |
| 86 return false; | 91 return false; |
| 87 | 92 |
| 88 for (int i = 0; i < number_of_lines; ++i) { | 93 for (int i = 0; i < number_of_lines; ++i) { |
| 89 EXPECT_EQ(static_cast<int>(sizeof(kTestTime)) - 1, | 94 EXPECT_EQ(static_cast<int>(sizeof(kTestTime)) - 1, |
| 90 test_list_file.WriteAtCurrentPos(kTestTime, | 95 test_list_file.WriteAtCurrentPos(kTestTime, |
| 91 sizeof(kTestTime) - 1)); | 96 sizeof(kTestTime) - 1)); |
| 92 EXPECT_EQ(1, test_list_file.WriteAtCurrentPos(",", 1)); | 97 EXPECT_EQ(1, test_list_file.WriteAtCurrentPos(",", 1)); |
| 93 EXPECT_EQ(static_cast<int>(sizeof(kTestReportId)) - 1, | 98 EXPECT_EQ(static_cast<int>(sizeof(kTestReportId)) - 1, |
| 94 test_list_file.WriteAtCurrentPos(kTestReportId, | 99 test_list_file.WriteAtCurrentPos(kTestReportId, |
| 95 sizeof(kTestReportId) - 1)); | 100 sizeof(kTestReportId) - 1)); |
| 96 EXPECT_EQ(1, test_list_file.WriteAtCurrentPos(",", 1)); | 101 EXPECT_EQ(1, test_list_file.WriteAtCurrentPos(",", 1)); |
| 97 EXPECT_EQ(static_cast<int>(sizeof(kTestLocalId)) - 1, | 102 EXPECT_EQ(static_cast<int>(sizeof(kTestLocalId)) - 1, |
| 98 test_list_file.WriteAtCurrentPos(kTestLocalId, | 103 test_list_file.WriteAtCurrentPos(kTestLocalId, |
| 99 sizeof(kTestLocalId) - 1)); | 104 sizeof(kTestLocalId) - 1)); |
| 105 EXPECT_EQ(1, test_list_file.WriteAtCurrentPos(",", 1)); |
| 106 EXPECT_EQ(static_cast<int>(sizeof(kTestTime)) - 1, |
| 107 test_list_file.WriteAtCurrentPos(kTestTime, |
| 108 sizeof(kTestTime) - 1)); |
| 100 EXPECT_EQ(1, test_list_file.WriteAtCurrentPos("\n", 1)); | 109 EXPECT_EQ(1, test_list_file.WriteAtCurrentPos("\n", 1)); |
| 101 } | 110 } |
| 102 return true; | 111 return true; |
| 103 } | 112 } |
| 104 | 113 |
| 105 std::vector<std::string> GetLinesFromListFile() { | 114 std::vector<std::string> GetLinesFromListFile() { |
| 106 std::string contents; | 115 std::string contents; |
| 107 int read = base::ReadFileToString(test_list_path_, &contents); | 116 int read = base::ReadFileToString(test_list_path_, &contents); |
| 108 EXPECT_GT(read, 0); | 117 EXPECT_GT(read, 0); |
| 109 if (read == 0) | 118 if (read == 0) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // since that's the normal use case, hence the delete. | 177 // since that's the normal use case, hence the delete. |
| 169 ASSERT_TRUE(base::CreateTemporaryFile(&test_list_path_)); | 178 ASSERT_TRUE(base::CreateTemporaryFile(&test_list_path_)); |
| 170 EXPECT_TRUE(base::DeleteFile(test_list_path_, false)); | 179 EXPECT_TRUE(base::DeleteFile(test_list_path_, false)); |
| 171 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader(new WebRtcLogUploader()); | 180 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader(new WebRtcLogUploader()); |
| 172 | 181 |
| 173 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, | 182 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, |
| 174 kTestLocalId); | 183 kTestLocalId); |
| 175 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, | 184 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, |
| 176 kTestLocalId); | 185 kTestLocalId); |
| 177 ASSERT_TRUE(VerifyNumberOfLines(2)); | 186 ASSERT_TRUE(VerifyNumberOfLines(2)); |
| 178 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly()); | 187 ASSERT_TRUE(VerifyLastLineHasLocalStorageInfoOnly()); |
| 179 | 188 |
| 180 const int expected_line_limit = 50; | 189 const int expected_line_limit = 50; |
| 181 ASSERT_TRUE(AddLinesToTestFile(expected_line_limit - 2)); | 190 ASSERT_TRUE(AddLinesToTestFile(expected_line_limit - 2)); |
| 182 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit)); | 191 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit)); |
| 183 ASSERT_TRUE(VerifyLastLineHasAllInfo()); | 192 ASSERT_TRUE(VerifyLastLineHasAllInfo()); |
| 184 | 193 |
| 185 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, | 194 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, |
| 186 kTestLocalId); | 195 kTestLocalId); |
| 187 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit)); | 196 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit)); |
| 188 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly()); | 197 ASSERT_TRUE(VerifyLastLineHasLocalStorageInfoOnly()); |
| 189 | 198 |
| 190 ASSERT_TRUE(AddLinesToTestFile(10)); | 199 ASSERT_TRUE(AddLinesToTestFile(10)); |
| 191 ASSERT_TRUE(VerifyNumberOfLines(60)); | 200 ASSERT_TRUE(VerifyNumberOfLines(60)); |
| 192 ASSERT_TRUE(VerifyLastLineHasAllInfo()); | 201 ASSERT_TRUE(VerifyLastLineHasAllInfo()); |
| 193 | 202 |
| 194 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, | 203 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, |
| 195 kTestLocalId); | 204 kTestLocalId); |
| 196 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit)); | 205 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit)); |
| 197 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly()); | 206 ASSERT_TRUE(VerifyLastLineHasLocalStorageInfoOnly()); |
| 198 | 207 |
| 199 webrtc_log_uploader->StartShutdown(); | 208 webrtc_log_uploader->StartShutdown(); |
| 200 } | 209 } |
| 201 | 210 |
| 202 TEST_F(WebRtcLogUploaderTest, AddUploadedLogInfoToUploadListFile) { | 211 TEST_F(WebRtcLogUploaderTest, AddUploadedLogInfoToUploadListFile) { |
| 203 // Get a temporary filename. We don't want the file to exist to begin with | 212 // Get a temporary filename. We don't want the file to exist to begin with |
| 204 // since that's the normal use case, hence the delete. | 213 // since that's the normal use case, hence the delete. |
| 205 ASSERT_TRUE(base::CreateTemporaryFile(&test_list_path_)); | 214 ASSERT_TRUE(base::CreateTemporaryFile(&test_list_path_)); |
| 206 EXPECT_TRUE(base::DeleteFile(test_list_path_, false)); | 215 EXPECT_TRUE(base::DeleteFile(test_list_path_, false)); |
| 207 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader(new WebRtcLogUploader()); | 216 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader(new WebRtcLogUploader()); |
| 208 | 217 |
| 209 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, | 218 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, |
| 210 kTestLocalId); | 219 kTestLocalId); |
| 211 ASSERT_TRUE(VerifyNumberOfLines(1)); | 220 ASSERT_TRUE(VerifyNumberOfLines(1)); |
| 212 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly()); | 221 ASSERT_TRUE(VerifyLastLineHasLocalStorageInfoOnly()); |
| 213 | 222 |
| 214 webrtc_log_uploader->AddUploadedLogInfoToUploadListFile( | 223 webrtc_log_uploader->AddUploadedLogInfoToUploadListFile( |
| 215 test_list_path_, kTestLocalId, kTestReportId); | 224 test_list_path_, kTestLocalId, kTestReportId); |
| 216 ASSERT_TRUE(VerifyNumberOfLines(1)); | 225 ASSERT_TRUE(VerifyNumberOfLines(1)); |
| 217 ASSERT_TRUE(VerifyLastLineHasAllInfo()); | 226 ASSERT_TRUE(VerifyLastLineHasAllInfo()); |
| 218 | 227 |
| 219 // Use a local ID that should not be found in the list. | 228 // Use a local ID that should not be found in the list. |
| 220 webrtc_log_uploader->AddUploadedLogInfoToUploadListFile( | 229 webrtc_log_uploader->AddUploadedLogInfoToUploadListFile( |
| 221 test_list_path_, "dummy id", kTestReportId); | 230 test_list_path_, "dummy id", kTestReportId); |
| 222 ASSERT_TRUE(VerifyNumberOfLines(2)); | 231 ASSERT_TRUE(VerifyNumberOfLines(2)); |
| 223 ASSERT_TRUE(VerifyLastLineHasUploadTimeAndIdOnly()); | 232 ASSERT_TRUE(VerifyLastLineHasUploadInfoOnly()); |
| 224 | 233 |
| 225 webrtc_log_uploader->StartShutdown(); | 234 webrtc_log_uploader->StartShutdown(); |
| 226 } | 235 } |
| 227 | 236 |
| 228 TEST_F(WebRtcLogUploaderTest, AddRtpDumpsToPostedData) { | 237 TEST_F(WebRtcLogUploaderTest, AddRtpDumpsToPostedData) { |
| 229 base::ScopedTempDir temp_dir; | 238 base::ScopedTempDir temp_dir; |
| 230 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 239 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 231 | 240 |
| 232 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader(new WebRtcLogUploader()); | 241 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader(new WebRtcLogUploader()); |
| 233 | 242 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 261 scoped_ptr<WebRtcLogBuffer> log(new WebRtcLogBuffer()); | 270 scoped_ptr<WebRtcLogBuffer> log(new WebRtcLogBuffer()); |
| 262 log->SetComplete(); | 271 log->SetComplete(); |
| 263 webrtc_log_uploader->LoggingStoppedDoUpload( | 272 webrtc_log_uploader->LoggingStoppedDoUpload( |
| 264 log.Pass(), make_scoped_ptr(new MetaDataMap()), upload_done_data); | 273 log.Pass(), make_scoped_ptr(new MetaDataMap()), upload_done_data); |
| 265 | 274 |
| 266 VerifyRtpDumpInMultipart(post_data, "rtpdump_recv", incoming_dump_content); | 275 VerifyRtpDumpInMultipart(post_data, "rtpdump_recv", incoming_dump_content); |
| 267 VerifyRtpDumpInMultipart(post_data, "rtpdump_send", outgoing_dump_content); | 276 VerifyRtpDumpInMultipart(post_data, "rtpdump_send", outgoing_dump_content); |
| 268 | 277 |
| 269 webrtc_log_uploader->StartShutdown(); | 278 webrtc_log_uploader->StartShutdown(); |
| 270 } | 279 } |
| OLD | NEW |