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

Side by Side Diff: cc/base/delayed_unique_notifier_unittest.cc

Issue 302003004: cc: Add HasPendingNotification to delayed unique notifier. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | « cc/base/delayed_unique_notifier.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <deque> 5 #include <deque>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/test/test_pending_task.h" 9 #include "base/test/test_pending_task.h"
10 #include "base/test/test_simple_task_runner.h" 10 #include "base/test/test_simple_task_runner.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 std::deque<base::TestPendingTask> tasks = TakePendingTasks(); 185 std::deque<base::TestPendingTask> tasks = TakePendingTasks();
186 186
187 ASSERT_EQ(1u, tasks.size()); 187 ASSERT_EQ(1u, tasks.size());
188 EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun()); 188 EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun());
189 189
190 // Time to run! 190 // Time to run!
191 tasks[0].task.Run(); 191 tasks[0].task.Run();
192 EXPECT_EQ(1, NotificationCount()); 192 EXPECT_EQ(1, NotificationCount());
193 } 193 }
194 194
195 TEST_F(DelayedUniqueNotifierTest, Cancel) { 195 TEST_F(DelayedUniqueNotifierTest, CancelAndHasPendingNotification) {
196 base::TimeDelta delay = base::TimeDelta::FromInternalValue(20); 196 base::TimeDelta delay = base::TimeDelta::FromInternalValue(20);
197 TestNotifier notifier( 197 TestNotifier notifier(
198 task_runner_, 198 task_runner_,
199 base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)), 199 base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)),
200 delay); 200 delay);
201 201
202 EXPECT_EQ(0, NotificationCount()); 202 EXPECT_EQ(0, NotificationCount());
203 203
204 // Schedule for |delay| seconds from now. 204 // Schedule for |delay| seconds from now.
205 base::TimeTicks schedule_time = 205 base::TimeTicks schedule_time =
206 notifier.Now() + base::TimeDelta::FromInternalValue(10); 206 notifier.Now() + base::TimeDelta::FromInternalValue(10);
207 notifier.SetNow(schedule_time); 207 notifier.SetNow(schedule_time);
208 notifier.Schedule(); 208 notifier.Schedule();
209 EXPECT_TRUE(notifier.HasPendingNotification());
209 210
210 // Cancel the run. 211 // Cancel the run.
211 notifier.Cancel(); 212 notifier.Cancel();
213 EXPECT_FALSE(notifier.HasPendingNotification());
212 214
213 std::deque<base::TestPendingTask> tasks = TakePendingTasks(); 215 std::deque<base::TestPendingTask> tasks = TakePendingTasks();
214 216
215 ASSERT_EQ(1u, tasks.size()); 217 ASSERT_EQ(1u, tasks.size());
216 EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun()); 218 EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun());
217 219
218 // Time to run, but a canceled task! 220 // Time to run, but a canceled task!
219 tasks[0].task.Run(); 221 tasks[0].task.Run();
220 EXPECT_EQ(0, NotificationCount()); 222 EXPECT_EQ(0, NotificationCount());
223 EXPECT_FALSE(notifier.HasPendingNotification());
221 224
222 tasks = TakePendingTasks(); 225 tasks = TakePendingTasks();
223 EXPECT_EQ(0u, tasks.size()); 226 EXPECT_EQ(0u, tasks.size());
224 227
225 notifier.Schedule(); 228 notifier.Schedule();
229 EXPECT_TRUE(notifier.HasPendingNotification());
226 tasks = TakePendingTasks(); 230 tasks = TakePendingTasks();
227 231
228 ASSERT_EQ(1u, tasks.size()); 232 ASSERT_EQ(1u, tasks.size());
229 EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun()); 233 EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun());
230 234
231 // Advance the time. 235 // Advance the time.
232 notifier.SetNow(notifier.Now() + delay); 236 notifier.SetNow(notifier.Now() + delay);
233 237
234 // This should run since it wasn't scheduled. 238 // This should run since it wasn't canceled.
235 tasks[0].task.Run(); 239 tasks[0].task.Run();
236 EXPECT_EQ(1, NotificationCount()); 240 EXPECT_EQ(1, NotificationCount());
241 EXPECT_FALSE(notifier.HasPendingNotification());
237 242
238 for (int i = 0; i < 10; ++i) 243 for (int i = 0; i < 10; ++i) {
239 notifier.Schedule(); 244 notifier.Schedule();
245 EXPECT_TRUE(notifier.HasPendingNotification());
246 notifier.Cancel();
247 EXPECT_FALSE(notifier.HasPendingNotification());
248 }
240 249
241 notifier.Cancel();
242 tasks = TakePendingTasks(); 250 tasks = TakePendingTasks();
243 251
244 ASSERT_EQ(1u, tasks.size()); 252 ASSERT_EQ(1u, tasks.size());
245 EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun()); 253 EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun());
246 254
247 // Time to run, but a canceled task! 255 // Time to run, but a canceled task!
248 notifier.SetNow(notifier.Now() + delay); 256 notifier.SetNow(notifier.Now() + delay);
249 tasks[0].task.Run(); 257 tasks[0].task.Run();
250 EXPECT_EQ(1, NotificationCount()); 258 EXPECT_EQ(1, NotificationCount());
251 259
252 tasks = TakePendingTasks(); 260 tasks = TakePendingTasks();
253 EXPECT_EQ(0u, tasks.size()); 261 EXPECT_EQ(0u, tasks.size());
262 EXPECT_FALSE(notifier.HasPendingNotification());
254 } 263 }
255 264
256 } // namespace 265 } // namespace
257 } // namespace cc 266 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/delayed_unique_notifier.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698