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

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

Issue 1059843002: Refactor NetLog::LogLevel --> NetLogCaptureMode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase again to fix a merge conflict 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
« no previous file with comments | « net/log/write_to_file_net_log_observer.cc ('k') | net/net.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/write_to_file_net_log_observer.h" 5 #include "net/log/write_to_file_net_log_observer.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(WriteToFileNetLogObserverTest, LogLevel) { 64 TEST_F(WriteToFileNetLogObserverTest, 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 WriteToFileNetLogObserver logger; 67 WriteToFileNetLogObserver 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::Default(), logger.capture_mode());
70 EXPECT_EQ(NetLog::LOG_STRIP_PRIVATE_DATA, net_log_.GetLogLevel()); 70 EXPECT_EQ(NetLogCaptureMode::Default(), 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::IncludeCookiesAndCredentials());
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::IncludeCookiesAndCredentials(),
78 EXPECT_EQ(NetLog::LOG_ALL_BUT_BYTES, net_log_.GetLogLevel()); 78 logger.capture_mode());
79 EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(),
80 net_log_.GetCaptureMode());
79 logger.StopObserving(nullptr); 81 logger.StopObserving(nullptr);
80 } 82 }
81 83
82 TEST_F(WriteToFileNetLogObserverTest, GeneratesValidJSONWithOneEvent) { 84 TEST_F(WriteToFileNetLogObserverTest, GeneratesValidJSONWithOneEvent) {
83 base::ScopedFILE file(base::OpenFile(log_path_, "w")); 85 base::ScopedFILE file(base::OpenFile(log_path_, "w"));
84 ASSERT_TRUE(file); 86 ASSERT_TRUE(file);
85 scoped_ptr<WriteToFileNetLogObserver> logger(new WriteToFileNetLogObserver()); 87 scoped_ptr<WriteToFileNetLogObserver> logger(new WriteToFileNetLogObserver());
86 logger->StartObserving(&net_log_, file.Pass(), nullptr, nullptr); 88 logger->StartObserving(&net_log_, file.Pass(), nullptr, nullptr);
87 89
88 const int kDummyId = 1; 90 const int kDummyId = 1;
89 NetLog::Source source(NetLog::SOURCE_HTTP2_SESSION, kDummyId); 91 NetLog::Source source(NetLog::SOURCE_HTTP2_SESSION, kDummyId);
90 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, source, 92 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, source,
91 NetLog::PHASE_BEGIN, base::TimeTicks::Now(), 93 NetLog::PHASE_BEGIN, base::TimeTicks::Now(),
92 NULL); 94 NULL);
93 NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); 95 NetLog::Entry entry(&entry_data, NetLogCaptureMode::IncludeSocketBytes());
94 logger->OnAddEntry(entry); 96 logger->OnAddEntry(entry);
95 logger->StopObserving(nullptr); 97 logger->StopObserving(nullptr);
96 logger.reset(); 98 logger.reset();
97 99
98 std::string input; 100 std::string input;
99 ASSERT_TRUE(base::ReadFileToString(log_path_, &input)); 101 ASSERT_TRUE(base::ReadFileToString(log_path_, &input));
100 102
101 base::JSONReader reader; 103 base::JSONReader reader;
102 scoped_ptr<base::Value> root(reader.ReadToValue(input)); 104 scoped_ptr<base::Value> root(reader.ReadToValue(input));
103 ASSERT_TRUE(root) << reader.GetErrorMessage(); 105 ASSERT_TRUE(root) << reader.GetErrorMessage();
104 106
105 base::DictionaryValue* dict; 107 base::DictionaryValue* dict;
106 ASSERT_TRUE(root->GetAsDictionary(&dict)); 108 ASSERT_TRUE(root->GetAsDictionary(&dict));
107 base::ListValue* events; 109 base::ListValue* events;
108 ASSERT_TRUE(dict->GetList("events", &events)); 110 ASSERT_TRUE(dict->GetList("events", &events));
109 ASSERT_EQ(1u, events->GetSize()); 111 ASSERT_EQ(1u, events->GetSize());
110 } 112 }
111 113
112 TEST_F(WriteToFileNetLogObserverTest, GeneratesValidJSONWithMultipleEvents) { 114 TEST_F(WriteToFileNetLogObserverTest, GeneratesValidJSONWithMultipleEvents) {
113 base::ScopedFILE file(base::OpenFile(log_path_, "w")); 115 base::ScopedFILE file(base::OpenFile(log_path_, "w"));
114 ASSERT_TRUE(file); 116 ASSERT_TRUE(file);
115 scoped_ptr<WriteToFileNetLogObserver> logger(new WriteToFileNetLogObserver()); 117 scoped_ptr<WriteToFileNetLogObserver> logger(new WriteToFileNetLogObserver());
116 logger->StartObserving(&net_log_, file.Pass(), nullptr, nullptr); 118 logger->StartObserving(&net_log_, file.Pass(), nullptr, nullptr);
117 119
118 const int kDummyId = 1; 120 const int kDummyId = 1;
119 NetLog::Source source(NetLog::SOURCE_HTTP2_SESSION, kDummyId); 121 NetLog::Source source(NetLog::SOURCE_HTTP2_SESSION, kDummyId);
120 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, source, 122 NetLog::EntryData entry_data(NetLog::TYPE_PROXY_SERVICE, source,
121 NetLog::PHASE_BEGIN, base::TimeTicks::Now(), 123 NetLog::PHASE_BEGIN, base::TimeTicks::Now(),
122 NULL); 124 NULL);
123 NetLog::Entry entry(&entry_data, NetLog::LOG_ALL); 125 NetLog::Entry entry(&entry_data, NetLogCaptureMode::IncludeSocketBytes());
124 126
125 // Add the entry multiple times. 127 // Add the entry multiple times.
126 logger->OnAddEntry(entry); 128 logger->OnAddEntry(entry);
127 logger->OnAddEntry(entry); 129 logger->OnAddEntry(entry);
128 logger->StopObserving(nullptr); 130 logger->StopObserving(nullptr);
129 logger.reset(); 131 logger.reset();
130 132
131 std::string input; 133 std::string input;
132 ASSERT_TRUE(base::ReadFileToString(log_path_, &input)); 134 ASSERT_TRUE(base::ReadFileToString(log_path_, &input));
133 135
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 ASSERT_EQ(1u, events->GetSize()); 235 ASSERT_EQ(1u, events->GetSize());
234 236
235 // Make sure additional information is present, but don't validate it. 237 // Make sure additional information is present, but don't validate it.
236 base::DictionaryValue* tab_info; 238 base::DictionaryValue* tab_info;
237 ASSERT_TRUE(dict->GetDictionary("tabInfo", &tab_info)); 239 ASSERT_TRUE(dict->GetDictionary("tabInfo", &tab_info));
238 } 240 }
239 241
240 } // namespace 242 } // namespace
241 243
242 } // namespace net 244 } // namespace net
OLDNEW
« no previous file with comments | « net/log/write_to_file_net_log_observer.cc ('k') | net/net.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698