Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: chrome/browser/net/net_log_temp_file_unittest.cc

Issue 102873002: Move GetFileSize, NormalizeFilePath to base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 return state; 88 return state;
89 } 89 }
90 90
91 // Make sure the export file has been created and is non-empty, as net 91 // Make sure the export file has been created and is non-empty, as net
92 // constants will always be written to it on creation. 92 // constants will always be written to it on creation.
93 void VerifyNetExportLog() { 93 void VerifyNetExportLog() {
94 EXPECT_EQ(net_export_log_, net_log_temp_file_->log_path_); 94 EXPECT_EQ(net_export_log_, net_log_temp_file_->log_path_);
95 EXPECT_TRUE(base::PathExists(net_export_log_)); 95 EXPECT_TRUE(base::PathExists(net_export_log_));
96 96
97 int64 file_size; 97 int64 file_size;
98 // file_util::GetFileSize returns proper file size on open handles. 98 // base::GetFileSize returns proper file size on open handles.
99 EXPECT_TRUE(file_util::GetFileSize(net_export_log_, &file_size)); 99 EXPECT_TRUE(base::GetFileSize(net_export_log_, &file_size));
100 EXPECT_GT(file_size, 0); 100 EXPECT_GT(file_size, 0);
101 } 101 }
102 102
103 // Verify state and GetFilePath return correct values if EnsureInit() fails. 103 // Verify state and GetFilePath return correct values if EnsureInit() fails.
104 void VerifyFilePathAndStateAfterEnsureInitFailure() { 104 void VerifyFilePathAndStateAfterEnsureInitFailure() {
105 EXPECT_EQ("UNINITIALIZED", GetStateString()); 105 EXPECT_EQ("UNINITIALIZED", GetStateString());
106 EXPECT_EQ(NetLogTempFile::STATE_UNINITIALIZED, 106 EXPECT_EQ(NetLogTempFile::STATE_UNINITIALIZED,
107 net_log_temp_file_->state()); 107 net_log_temp_file_->state());
108 108
109 base::FilePath net_export_file_path; 109 base::FilePath net_export_file_path;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 VerifyFileAndStateAfterDoStop(); 214 VerifyFileAndStateAfterDoStop();
215 } 215 }
216 216
217 TEST_F(NetLogTempFileTest, DoStartClearsFile) { 217 TEST_F(NetLogTempFileTest, DoStartClearsFile) {
218 // Verify file sizes after two consecutives start/stop are the same (even if 218 // Verify file sizes after two consecutives start/stop are the same (even if
219 // we add some junk data in between). 219 // we add some junk data in between).
220 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START); 220 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START);
221 VerifyFileAndStateAfterDoStart(); 221 VerifyFileAndStateAfterDoStart();
222 222
223 int64 start_file_size; 223 int64 start_file_size;
224 EXPECT_TRUE(file_util::GetFileSize(net_export_log_, &start_file_size)); 224 EXPECT_TRUE(base::GetFileSize(net_export_log_, &start_file_size));
225 225
226 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); 226 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP);
227 VerifyFileAndStateAfterDoStop(); 227 VerifyFileAndStateAfterDoStop();
228 228
229 int64 stop_file_size; 229 int64 stop_file_size;
230 EXPECT_TRUE(file_util::GetFileSize(net_export_log_, &stop_file_size)); 230 EXPECT_TRUE(base::GetFileSize(net_export_log_, &stop_file_size));
231 EXPECT_GE(stop_file_size, start_file_size); 231 EXPECT_GE(stop_file_size, start_file_size);
232 232
233 // Add some junk at the end of the file. 233 // Add some junk at the end of the file.
234 std::string junk_data("Hello"); 234 std::string junk_data("Hello");
235 EXPECT_GT(file_util::AppendToFile( 235 EXPECT_GT(file_util::AppendToFile(
236 net_export_log_, junk_data.c_str(), junk_data.size()), 0); 236 net_export_log_, junk_data.c_str(), junk_data.size()), 0);
237 237
238 int64 junk_file_size; 238 int64 junk_file_size;
239 EXPECT_TRUE(file_util::GetFileSize(net_export_log_, &junk_file_size)); 239 EXPECT_TRUE(base::GetFileSize(net_export_log_, &junk_file_size));
240 EXPECT_GT(junk_file_size, stop_file_size); 240 EXPECT_GT(junk_file_size, stop_file_size);
241 241
242 // Execute DO_START/DO_STOP commands and make sure the file is back to the 242 // Execute DO_START/DO_STOP commands and make sure the file is back to the
243 // size before addition of junk data. 243 // size before addition of junk data.
244 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START); 244 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START);
245 VerifyFileAndStateAfterDoStart(); 245 VerifyFileAndStateAfterDoStart();
246 246
247 int64 new_start_file_size; 247 int64 new_start_file_size;
248 EXPECT_TRUE(file_util::GetFileSize(net_export_log_, &new_start_file_size)); 248 EXPECT_TRUE(base::GetFileSize(net_export_log_, &new_start_file_size));
249 EXPECT_EQ(new_start_file_size, start_file_size); 249 EXPECT_EQ(new_start_file_size, start_file_size);
250 250
251 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); 251 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP);
252 VerifyFileAndStateAfterDoStop(); 252 VerifyFileAndStateAfterDoStop();
253 253
254 int64 new_stop_file_size; 254 int64 new_stop_file_size;
255 EXPECT_TRUE(file_util::GetFileSize(net_export_log_, &new_stop_file_size)); 255 EXPECT_TRUE(base::GetFileSize(net_export_log_, &new_stop_file_size));
256 EXPECT_EQ(new_stop_file_size, stop_file_size); 256 EXPECT_EQ(new_stop_file_size, stop_file_size);
257 } 257 }
258 258
259 TEST_F(NetLogTempFileTest, CheckAddEvent) { 259 TEST_F(NetLogTempFileTest, CheckAddEvent) {
260 // Add an event to |net_log_| and then test to make sure that, after we stop 260 // Add an event to |net_log_| and then test to make sure that, after we stop
261 // logging, the file is larger than the file created without that event. 261 // logging, the file is larger than the file created without that event.
262 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START); 262 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START);
263 VerifyFileAndStateAfterDoStart(); 263 VerifyFileAndStateAfterDoStart();
264 264
265 // Get file size without the event. 265 // Get file size without the event.
266 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); 266 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP);
267 VerifyFileAndStateAfterDoStop(); 267 VerifyFileAndStateAfterDoStop();
268 268
269 int64 stop_file_size; 269 int64 stop_file_size;
270 EXPECT_TRUE(file_util::GetFileSize(net_export_log_, &stop_file_size)); 270 EXPECT_TRUE(base::GetFileSize(net_export_log_, &stop_file_size));
271 271
272 // Perform DO_START and add an Event and then DO_STOP and then compare 272 // Perform DO_START and add an Event and then DO_STOP and then compare
273 // file sizes. 273 // file sizes.
274 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START); 274 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_START);
275 VerifyFileAndStateAfterDoStart(); 275 VerifyFileAndStateAfterDoStart();
276 276
277 // Log an event. 277 // Log an event.
278 net_log_->AddGlobalEntry(net::NetLog::TYPE_CANCELLED); 278 net_log_->AddGlobalEntry(net::NetLog::TYPE_CANCELLED);
279 279
280 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP); 280 net_log_temp_file_->ProcessCommand(NetLogTempFile::DO_STOP);
281 VerifyFileAndStateAfterDoStop(); 281 VerifyFileAndStateAfterDoStop();
282 282
283 int64 new_stop_file_size; 283 int64 new_stop_file_size;
284 EXPECT_TRUE(file_util::GetFileSize(net_export_log_, &new_stop_file_size)); 284 EXPECT_TRUE(base::GetFileSize(net_export_log_, &new_stop_file_size));
285 EXPECT_GE(new_stop_file_size, stop_file_size); 285 EXPECT_GE(new_stop_file_size, stop_file_size);
286 } 286 }
OLDNEW
« no previous file with comments | « chrome/browser/history/thumbnail_database.cc ('k') | chrome/browser/net/sqlite_server_bound_cert_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698