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

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

Issue 9233018: Convert use of int ms to TimeDelta in files owned by brettw. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase onto master. Created 8 years, 11 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 | « chrome/browser/web_resource/web_resource_service.cc ('k') | chrome/common/profiling.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 "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
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(FROM_HERE, 78 MessageLoop::current()->PostDelayedTask(
79 MessageLoop::QuitClosure(), 100); 79 FROM_HERE,
80 MessageLoop::QuitClosure(),
81 base::TimeDelta::FromMilliseconds(100));
80 MessageLoop::current()->Run(); 82 MessageLoop::current()->Run();
81 EXPECT_FALSE(writer.HasPendingWrite()); 83 EXPECT_FALSE(writer.HasPendingWrite());
82 ASSERT_TRUE(file_util::PathExists(writer.path())); 84 ASSERT_TRUE(file_util::PathExists(writer.path()));
83 EXPECT_EQ("foo", GetFileContent(writer.path())); 85 EXPECT_EQ("foo", GetFileContent(writer.path()));
84 } 86 }
85 87
86 TEST_F(ImportantFileWriterTest, DoScheduledWrite) { 88 TEST_F(ImportantFileWriterTest, DoScheduledWrite) {
87 ImportantFileWriter writer(file_, 89 ImportantFileWriter writer(file_,
88 base::MessageLoopProxy::current()); 90 base::MessageLoopProxy::current());
89 EXPECT_FALSE(writer.HasPendingWrite()); 91 EXPECT_FALSE(writer.HasPendingWrite());
90 DataSerializer serializer("foo"); 92 DataSerializer serializer("foo");
91 writer.ScheduleWrite(&serializer); 93 writer.ScheduleWrite(&serializer);
92 EXPECT_TRUE(writer.HasPendingWrite()); 94 EXPECT_TRUE(writer.HasPendingWrite());
93 writer.DoScheduledWrite(); 95 writer.DoScheduledWrite();
94 MessageLoop::current()->PostDelayedTask(FROM_HERE, 96 MessageLoop::current()->PostDelayedTask(
95 MessageLoop::QuitClosure(), 100); 97 FROM_HERE,
98 MessageLoop::QuitClosure(),
99 base::TimeDelta::FromMilliseconds(100));
96 MessageLoop::current()->Run(); 100 MessageLoop::current()->Run();
97 EXPECT_FALSE(writer.HasPendingWrite()); 101 EXPECT_FALSE(writer.HasPendingWrite());
98 ASSERT_TRUE(file_util::PathExists(writer.path())); 102 ASSERT_TRUE(file_util::PathExists(writer.path()));
99 EXPECT_EQ("foo", GetFileContent(writer.path())); 103 EXPECT_EQ("foo", GetFileContent(writer.path()));
100 } 104 }
101 105
102 // Flaky - http://crbug.com/109292 106 // Flaky - http://crbug.com/109292
103 TEST_F(ImportantFileWriterTest, FLAKY_BatchingWrites) { 107 TEST_F(ImportantFileWriterTest, FLAKY_BatchingWrites) {
104 ImportantFileWriter writer(file_, 108 ImportantFileWriter writer(file_,
105 base::MessageLoopProxy::current()); 109 base::MessageLoopProxy::current());
106 writer.set_commit_interval(base::TimeDelta::FromMilliseconds(25)); 110 writer.set_commit_interval(base::TimeDelta::FromMilliseconds(25));
107 DataSerializer foo("foo"), bar("bar"), baz("baz"); 111 DataSerializer foo("foo"), bar("bar"), baz("baz");
108 writer.ScheduleWrite(&foo); 112 writer.ScheduleWrite(&foo);
109 writer.ScheduleWrite(&bar); 113 writer.ScheduleWrite(&bar);
110 writer.ScheduleWrite(&baz); 114 writer.ScheduleWrite(&baz);
111 MessageLoop::current()->PostDelayedTask(FROM_HERE, 115 MessageLoop::current()->PostDelayedTask(
112 MessageLoop::QuitClosure(), 100); 116 FROM_HERE,
117 MessageLoop::QuitClosure(),
118 base::TimeDelta::FromMilliseconds(100));
113 MessageLoop::current()->Run(); 119 MessageLoop::current()->Run();
114 ASSERT_TRUE(file_util::PathExists(writer.path())); 120 ASSERT_TRUE(file_util::PathExists(writer.path()));
115 EXPECT_EQ("baz", GetFileContent(writer.path())); 121 EXPECT_EQ("baz", GetFileContent(writer.path()));
116 } 122 }
OLDNEW
« no previous file with comments | « chrome/browser/web_resource/web_resource_service.cc ('k') | chrome/common/profiling.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698