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

Side by Side Diff: net/log/net_log_logger_unittest.cc

Issue 1059843002: Refactor NetLog::LogLevel --> NetLogCaptureMode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update copyright Created 5 years, 8 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 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 "net/log/net_log_logger.h" 5 #include "net/log/net_log_logger.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_file.h" 9 #include "base/files/scoped_file.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 base::DictionaryValue* dict; 54 base::DictionaryValue* dict;
55 ASSERT_TRUE(root->GetAsDictionary(&dict)); 55 ASSERT_TRUE(root->GetAsDictionary(&dict));
56 base::ListValue* events; 56 base::ListValue* events;
57 ASSERT_TRUE(dict->GetList("events", &events)); 57 ASSERT_TRUE(dict->GetList("events", &events));
58 ASSERT_EQ(0u, events->GetSize()); 58 ASSERT_EQ(0u, events->GetSize());
59 59
60 base::DictionaryValue* constants; 60 base::DictionaryValue* constants;
61 ASSERT_TRUE(dict->GetDictionary("constants", &constants)); 61 ASSERT_TRUE(dict->GetDictionary("constants", &constants));
62 } 62 }
63 63
64 TEST_F(NetLogLoggerTest, LogLevel) { 64 TEST_F(NetLogLoggerTest, CaptureMode) {
65 base::ScopedFILE file(base::OpenFile(log_path_, "w")); 65 base::ScopedFILE file(base::OpenFile(log_path_, "w"));
66 ASSERT_TRUE(file); 66 ASSERT_TRUE(file);
67 NetLogLogger logger; 67 NetLogLogger logger;
68 logger.StartObserving(&net_log_, file.Pass(), nullptr, nullptr); 68 logger.StartObserving(&net_log_, file.Pass(), nullptr, nullptr);
69 EXPECT_EQ(NetLog::LOG_STRIP_PRIVATE_DATA, logger.log_level()); 69 EXPECT_EQ(NetLogCaptureMode::StripPrivateData(), logger.capture_mode());
70 EXPECT_EQ(NetLog::LOG_STRIP_PRIVATE_DATA, net_log_.GetLogLevel()); 70 EXPECT_EQ(NetLogCaptureMode::StripPrivateData(), net_log_.GetCaptureMode());
71 logger.StopObserving(nullptr); 71 logger.StopObserving(nullptr);
72 72
73 file.reset(base::OpenFile(log_path_, "w")); 73 file.reset(base::OpenFile(log_path_, "w"));
74 ASSERT_TRUE(file); 74 ASSERT_TRUE(file);
75 logger.set_log_level(NetLog::LOG_ALL_BUT_BYTES); 75 logger.set_capture_mode(NetLogCaptureMode::AllButBytes());
76 logger.StartObserving(&net_log_, file.Pass(), nullptr, nullptr); 76 logger.StartObserving(&net_log_, file.Pass(), nullptr, nullptr);
77 EXPECT_EQ(NetLog::LOG_ALL_BUT_BYTES, logger.log_level()); 77 EXPECT_EQ(NetLogCaptureMode::AllButBytes(), logger.capture_mode());
78 EXPECT_EQ(NetLog::LOG_ALL_BUT_BYTES, net_log_.GetLogLevel()); 78 EXPECT_EQ(NetLogCaptureMode::AllButBytes(), net_log_.GetCaptureMode());
79 logger.StopObserving(nullptr); 79 logger.StopObserving(nullptr);
80 } 80 }
81 81
82 TEST_F(NetLogLoggerTest, GeneratesValidJSONWithOneEvent) { 82 TEST_F(NetLogLoggerTest, GeneratesValidJSONWithOneEvent) {
83 base::ScopedFILE file(base::OpenFile(log_path_, "w")); 83 base::ScopedFILE file(base::OpenFile(log_path_, "w"));
84 ASSERT_TRUE(file); 84 ASSERT_TRUE(file);
85 scoped_ptr<NetLogLogger> logger(new NetLogLogger()); 85 scoped_ptr<NetLogLogger> logger(new NetLogLogger());
86 logger->StartObserving(&net_log_, file.Pass(), nullptr, nullptr); 86 logger->StartObserving(&net_log_, file.Pass(), nullptr, nullptr);
87 87
88 const int kDummyId = 1; 88 const int kDummyId = 1;
89 NetLog::Source source(NetLog::SOURCE_HTTP2_SESSION, kDummyId); 89 NetLog::Source source(NetLog::SOURCE_HTTP2_SESSION, kDummyId);
90 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, source, 90 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, source,
91 NetLog::PHASE_BEGIN, base::TimeTicks::Now(), 91 NetLog::PHASE_BEGIN, base::TimeTicks::Now(),
92 NULL); 92 NULL);
93 NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); 93 NetLog::Entry entry(&entry_data, NetLogCaptureMode::All());
94 logger->OnAddEntry(entry); 94 logger->OnAddEntry(entry);
95 logger->StopObserving(nullptr); 95 logger->StopObserving(nullptr);
96 logger.reset(); 96 logger.reset();
97 97
98 std::string input; 98 std::string input;
99 ASSERT_TRUE(base::ReadFileToString(log_path_, &input)); 99 ASSERT_TRUE(base::ReadFileToString(log_path_, &input));
100 100
101 base::JSONReader reader; 101 base::JSONReader reader;
102 scoped_ptr<base::Value> root(reader.ReadToValue(input)); 102 scoped_ptr<base::Value> root(reader.ReadToValue(input));
103 ASSERT_TRUE(root) << reader.GetErrorMessage(); 103 ASSERT_TRUE(root) << reader.GetErrorMessage();
104 104
105 base::DictionaryValue* dict; 105 base::DictionaryValue* dict;
106 ASSERT_TRUE(root->GetAsDictionary(&dict)); 106 ASSERT_TRUE(root->GetAsDictionary(&dict));
107 base::ListValue* events; 107 base::ListValue* events;
108 ASSERT_TRUE(dict->GetList("events", &events)); 108 ASSERT_TRUE(dict->GetList("events", &events));
109 ASSERT_EQ(1u, events->GetSize()); 109 ASSERT_EQ(1u, events->GetSize());
110 } 110 }
111 111
112 TEST_F(NetLogLoggerTest, GeneratesValidJSONWithMultipleEvents) { 112 TEST_F(NetLogLoggerTest, GeneratesValidJSONWithMultipleEvents) {
113 base::ScopedFILE file(base::OpenFile(log_path_, "w")); 113 base::ScopedFILE file(base::OpenFile(log_path_, "w"));
114 ASSERT_TRUE(file); 114 ASSERT_TRUE(file);
115 scoped_ptr<NetLogLogger> logger(new NetLogLogger()); 115 scoped_ptr<NetLogLogger> logger(new NetLogLogger());
116 logger->StartObserving(&net_log_, file.Pass(), nullptr, nullptr); 116 logger->StartObserving(&net_log_, file.Pass(), nullptr, nullptr);
117 117
118 const int kDummyId = 1; 118 const int kDummyId = 1;
119 NetLog::Source source(NetLog::SOURCE_HTTP2_SESSION, kDummyId); 119 NetLog::Source source(NetLog::SOURCE_HTTP2_SESSION, kDummyId);
120 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, source, 120 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, source,
121 NetLog::PHASE_BEGIN, base::TimeTicks::Now(), 121 NetLog::PHASE_BEGIN, base::TimeTicks::Now(),
122 NULL); 122 NULL);
123 NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); 123 NetLog::Entry entry(&entry_data, NetLogCaptureMode::All());
124 124
125 // Add the entry multiple times. 125 // Add the entry multiple times.
126 logger->OnAddEntry(entry); 126 logger->OnAddEntry(entry);
127 logger->OnAddEntry(entry); 127 logger->OnAddEntry(entry);
128 logger->StopObserving(nullptr); 128 logger->StopObserving(nullptr);
129 logger.reset(); 129 logger.reset();
130 130
131 std::string input; 131 std::string input;
132 ASSERT_TRUE(base::ReadFileToString(log_path_, &input)); 132 ASSERT_TRUE(base::ReadFileToString(log_path_, &input));
133 133
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 ASSERT_EQ(1u, events->GetSize()); 232 ASSERT_EQ(1u, events->GetSize());
233 233
234 // Make sure additional information is present, but don't validate it. 234 // Make sure additional information is present, but don't validate it.
235 base::DictionaryValue* tab_info; 235 base::DictionaryValue* tab_info;
236 ASSERT_TRUE(dict->GetDictionary("tabInfo", &tab_info)); 236 ASSERT_TRUE(dict->GetDictionary("tabInfo", &tab_info));
237 } 237 }
238 238
239 } // namespace 239 } // namespace
240 240
241 } // namespace net 241 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698