summaryrefslogtreecommitdiffstats
path: root/chrome/browser/media/webrtc_log_util_unittest.cc
diff options
context:
space:
mode:
authorgrunell@chromium.org <grunell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-25 17:20:35 +0000
committergrunell@chromium.org <grunell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-25 17:20:35 +0000
commit25021cfb0ed27341537abcbf5439c75a6cf06238 (patch)
treeced81c9ed3e859cf4b99cbe716ba105a55ca930e /chrome/browser/media/webrtc_log_util_unittest.cc
parent438df243074fd3191906cb9ac1209e115d4b7d60 (diff)
downloadchromium_src-25021cfb0ed27341537abcbf5439c75a6cf06238.zip
chromium_src-25021cfb0ed27341537abcbf5439c75a6cf06238.tar.gz
chromium_src-25021cfb0ed27341537abcbf5439c75a6cf06238.tar.bz2
Store WebRTC logs locally to disk
- Write logs to disk locally. - Rename files webrtc_log_upload_list.h/cc -> webrtc_log_list.h/cc. - Remove WebRtcLogUploadList class. (Make member functions ordinary functions.) - Update UploadList to include an optional local ID. - Write info about a stored log to the log list file (using the new format). - Change adding upload info so that it updates the existing entry in the list file. - Add webrtc_log_util.h/cc with some utility functions. - Update chrome://webrtc-logs listing to a new format, which includes showing the local file path. - Remove logs older than 5 days. - Remove logs if clearing browser data. - Adding test to, updating existing test in and refactoring of WebRtcLogUploaderTest. - Update and add various related tests. BUG=323982 Review URL: https://codereview.chromium.org/191083002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259240 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/media/webrtc_log_util_unittest.cc')
-rw-r--r--chrome/browser/media/webrtc_log_util_unittest.cc70
1 files changed, 70 insertions, 0 deletions
diff --git a/chrome/browser/media/webrtc_log_util_unittest.cc b/chrome/browser/media/webrtc_log_util_unittest.cc
new file mode 100644
index 0000000..f576c17
--- /dev/null
+++ b/chrome/browser/media/webrtc_log_util_unittest.cc
@@ -0,0 +1,70 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/file_util.h"
+#include "base/files/file_enumerator.h"
+#include "base/files/file_path.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/message_loop/message_loop.h"
+#include "base/time/time.h"
+#include "chrome/browser/media/webrtc_log_util.h"
+#include "content/public/test/test_browser_thread.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+const int kExpectedDaysToKeepLogFiles = 5;
+
+class WebRtcLogUtilTest : public testing::Test {
+ public:
+ WebRtcLogUtilTest()
+ : file_thread_(content::BrowserThread::FILE, &message_loop_) {}
+
+ virtual void SetUp() {
+ // Create three files. One with modified date as of now, one with date one
+ // day younger than the keep limit, one with date one day older than the
+ // limit. The two former are expected to be kept and the last to be deleted
+ // when deleting old logs.
+ ASSERT_TRUE(dir_.CreateUniqueTempDir());
+ base::FilePath file;
+ ASSERT_TRUE(CreateTemporaryFileInDir(dir_.path(), &file));
+ ASSERT_TRUE(CreateTemporaryFileInDir(dir_.path(), &file));
+ base::Time time_expect_to_keep =
+ base::Time::Now() -
+ base::TimeDelta::FromDays(kExpectedDaysToKeepLogFiles - 1);
+ TouchFile(file, time_expect_to_keep, time_expect_to_keep);
+ ASSERT_TRUE(CreateTemporaryFileInDir(dir_.path(), &file));
+ base::Time time_expect_to_delete =
+ base::Time::Now() -
+ base::TimeDelta::FromDays(kExpectedDaysToKeepLogFiles + 1);
+ TouchFile(file, time_expect_to_delete, time_expect_to_delete);
+ }
+
+ void VerifyFiles(int expected_files) {
+ base::FileEnumerator files(dir_.path(), false, base::FileEnumerator::FILES);
+ int file_counter = 0;
+ for (base::FilePath name = files.Next(); !name.empty();
+ name = files.Next()) {
+ EXPECT_LT(base::Time::Now() - files.GetInfo().GetLastModifiedTime(),
+ base::TimeDelta::FromDays(kExpectedDaysToKeepLogFiles));
+ ++file_counter;
+ }
+ EXPECT_EQ(expected_files, file_counter);
+ }
+
+ base::MessageLoopForUI message_loop_;
+ content::TestBrowserThread file_thread_;
+ base::ScopedTempDir dir_;
+};
+
+TEST_F(WebRtcLogUtilTest, DeleteOldWebRtcLogFiles) {
+ WebRtcLogUtil::DeleteOldWebRtcLogFiles(dir_.path());
+ VerifyFiles(2);
+}
+
+TEST_F(WebRtcLogUtilTest, DeleteOldAndRecentWebRtcLogFiles) {
+ base::Time time_begin_delete =
+ base::Time::Now() - base::TimeDelta::FromDays(1);
+ WebRtcLogUtil::DeleteOldAndRecentWebRtcLogFiles(dir_.path(),
+ time_begin_delete);
+ VerifyFiles(1);
+}