| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/browser/net/chrome_net_log.h" | 15 #include "chrome/browser/net/chrome_net_log.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
| 17 #include "net/log/write_to_file_net_log_observer.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 using content::BrowserThread; | 20 using content::BrowserThread; |
| 20 | 21 |
| 21 class TestNetLogTempFile : public NetLogTempFile { | 22 class TestNetLogTempFile : public NetLogTempFile { |
| 22 public: | 23 public: |
| 23 explicit TestNetLogTempFile(ChromeNetLog* chrome_net_log) | 24 explicit TestNetLogTempFile(ChromeNetLog* chrome_net_log) |
| 24 : NetLogTempFile(chrome_net_log), | 25 : NetLogTempFile(chrome_net_log), |
| 25 lie_about_net_export_log_directory_(false), | 26 lie_about_net_export_log_directory_(false), |
| 26 lie_about_file_existence_(false) { | 27 lie_about_file_existence_(false) { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 private: | 192 private: |
| 192 // Checks state after one of the DO_START* commands. | 193 // Checks state after one of the DO_START* commands. |
| 193 void VerifyFileAndStateAfterStart( | 194 void VerifyFileAndStateAfterStart( |
| 194 NetLogTempFile::LogType expected_log_type, | 195 NetLogTempFile::LogType expected_log_type, |
| 195 const std::string& expected_log_type_string, | 196 const std::string& expected_log_type_string, |
| 196 net::NetLogCaptureMode expected_capture_mode) const { | 197 net::NetLogCaptureMode expected_capture_mode) const { |
| 197 EXPECT_EQ(NetLogTempFile::STATE_LOGGING, net_log_temp_file_->state()); | 198 EXPECT_EQ(NetLogTempFile::STATE_LOGGING, net_log_temp_file_->state()); |
| 198 EXPECT_EQ("LOGGING", GetStateString()); | 199 EXPECT_EQ("LOGGING", GetStateString()); |
| 199 EXPECT_EQ(expected_log_type, net_log_temp_file_->log_type()); | 200 EXPECT_EQ(expected_log_type, net_log_temp_file_->log_type()); |
| 200 EXPECT_EQ(expected_log_type_string, GetLogTypeString()); | 201 EXPECT_EQ(expected_log_type_string, GetLogTypeString()); |
| 201 | 202 EXPECT_EQ(expected_capture_mode, |
| 202 EXPECT_EQ(expected_capture_mode, net_log_->GetCaptureMode()); | 203 net_log_temp_file_->write_to_file_observer_->capture_mode()); |
| 203 | 204 |
| 204 // Check GetFilePath returns false when still writing to the file. | 205 // Check GetFilePath returns false when still writing to the file. |
| 205 base::FilePath net_export_file_path; | 206 base::FilePath net_export_file_path; |
| 206 EXPECT_FALSE(net_log_temp_file_->GetFilePath(&net_export_file_path)); | 207 EXPECT_FALSE(net_log_temp_file_->GetFilePath(&net_export_file_path)); |
| 207 | 208 |
| 208 VerifyNetExportLogExists(); | 209 VerifyNetExportLogExists(); |
| 209 } | 210 } |
| 210 | 211 |
| 211 void VerifyFileAndStateAfterDoStop( | 212 void VerifyFileAndStateAfterDoStop( |
| 212 NetLogTempFile::LogType expected_log_type, | 213 NetLogTempFile::LogType expected_log_type, |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 // Log an event. | 392 // Log an event. |
| 392 net_log_->AddGlobalEntry(net::NetLog::TYPE_CANCELLED); | 393 net_log_->AddGlobalEntry(net::NetLog::TYPE_CANCELLED); |
| 393 | 394 |
| 394 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); | 395 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); |
| 395 VerifyFileAndStateAfterDoStop(); | 396 VerifyFileAndStateAfterDoStop(); |
| 396 | 397 |
| 397 int64 new_stop_file_size; | 398 int64 new_stop_file_size; |
| 398 EXPECT_TRUE(base::GetFileSize(net_export_log_, &new_stop_file_size)); | 399 EXPECT_TRUE(base::GetFileSize(net_export_log_, &new_stop_file_size)); |
| 399 EXPECT_GE(new_stop_file_size, stop_file_size); | 400 EXPECT_GE(new_stop_file_size, stop_file_size); |
| 400 } | 401 } |
| OLD | NEW |