OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/files/important_file_writer.h" | 5 #include "base/files/important_file_writer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/test/histogram_tester.h" |
18 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
21 #include "base/timer/mock_timer.h" | 22 #include "base/timer/mock_timer.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
24 namespace base { | 25 namespace base { |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 writer.ScheduleWrite(&serializer); | 319 writer.ScheduleWrite(&serializer); |
319 EXPECT_TRUE(writer.HasPendingWrite()); | 320 EXPECT_TRUE(writer.HasPendingWrite()); |
320 | 321 |
321 writer.DoScheduledWrite(); | 322 writer.DoScheduledWrite(); |
322 EXPECT_FALSE(timer.IsRunning()); | 323 EXPECT_FALSE(timer.IsRunning()); |
323 EXPECT_FALSE(writer.HasPendingWrite()); | 324 EXPECT_FALSE(writer.HasPendingWrite()); |
324 RunLoop().RunUntilIdle(); | 325 RunLoop().RunUntilIdle(); |
325 EXPECT_FALSE(PathExists(writer.path())); | 326 EXPECT_FALSE(PathExists(writer.path())); |
326 } | 327 } |
327 | 328 |
| 329 TEST_F(ImportantFileWriterTest, WriteFileAtomicallyHistogramSuffixTest) { |
| 330 base::HistogramTester histogram_tester; |
| 331 EXPECT_FALSE(PathExists(file_)); |
| 332 EXPECT_TRUE(ImportantFileWriter::WriteFileAtomically(file_, "baz", "test")); |
| 333 EXPECT_TRUE(PathExists(file_)); |
| 334 EXPECT_EQ("baz", GetFileContent(file_)); |
| 335 histogram_tester.ExpectTotalCount("ImportantFile.FileCreateError", 0); |
| 336 histogram_tester.ExpectTotalCount("ImportantFile.FileCreateError.test", 0); |
| 337 |
| 338 FilePath invalid_file_ = FilePath().AppendASCII("bad/../path"); |
| 339 EXPECT_FALSE(PathExists(invalid_file_)); |
| 340 EXPECT_FALSE( |
| 341 ImportantFileWriter::WriteFileAtomically(invalid_file_, nullptr)); |
| 342 histogram_tester.ExpectTotalCount("ImportantFile.FileCreateError", 1); |
| 343 histogram_tester.ExpectTotalCount("ImportantFile.FileCreateError.test", 0); |
| 344 EXPECT_FALSE( |
| 345 ImportantFileWriter::WriteFileAtomically(invalid_file_, nullptr, "test")); |
| 346 histogram_tester.ExpectTotalCount("ImportantFile.FileCreateError", 1); |
| 347 histogram_tester.ExpectTotalCount("ImportantFile.FileCreateError.test", 1); |
| 348 } |
| 349 |
328 } // namespace base | 350 } // namespace base |
OLD | NEW |