summaryrefslogtreecommitdiffstats
path: root/chrome/browser/media/webrtc_log_uploader_unittest.cc
diff options
context:
space:
mode:
authorjiayl@chromium.org <jiayl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-31 01:32:29 +0000
committerjiayl@chromium.org <jiayl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-31 01:32:29 +0000
commit1af8cff30738e0add99842dfe853f5b3d6bb938c (patch)
tree9f9ff2f38516c9fc8b200fc6bded6338539e1f59 /chrome/browser/media/webrtc_log_uploader_unittest.cc
parent6cff678a31f4c7676d9743aadd0156d658a2fbf9 (diff)
downloadchromium_src-1af8cff30738e0add99842dfe853f5b3d6bb938c.zip
chromium_src-1af8cff30738e0add99842dfe853f5b3d6bb938c.tar.gz
chromium_src-1af8cff30738e0add99842dfe853f5b3d6bb938c.tar.bz2
Implements RTP header dumping.
WebRtcRtpDumpHandler implements RTP header dump creation. It's owned by WebRtcLoggingHandlerHost and receives RTP packet callbacks through P2PSocketHost. WebRtcRtpDumpWriter is owned by WebRtcDumpHandler and writes the RTP header into a memory buffer. When the in-memory buffer is full, it compresses the data and writes it to the disk. After the dumping is stopped, WebRtcLoggingHandlerHost calls ReleaseDump to get the completed dump as a .gz file and uploads it. BUG=363459 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=273745 Review URL: https://codereview.chromium.org/264793017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273980 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/media/webrtc_log_uploader_unittest.cc')
-rw-r--r--chrome/browser/media/webrtc_log_uploader_unittest.cc106
1 files changed, 89 insertions, 17 deletions
diff --git a/chrome/browser/media/webrtc_log_uploader_unittest.cc b/chrome/browser/media/webrtc_log_uploader_unittest.cc
index 21cdfba..dd78dc5 100644
--- a/chrome/browser/media/webrtc_log_uploader_unittest.cc
+++ b/chrome/browser/media/webrtc_log_uploader_unittest.cc
@@ -7,6 +7,7 @@
#include "base/file_util.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
+#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
@@ -128,6 +129,34 @@ class WebRtcLogUploaderTest : public testing::Test {
return lines[lines.size() - 1];
}
+ void VerifyRtpDumpInMultipart(const std::string& post_data,
+ const std::string& dump_name,
+ const std::string& dump_content) {
+ std::vector<std::string> lines;
+ base::SplitStringUsingSubstr(post_data, "\r\n", &lines);
+
+ std::string name_line = "Content-Disposition: form-data; name=\"";
+ name_line.append(dump_name);
+ name_line.append("\"");
+ name_line.append("; filename=\"");
+ name_line.append(dump_name);
+ name_line.append(".gz\"");
+
+ size_t i = 0;
+ for (; i < lines.size(); ++i) {
+ if (lines[i] == name_line)
+ break;
+ }
+
+ // The RTP dump takes 4 lines: content-disposition, content-type, empty
+ // line, dump content.
+ EXPECT_LT(i, lines.size() - 3);
+
+ EXPECT_EQ("Content-Type: application/gzip", lines[i + 1]);
+ EXPECT_EQ("", lines[i + 2]);
+ EXPECT_EQ(dump_content, lines[i + 3]);
+ }
+
base::FilePath test_list_path_;
};
@@ -136,13 +165,12 @@ TEST_F(WebRtcLogUploaderTest, AddLocallyStoredLogInfoToUploadListFile) {
// since that's the normal use case, hence the delete.
ASSERT_TRUE(base::CreateTemporaryFile(&test_list_path_));
EXPECT_TRUE(base::DeleteFile(test_list_path_, false));
- scoped_ptr<WebRtcLogUploader> webrtc_log_uploader_(
- new WebRtcLogUploader());
+ scoped_ptr<WebRtcLogUploader> webrtc_log_uploader(new WebRtcLogUploader());
- webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
- kTestLocalId);
- webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
- kTestLocalId);
+ webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
+ kTestLocalId);
+ webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
+ kTestLocalId);
ASSERT_TRUE(VerifyNumberOfLines(2));
ASSERT_TRUE(VerifyLastLineHasLocalIdOnly());
@@ -151,8 +179,8 @@ TEST_F(WebRtcLogUploaderTest, AddLocallyStoredLogInfoToUploadListFile) {
ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit));
ASSERT_TRUE(VerifyLastLineHasAllInfo());
- webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
- kTestLocalId);
+ webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
+ kTestLocalId);
ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit));
ASSERT_TRUE(VerifyLastLineHasLocalIdOnly());
@@ -160,12 +188,12 @@ TEST_F(WebRtcLogUploaderTest, AddLocallyStoredLogInfoToUploadListFile) {
ASSERT_TRUE(VerifyNumberOfLines(60));
ASSERT_TRUE(VerifyLastLineHasAllInfo());
- webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
- kTestLocalId);
+ webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
+ kTestLocalId);
ASSERT_TRUE(VerifyNumberOfLines(expected_line_limit));
ASSERT_TRUE(VerifyLastLineHasLocalIdOnly());
- webrtc_log_uploader_->StartShutdown();
+ webrtc_log_uploader->StartShutdown();
}
TEST_F(WebRtcLogUploaderTest, AddUploadedLogInfoToUploadListFile) {
@@ -173,23 +201,67 @@ TEST_F(WebRtcLogUploaderTest, AddUploadedLogInfoToUploadListFile) {
// since that's the normal use case, hence the delete.
ASSERT_TRUE(base::CreateTemporaryFile(&test_list_path_));
EXPECT_TRUE(base::DeleteFile(test_list_path_, false));
- scoped_ptr<WebRtcLogUploader> webrtc_log_uploader_(new WebRtcLogUploader());
+ scoped_ptr<WebRtcLogUploader> webrtc_log_uploader(new WebRtcLogUploader());
- webrtc_log_uploader_->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
- kTestLocalId);
+ webrtc_log_uploader->AddLocallyStoredLogInfoToUploadListFile(test_list_path_,
+ kTestLocalId);
ASSERT_TRUE(VerifyNumberOfLines(1));
ASSERT_TRUE(VerifyLastLineHasLocalIdOnly());
- webrtc_log_uploader_->AddUploadedLogInfoToUploadListFile(
+ webrtc_log_uploader->AddUploadedLogInfoToUploadListFile(
test_list_path_, kTestLocalId, kTestReportId);
ASSERT_TRUE(VerifyNumberOfLines(1));
ASSERT_TRUE(VerifyLastLineHasAllInfo());
// Use a local ID that should not be found in the list.
- webrtc_log_uploader_->AddUploadedLogInfoToUploadListFile(
+ webrtc_log_uploader->AddUploadedLogInfoToUploadListFile(
test_list_path_, "dummy id", kTestReportId);
ASSERT_TRUE(VerifyNumberOfLines(2));
ASSERT_TRUE(VerifyLastLineHasUploadTimeAndIdOnly());
- webrtc_log_uploader_->StartShutdown();
+ webrtc_log_uploader->StartShutdown();
+}
+
+TEST_F(WebRtcLogUploaderTest, AddRtpDumpsToPostedData) {
+ base::ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+
+ scoped_ptr<WebRtcLogUploader> webrtc_log_uploader(new WebRtcLogUploader());
+
+ std::string post_data;
+ webrtc_log_uploader->OverrideUploadWithBufferForTesting(&post_data);
+
+ // Create the fake dump files.
+ const base::FilePath incoming_dump = temp_dir.path().AppendASCII("recv");
+ const base::FilePath outgoing_dump = temp_dir.path().AppendASCII("send");
+ const std::string incoming_dump_content = "dummy incoming";
+ const std::string outgoing_dump_content = "dummy outgoing";
+
+ base::WriteFile(incoming_dump,
+ &incoming_dump_content[0],
+ incoming_dump_content.size());
+ base::WriteFile(outgoing_dump,
+ &outgoing_dump_content[0],
+ outgoing_dump_content.size());
+
+ WebRtcLogUploadDoneData upload_done_data;
+ upload_done_data.log_path = temp_dir.path().AppendASCII("log");
+
+ upload_done_data.incoming_rtp_dump = incoming_dump;
+ upload_done_data.outgoing_rtp_dump = outgoing_dump;
+
+ const size_t log_length = 100;
+ scoped_ptr<unsigned char[]> log(new unsigned char[log_length]);
+ memset(log.get(), 0, log_length);
+
+ webrtc_log_uploader->LoggingStoppedDoUpload(
+ log.Pass(),
+ log_length,
+ std::map<std::string, std::string>(),
+ upload_done_data);
+
+ VerifyRtpDumpInMultipart(post_data, "rtpdump_recv", incoming_dump_content);
+ VerifyRtpDumpInMultipart(post_data, "rtpdump_send", outgoing_dump_content);
+
+ webrtc_log_uploader->StartShutdown();
}