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

Side by Side Diff: base/files/important_file_writer_unittest.cc

Issue 1265363002: Cleanup nits in ImportantFileWriter and JsonPrefStore. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review Created 5 years, 4 months 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
« no previous file with comments | « base/files/important_file_writer.cc ('k') | base/prefs/json_pref_store.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 EXPECT_FALSE(successful_write_observer_.GetAndResetObservationState()); 138 EXPECT_FALSE(successful_write_observer_.GetAndResetObservationState());
139 writer.WriteNow(make_scoped_ptr(new std::string("baz"))); 139 writer.WriteNow(make_scoped_ptr(new std::string("baz")));
140 RunLoop().RunUntilIdle(); 140 RunLoop().RunUntilIdle();
141 141
142 EXPECT_FALSE(successful_write_observer_.GetAndResetObservationState()); 142 EXPECT_FALSE(successful_write_observer_.GetAndResetObservationState());
143 ASSERT_TRUE(PathExists(writer.path())); 143 ASSERT_TRUE(PathExists(writer.path()));
144 EXPECT_EQ("baz", GetFileContent(writer.path())); 144 EXPECT_EQ("baz", GetFileContent(writer.path()));
145 } 145 }
146 146
147 TEST_F(ImportantFileWriterTest, ScheduleWrite) { 147 TEST_F(ImportantFileWriterTest, ScheduleWrite) {
148 ImportantFileWriter writer(file_, ThreadTaskRunnerHandle::Get()); 148 ImportantFileWriter writer(file_,
149 writer.set_commit_interval(TimeDelta::FromMilliseconds(25)); 149 ThreadTaskRunnerHandle::Get(),
150 TimeDelta::FromMilliseconds(25));
150 EXPECT_FALSE(writer.HasPendingWrite()); 151 EXPECT_FALSE(writer.HasPendingWrite());
151 DataSerializer serializer("foo"); 152 DataSerializer serializer("foo");
152 writer.ScheduleWrite(&serializer); 153 writer.ScheduleWrite(&serializer);
153 EXPECT_TRUE(writer.HasPendingWrite()); 154 EXPECT_TRUE(writer.HasPendingWrite());
154 ThreadTaskRunnerHandle::Get()->PostDelayedTask( 155 ThreadTaskRunnerHandle::Get()->PostDelayedTask(
155 FROM_HERE, MessageLoop::QuitWhenIdleClosure(), 156 FROM_HERE, MessageLoop::QuitWhenIdleClosure(),
156 TimeDelta::FromMilliseconds(100)); 157 TimeDelta::FromMilliseconds(100));
157 MessageLoop::current()->Run(); 158 MessageLoop::current()->Run();
158 EXPECT_FALSE(writer.HasPendingWrite()); 159 EXPECT_FALSE(writer.HasPendingWrite());
159 ASSERT_TRUE(PathExists(writer.path())); 160 ASSERT_TRUE(PathExists(writer.path()));
(...skipping 10 matching lines...) Expand all
170 ThreadTaskRunnerHandle::Get()->PostDelayedTask( 171 ThreadTaskRunnerHandle::Get()->PostDelayedTask(
171 FROM_HERE, MessageLoop::QuitWhenIdleClosure(), 172 FROM_HERE, MessageLoop::QuitWhenIdleClosure(),
172 TimeDelta::FromMilliseconds(100)); 173 TimeDelta::FromMilliseconds(100));
173 MessageLoop::current()->Run(); 174 MessageLoop::current()->Run();
174 EXPECT_FALSE(writer.HasPendingWrite()); 175 EXPECT_FALSE(writer.HasPendingWrite());
175 ASSERT_TRUE(PathExists(writer.path())); 176 ASSERT_TRUE(PathExists(writer.path()));
176 EXPECT_EQ("foo", GetFileContent(writer.path())); 177 EXPECT_EQ("foo", GetFileContent(writer.path()));
177 } 178 }
178 179
179 TEST_F(ImportantFileWriterTest, BatchingWrites) { 180 TEST_F(ImportantFileWriterTest, BatchingWrites) {
180 ImportantFileWriter writer(file_, ThreadTaskRunnerHandle::Get()); 181 ImportantFileWriter writer(file_,
181 writer.set_commit_interval(TimeDelta::FromMilliseconds(25)); 182 ThreadTaskRunnerHandle::Get(),
183 TimeDelta::FromMilliseconds(25));
182 DataSerializer foo("foo"), bar("bar"), baz("baz"); 184 DataSerializer foo("foo"), bar("bar"), baz("baz");
183 writer.ScheduleWrite(&foo); 185 writer.ScheduleWrite(&foo);
184 writer.ScheduleWrite(&bar); 186 writer.ScheduleWrite(&bar);
185 writer.ScheduleWrite(&baz); 187 writer.ScheduleWrite(&baz);
186 ThreadTaskRunnerHandle::Get()->PostDelayedTask( 188 ThreadTaskRunnerHandle::Get()->PostDelayedTask(
187 FROM_HERE, MessageLoop::QuitWhenIdleClosure(), 189 FROM_HERE, MessageLoop::QuitWhenIdleClosure(),
188 TimeDelta::FromMilliseconds(100)); 190 TimeDelta::FromMilliseconds(100));
189 MessageLoop::current()->Run(); 191 MessageLoop::current()->Run();
190 ASSERT_TRUE(PathExists(writer.path())); 192 ASSERT_TRUE(PathExists(writer.path()));
191 EXPECT_EQ("baz", GetFileContent(writer.path())); 193 EXPECT_EQ("baz", GetFileContent(writer.path()));
192 } 194 }
193 195
194 } // namespace base 196 } // namespace base
OLDNEW
« no previous file with comments | « base/files/important_file_writer.cc ('k') | base/prefs/json_pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698