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

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

Issue 15984016: Call scoped_refptr<T>::get() rather than relying on implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « base/files/file_path_watcher_linux.cc ('k') | base/prefs/json_pref_store_unittest.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/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 protected: 54 protected:
55 FilePath file_; 55 FilePath file_;
56 MessageLoop loop_; 56 MessageLoop loop_;
57 57
58 private: 58 private:
59 ScopedTempDir temp_dir_; 59 ScopedTempDir temp_dir_;
60 }; 60 };
61 61
62 TEST_F(ImportantFileWriterTest, Basic) { 62 TEST_F(ImportantFileWriterTest, Basic) {
63 ImportantFileWriter writer(file_, 63 ImportantFileWriter writer(file_, MessageLoopProxy::current().get());
64 MessageLoopProxy::current());
65 EXPECT_FALSE(file_util::PathExists(writer.path())); 64 EXPECT_FALSE(file_util::PathExists(writer.path()));
66 writer.WriteNow("foo"); 65 writer.WriteNow("foo");
67 RunLoop().RunUntilIdle(); 66 RunLoop().RunUntilIdle();
68 67
69 ASSERT_TRUE(file_util::PathExists(writer.path())); 68 ASSERT_TRUE(file_util::PathExists(writer.path()));
70 EXPECT_EQ("foo", GetFileContent(writer.path())); 69 EXPECT_EQ("foo", GetFileContent(writer.path()));
71 } 70 }
72 71
73 TEST_F(ImportantFileWriterTest, ScheduleWrite) { 72 TEST_F(ImportantFileWriterTest, ScheduleWrite) {
74 ImportantFileWriter writer(file_, 73 ImportantFileWriter writer(file_, MessageLoopProxy::current().get());
75 MessageLoopProxy::current());
76 writer.set_commit_interval(TimeDelta::FromMilliseconds(25)); 74 writer.set_commit_interval(TimeDelta::FromMilliseconds(25));
77 EXPECT_FALSE(writer.HasPendingWrite()); 75 EXPECT_FALSE(writer.HasPendingWrite());
78 DataSerializer serializer("foo"); 76 DataSerializer serializer("foo");
79 writer.ScheduleWrite(&serializer); 77 writer.ScheduleWrite(&serializer);
80 EXPECT_TRUE(writer.HasPendingWrite()); 78 EXPECT_TRUE(writer.HasPendingWrite());
81 MessageLoop::current()->PostDelayedTask( 79 MessageLoop::current()->PostDelayedTask(
82 FROM_HERE, 80 FROM_HERE,
83 MessageLoop::QuitWhenIdleClosure(), 81 MessageLoop::QuitWhenIdleClosure(),
84 TimeDelta::FromMilliseconds(100)); 82 TimeDelta::FromMilliseconds(100));
85 MessageLoop::current()->Run(); 83 MessageLoop::current()->Run();
86 EXPECT_FALSE(writer.HasPendingWrite()); 84 EXPECT_FALSE(writer.HasPendingWrite());
87 ASSERT_TRUE(file_util::PathExists(writer.path())); 85 ASSERT_TRUE(file_util::PathExists(writer.path()));
88 EXPECT_EQ("foo", GetFileContent(writer.path())); 86 EXPECT_EQ("foo", GetFileContent(writer.path()));
89 } 87 }
90 88
91 TEST_F(ImportantFileWriterTest, DoScheduledWrite) { 89 TEST_F(ImportantFileWriterTest, DoScheduledWrite) {
92 ImportantFileWriter writer(file_, 90 ImportantFileWriter writer(file_, MessageLoopProxy::current().get());
93 MessageLoopProxy::current());
94 EXPECT_FALSE(writer.HasPendingWrite()); 91 EXPECT_FALSE(writer.HasPendingWrite());
95 DataSerializer serializer("foo"); 92 DataSerializer serializer("foo");
96 writer.ScheduleWrite(&serializer); 93 writer.ScheduleWrite(&serializer);
97 EXPECT_TRUE(writer.HasPendingWrite()); 94 EXPECT_TRUE(writer.HasPendingWrite());
98 writer.DoScheduledWrite(); 95 writer.DoScheduledWrite();
99 MessageLoop::current()->PostDelayedTask( 96 MessageLoop::current()->PostDelayedTask(
100 FROM_HERE, 97 FROM_HERE,
101 MessageLoop::QuitWhenIdleClosure(), 98 MessageLoop::QuitWhenIdleClosure(),
102 TimeDelta::FromMilliseconds(100)); 99 TimeDelta::FromMilliseconds(100));
103 MessageLoop::current()->Run(); 100 MessageLoop::current()->Run();
104 EXPECT_FALSE(writer.HasPendingWrite()); 101 EXPECT_FALSE(writer.HasPendingWrite());
105 ASSERT_TRUE(file_util::PathExists(writer.path())); 102 ASSERT_TRUE(file_util::PathExists(writer.path()));
106 EXPECT_EQ("foo", GetFileContent(writer.path())); 103 EXPECT_EQ("foo", GetFileContent(writer.path()));
107 } 104 }
108 105
109 TEST_F(ImportantFileWriterTest, BatchingWrites) { 106 TEST_F(ImportantFileWriterTest, BatchingWrites) {
110 ImportantFileWriter writer(file_, 107 ImportantFileWriter writer(file_, MessageLoopProxy::current().get());
111 MessageLoopProxy::current());
112 writer.set_commit_interval(TimeDelta::FromMilliseconds(25)); 108 writer.set_commit_interval(TimeDelta::FromMilliseconds(25));
113 DataSerializer foo("foo"), bar("bar"), baz("baz"); 109 DataSerializer foo("foo"), bar("bar"), baz("baz");
114 writer.ScheduleWrite(&foo); 110 writer.ScheduleWrite(&foo);
115 writer.ScheduleWrite(&bar); 111 writer.ScheduleWrite(&bar);
116 writer.ScheduleWrite(&baz); 112 writer.ScheduleWrite(&baz);
117 MessageLoop::current()->PostDelayedTask( 113 MessageLoop::current()->PostDelayedTask(
118 FROM_HERE, 114 FROM_HERE,
119 MessageLoop::QuitWhenIdleClosure(), 115 MessageLoop::QuitWhenIdleClosure(),
120 TimeDelta::FromMilliseconds(100)); 116 TimeDelta::FromMilliseconds(100));
121 MessageLoop::current()->Run(); 117 MessageLoop::current()->Run();
122 ASSERT_TRUE(file_util::PathExists(writer.path())); 118 ASSERT_TRUE(file_util::PathExists(writer.path()));
123 EXPECT_EQ("baz", GetFileContent(writer.path())); 119 EXPECT_EQ("baz", GetFileContent(writer.path()));
124 } 120 }
125 121
126 } // namespace base 122 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_path_watcher_linux.cc ('k') | base/prefs/json_pref_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698