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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 EXPECT_EQ(NetLogTempFile::LOG_TYPE_NORMAL, net_log_temp_file_->log_type()); | 169 EXPECT_EQ(NetLogTempFile::LOG_TYPE_NORMAL, net_log_temp_file_->log_type()); |
170 | 170 |
171 base::FilePath net_export_file_path; | 171 base::FilePath net_export_file_path; |
172 EXPECT_TRUE(net_log_temp_file_->GetFilePath(&net_export_file_path)); | 172 EXPECT_TRUE(net_log_temp_file_->GetFilePath(&net_export_file_path)); |
173 EXPECT_TRUE(base::PathExists(net_export_file_path)); | 173 EXPECT_TRUE(base::PathExists(net_export_file_path)); |
174 EXPECT_EQ(net_export_log_, net_export_file_path); | 174 EXPECT_EQ(net_export_log_, net_export_file_path); |
175 | 175 |
176 VerifyNetExportLog(); | 176 VerifyNetExportLog(); |
177 } | 177 } |
178 | 178 |
| 179 // Make sure the export file has been successfully initialized. |
| 180 void VerifyFileAndStateAfterDoStopWithStripPrivateData() { |
| 181 EXPECT_EQ("NOT_LOGGING", GetStateString()); |
| 182 EXPECT_EQ(NetLogTempFile::STATE_NOT_LOGGING, net_log_temp_file_->state()); |
| 183 EXPECT_EQ("STRIP_PRIVATE_DATA", GetLogTypeString()); |
| 184 EXPECT_EQ(NetLogTempFile::LOG_TYPE_STRIP_PRIVATE_DATA, |
| 185 net_log_temp_file_->log_type()); |
| 186 |
| 187 base::FilePath net_export_file_path; |
| 188 EXPECT_TRUE(net_log_temp_file_->GetFilePath(&net_export_file_path)); |
| 189 EXPECT_TRUE(base::PathExists(net_export_file_path)); |
| 190 EXPECT_EQ(net_export_log_, net_export_file_path); |
| 191 |
| 192 VerifyNetExportLog(); |
| 193 } |
| 194 |
179 scoped_ptr<ChromeNetLog> net_log_; | 195 scoped_ptr<ChromeNetLog> net_log_; |
180 // |net_log_temp_file_| is initialized after |net_log_| so that it can stop | 196 // |net_log_temp_file_| is initialized after |net_log_| so that it can stop |
181 // obvserving on destruction. | 197 // obvserving on destruction. |
182 scoped_ptr<TestNetLogTempFile> net_log_temp_file_; | 198 scoped_ptr<TestNetLogTempFile> net_log_temp_file_; |
183 base::FilePath net_export_log_; | 199 base::FilePath net_export_log_; |
184 | 200 |
185 private: | 201 private: |
186 base::MessageLoop message_loop_; | 202 base::MessageLoop message_loop_; |
187 content::TestBrowserThread file_user_blocking_thread_; | 203 content::TestBrowserThread file_user_blocking_thread_; |
188 }; | 204 }; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 VerifyFileAndStateAfterDoStart(); | 253 VerifyFileAndStateAfterDoStart(); |
238 | 254 |
239 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); | 255 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); |
240 VerifyFileAndStateAfterDoStop(); | 256 VerifyFileAndStateAfterDoStop(); |
241 | 257 |
242 // Calling DO_STOP second time should be a no-op. | 258 // Calling DO_STOP second time should be a no-op. |
243 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); | 259 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); |
244 VerifyFileAndStateAfterDoStop(); | 260 VerifyFileAndStateAfterDoStop(); |
245 } | 261 } |
246 | 262 |
| 263 TEST_F(NetLogTempFileTest, |
| 264 ProcessCommandDoStartAndStopWithPrivateDataStripping) { |
| 265 net_log_temp_file_->ProcessCommand( |
| 266 NetLogTempFile::DO_START_STRIP_PRIVATE_DATA); |
| 267 VerifyFileAndStateAfterDoStartStripPrivateData(); |
| 268 |
| 269 // Calling DO_START_STRIP_PRIVATE_DATA second time should be a no-op. |
| 270 net_log_temp_file_->ProcessCommand( |
| 271 NetLogTempFile::DO_START_STRIP_PRIVATE_DATA); |
| 272 VerifyFileAndStateAfterDoStartStripPrivateData(); |
| 273 |
| 274 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); |
| 275 VerifyFileAndStateAfterDoStopWithStripPrivateData(); |
| 276 |
| 277 // Calling DO_STOP second time should be a no-op. |
| 278 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); |
| 279 VerifyFileAndStateAfterDoStopWithStripPrivateData(); |
| 280 } |
| 281 |
247 TEST_F(NetLogTempFileTest, DoStartClearsFile) { | 282 TEST_F(NetLogTempFileTest, DoStartClearsFile) { |
248 // Verify file sizes after two consecutives start/stop are the same (even if | 283 // Verify file sizes after two consecutives start/stop are the same (even if |
249 // we add some junk data in between). | 284 // we add some junk data in between). |
250 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START); | 285 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START); |
251 VerifyFileAndStateAfterDoStart(); | 286 VerifyFileAndStateAfterDoStart(); |
252 | 287 |
253 int64 start_file_size; | 288 int64 start_file_size; |
254 EXPECT_TRUE(base::GetFileSize(net_export_log_, &start_file_size)); | 289 EXPECT_TRUE(base::GetFileSize(net_export_log_, &start_file_size)); |
255 | 290 |
256 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); | 291 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 // Log an event. | 342 // Log an event. |
308 net_log_->AddGlobalEntry(net::NetLog::TYPE_CANCELLED); | 343 net_log_->AddGlobalEntry(net::NetLog::TYPE_CANCELLED); |
309 | 344 |
310 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); | 345 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); |
311 VerifyFileAndStateAfterDoStop(); | 346 VerifyFileAndStateAfterDoStop(); |
312 | 347 |
313 int64 new_stop_file_size; | 348 int64 new_stop_file_size; |
314 EXPECT_TRUE(base::GetFileSize(net_export_log_, &new_stop_file_size)); | 349 EXPECT_TRUE(base::GetFileSize(net_export_log_, &new_stop_file_size)); |
315 EXPECT_GE(new_stop_file_size, stop_file_size); | 350 EXPECT_GE(new_stop_file_size, stop_file_size); |
316 } | 351 } |
OLD | NEW |