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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/run_loop.h" |
13 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
14 #include "base/time.h" | 15 #include "base/time.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 std::string GetFileContent(const FilePath& path) { | 22 std::string GetFileContent(const FilePath& path) { |
22 std::string content; | 23 std::string content; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 57 |
57 private: | 58 private: |
58 ScopedTempDir temp_dir_; | 59 ScopedTempDir temp_dir_; |
59 }; | 60 }; |
60 | 61 |
61 TEST_F(ImportantFileWriterTest, Basic) { | 62 TEST_F(ImportantFileWriterTest, Basic) { |
62 ImportantFileWriter writer(file_, | 63 ImportantFileWriter writer(file_, |
63 MessageLoopProxy::current()); | 64 MessageLoopProxy::current()); |
64 EXPECT_FALSE(file_util::PathExists(writer.path())); | 65 EXPECT_FALSE(file_util::PathExists(writer.path())); |
65 writer.WriteNow("foo"); | 66 writer.WriteNow("foo"); |
66 loop_.RunUntilIdle(); | 67 RunLoop().RunUntilIdle(); |
67 | 68 |
68 ASSERT_TRUE(file_util::PathExists(writer.path())); | 69 ASSERT_TRUE(file_util::PathExists(writer.path())); |
69 EXPECT_EQ("foo", GetFileContent(writer.path())); | 70 EXPECT_EQ("foo", GetFileContent(writer.path())); |
70 } | 71 } |
71 | 72 |
72 TEST_F(ImportantFileWriterTest, ScheduleWrite) { | 73 TEST_F(ImportantFileWriterTest, ScheduleWrite) { |
73 ImportantFileWriter writer(file_, | 74 ImportantFileWriter writer(file_, |
74 MessageLoopProxy::current()); | 75 MessageLoopProxy::current()); |
75 writer.set_commit_interval(TimeDelta::FromMilliseconds(25)); | 76 writer.set_commit_interval(TimeDelta::FromMilliseconds(25)); |
76 EXPECT_FALSE(writer.HasPendingWrite()); | 77 EXPECT_FALSE(writer.HasPendingWrite()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 MessageLoop::current()->PostDelayedTask( | 117 MessageLoop::current()->PostDelayedTask( |
117 FROM_HERE, | 118 FROM_HERE, |
118 MessageLoop::QuitWhenIdleClosure(), | 119 MessageLoop::QuitWhenIdleClosure(), |
119 TimeDelta::FromMilliseconds(100)); | 120 TimeDelta::FromMilliseconds(100)); |
120 MessageLoop::current()->Run(); | 121 MessageLoop::current()->Run(); |
121 ASSERT_TRUE(file_util::PathExists(writer.path())); | 122 ASSERT_TRUE(file_util::PathExists(writer.path())); |
122 EXPECT_EQ("baz", GetFileContent(writer.path())); | 123 EXPECT_EQ("baz", GetFileContent(writer.path())); |
123 } | 124 } |
124 | 125 |
125 } // namespace base | 126 } // namespace base |
OLD | NEW |