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

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

Issue 683113005: Update from chromium https://crrev.com/302282 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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 | « cc/base/delayed_unique_notifier.cc ('k') | cc/cc_tests.gyp » ('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 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // Time to run, but a canceled task! 255 // Time to run, but a canceled task!
256 notifier.SetNow(notifier.Now() + delay); 256 notifier.SetNow(notifier.Now() + delay);
257 tasks[0].task.Run(); 257 tasks[0].task.Run();
258 EXPECT_EQ(1, NotificationCount()); 258 EXPECT_EQ(1, NotificationCount());
259 259
260 tasks = TakePendingTasks(); 260 tasks = TakePendingTasks();
261 EXPECT_EQ(0u, tasks.size()); 261 EXPECT_EQ(0u, tasks.size());
262 EXPECT_FALSE(notifier.HasPendingNotification()); 262 EXPECT_FALSE(notifier.HasPendingNotification());
263 } 263 }
264 264
265 TEST_F(DelayedUniqueNotifierTest, ShutdownWithScheduledTask) {
266 base::TimeDelta delay = base::TimeDelta::FromInternalValue(20);
267 TestNotifier notifier(
268 task_runner_.get(),
269 base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)),
270 delay);
271
272 EXPECT_EQ(0, NotificationCount());
273
274 // Schedule for |delay| seconds from now.
275 base::TimeTicks schedule_time =
276 notifier.Now() + base::TimeDelta::FromInternalValue(10);
277 notifier.SetNow(schedule_time);
278 notifier.Schedule();
279 EXPECT_TRUE(notifier.HasPendingNotification());
280
281 // Shutdown the notifier.
282 notifier.Shutdown();
283
284 // The task is still there, but...
285 std::deque<base::TestPendingTask> tasks = TakePendingTasks();
286 ASSERT_EQ(1u, tasks.size());
287
288 // Running the task after shutdown does nothing since it's cancelled.
289 tasks[0].task.Run();
290 EXPECT_EQ(0, NotificationCount());
291
292 tasks = TakePendingTasks();
293 EXPECT_EQ(0u, tasks.size());
294
295 // We are no longer able to schedule tasks.
296 notifier.Schedule();
297 tasks = TakePendingTasks();
298 ASSERT_EQ(0u, tasks.size());
299
300 // Verify after the scheduled time happens there is still no task.
301 notifier.SetNow(notifier.Now() + delay);
302 tasks = TakePendingTasks();
303 ASSERT_EQ(0u, tasks.size());
304 }
305
306 TEST_F(DelayedUniqueNotifierTest, ShutdownPreventsSchedule) {
307 base::TimeDelta delay = base::TimeDelta::FromInternalValue(20);
308 TestNotifier notifier(
309 task_runner_.get(),
310 base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)),
311 delay);
312
313 EXPECT_EQ(0, NotificationCount());
314
315 // Schedule for |delay| seconds from now.
316 base::TimeTicks schedule_time =
317 notifier.Now() + base::TimeDelta::FromInternalValue(10);
318 notifier.SetNow(schedule_time);
319
320 // Shutdown the notifier.
321 notifier.Shutdown();
322
323 // Scheduling a task no longer does anything.
324 notifier.Schedule();
325 std::deque<base::TestPendingTask> tasks = TakePendingTasks();
326 ASSERT_EQ(0u, tasks.size());
327
328 // Verify after the scheduled time happens there is still no task.
329 notifier.SetNow(notifier.Now() + delay);
330 tasks = TakePendingTasks();
331 ASSERT_EQ(0u, tasks.size());
332 }
333
265 } // namespace 334 } // namespace
266 } // namespace cc 335 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/delayed_unique_notifier.cc ('k') | cc/cc_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698