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

Side by Side Diff: chrome/common/important_file_writer_unittest.cc

Issue 7583053: Add MessageLoopProxy::current (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: No need for MessageLoopProxy destruction observer. Created 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/weak_handle.cc ('k') | chrome/common/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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 protected: 51 protected:
52 FilePath file_; 52 FilePath file_;
53 MessageLoop loop_; 53 MessageLoop loop_;
54 54
55 private: 55 private:
56 ScopedTempDir temp_dir_; 56 ScopedTempDir temp_dir_;
57 }; 57 };
58 58
59 TEST_F(ImportantFileWriterTest, Basic) { 59 TEST_F(ImportantFileWriterTest, Basic) {
60 ImportantFileWriter writer(file_, 60 ImportantFileWriter writer(file_,
61 base::MessageLoopProxy::CreateForCurrentThread()); 61 base::MessageLoopProxy::current());
62 EXPECT_FALSE(file_util::PathExists(writer.path())); 62 EXPECT_FALSE(file_util::PathExists(writer.path()));
63 writer.WriteNow("foo"); 63 writer.WriteNow("foo");
64 loop_.RunAllPending(); 64 loop_.RunAllPending();
65 65
66 ASSERT_TRUE(file_util::PathExists(writer.path())); 66 ASSERT_TRUE(file_util::PathExists(writer.path()));
67 EXPECT_EQ("foo", GetFileContent(writer.path())); 67 EXPECT_EQ("foo", GetFileContent(writer.path()));
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::CreateForCurrentThread()); 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(FROM_HERE,
79 new MessageLoop::QuitTask(), 100); 79 new MessageLoop::QuitTask(), 100);
80 MessageLoop::current()->Run(); 80 MessageLoop::current()->Run();
81 EXPECT_FALSE(writer.HasPendingWrite()); 81 EXPECT_FALSE(writer.HasPendingWrite());
82 ASSERT_TRUE(file_util::PathExists(writer.path())); 82 ASSERT_TRUE(file_util::PathExists(writer.path()));
83 EXPECT_EQ("foo", GetFileContent(writer.path())); 83 EXPECT_EQ("foo", GetFileContent(writer.path()));
84 } 84 }
85 85
86 TEST_F(ImportantFileWriterTest, DoScheduledWrite) { 86 TEST_F(ImportantFileWriterTest, DoScheduledWrite) {
87 ImportantFileWriter writer(file_, 87 ImportantFileWriter writer(file_,
88 base::MessageLoopProxy::CreateForCurrentThread()); 88 base::MessageLoopProxy::current());
89 EXPECT_FALSE(writer.HasPendingWrite()); 89 EXPECT_FALSE(writer.HasPendingWrite());
90 DataSerializer serializer("foo"); 90 DataSerializer serializer("foo");
91 writer.ScheduleWrite(&serializer); 91 writer.ScheduleWrite(&serializer);
92 EXPECT_TRUE(writer.HasPendingWrite()); 92 EXPECT_TRUE(writer.HasPendingWrite());
93 writer.DoScheduledWrite(); 93 writer.DoScheduledWrite();
94 MessageLoop::current()->PostDelayedTask(FROM_HERE, 94 MessageLoop::current()->PostDelayedTask(FROM_HERE,
95 new MessageLoop::QuitTask(), 100); 95 new MessageLoop::QuitTask(), 100);
96 MessageLoop::current()->Run(); 96 MessageLoop::current()->Run();
97 EXPECT_FALSE(writer.HasPendingWrite()); 97 EXPECT_FALSE(writer.HasPendingWrite());
98 ASSERT_TRUE(file_util::PathExists(writer.path())); 98 ASSERT_TRUE(file_util::PathExists(writer.path()));
99 EXPECT_EQ("foo", GetFileContent(writer.path())); 99 EXPECT_EQ("foo", GetFileContent(writer.path()));
100 } 100 }
101 101
102 TEST_F(ImportantFileWriterTest, BatchingWrites) { 102 TEST_F(ImportantFileWriterTest, BatchingWrites) {
103 ImportantFileWriter writer(file_, 103 ImportantFileWriter writer(file_,
104 base::MessageLoopProxy::CreateForCurrentThread()); 104 base::MessageLoopProxy::current());
105 writer.set_commit_interval(base::TimeDelta::FromMilliseconds(25)); 105 writer.set_commit_interval(base::TimeDelta::FromMilliseconds(25));
106 DataSerializer foo("foo"), bar("bar"), baz("baz"); 106 DataSerializer foo("foo"), bar("bar"), baz("baz");
107 writer.ScheduleWrite(&foo); 107 writer.ScheduleWrite(&foo);
108 writer.ScheduleWrite(&bar); 108 writer.ScheduleWrite(&bar);
109 writer.ScheduleWrite(&baz); 109 writer.ScheduleWrite(&baz);
110 MessageLoop::current()->PostDelayedTask(FROM_HERE, 110 MessageLoop::current()->PostDelayedTask(FROM_HERE,
111 new MessageLoop::QuitTask(), 100); 111 new MessageLoop::QuitTask(), 100);
112 MessageLoop::current()->Run(); 112 MessageLoop::current()->Run();
113 ASSERT_TRUE(file_util::PathExists(writer.path())); 113 ASSERT_TRUE(file_util::PathExists(writer.path()));
114 EXPECT_EQ("baz", GetFileContent(writer.path())); 114 EXPECT_EQ("baz", GetFileContent(writer.path()));
115 } 115 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/weak_handle.cc ('k') | chrome/common/json_pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698