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

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

Issue 502203003: Remove implicit conversions from scoped_refptr to T* in cc/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change to use .get() instead of rewriting local variable Created 6 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
« no previous file with comments | « no previous file | cc/debug/frame_viewer_instrumentation.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 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 52
53 protected: 53 protected:
54 int notification_count_; 54 int notification_count_;
55 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 55 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
56 }; 56 };
57 57
58 TEST_F(DelayedUniqueNotifierTest, ZeroDelay) { 58 TEST_F(DelayedUniqueNotifierTest, ZeroDelay) {
59 base::TimeDelta delay = base::TimeDelta::FromInternalValue(0); 59 base::TimeDelta delay = base::TimeDelta::FromInternalValue(0);
60 TestNotifier notifier( 60 TestNotifier notifier(
61 task_runner_, 61 task_runner_.get(),
62 base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)), 62 base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)),
63 delay); 63 delay);
64 64
65 EXPECT_EQ(0, NotificationCount()); 65 EXPECT_EQ(0, NotificationCount());
66 66
67 // Basic schedule for |delay| from now. 67 // Basic schedule for |delay| from now.
68 base::TimeTicks schedule_time = 68 base::TimeTicks schedule_time =
69 base::TimeTicks() + base::TimeDelta::FromInternalValue(10); 69 base::TimeTicks() + base::TimeDelta::FromInternalValue(10);
70 70
71 notifier.SetNow(schedule_time); 71 notifier.SetNow(schedule_time);
(...skipping 14 matching lines...) Expand all
86 ASSERT_EQ(1u, tasks.size()); 86 ASSERT_EQ(1u, tasks.size());
87 EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun()); 87 EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun());
88 88
89 tasks[0].task.Run(); 89 tasks[0].task.Run();
90 EXPECT_EQ(2, NotificationCount()); 90 EXPECT_EQ(2, NotificationCount());
91 } 91 }
92 92
93 TEST_F(DelayedUniqueNotifierTest, SmallDelay) { 93 TEST_F(DelayedUniqueNotifierTest, SmallDelay) {
94 base::TimeDelta delay = base::TimeDelta::FromInternalValue(20); 94 base::TimeDelta delay = base::TimeDelta::FromInternalValue(20);
95 TestNotifier notifier( 95 TestNotifier notifier(
96 task_runner_, 96 task_runner_.get(),
97 base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)), 97 base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)),
98 delay); 98 delay);
99 99
100 EXPECT_EQ(0, NotificationCount()); 100 EXPECT_EQ(0, NotificationCount());
101 101
102 // Basic schedule for |delay| from now (now: 30, run time: 50). 102 // Basic schedule for |delay| from now (now: 30, run time: 50).
103 base::TimeTicks schedule_time = 103 base::TimeTicks schedule_time =
104 base::TimeTicks() + base::TimeDelta::FromInternalValue(30); 104 base::TimeTicks() + base::TimeDelta::FromInternalValue(30);
105 105
106 notifier.SetNow(schedule_time); 106 notifier.SetNow(schedule_time);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 tasks[0].task.Run(); 146 tasks[0].task.Run();
147 EXPECT_EQ(1, NotificationCount()); 147 EXPECT_EQ(1, NotificationCount());
148 148
149 tasks = TakePendingTasks(); 149 tasks = TakePendingTasks();
150 EXPECT_EQ(0u, tasks.size()); 150 EXPECT_EQ(0u, tasks.size());
151 } 151 }
152 152
153 TEST_F(DelayedUniqueNotifierTest, RescheduleDelay) { 153 TEST_F(DelayedUniqueNotifierTest, RescheduleDelay) {
154 base::TimeDelta delay = base::TimeDelta::FromInternalValue(20); 154 base::TimeDelta delay = base::TimeDelta::FromInternalValue(20);
155 TestNotifier notifier( 155 TestNotifier notifier(
156 task_runner_, 156 task_runner_.get(),
157 base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)), 157 base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)),
158 delay); 158 delay);
159 159
160 base::TimeTicks schedule_time; 160 base::TimeTicks schedule_time;
161 // Move time 19 units forward and reschedule, expecting that we still need to 161 // Move time 19 units forward and reschedule, expecting that we still need to
162 // run in |delay| time and we don't get a notification. 162 // run in |delay| time and we don't get a notification.
163 for (int i = 0; i < 10; ++i) { 163 for (int i = 0; i < 10; ++i) {
164 EXPECT_EQ(0, NotificationCount()); 164 EXPECT_EQ(0, NotificationCount());
165 165
166 // Move time forward 19 units. 166 // Move time forward 19 units.
(...skipping 21 matching lines...) Expand all
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, CancelAndHasPendingNotification) { 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_.get(),
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();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } // namespace 265 } // namespace
266 } // namespace cc 266 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/debug/frame_viewer_instrumentation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698