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

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

Issue 11275088: Remove implicit scoped_refptr operator T* Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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 | « no previous file | base/memory/ref_counted.h » ('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_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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 protected: 53 protected:
54 FilePath file_; 54 FilePath file_;
55 MessageLoop loop_; 55 MessageLoop loop_;
56 56
57 private: 57 private:
58 ScopedTempDir temp_dir_; 58 ScopedTempDir temp_dir_;
59 }; 59 };
60 60
61 TEST_F(ImportantFileWriterTest, Basic) { 61 TEST_F(ImportantFileWriterTest, Basic) {
62 ImportantFileWriter writer(file_, 62 ImportantFileWriter writer(file_,
63 MessageLoopProxy::current()); 63 MessageLoopProxy::current().get());
64 EXPECT_FALSE(file_util::PathExists(writer.path())); 64 EXPECT_FALSE(file_util::PathExists(writer.path()));
65 writer.WriteNow("foo"); 65 writer.WriteNow("foo");
66 loop_.RunUntilIdle(); 66 loop_.RunUntilIdle();
67 67
68 ASSERT_TRUE(file_util::PathExists(writer.path())); 68 ASSERT_TRUE(file_util::PathExists(writer.path()));
69 EXPECT_EQ("foo", GetFileContent(writer.path())); 69 EXPECT_EQ("foo", GetFileContent(writer.path()));
70 } 70 }
71 71
72 TEST_F(ImportantFileWriterTest, ScheduleWrite) { 72 TEST_F(ImportantFileWriterTest, ScheduleWrite) {
73 ImportantFileWriter writer(file_, 73 ImportantFileWriter writer(file_,
74 MessageLoopProxy::current()); 74 MessageLoopProxy::current().get());
75 writer.set_commit_interval(TimeDelta::FromMilliseconds(25)); 75 writer.set_commit_interval(TimeDelta::FromMilliseconds(25));
76 EXPECT_FALSE(writer.HasPendingWrite()); 76 EXPECT_FALSE(writer.HasPendingWrite());
77 DataSerializer serializer("foo"); 77 DataSerializer serializer("foo");
78 writer.ScheduleWrite(&serializer); 78 writer.ScheduleWrite(&serializer);
79 EXPECT_TRUE(writer.HasPendingWrite()); 79 EXPECT_TRUE(writer.HasPendingWrite());
80 MessageLoop::current()->PostDelayedTask( 80 MessageLoop::current()->PostDelayedTask(
81 FROM_HERE, 81 FROM_HERE,
82 MessageLoop::QuitClosure(), 82 MessageLoop::QuitClosure(),
83 TimeDelta::FromMilliseconds(100)); 83 TimeDelta::FromMilliseconds(100));
84 MessageLoop::current()->Run(); 84 MessageLoop::current()->Run();
85 EXPECT_FALSE(writer.HasPendingWrite()); 85 EXPECT_FALSE(writer.HasPendingWrite());
86 ASSERT_TRUE(file_util::PathExists(writer.path())); 86 ASSERT_TRUE(file_util::PathExists(writer.path()));
87 EXPECT_EQ("foo", GetFileContent(writer.path())); 87 EXPECT_EQ("foo", GetFileContent(writer.path()));
88 } 88 }
89 89
90 TEST_F(ImportantFileWriterTest, DoScheduledWrite) { 90 TEST_F(ImportantFileWriterTest, DoScheduledWrite) {
91 ImportantFileWriter writer(file_, 91 ImportantFileWriter writer(file_,
92 MessageLoopProxy::current()); 92 MessageLoopProxy::current().get());
93 EXPECT_FALSE(writer.HasPendingWrite()); 93 EXPECT_FALSE(writer.HasPendingWrite());
94 DataSerializer serializer("foo"); 94 DataSerializer serializer("foo");
95 writer.ScheduleWrite(&serializer); 95 writer.ScheduleWrite(&serializer);
96 EXPECT_TRUE(writer.HasPendingWrite()); 96 EXPECT_TRUE(writer.HasPendingWrite());
97 writer.DoScheduledWrite(); 97 writer.DoScheduledWrite();
98 MessageLoop::current()->PostDelayedTask( 98 MessageLoop::current()->PostDelayedTask(
99 FROM_HERE, 99 FROM_HERE,
100 MessageLoop::QuitClosure(), 100 MessageLoop::QuitClosure(),
101 TimeDelta::FromMilliseconds(100)); 101 TimeDelta::FromMilliseconds(100));
102 MessageLoop::current()->Run(); 102 MessageLoop::current()->Run();
103 EXPECT_FALSE(writer.HasPendingWrite()); 103 EXPECT_FALSE(writer.HasPendingWrite());
104 ASSERT_TRUE(file_util::PathExists(writer.path())); 104 ASSERT_TRUE(file_util::PathExists(writer.path()));
105 EXPECT_EQ("foo", GetFileContent(writer.path())); 105 EXPECT_EQ("foo", GetFileContent(writer.path()));
106 } 106 }
107 107
108 // Flaky - http://crbug.com/109292 108 // Flaky - http://crbug.com/109292
109 TEST_F(ImportantFileWriterTest, DISABLED_BatchingWrites) { 109 TEST_F(ImportantFileWriterTest, DISABLED_BatchingWrites) {
110 ImportantFileWriter writer(file_, 110 ImportantFileWriter writer(file_,
111 MessageLoopProxy::current()); 111 MessageLoopProxy::current().get());
112 writer.set_commit_interval(TimeDelta::FromMilliseconds(25)); 112 writer.set_commit_interval(TimeDelta::FromMilliseconds(25));
113 DataSerializer foo("foo"), bar("bar"), baz("baz"); 113 DataSerializer foo("foo"), bar("bar"), baz("baz");
114 writer.ScheduleWrite(&foo); 114 writer.ScheduleWrite(&foo);
115 writer.ScheduleWrite(&bar); 115 writer.ScheduleWrite(&bar);
116 writer.ScheduleWrite(&baz); 116 writer.ScheduleWrite(&baz);
117 MessageLoop::current()->PostDelayedTask( 117 MessageLoop::current()->PostDelayedTask(
118 FROM_HERE, 118 FROM_HERE,
119 MessageLoop::QuitClosure(), 119 MessageLoop::QuitClosure(),
120 TimeDelta::FromMilliseconds(100)); 120 TimeDelta::FromMilliseconds(100));
121 MessageLoop::current()->Run(); 121 MessageLoop::current()->Run();
122 ASSERT_TRUE(file_util::PathExists(writer.path())); 122 ASSERT_TRUE(file_util::PathExists(writer.path()));
123 EXPECT_EQ("baz", GetFileContent(writer.path())); 123 EXPECT_EQ("baz", GetFileContent(writer.path()));
124 } 124 }
125 125
126 } // namespace base 126 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/memory/ref_counted.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698