| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 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( |
| 152 net::NetLog::LOG_ALL_BUT_BYTES); | 152 NetLogTempFile::LOG_TYPE_NORMAL, "NORMAL", |
| 153 net::NetLogCaptureMode::IncludeCookiesAndCredentials()); |
| 153 } | 154 } |
| 154 | 155 |
| 155 void VerifyFileAndStateAfterDoStartStripPrivateData() const { | 156 void VerifyFileAndStateAfterDoStartStripPrivateData() const { |
| 156 VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_STRIP_PRIVATE_DATA, | 157 VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_STRIP_PRIVATE_DATA, |
| 157 "STRIP_PRIVATE_DATA", | 158 "STRIP_PRIVATE_DATA", |
| 158 net::NetLog::LOG_STRIP_PRIVATE_DATA); | 159 net::NetLogCaptureMode::Default()); |
| 159 } | 160 } |
| 160 | 161 |
| 161 void VerifyFileAndStateAfterDoStartLogBytes() const { | 162 void VerifyFileAndStateAfterDoStartLogBytes() const { |
| 162 VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_LOG_BYTES, | 163 VerifyFileAndStateAfterStart(NetLogTempFile::LOG_TYPE_LOG_BYTES, |
| 163 "LOG_BYTES", net::NetLog::LOG_ALL); | 164 "LOG_BYTES", net::NetLogCaptureMode::All()); |
| 164 } | 165 } |
| 165 | 166 |
| 166 // Make sure the export file has been successfully initialized after DO_STOP | 167 // Make sure the export file has been successfully initialized after DO_STOP |
| 167 // command following a DO_START command of the given type. | 168 // command following a DO_START command of the given type. |
| 168 | 169 |
| 169 void VerifyFileAndStateAfterDoStop() const { | 170 void VerifyFileAndStateAfterDoStop() const { |
| 170 VerifyFileAndStateAfterDoStop(NetLogTempFile::LOG_TYPE_NORMAL, "NORMAL"); | 171 VerifyFileAndStateAfterDoStop(NetLogTempFile::LOG_TYPE_NORMAL, "NORMAL"); |
| 171 } | 172 } |
| 172 | 173 |
| 173 void VerifyFileAndStateAfterDoStopWithStripPrivateData() const { | 174 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 | 185 // |net_log_temp_file_| is initialized after |net_log_| so that it can stop |
| 185 // obvserving on destruction. | 186 // obvserving on destruction. |
| 186 scoped_ptr<TestNetLogTempFile> net_log_temp_file_; | 187 scoped_ptr<TestNetLogTempFile> net_log_temp_file_; |
| 187 base::FilePath net_export_log_; | 188 base::FilePath net_export_log_; |
| 188 | 189 |
| 189 private: | 190 private: |
| 190 // Checks state after one of the DO_START* commands. | 191 // Checks state after one of the DO_START* commands. |
| 191 void VerifyFileAndStateAfterStart( | 192 void VerifyFileAndStateAfterStart( |
| 192 NetLogTempFile::LogType expected_log_type, | 193 NetLogTempFile::LogType expected_log_type, |
| 193 const std::string& expected_log_type_string, | 194 const std::string& expected_log_type_string, |
| 194 net::NetLog::LogLevel expected_log_level) const { | 195 net::NetLogCaptureMode expected_capture_mode) const { |
| 195 EXPECT_EQ(NetLogTempFile::STATE_LOGGING, net_log_temp_file_->state()); | 196 EXPECT_EQ(NetLogTempFile::STATE_LOGGING, net_log_temp_file_->state()); |
| 196 EXPECT_EQ("LOGGING", GetStateString()); | 197 EXPECT_EQ("LOGGING", GetStateString()); |
| 197 EXPECT_EQ(expected_log_type, net_log_temp_file_->log_type()); | 198 EXPECT_EQ(expected_log_type, net_log_temp_file_->log_type()); |
| 198 EXPECT_EQ(expected_log_type_string, GetLogTypeString()); | 199 EXPECT_EQ(expected_log_type_string, GetLogTypeString()); |
| 199 | 200 |
| 200 EXPECT_EQ(expected_log_level, net_log_->GetLogLevel()); | 201 EXPECT_EQ(expected_capture_mode, net_log_->GetCaptureMode()); |
| 201 | 202 |
| 202 // Check GetFilePath returns false when still writing to the file. | 203 // Check GetFilePath returns false when still writing to the file. |
| 203 base::FilePath net_export_file_path; | 204 base::FilePath net_export_file_path; |
| 204 EXPECT_FALSE(net_log_temp_file_->GetFilePath(&net_export_file_path)); | 205 EXPECT_FALSE(net_log_temp_file_->GetFilePath(&net_export_file_path)); |
| 205 | 206 |
| 206 VerifyNetExportLogExists(); | 207 VerifyNetExportLogExists(); |
| 207 } | 208 } |
| 208 | 209 |
| 209 void VerifyFileAndStateAfterDoStop( | 210 void VerifyFileAndStateAfterDoStop( |
| 210 NetLogTempFile::LogType expected_log_type, | 211 NetLogTempFile::LogType expected_log_type, |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 // Log an event. | 390 // Log an event. |
| 390 net_log_->AddGlobalEntry(net::NetLog::TYPE_CANCELLED); | 391 net_log_->AddGlobalEntry(net::NetLog::TYPE_CANCELLED); |
| 391 | 392 |
| 392 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); | 393 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); |
| 393 VerifyFileAndStateAfterDoStop(); | 394 VerifyFileAndStateAfterDoStop(); |
| 394 | 395 |
| 395 int64 new_stop_file_size; | 396 int64 new_stop_file_size; |
| 396 EXPECT_TRUE(base::GetFileSize(net_export_log_, &new_stop_file_size)); | 397 EXPECT_TRUE(base::GetFileSize(net_export_log_, &new_stop_file_size)); |
| 397 EXPECT_GE(new_stop_file_size, stop_file_size); | 398 EXPECT_GE(new_stop_file_size, stop_file_size); |
| 398 } | 399 } |
| OLD | NEW |