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( | 78 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
79 FROM_HERE, | 79 MessageLoop::QuitClosure(), 100); |
80 MessageLoop::QuitClosure(), | |
81 base::TimeDelta::FromMilliseconds(100)); | |
82 MessageLoop::current()->Run(); | 80 MessageLoop::current()->Run(); |
83 EXPECT_FALSE(writer.HasPendingWrite()); | 81 EXPECT_FALSE(writer.HasPendingWrite()); |
84 ASSERT_TRUE(file_util::PathExists(writer.path())); | 82 ASSERT_TRUE(file_util::PathExists(writer.path())); |
85 EXPECT_EQ("foo", GetFileContent(writer.path())); | 83 EXPECT_EQ("foo", GetFileContent(writer.path())); |
86 } | 84 } |
87 | 85 |
88 TEST_F(ImportantFileWriterTest, DoScheduledWrite) { | 86 TEST_F(ImportantFileWriterTest, DoScheduledWrite) { |
89 ImportantFileWriter writer(file_, | 87 ImportantFileWriter writer(file_, |
90 base::MessageLoopProxy::current()); | 88 base::MessageLoopProxy::current()); |
91 EXPECT_FALSE(writer.HasPendingWrite()); | 89 EXPECT_FALSE(writer.HasPendingWrite()); |
92 DataSerializer serializer("foo"); | 90 DataSerializer serializer("foo"); |
93 writer.ScheduleWrite(&serializer); | 91 writer.ScheduleWrite(&serializer); |
94 EXPECT_TRUE(writer.HasPendingWrite()); | 92 EXPECT_TRUE(writer.HasPendingWrite()); |
95 writer.DoScheduledWrite(); | 93 writer.DoScheduledWrite(); |
96 MessageLoop::current()->PostDelayedTask( | 94 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
97 FROM_HERE, | 95 MessageLoop::QuitClosure(), 100); |
98 MessageLoop::QuitClosure(), | |
99 base::TimeDelta::FromMilliseconds(100)); | |
100 MessageLoop::current()->Run(); | 96 MessageLoop::current()->Run(); |
101 EXPECT_FALSE(writer.HasPendingWrite()); | 97 EXPECT_FALSE(writer.HasPendingWrite()); |
102 ASSERT_TRUE(file_util::PathExists(writer.path())); | 98 ASSERT_TRUE(file_util::PathExists(writer.path())); |
103 EXPECT_EQ("foo", GetFileContent(writer.path())); | 99 EXPECT_EQ("foo", GetFileContent(writer.path())); |
104 } | 100 } |
105 | 101 |
106 // Flaky - http://crbug.com/109292 | 102 // Flaky - http://crbug.com/109292 |
107 TEST_F(ImportantFileWriterTest, FLAKY_BatchingWrites) { | 103 TEST_F(ImportantFileWriterTest, FLAKY_BatchingWrites) { |
108 ImportantFileWriter writer(file_, | 104 ImportantFileWriter writer(file_, |
109 base::MessageLoopProxy::current()); | 105 base::MessageLoopProxy::current()); |
110 writer.set_commit_interval(base::TimeDelta::FromMilliseconds(25)); | 106 writer.set_commit_interval(base::TimeDelta::FromMilliseconds(25)); |
111 DataSerializer foo("foo"), bar("bar"), baz("baz"); | 107 DataSerializer foo("foo"), bar("bar"), baz("baz"); |
112 writer.ScheduleWrite(&foo); | 108 writer.ScheduleWrite(&foo); |
113 writer.ScheduleWrite(&bar); | 109 writer.ScheduleWrite(&bar); |
114 writer.ScheduleWrite(&baz); | 110 writer.ScheduleWrite(&baz); |
115 MessageLoop::current()->PostDelayedTask( | 111 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
116 FROM_HERE, | 112 MessageLoop::QuitClosure(), 100); |
117 MessageLoop::QuitClosure(), | |
118 base::TimeDelta::FromMilliseconds(100)); | |
119 MessageLoop::current()->Run(); | 113 MessageLoop::current()->Run(); |
120 ASSERT_TRUE(file_util::PathExists(writer.path())); | 114 ASSERT_TRUE(file_util::PathExists(writer.path())); |
121 EXPECT_EQ("baz", GetFileContent(writer.path())); | 115 EXPECT_EQ("baz", GetFileContent(writer.path())); |
122 } | 116 } |
OLD | NEW |