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/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 scoped_ptr<base::DictionaryValue> dict(net_log_temp_file_->GetState()); | 86 scoped_ptr<base::DictionaryValue> dict(net_log_temp_file_->GetState()); |
87 std::string state; | 87 std::string state; |
88 EXPECT_TRUE(dict->GetString("state", &state)); | 88 EXPECT_TRUE(dict->GetString("state", &state)); |
89 return state; | 89 return state; |
90 } | 90 } |
91 | 91 |
92 // Make sure the export file has been created and is non-empty, as net | 92 // Make sure the export file has been created and is non-empty, as net |
93 // constants will always be written to it on creation. | 93 // constants will always be written to it on creation. |
94 void VerifyNetExportLog() { | 94 void VerifyNetExportLog() { |
95 EXPECT_EQ(net_export_log_, net_log_temp_file_->log_path_); | 95 EXPECT_EQ(net_export_log_, net_log_temp_file_->log_path_); |
96 EXPECT_TRUE(file_util::PathExists(net_export_log_)); | 96 EXPECT_TRUE(base::PathExists(net_export_log_)); |
97 | 97 |
98 int64 file_size; | 98 int64 file_size; |
99 // file_util::GetFileSize returns proper file size on open handles. | 99 // file_util::GetFileSize returns proper file size on open handles. |
100 EXPECT_TRUE(file_util::GetFileSize(net_export_log_, &file_size)); | 100 EXPECT_TRUE(file_util::GetFileSize(net_export_log_, &file_size)); |
101 EXPECT_GT(file_size, 0); | 101 EXPECT_GT(file_size, 0); |
102 } | 102 } |
103 | 103 |
104 // Verify state and GetFilePath return correct values if EnsureInit() fails. | 104 // Verify state and GetFilePath return correct values if EnsureInit() fails. |
105 void VerifyFilePathAndStateAfterEnsureInitFailure() { | 105 void VerifyFilePathAndStateAfterEnsureInitFailure() { |
106 EXPECT_EQ("UNINITIALIZED", GetStateString()); | 106 EXPECT_EQ("UNINITIALIZED", GetStateString()); |
(...skipping 28 matching lines...) Expand all Loading... |
135 } | 135 } |
136 | 136 |
137 // Make sure the export file has been successfully initialized. | 137 // Make sure the export file has been successfully initialized. |
138 void VerifyFileAndStateAfterDoStop() { | 138 void VerifyFileAndStateAfterDoStop() { |
139 EXPECT_EQ("ALLOW_START_SEND", GetStateString()); | 139 EXPECT_EQ("ALLOW_START_SEND", GetStateString()); |
140 EXPECT_EQ(NetLogTempFile::STATE_ALLOW_START_SEND, | 140 EXPECT_EQ(NetLogTempFile::STATE_ALLOW_START_SEND, |
141 net_log_temp_file_->state()); | 141 net_log_temp_file_->state()); |
142 | 142 |
143 base::FilePath net_export_file_path; | 143 base::FilePath net_export_file_path; |
144 EXPECT_TRUE(net_log_temp_file_->GetFilePath(&net_export_file_path)); | 144 EXPECT_TRUE(net_log_temp_file_->GetFilePath(&net_export_file_path)); |
145 EXPECT_TRUE(file_util::PathExists(net_export_file_path)); | 145 EXPECT_TRUE(base::PathExists(net_export_file_path)); |
146 EXPECT_EQ(net_export_log_, net_export_file_path); | 146 EXPECT_EQ(net_export_log_, net_export_file_path); |
147 | 147 |
148 VerifyNetExportLog(); | 148 VerifyNetExportLog(); |
149 } | 149 } |
150 | 150 |
151 scoped_ptr<ChromeNetLog> net_log_; | 151 scoped_ptr<ChromeNetLog> net_log_; |
152 // |net_log_temp_file_| is initialized after |net_log_| so that it can stop | 152 // |net_log_temp_file_| is initialized after |net_log_| so that it can stop |
153 // obvserving on destruction. | 153 // obvserving on destruction. |
154 scoped_ptr<TestNetLogTempFile> net_log_temp_file_; | 154 scoped_ptr<TestNetLogTempFile> net_log_temp_file_; |
155 base::FilePath net_export_log_; | 155 base::FilePath net_export_log_; |
(...skipping 24 matching lines...) Expand all Loading... |
180 VerifyFilePathAndStateAfterEnsureInit(); | 180 VerifyFilePathAndStateAfterEnsureInit(); |
181 } | 181 } |
182 | 182 |
183 TEST_F(NetLogTempFileTest, EnsureInitAllowStartOrSend) { | 183 TEST_F(NetLogTempFileTest, EnsureInitAllowStartOrSend) { |
184 EXPECT_TRUE(net_log_temp_file_->EnsureInit()); | 184 EXPECT_TRUE(net_log_temp_file_->EnsureInit()); |
185 | 185 |
186 EXPECT_EQ("ALLOW_START_SEND", GetStateString()); | 186 EXPECT_EQ("ALLOW_START_SEND", GetStateString()); |
187 EXPECT_EQ(NetLogTempFile::STATE_ALLOW_START_SEND, | 187 EXPECT_EQ(NetLogTempFile::STATE_ALLOW_START_SEND, |
188 net_log_temp_file_->state()); | 188 net_log_temp_file_->state()); |
189 EXPECT_EQ(net_export_log_, net_log_temp_file_->log_path_); | 189 EXPECT_EQ(net_export_log_, net_log_temp_file_->log_path_); |
190 EXPECT_TRUE(file_util::PathExists(net_export_log_)); | 190 EXPECT_TRUE(base::PathExists(net_export_log_)); |
191 | 191 |
192 base::FilePath net_export_file_path; | 192 base::FilePath net_export_file_path; |
193 EXPECT_TRUE(net_log_temp_file_->GetFilePath(&net_export_file_path)); | 193 EXPECT_TRUE(net_log_temp_file_->GetFilePath(&net_export_file_path)); |
194 EXPECT_TRUE(file_util::PathExists(net_export_file_path)); | 194 EXPECT_TRUE(base::PathExists(net_export_file_path)); |
195 EXPECT_EQ(net_export_log_, net_export_file_path); | 195 EXPECT_EQ(net_export_log_, net_export_file_path); |
196 | 196 |
197 // GetFilePath should return false if NetExportLogExists() fails. | 197 // GetFilePath should return false if NetExportLogExists() fails. |
198 net_log_temp_file_->set_lie_about_file_existence(true); | 198 net_log_temp_file_->set_lie_about_file_existence(true); |
199 EXPECT_FALSE(net_log_temp_file_->GetFilePath(&net_export_file_path)); | 199 EXPECT_FALSE(net_log_temp_file_->GetFilePath(&net_export_file_path)); |
200 } | 200 } |
201 | 201 |
202 TEST_F(NetLogTempFileTest, ProcessCommandDoStartAndStop) { | 202 TEST_F(NetLogTempFileTest, ProcessCommandDoStartAndStop) { |
203 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START); | 203 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START); |
204 VerifyFileAndStateAfterDoStart(); | 204 VerifyFileAndStateAfterDoStart(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 // Log an event. | 278 // Log an event. |
279 net_log_->AddGlobalEntry(net::NetLog::TYPE_CANCELLED); | 279 net_log_->AddGlobalEntry(net::NetLog::TYPE_CANCELLED); |
280 | 280 |
281 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); | 281 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); |
282 VerifyFileAndStateAfterDoStop(); | 282 VerifyFileAndStateAfterDoStop(); |
283 | 283 |
284 int64 new_stop_file_size; | 284 int64 new_stop_file_size; |
285 EXPECT_TRUE(file_util::GetFileSize(net_export_log_, &new_stop_file_size)); | 285 EXPECT_TRUE(file_util::GetFileSize(net_export_log_, &new_stop_file_size)); |
286 EXPECT_GE(new_stop_file_size, stop_file_size); | 286 EXPECT_GE(new_stop_file_size, stop_file_size); |
287 } | 287 } |
OLD | NEW |