OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/net/net_log_temp_file.h" | 5 #include "chrome/browser/net/net_log_temp_file.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 base::FilePath net_export_file_path; | 142 base::FilePath net_export_file_path; |
143 EXPECT_FALSE(net_log_temp_file_->GetFilePath(&net_export_file_path)); | 143 EXPECT_FALSE(net_log_temp_file_->GetFilePath(&net_export_file_path)); |
144 EXPECT_FALSE(net_log_temp_file_->NetExportLogExists()); | 144 EXPECT_FALSE(net_log_temp_file_->NetExportLogExists()); |
145 } | 145 } |
146 | 146 |
147 // The following methods make sure the export file has been successfully | 147 // The following methods make sure the export file has been successfully |
148 // initialized by a DO_START command of the given type. | 148 // initialized by a DO_START command of the given type. |
149 | 149 |
150 void VerifyFileAndStateAfterDoStart() { | 150 void VerifyFileAndStateAfterDoStart() { |
151 VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_NORMAL, "NORMAL", | 151 VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_NORMAL, "NORMAL", |
152 net::NetLog::LOG_ALL_BUT_BYTES); | 152 net::NetLogCaptureMode::AllButBytes()); |
153 } | 153 } |
154 | 154 |
155 void VerifyFileAndStateAfterDoStartStripPrivateData() const { | 155 void VerifyFileAndStateAfterDoStartStripPrivateData() const { |
156 VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_STRIP_PRIVATE_DATA, | 156 VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_STRIP_PRIVATE_DATA, |
157 "STRIP_PRIVATE_DATA", | 157 "STRIP_PRIVATE_DATA", |
158 net::NetLog::LOG_STRIP_PRIVATE_DATA); | 158 net::NetLogCaptureMode::StripPrivateData()); |
159 } | 159 } |
160 | 160 |
161 void VerifyFileAndStateAfterDoStartLogBytes() const { | 161 void VerifyFileAndStateAfterDoStartLogBytes() const { |
162 VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_LOG_BYTES, | 162 VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_LOG_BYTES, |
163 "LOG_BYTES", net::NetLog::LOG_ALL); | 163 "LOG_BYTES", net::NetLogCaptureMode::All()); |
164 } | 164 } |
165 | 165 |
166 // Make sure the export file has been successfully initialized after DO_STOP | 166 // Make sure the export file has been successfully initialized after DO_STOP |
167 // command following a DO_START command of the given type. | 167 // command following a DO_START command of the given type. |
168 | 168 |
169 void VerifyFileAndStateAfterDoStop() const { | 169 void VerifyFileAndStateAfterDoStop() const { |
170 VerifyFileAndStateAfterDoStop(NetLogTempFile::LOG_TYPE_NORMAL, "NORMAL"); | 170 VerifyFileAndStateAfterDoStop(NetLogTempFile::LOG_TYPE_NORMAL, "NORMAL"); |
171 } | 171 } |
172 | 172 |
173 void VerifyFileAndStateAfterDoStopWithStripPrivateData() const { | 173 void VerifyFileAndStateAfterDoStopWithStripPrivateData() const { |
(...skipping 10 matching lines...) Expand all Loading... |
184 // |net_log_temp_file_| is initialized after |net_log_| so that it can stop | 184 // |net_log_temp_file_| is initialized after |net_log_| so that it can stop |
185 // obvserving on destruction. | 185 // obvserving on destruction. |
186 scoped_ptr<TestNetLogTempFile> net_log_temp_file_; | 186 scoped_ptr<TestNetLogTempFile> net_log_temp_file_; |
187 base::FilePath net_export_log_; | 187 base::FilePath net_export_log_; |
188 | 188 |
189 private: | 189 private: |
190 // Checks state after one of the DO_START* commands. | 190 // Checks state after one of the DO_START* commands. |
191 void VerifyFileAndStateAfterStart( | 191 void VerifyFileAndStateAfterStart( |
192 NetLogTempFile::LogType expected_log_type, | 192 NetLogTempFile::LogType expected_log_type, |
193 const std::string& expected_log_type_string, | 193 const std::string& expected_log_type_string, |
194 net::NetLog::LogLevel expected_log_level) const { | 194 net::NetLogCaptureMode expected_capture_mode) const { |
195 EXPECT_EQ(NetLogTempFile::STATE_LOGGING, net_log_temp_file_->state()); | 195 EXPECT_EQ(NetLogTempFile::STATE_LOGGING, net_log_temp_file_->state()); |
196 EXPECT_EQ("LOGGING", GetStateString()); | 196 EXPECT_EQ("LOGGING", GetStateString()); |
197 EXPECT_EQ(expected_log_type, net_log_temp_file_->log_type()); | 197 EXPECT_EQ(expected_log_type, net_log_temp_file_->log_type()); |
198 EXPECT_EQ(expected_log_type_string, GetLogTypeString()); | 198 EXPECT_EQ(expected_log_type_string, GetLogTypeString()); |
199 | 199 |
200 EXPECT_EQ(expected_log_level, net_log_->GetLogLevel()); | 200 EXPECT_EQ(expected_capture_mode, net_log_->GetCaptureMode()); |
201 | 201 |
202 // Check GetFilePath returns false when still writing to the file. | 202 // Check GetFilePath returns false when still writing to the file. |
203 base::FilePath net_export_file_path; | 203 base::FilePath net_export_file_path; |
204 EXPECT_FALSE(net_log_temp_file_->GetFilePath(&net_export_file_path)); | 204 EXPECT_FALSE(net_log_temp_file_->GetFilePath(&net_export_file_path)); |
205 | 205 |
206 VerifyNetExportLogExists(); | 206 VerifyNetExportLogExists(); |
207 } | 207 } |
208 | 208 |
209 void VerifyFileAndStateAfterDoStop( | 209 void VerifyFileAndStateAfterDoStop( |
210 NetLogTempFile::LogType expected_log_type, | 210 NetLogTempFile::LogType expected_log_type, |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 // Log an event. | 389 // Log an event. |
390 net_log_->AddGlobalEntry(net::NetLog::TYPE_CANCELLED); | 390 net_log_->AddGlobalEntry(net::NetLog::TYPE_CANCELLED); |
391 | 391 |
392 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); | 392 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); |
393 VerifyFileAndStateAfterDoStop(); | 393 VerifyFileAndStateAfterDoStop(); |
394 | 394 |
395 int64 new_stop_file_size; | 395 int64 new_stop_file_size; |
396 EXPECT_TRUE(base::GetFileSize(net_export_log_, &new_stop_file_size)); | 396 EXPECT_TRUE(base::GetFileSize(net_export_log_, &new_stop_file_size)); |
397 EXPECT_GE(new_stop_file_size, stop_file_size); | 397 EXPECT_GE(new_stop_file_size, stop_file_size); |
398 } | 398 } |
OLD | NEW |