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

Side by Side Diff: chrome/browser/media/webrtc_log_uploader_unittest.cc

Issue 264793017: Implements RTP header dumping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix leak Created 6 years, 6 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
OLDNEW
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/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "chrome/browser/media/webrtc_log_uploader.h" 15 #include "chrome/browser/media/webrtc_log_uploader.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 const char kTestTime[] = "time"; 18 const char kTestTime[] = "time";
18 const char kTestReportId[] = "report-id"; 19 const char kTestReportId[] = "report-id";
19 const char kTestLocalId[] = "local-id"; 20 const char kTestLocalId[] = "local-id";
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 122 }
122 123
123 std::string GetLastLineFromListFile() { 124 std::string GetLastLineFromListFile() {
124 std::vector<std::string> lines = GetLinesFromListFile(); 125 std::vector<std::string> lines = GetLinesFromListFile();
125 EXPECT_GT(lines.size(), 0u); 126 EXPECT_GT(lines.size(), 0u);
126 if (lines.empty()) 127 if (lines.empty())
127 return std::string(); 128 return std::string();
128 return lines[lines.size() - 1]; 129 return lines[lines.size() - 1];
129 } 130 }
130 131
132 void VerifyRtpDumpInMultipart(const std::string& post_data,
133 const std::string& dump_name,
134 const std::string& dump_content) {
135 std::vector<std::string> lines;
136 base::SplitStringUsingSubstr(post_data, "\r\n", &lines);
137
138 std::string name_line = "Content-Disposition: form-data; name=\"";
139 name_line.append(dump_name);
140 name_line.append("\"");
141 name_line.append("; filename=\"");
142 name_line.append(dump_name);
143 name_line.append(".gz\"");
144
145 size_t i = 0;
146 for (; i < lines.size(); ++i) {
147 if (lines[i] == name_line)
148 break;
149 }
150
151 // The RTP dump takes 4 lines: content-disposition, content-type, empty
152 // line, dump content.
153 EXPECT_LT(i, lines.size() - 3);
154
155 EXPECT_EQ("Content-Type: application/gzip", lines[i + 1]);
156 EXPECT_EQ("", lines[i + 2]);
157 EXPECT_EQ(dump_content, lines[i + 3]);
158 }
159
131 base::FilePath test_list_path_; 160 base::FilePath test_list_path_;
132 }; 161 };
133 162
134 TEST_F(WebRtcLogUploaderTest, AddLocallyStoredLogInfoToUploadListFile) { 163 TEST_F(WebRtcLogUploaderTest, AddLocallyStoredLogInfoToUploadListFile) {
135 // Get a temporary filename. We don't want the file to exist to begin with 164 // Get a temporary filename. We don't want the file to exist to begin with
136 // since that's the normal use case, hence the delete. 165 // since that's the normal use case, hence the delete.
137 ASSERT_TRUE(base::CreateTemporaryFile(&test_list_path_)); 166 ASSERT_TRUE(base::CreateTemporaryFile(&test_list_path_));
138 EXPECT_TRUE(base::DeleteFile(test_list_path_, false)); 167 EXPECT_TRUE(base::DeleteFile(test_list_path_, false));
139 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader_( 168 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader(new WebRtcLogUploader());
140 new WebRtcLogUploader());
141 169
142 webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, 170 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
143 kTestLocalId); 171 kTestLocalId);
144 webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, 172 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
145 kTestLocalId); 173 kTestLocalId);
146 ASSERT_TRUE(VerifyNumberOfLines(2)); 174 ASSERT_TRUE(VerifyNumberOfLines(2));
147 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly()); 175 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly());
148 176
149 const int expected_line_limit = 50; 177 const int expected_line_limit = 50;
150 ASSERT_TRUE(AddLinesToTestFile(expected_line_limit - 2)); 178 ASSERT_TRUE(AddLinesToTestFile(expected_line_limit - 2));
151 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit)); 179 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit));
152 ASSERT_TRUE(VerifyLastLineHasAllInfo()); 180 ASSERT_TRUE(VerifyLastLineHasAllInfo());
153 181
154 webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, 182 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
155 kTestLocalId); 183 kTestLocalId);
156 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit)); 184 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit));
157 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly()); 185 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly());
158 186
159 ASSERT_TRUE(AddLinesToTestFile(10)); 187 ASSERT_TRUE(AddLinesToTestFile(10));
160 ASSERT_TRUE(VerifyNumberOfLines(60)); 188 ASSERT_TRUE(VerifyNumberOfLines(60));
161 ASSERT_TRUE(VerifyLastLineHasAllInfo()); 189 ASSERT_TRUE(VerifyLastLineHasAllInfo());
162 190
163 webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, 191 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
164 kTestLocalId); 192 kTestLocalId);
165 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit)); 193 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit));
166 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly()); 194 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly());
167 195
168 webrtc_log_uploader_->StartShutdown(); 196 webrtc_log_uploader->StartShutdown();
169 } 197 }
170 198
171 TEST_F(WebRtcLogUploaderTest, AddUploadedLogInfoToUploadListFile) { 199 TEST_F(WebRtcLogUploaderTest, AddUploadedLogInfoToUploadListFile) {
172 // Get a temporary filename. We don't want the file to exist to begin with 200 // Get a temporary filename. We don't want the file to exist to begin with
173 // since that's the normal use case, hence the delete. 201 // since that's the normal use case, hence the delete.
174 ASSERT_TRUE(base::CreateTemporaryFile(&test_list_path_)); 202 ASSERT_TRUE(base::CreateTemporaryFile(&test_list_path_));
175 EXPECT_TRUE(base::DeleteFile(test_list_path_, false)); 203 EXPECT_TRUE(base::DeleteFile(test_list_path_, false));
176 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader_(new WebRtcLogUploader()); 204 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader(new WebRtcLogUploader());
177 205
178 webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, 206 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
179 kTestLocalId); 207 kTestLocalId);
180 ASSERT_TRUE(VerifyNumberOfLines(1)); 208 ASSERT_TRUE(VerifyNumberOfLines(1));
181 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly()); 209 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly());
182 210
183 webrtc_log_uploader_->AddUploadedLogInfoToUploadListFile( 211 webrtc_log_uploader->AddUploadedLogInfoToUploadListFile(
184 test_list_path_, kTestLocalId, kTestReportId); 212 test_list_path_, kTestLocalId, kTestReportId);
185 ASSERT_TRUE(VerifyNumberOfLines(1)); 213 ASSERT_TRUE(VerifyNumberOfLines(1));
186 ASSERT_TRUE(VerifyLastLineHasAllInfo()); 214 ASSERT_TRUE(VerifyLastLineHasAllInfo());
187 215
188 // Use a local ID that should not be found in the list. 216 // Use a local ID that should not be found in the list.
189 webrtc_log_uploader_->AddUploadedLogInfoToUploadListFile( 217 webrtc_log_uploader->AddUploadedLogInfoToUploadListFile(
190 test_list_path_, "dummy id", kTestReportId); 218 test_list_path_, "dummy id", kTestReportId);
191 ASSERT_TRUE(VerifyNumberOfLines(2)); 219 ASSERT_TRUE(VerifyNumberOfLines(2));
192 ASSERT_TRUE(VerifyLastLineHasUploadTimeAndIdOnly()); 220 ASSERT_TRUE(VerifyLastLineHasUploadTimeAndIdOnly());
193 221
194 webrtc_log_uploader_->StartShutdown(); 222 webrtc_log_uploader->StartShutdown();
195 } 223 }
224
225 TEST_F(WebRtcLogUploaderTest, AddRtpDumpsToPostedData) {
226 base::ScopedTempDir temp_dir;
227 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
228
229 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader(new WebRtcLogUploader());
230
231 std::string post_data;
232 webrtc_log_uploader->OverrideUploadWithBufferForTesting(&post_data);
233
234 // Create the fake dump files.
235 const base::FilePath incoming_dump = temp_dir.path().AppendASCII("recv");
236 const base::FilePath outgoing_dump = temp_dir.path().AppendASCII("send");
237 const std::string incoming_dump_content = "dummy incoming";
238 const std::string outgoing_dump_content = "dummy outgoing";
239
240 base::WriteFile(incoming_dump,
241 &incoming_dump_content[0],
242 incoming_dump_content.size());
243 base::WriteFile(outgoing_dump,
244 &outgoing_dump_content[0],
245 outgoing_dump_content.size());
246
247 WebRtcLogUploadDoneData upload_done_data;
248 upload_done_data.log_path = temp_dir.path().AppendASCII("log");
249
250 upload_done_data.incoming_rtp_dump = incoming_dump;
251 upload_done_data.outgoing_rtp_dump = outgoing_dump;
252
253 const size_t log_length = 100;
254 scoped_ptr<unsigned char[]> log(new unsigned char[log_length]);
255 memset(log.get(), 0, log_length);
256
257 webrtc_log_uploader->LoggingStoppedDoUpload(
258 log.Pass(),
259 log_length,
260 std::map<std::string, std::string>(),
261 upload_done_data);
262
263 VerifyRtpDumpInMultipart(post_data, "rtpdump_recv", incoming_dump_content);
264 VerifyRtpDumpInMultipart(post_data, "rtpdump_send", outgoing_dump_content);
265
266 webrtc_log_uploader->StartShutdown();
267 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_log_uploader.cc ('k') | chrome/browser/media/webrtc_logging_handler_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698