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

Side by Side Diff: chrome/browser/media/webrtc/webrtc_log_util_unittest.cc

Issue 2318033002: c/browser, c/common, components M-N: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Fix ItunesFileUtilTest Created 4 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/files/file_enumerator.h" 5 #include "base/files/file_enumerator.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "chrome/browser/media/webrtc/webrtc_log_util.h" 11 #include "chrome/browser/media/webrtc/webrtc_log_util.h"
12 #include "content/public/test/test_browser_thread.h" 12 #include "content/public/test/test_browser_thread.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 const int kExpectedDaysToKeepLogFiles = 5; 15 const int kExpectedDaysToKeepLogFiles = 5;
16 16
17 class WebRtcLogUtilTest : public testing::Test { 17 class WebRtcLogUtilTest : public testing::Test {
18 public: 18 public:
19 WebRtcLogUtilTest() 19 WebRtcLogUtilTest()
20 : file_thread_(content::BrowserThread::FILE, &message_loop_) {} 20 : file_thread_(content::BrowserThread::FILE, &message_loop_) {}
21 21
22 void SetUp() override { 22 void SetUp() override {
23 // Create three files. One with modified date as of now, one with date one 23 // Create three files. One with modified date as of now, one with date one
24 // day younger than the keep limit, one with date one day older than the 24 // day younger than the keep limit, one with date one day older than the
25 // limit. The two former are expected to be kept and the last to be deleted 25 // limit. The two former are expected to be kept and the last to be deleted
26 // when deleting old logs. 26 // when deleting old logs.
27 ASSERT_TRUE(dir_.CreateUniqueTempDir()); 27 ASSERT_TRUE(dir_.CreateUniqueTempDir());
28 base::FilePath file; 28 base::FilePath file;
29 ASSERT_TRUE(CreateTemporaryFileInDir(dir_.path(), &file)); 29 ASSERT_TRUE(CreateTemporaryFileInDir(dir_.GetPath(), &file));
30 ASSERT_TRUE(CreateTemporaryFileInDir(dir_.path(), &file)); 30 ASSERT_TRUE(CreateTemporaryFileInDir(dir_.GetPath(), &file));
31 base::Time time_expect_to_keep = 31 base::Time time_expect_to_keep =
32 base::Time::Now() - 32 base::Time::Now() -
33 base::TimeDelta::FromDays(kExpectedDaysToKeepLogFiles - 1); 33 base::TimeDelta::FromDays(kExpectedDaysToKeepLogFiles - 1);
34 TouchFile(file, time_expect_to_keep, time_expect_to_keep); 34 TouchFile(file, time_expect_to_keep, time_expect_to_keep);
35 ASSERT_TRUE(CreateTemporaryFileInDir(dir_.path(), &file)); 35 ASSERT_TRUE(CreateTemporaryFileInDir(dir_.GetPath(), &file));
36 base::Time time_expect_to_delete = 36 base::Time time_expect_to_delete =
37 base::Time::Now() - 37 base::Time::Now() -
38 base::TimeDelta::FromDays(kExpectedDaysToKeepLogFiles + 1); 38 base::TimeDelta::FromDays(kExpectedDaysToKeepLogFiles + 1);
39 TouchFile(file, time_expect_to_delete, time_expect_to_delete); 39 TouchFile(file, time_expect_to_delete, time_expect_to_delete);
40 } 40 }
41 41
42 void VerifyFiles(int expected_files) { 42 void VerifyFiles(int expected_files) {
43 base::FileEnumerator files(dir_.path(), false, base::FileEnumerator::FILES); 43 base::FileEnumerator files(dir_.GetPath(), false,
44 base::FileEnumerator::FILES);
44 int file_counter = 0; 45 int file_counter = 0;
45 for (base::FilePath name = files.Next(); !name.empty(); 46 for (base::FilePath name = files.Next(); !name.empty();
46 name = files.Next()) { 47 name = files.Next()) {
47 EXPECT_LT(base::Time::Now() - files.GetInfo().GetLastModifiedTime(), 48 EXPECT_LT(base::Time::Now() - files.GetInfo().GetLastModifiedTime(),
48 base::TimeDelta::FromDays(kExpectedDaysToKeepLogFiles)); 49 base::TimeDelta::FromDays(kExpectedDaysToKeepLogFiles));
49 ++file_counter; 50 ++file_counter;
50 } 51 }
51 EXPECT_EQ(expected_files, file_counter); 52 EXPECT_EQ(expected_files, file_counter);
52 } 53 }
53 54
54 base::MessageLoopForUI message_loop_; 55 base::MessageLoopForUI message_loop_;
55 content::TestBrowserThread file_thread_; 56 content::TestBrowserThread file_thread_;
56 base::ScopedTempDir dir_; 57 base::ScopedTempDir dir_;
57 }; 58 };
58 59
59 TEST_F(WebRtcLogUtilTest, DeleteOldWebRtcLogFiles) { 60 TEST_F(WebRtcLogUtilTest, DeleteOldWebRtcLogFiles) {
60 WebRtcLogUtil::DeleteOldWebRtcLogFiles(dir_.path()); 61 WebRtcLogUtil::DeleteOldWebRtcLogFiles(dir_.GetPath());
61 VerifyFiles(2); 62 VerifyFiles(2);
62 } 63 }
63 64
64 TEST_F(WebRtcLogUtilTest, DeleteOldAndRecentWebRtcLogFiles) { 65 TEST_F(WebRtcLogUtilTest, DeleteOldAndRecentWebRtcLogFiles) {
65 base::Time time_begin_delete = 66 base::Time time_begin_delete =
66 base::Time::Now() - base::TimeDelta::FromDays(1); 67 base::Time::Now() - base::TimeDelta::FromDays(1);
67 WebRtcLogUtil::DeleteOldAndRecentWebRtcLogFiles(dir_.path(), 68 WebRtcLogUtil::DeleteOldAndRecentWebRtcLogFiles(dir_.GetPath(),
68 time_begin_delete); 69 time_begin_delete);
69 VerifyFiles(1); 70 VerifyFiles(1);
70 } 71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698