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

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

Issue 307063003: Revert 273745 "Implements RTP header dumping." due to memory leak (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 | Annotate | Revision Log
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"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
14 #include "base/time/time.h" 13 #include "base/time/time.h"
15 #include "chrome/browser/media/webrtc_log_uploader.h" 14 #include "chrome/browser/media/webrtc_log_uploader.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 16
18 const char kTestTime[] = "time"; 17 const char kTestTime[] = "time";
19 const char kTestReportId[] = "report-id"; 18 const char kTestReportId[] = "report-id";
20 const char kTestLocalId[] = "local-id"; 19 const char kTestLocalId[] = "local-id";
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 121 }
123 122
124 std::string GetLastLineFromListFile() { 123 std::string GetLastLineFromListFile() {
125 std::vector<std::string> lines = GetLinesFromListFile(); 124 std::vector<std::string> lines = GetLinesFromListFile();
126 EXPECT_GT(lines.size(), 0u); 125 EXPECT_GT(lines.size(), 0u);
127 if (lines.empty()) 126 if (lines.empty())
128 return std::string(); 127 return std::string();
129 return lines[lines.size() - 1]; 128 return lines[lines.size() - 1];
130 } 129 }
131 130
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
160 base::FilePath test_list_path_; 131 base::FilePath test_list_path_;
161 }; 132 };
162 133
163 TEST_F(WebRtcLogUploaderTest, AddLocallyStoredLogInfoToUploadListFile) { 134 TEST_F(WebRtcLogUploaderTest, AddLocallyStoredLogInfoToUploadListFile) {
164 // Get a temporary filename. We don't want the file to exist to begin with 135 // Get a temporary filename. We don't want the file to exist to begin with
165 // since that's the normal use case, hence the delete. 136 // since that's the normal use case, hence the delete.
166 ASSERT_TRUE(base::CreateTemporaryFile(&test_list_path_)); 137 ASSERT_TRUE(base::CreateTemporaryFile(&test_list_path_));
167 EXPECT_TRUE(base::DeleteFile(test_list_path_, false)); 138 EXPECT_TRUE(base::DeleteFile(test_list_path_, false));
168 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader(new WebRtcLogUploader()); 139 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader_(
140 new WebRtcLogUploader());
169 141
170 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, 142 webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
171 kTestLocalId); 143 kTestLocalId);
172 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, 144 webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
173 kTestLocalId); 145 kTestLocalId);
174 ASSERT_TRUE(VerifyNumberOfLines(2)); 146 ASSERT_TRUE(VerifyNumberOfLines(2));
175 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly()); 147 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly());
176 148
177 const int expected_line_limit = 50; 149 const int expected_line_limit = 50;
178 ASSERT_TRUE(AddLinesToTestFile(expected_line_limit - 2)); 150 ASSERT_TRUE(AddLinesToTestFile(expected_line_limit - 2));
179 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit)); 151 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit));
180 ASSERT_TRUE(VerifyLastLineHasAllInfo()); 152 ASSERT_TRUE(VerifyLastLineHasAllInfo());
181 153
182 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, 154 webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
183 kTestLocalId); 155 kTestLocalId);
184 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit)); 156 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit));
185 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly()); 157 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly());
186 158
187 ASSERT_TRUE(AddLinesToTestFile(10)); 159 ASSERT_TRUE(AddLinesToTestFile(10));
188 ASSERT_TRUE(VerifyNumberOfLines(60)); 160 ASSERT_TRUE(VerifyNumberOfLines(60));
189 ASSERT_TRUE(VerifyLastLineHasAllInfo()); 161 ASSERT_TRUE(VerifyLastLineHasAllInfo());
190 162
191 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, 163 webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
192 kTestLocalId); 164 kTestLocalId);
193 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit)); 165 ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit));
194 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly()); 166 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly());
195 167
196 webrtc_log_uploader->StartShutdown(); 168 webrtc_log_uploader_->StartShutdown();
197 } 169 }
198 170
199 TEST_F(WebRtcLogUploaderTest, AddUploadedLogInfoToUploadListFile) { 171 TEST_F(WebRtcLogUploaderTest, AddUploadedLogInfoToUploadListFile) {
200 // Get a temporary filename. We don't want the file to exist to begin with 172 // Get a temporary filename. We don't want the file to exist to begin with
201 // since that's the normal use case, hence the delete. 173 // since that's the normal use case, hence the delete.
202 ASSERT_TRUE(base::CreateTemporaryFile(&test_list_path_)); 174 ASSERT_TRUE(base::CreateTemporaryFile(&test_list_path_));
203 EXPECT_TRUE(base::DeleteFile(test_list_path_, false)); 175 EXPECT_TRUE(base::DeleteFile(test_list_path_, false));
204 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader(new WebRtcLogUploader()); 176 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader_(new WebRtcLogUploader());
205 177
206 webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_, 178 webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
207 kTestLocalId); 179 kTestLocalId);
208 ASSERT_TRUE(VerifyNumberOfLines(1)); 180 ASSERT_TRUE(VerifyNumberOfLines(1));
209 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly()); 181 ASSERT_TRUE(VerifyLastLineHasLocalIdOnly());
210 182
211 webrtc_log_uploader->AddUploadedLogInfoToUploadListFile( 183 webrtc_log_uploader_->AddUploadedLogInfoToUploadListFile(
212 test_list_path_, kTestLocalId, kTestReportId); 184 test_list_path_, kTestLocalId, kTestReportId);
213 ASSERT_TRUE(VerifyNumberOfLines(1)); 185 ASSERT_TRUE(VerifyNumberOfLines(1));
214 ASSERT_TRUE(VerifyLastLineHasAllInfo()); 186 ASSERT_TRUE(VerifyLastLineHasAllInfo());
215 187
216 // Use a local ID that should not be found in the list. 188 // Use a local ID that should not be found in the list.
217 webrtc_log_uploader->AddUploadedLogInfoToUploadListFile( 189 webrtc_log_uploader_->AddUploadedLogInfoToUploadListFile(
218 test_list_path_, "dummy id", kTestReportId); 190 test_list_path_, "dummy id", kTestReportId);
219 ASSERT_TRUE(VerifyNumberOfLines(2)); 191 ASSERT_TRUE(VerifyNumberOfLines(2));
220 ASSERT_TRUE(VerifyLastLineHasUploadTimeAndIdOnly()); 192 ASSERT_TRUE(VerifyLastLineHasUploadTimeAndIdOnly());
221 193
222 webrtc_log_uploader->StartShutdown(); 194 webrtc_log_uploader_->StartShutdown();
223 } 195 }
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 | « trunk/src/chrome/browser/media/webrtc_log_uploader.cc ('k') | trunk/src/chrome/browser/media/webrtc_logging_handler_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698