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 "chrome/common/important_file_writer.h" | 5 #include "chrome/common/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/logging.h" | 10 #include "base/logging.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 68 } |
69 | 69 |
70 TEST_F(ImportantFileWriterTest, ScheduleWrite) { | 70 TEST_F(ImportantFileWriterTest, ScheduleWrite) { |
71 ImportantFileWriter writer(file_, | 71 ImportantFileWriter writer(file_, |
72 base::MessageLoopProxy::current()); | 72 base::MessageLoopProxy::current()); |
73 writer.set_commit_interval(base::TimeDelta::FromMilliseconds(25)); | 73 writer.set_commit_interval(base::TimeDelta::FromMilliseconds(25)); |
74 EXPECT_FALSE(writer.HasPendingWrite()); | 74 EXPECT_FALSE(writer.HasPendingWrite()); |
75 DataSerializer serializer("foo"); | 75 DataSerializer serializer("foo"); |
76 writer.ScheduleWrite(&serializer); | 76 writer.ScheduleWrite(&serializer); |
77 EXPECT_TRUE(writer.HasPendingWrite()); | 77 EXPECT_TRUE(writer.HasPendingWrite()); |
78 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 78 MessageLoop::current()->PostDelayedTask( |
79 MessageLoop::QuitClosure(), 100); | 79 FROM_HERE, |
| 80 MessageLoop::QuitClosure(), |
| 81 base::TimeDelta::FromMilliseconds(100)); |
80 MessageLoop::current()->Run(); | 82 MessageLoop::current()->Run(); |
81 EXPECT_FALSE(writer.HasPendingWrite()); | 83 EXPECT_FALSE(writer.HasPendingWrite()); |
82 ASSERT_TRUE(file_util::PathExists(writer.path())); | 84 ASSERT_TRUE(file_util::PathExists(writer.path())); |
83 EXPECT_EQ("foo", GetFileContent(writer.path())); | 85 EXPECT_EQ("foo", GetFileContent(writer.path())); |
84 } | 86 } |
85 | 87 |
86 TEST_F(ImportantFileWriterTest, DoScheduledWrite) { | 88 TEST_F(ImportantFileWriterTest, DoScheduledWrite) { |
87 ImportantFileWriter writer(file_, | 89 ImportantFileWriter writer(file_, |
88 base::MessageLoopProxy::current()); | 90 base::MessageLoopProxy::current()); |
89 EXPECT_FALSE(writer.HasPendingWrite()); | 91 EXPECT_FALSE(writer.HasPendingWrite()); |
90 DataSerializer serializer("foo"); | 92 DataSerializer serializer("foo"); |
91 writer.ScheduleWrite(&serializer); | 93 writer.ScheduleWrite(&serializer); |
92 EXPECT_TRUE(writer.HasPendingWrite()); | 94 EXPECT_TRUE(writer.HasPendingWrite()); |
93 writer.DoScheduledWrite(); | 95 writer.DoScheduledWrite(); |
94 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 96 MessageLoop::current()->PostDelayedTask( |
95 MessageLoop::QuitClosure(), 100); | 97 FROM_HERE, |
| 98 MessageLoop::QuitClosure(), |
| 99 base::TimeDelta::FromMilliseconds(100)); |
96 MessageLoop::current()->Run(); | 100 MessageLoop::current()->Run(); |
97 EXPECT_FALSE(writer.HasPendingWrite()); | 101 EXPECT_FALSE(writer.HasPendingWrite()); |
98 ASSERT_TRUE(file_util::PathExists(writer.path())); | 102 ASSERT_TRUE(file_util::PathExists(writer.path())); |
99 EXPECT_EQ("foo", GetFileContent(writer.path())); | 103 EXPECT_EQ("foo", GetFileContent(writer.path())); |
100 } | 104 } |
101 | 105 |
102 // Flaky - http://crbug.com/109292 | 106 // Flaky - http://crbug.com/109292 |
103 TEST_F(ImportantFileWriterTest, FLAKY_BatchingWrites) { | 107 TEST_F(ImportantFileWriterTest, FLAKY_BatchingWrites) { |
104 ImportantFileWriter writer(file_, | 108 ImportantFileWriter writer(file_, |
105 base::MessageLoopProxy::current()); | 109 base::MessageLoopProxy::current()); |
106 writer.set_commit_interval(base::TimeDelta::FromMilliseconds(25)); | 110 writer.set_commit_interval(base::TimeDelta::FromMilliseconds(25)); |
107 DataSerializer foo("foo"), bar("bar"), baz("baz"); | 111 DataSerializer foo("foo"), bar("bar"), baz("baz"); |
108 writer.ScheduleWrite(&foo); | 112 writer.ScheduleWrite(&foo); |
109 writer.ScheduleWrite(&bar); | 113 writer.ScheduleWrite(&bar); |
110 writer.ScheduleWrite(&baz); | 114 writer.ScheduleWrite(&baz); |
111 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 115 MessageLoop::current()->PostDelayedTask( |
112 MessageLoop::QuitClosure(), 100); | 116 FROM_HERE, |
| 117 MessageLoop::QuitClosure(), |
| 118 base::TimeDelta::FromMilliseconds(100)); |
113 MessageLoop::current()->Run(); | 119 MessageLoop::current()->Run(); |
114 ASSERT_TRUE(file_util::PathExists(writer.path())); | 120 ASSERT_TRUE(file_util::PathExists(writer.path())); |
115 EXPECT_EQ("baz", GetFileContent(writer.path())); | 121 EXPECT_EQ("baz", GetFileContent(writer.path())); |
116 } | 122 } |
OLD | NEW |