Chromium Code Reviews| Index: net/base/net_log_logger_unittest.cc |
| diff --git a/net/base/net_log_logger_unittest.cc b/net/base/net_log_logger_unittest.cc |
| index 065e934fae20189f5135ec354dd076a46e7e50ae..2f63b8d75a5f7caf8307e35e5bd0e27bc9e0a0ee 100644 |
| --- a/net/base/net_log_logger_unittest.cc |
| +++ b/net/base/net_log_logger_unittest.cc |
| @@ -9,10 +9,13 @@ |
| #include "base/files/scoped_temp_dir.h" |
| #include "base/json/json_reader.h" |
| #include "base/values.h" |
| +#include "net/base/net_log.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace net { |
| +namespace { |
|
davidben
2014/09/30 17:33:50
I've always been unclear on whether tests should b
|
| + |
| class NetLogLoggerTest : public testing::Test { |
| public: |
| virtual void SetUp() { |
| @@ -26,13 +29,12 @@ class NetLogLoggerTest : public testing::Test { |
| }; |
| TEST_F(NetLogLoggerTest, GeneratesValidJSONForNoEvents) { |
| - { |
| - // Create and destroy a logger. |
| - FILE* file = base::OpenFile(log_path_, "w"); |
| - ASSERT_TRUE(file); |
| - scoped_ptr<base::Value> constants(NetLogLogger::GetConstants()); |
| - NetLogLogger logger(file, *constants); |
| - } |
| + // Create and destroy a logger. |
| + FILE* file = base::OpenFile(log_path_, "w"); |
| + ASSERT_TRUE(file); |
| + scoped_ptr<base::Value> constants(NetLogLogger::GetConstants()); |
| + scoped_ptr<NetLogLogger> logger(new NetLogLogger(file, *constants)); |
| + logger.reset(); |
| std::string input; |
| ASSERT_TRUE(base::ReadFileToString(log_path_, &input)); |
| @@ -48,23 +50,42 @@ TEST_F(NetLogLoggerTest, GeneratesValidJSONForNoEvents) { |
| ASSERT_EQ(0u, events->GetSize()); |
| } |
| +// Make sure the log level is LOG_STRIP_PRIVATE_DATA by default. |
| +TEST_F(NetLogLoggerTest, LogLevel) { |
| + FILE* file = base::OpenFile(log_path_, "w"); |
| + ASSERT_TRUE(file); |
| + scoped_ptr<base::Value> constants(NetLogLogger::GetConstants()); |
| + NetLogLogger logger(file, *constants); |
| + |
| + NetLog net_log; |
| + logger.StartObserving(&net_log); |
| + EXPECT_EQ(NetLog::LOG_STRIP_PRIVATE_DATA, logger.log_level()); |
| + EXPECT_EQ(NetLog::LOG_STRIP_PRIVATE_DATA, net_log.GetLogLevel()); |
| + logger.StopObserving(); |
| + |
| + logger.set_log_level(NetLog::LOG_ALL_BUT_BYTES); |
| + logger.StartObserving(&net_log); |
| + EXPECT_EQ(NetLog::LOG_ALL_BUT_BYTES, logger.log_level()); |
| + EXPECT_EQ(NetLog::LOG_ALL_BUT_BYTES, net_log.GetLogLevel()); |
| + logger.StopObserving(); |
| +} |
| + |
| TEST_F(NetLogLoggerTest, GeneratesValidJSONWithOneEvent) { |
| - { |
| - FILE* file = base::OpenFile(log_path_, "w"); |
| - ASSERT_TRUE(file); |
| - scoped_ptr<base::Value> constants(NetLogLogger::GetConstants()); |
| - NetLogLogger logger(file, *constants); |
| - |
| - const int kDummyId = 1; |
| - NetLog::Source source(NetLog::SOURCE_SPDY_SESSION, kDummyId); |
| - NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, |
| - source, |
| - NetLog::PHASE_BEGIN, |
| - base::TimeTicks::Now(), |
| - NULL); |
| - NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); |
| - logger.OnAddEntry(entry); |
| - } |
| + FILE* file = base::OpenFile(log_path_, "w"); |
| + ASSERT_TRUE(file); |
| + scoped_ptr<base::Value> constants(NetLogLogger::GetConstants()); |
| + scoped_ptr<NetLogLogger> logger(new NetLogLogger(file, *constants)); |
| + |
| + const int kDummyId = 1; |
| + NetLog::Source source(NetLog::SOURCE_SPDY_SESSION, kDummyId); |
| + NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, |
| + source, |
| + NetLog::PHASE_BEGIN, |
| + base::TimeTicks::Now(), |
| + NULL); |
| + NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); |
| + logger->OnAddEntry(entry); |
| + logger.reset(); |
| std::string input; |
| ASSERT_TRUE(base::ReadFileToString(log_path_, &input)); |
| @@ -81,25 +102,24 @@ TEST_F(NetLogLoggerTest, GeneratesValidJSONWithOneEvent) { |
| } |
| TEST_F(NetLogLoggerTest, GeneratesValidJSONWithMultipleEvents) { |
| - { |
| - FILE* file = base::OpenFile(log_path_, "w"); |
| - ASSERT_TRUE(file); |
| - scoped_ptr<base::Value> constants(NetLogLogger::GetConstants()); |
| - NetLogLogger logger(file, *constants); |
| - |
| - const int kDummyId = 1; |
| - NetLog::Source source(NetLog::SOURCE_SPDY_SESSION, kDummyId); |
| - NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, |
| - source, |
| - NetLog::PHASE_BEGIN, |
| - base::TimeTicks::Now(), |
| - NULL); |
| - NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); |
| - |
| - // Add the entry multiple times. |
| - logger.OnAddEntry(entry); |
| - logger.OnAddEntry(entry); |
| - } |
| + FILE* file = base::OpenFile(log_path_, "w"); |
| + ASSERT_TRUE(file); |
| + scoped_ptr<base::Value> constants(NetLogLogger::GetConstants()); |
| + scoped_ptr<NetLogLogger> logger(new NetLogLogger(file, *constants)); |
| + |
| + const int kDummyId = 1; |
| + NetLog::Source source(NetLog::SOURCE_SPDY_SESSION, kDummyId); |
| + NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, |
| + source, |
| + NetLog::PHASE_BEGIN, |
| + base::TimeTicks::Now(), |
| + NULL); |
| + NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); |
| + |
| + // Add the entry multiple times. |
| + logger->OnAddEntry(entry); |
| + logger->OnAddEntry(entry); |
| + logger.reset(); |
| std::string input; |
| ASSERT_TRUE(base::ReadFileToString(log_path_, &input)); |
| @@ -115,4 +135,6 @@ TEST_F(NetLogLoggerTest, GeneratesValidJSONWithMultipleEvents) { |
| ASSERT_EQ(2u, events->GetSize()); |
| } |
| +} // namespace |
| + |
| } // namespace net |