OLD | NEW |
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 "ui/events/platform/platform_event_source.h" | 5 #include "ui/events/platform/platform_event_source.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include <memory> |
10 #include <utility> | 11 #include <utility> |
11 | 12 |
12 #include "base/bind.h" | 13 #include "base/bind.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "ui/events/platform/platform_event_dispatcher.h" | 19 #include "ui/events/platform/platform_event_dispatcher.h" |
20 #include "ui/events/platform/platform_event_observer.h" | 20 #include "ui/events/platform/platform_event_observer.h" |
21 #include "ui/events/platform/scoped_event_dispatcher.h" | 21 #include "ui/events/platform/scoped_event_dispatcher.h" |
22 | 22 |
23 namespace ui { | 23 namespace ui { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 scoped_ptr<PlatformEvent> CreatePlatformEvent() { | 27 std::unique_ptr<PlatformEvent> CreatePlatformEvent() { |
28 scoped_ptr<PlatformEvent> event(new PlatformEvent()); | 28 std::unique_ptr<PlatformEvent> event(new PlatformEvent()); |
29 memset(event.get(), 0, sizeof(PlatformEvent)); | 29 memset(event.get(), 0, sizeof(PlatformEvent)); |
30 return event; | 30 return event; |
31 } | 31 } |
32 | 32 |
33 template <typename T> | 33 template <typename T> |
34 void DestroyScopedPtr(scoped_ptr<T> object) {} | 34 void DestroyScopedPtr(std::unique_ptr<T> object) {} |
35 | 35 |
36 void RemoveDispatcher(PlatformEventDispatcher* dispatcher) { | 36 void RemoveDispatcher(PlatformEventDispatcher* dispatcher) { |
37 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(dispatcher); | 37 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(dispatcher); |
38 } | 38 } |
39 | 39 |
40 void RemoveDispatchers(PlatformEventDispatcher* first, | 40 void RemoveDispatchers(PlatformEventDispatcher* first, |
41 PlatformEventDispatcher* second) { | 41 PlatformEventDispatcher* second) { |
42 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(first); | 42 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(first); |
43 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(second); | 43 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(second); |
44 } | 44 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 PlatformEventTest() {} | 141 PlatformEventTest() {} |
142 ~PlatformEventTest() override {} | 142 ~PlatformEventTest() override {} |
143 | 143 |
144 TestPlatformEventSource* source() { return source_.get(); } | 144 TestPlatformEventSource* source() { return source_.get(); } |
145 | 145 |
146 protected: | 146 protected: |
147 // testing::Test: | 147 // testing::Test: |
148 void SetUp() override { source_.reset(new TestPlatformEventSource()); } | 148 void SetUp() override { source_.reset(new TestPlatformEventSource()); } |
149 | 149 |
150 private: | 150 private: |
151 scoped_ptr<TestPlatformEventSource> source_; | 151 std::unique_ptr<TestPlatformEventSource> source_; |
152 | 152 |
153 DISALLOW_COPY_AND_ASSIGN(PlatformEventTest); | 153 DISALLOW_COPY_AND_ASSIGN(PlatformEventTest); |
154 }; | 154 }; |
155 | 155 |
156 // Tests that a dispatcher receives an event. | 156 // Tests that a dispatcher receives an event. |
157 TEST_F(PlatformEventTest, DispatcherBasic) { | 157 TEST_F(PlatformEventTest, DispatcherBasic) { |
158 std::vector<int> list_dispatcher; | 158 std::vector<int> list_dispatcher; |
159 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 159 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
160 source()->Dispatch(*event); | 160 source()->Dispatch(*event); |
161 EXPECT_EQ(0u, list_dispatcher.size()); | 161 EXPECT_EQ(0u, list_dispatcher.size()); |
162 { | 162 { |
163 TestPlatformEventDispatcher dispatcher(1, &list_dispatcher); | 163 TestPlatformEventDispatcher dispatcher(1, &list_dispatcher); |
164 | 164 |
165 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 165 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
166 source()->Dispatch(*event); | 166 source()->Dispatch(*event); |
167 ASSERT_EQ(1u, list_dispatcher.size()); | 167 ASSERT_EQ(1u, list_dispatcher.size()); |
168 EXPECT_EQ(1, list_dispatcher[0]); | 168 EXPECT_EQ(1, list_dispatcher[0]); |
169 } | 169 } |
170 | 170 |
171 list_dispatcher.clear(); | 171 list_dispatcher.clear(); |
172 event = CreatePlatformEvent(); | 172 event = CreatePlatformEvent(); |
173 source()->Dispatch(*event); | 173 source()->Dispatch(*event); |
174 EXPECT_EQ(0u, list_dispatcher.size()); | 174 EXPECT_EQ(0u, list_dispatcher.size()); |
175 } | 175 } |
176 | 176 |
177 // Tests that dispatchers receive events in the correct order. | 177 // Tests that dispatchers receive events in the correct order. |
178 TEST_F(PlatformEventTest, DispatcherOrder) { | 178 TEST_F(PlatformEventTest, DispatcherOrder) { |
179 std::vector<int> list_dispatcher; | 179 std::vector<int> list_dispatcher; |
180 int sequence[] = {21, 3, 6, 45}; | 180 int sequence[] = {21, 3, 6, 45}; |
181 ScopedVector<TestPlatformEventDispatcher> dispatchers; | 181 ScopedVector<TestPlatformEventDispatcher> dispatchers; |
182 for (size_t i = 0; i < arraysize(sequence); ++i) { | 182 for (size_t i = 0; i < arraysize(sequence); ++i) { |
183 dispatchers.push_back( | 183 dispatchers.push_back( |
184 new TestPlatformEventDispatcher(sequence[i], &list_dispatcher)); | 184 new TestPlatformEventDispatcher(sequence[i], &list_dispatcher)); |
185 } | 185 } |
186 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 186 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
187 source()->Dispatch(*event); | 187 source()->Dispatch(*event); |
188 ASSERT_EQ(arraysize(sequence), list_dispatcher.size()); | 188 ASSERT_EQ(arraysize(sequence), list_dispatcher.size()); |
189 EXPECT_EQ(std::vector<int>(sequence, sequence + arraysize(sequence)), | 189 EXPECT_EQ(std::vector<int>(sequence, sequence + arraysize(sequence)), |
190 list_dispatcher); | 190 list_dispatcher); |
191 } | 191 } |
192 | 192 |
193 // Tests that if a dispatcher consumes the event, the subsequent dispatchers do | 193 // Tests that if a dispatcher consumes the event, the subsequent dispatchers do |
194 // not receive the event. | 194 // not receive the event. |
195 TEST_F(PlatformEventTest, DispatcherConsumesEventToStopDispatch) { | 195 TEST_F(PlatformEventTest, DispatcherConsumesEventToStopDispatch) { |
196 std::vector<int> list_dispatcher; | 196 std::vector<int> list_dispatcher; |
197 TestPlatformEventDispatcher first(12, &list_dispatcher); | 197 TestPlatformEventDispatcher first(12, &list_dispatcher); |
198 TestPlatformEventDispatcher second(23, &list_dispatcher); | 198 TestPlatformEventDispatcher second(23, &list_dispatcher); |
199 | 199 |
200 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 200 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
201 source()->Dispatch(*event); | 201 source()->Dispatch(*event); |
202 ASSERT_EQ(2u, list_dispatcher.size()); | 202 ASSERT_EQ(2u, list_dispatcher.size()); |
203 EXPECT_EQ(12, list_dispatcher[0]); | 203 EXPECT_EQ(12, list_dispatcher[0]); |
204 EXPECT_EQ(23, list_dispatcher[1]); | 204 EXPECT_EQ(23, list_dispatcher[1]); |
205 list_dispatcher.clear(); | 205 list_dispatcher.clear(); |
206 | 206 |
207 first.set_post_dispatch_action(POST_DISPATCH_STOP_PROPAGATION); | 207 first.set_post_dispatch_action(POST_DISPATCH_STOP_PROPAGATION); |
208 event = CreatePlatformEvent(); | 208 event = CreatePlatformEvent(); |
209 source()->Dispatch(*event); | 209 source()->Dispatch(*event); |
210 ASSERT_EQ(1u, list_dispatcher.size()); | 210 ASSERT_EQ(1u, list_dispatcher.size()); |
211 EXPECT_EQ(12, list_dispatcher[0]); | 211 EXPECT_EQ(12, list_dispatcher[0]); |
212 } | 212 } |
213 | 213 |
214 // Tests that observers receive events. | 214 // Tests that observers receive events. |
215 TEST_F(PlatformEventTest, ObserverBasic) { | 215 TEST_F(PlatformEventTest, ObserverBasic) { |
216 std::vector<int> list_observer; | 216 std::vector<int> list_observer; |
217 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 217 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
218 source()->Dispatch(*event); | 218 source()->Dispatch(*event); |
219 EXPECT_EQ(0u, list_observer.size()); | 219 EXPECT_EQ(0u, list_observer.size()); |
220 { | 220 { |
221 TestPlatformEventObserver observer(31, &list_observer); | 221 TestPlatformEventObserver observer(31, &list_observer); |
222 | 222 |
223 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 223 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
224 source()->Dispatch(*event); | 224 source()->Dispatch(*event); |
225 ASSERT_EQ(1u, list_observer.size()); | 225 ASSERT_EQ(1u, list_observer.size()); |
226 EXPECT_EQ(31, list_observer[0]); | 226 EXPECT_EQ(31, list_observer[0]); |
227 } | 227 } |
228 | 228 |
229 list_observer.clear(); | 229 list_observer.clear(); |
230 event = CreatePlatformEvent(); | 230 event = CreatePlatformEvent(); |
231 source()->Dispatch(*event); | 231 source()->Dispatch(*event); |
232 EXPECT_EQ(0u, list_observer.size()); | 232 EXPECT_EQ(0u, list_observer.size()); |
233 } | 233 } |
234 | 234 |
235 // Tests that observers receive events in the correct order. | 235 // Tests that observers receive events in the correct order. |
236 TEST_F(PlatformEventTest, ObserverOrder) { | 236 TEST_F(PlatformEventTest, ObserverOrder) { |
237 std::vector<int> list_observer; | 237 std::vector<int> list_observer; |
238 const int sequence[] = {21, 3, 6, 45}; | 238 const int sequence[] = {21, 3, 6, 45}; |
239 ScopedVector<TestPlatformEventObserver> observers; | 239 ScopedVector<TestPlatformEventObserver> observers; |
240 for (size_t i = 0; i < arraysize(sequence); ++i) { | 240 for (size_t i = 0; i < arraysize(sequence); ++i) { |
241 observers.push_back( | 241 observers.push_back( |
242 new TestPlatformEventObserver(sequence[i], &list_observer)); | 242 new TestPlatformEventObserver(sequence[i], &list_observer)); |
243 } | 243 } |
244 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 244 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
245 source()->Dispatch(*event); | 245 source()->Dispatch(*event); |
246 ASSERT_EQ(arraysize(sequence), list_observer.size()); | 246 ASSERT_EQ(arraysize(sequence), list_observer.size()); |
247 EXPECT_EQ(std::vector<int>(sequence, sequence + arraysize(sequence)), | 247 EXPECT_EQ(std::vector<int>(sequence, sequence + arraysize(sequence)), |
248 list_observer); | 248 list_observer); |
249 } | 249 } |
250 | 250 |
251 // Tests that observers and dispatchers receive events in the correct order. | 251 // Tests that observers and dispatchers receive events in the correct order. |
252 TEST_F(PlatformEventTest, DispatcherAndObserverOrder) { | 252 TEST_F(PlatformEventTest, DispatcherAndObserverOrder) { |
253 std::vector<int> list; | 253 std::vector<int> list; |
254 TestPlatformEventDispatcher first_d(12, &list); | 254 TestPlatformEventDispatcher first_d(12, &list); |
255 TestPlatformEventObserver first_o(10, &list); | 255 TestPlatformEventObserver first_o(10, &list); |
256 TestPlatformEventDispatcher second_d(23, &list); | 256 TestPlatformEventDispatcher second_d(23, &list); |
257 TestPlatformEventObserver second_o(20, &list); | 257 TestPlatformEventObserver second_o(20, &list); |
258 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 258 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
259 source()->Dispatch(*event); | 259 source()->Dispatch(*event); |
260 const int expected[] = {10, 20, 12, 23}; | 260 const int expected[] = {10, 20, 12, 23}; |
261 EXPECT_EQ(std::vector<int>(expected, expected + arraysize(expected)), list); | 261 EXPECT_EQ(std::vector<int>(expected, expected + arraysize(expected)), list); |
262 } | 262 } |
263 | 263 |
264 // Tests that an overridden dispatcher receives events before the default | 264 // Tests that an overridden dispatcher receives events before the default |
265 // dispatchers. | 265 // dispatchers. |
266 TEST_F(PlatformEventTest, OverriddenDispatcherBasic) { | 266 TEST_F(PlatformEventTest, OverriddenDispatcherBasic) { |
267 std::vector<int> list; | 267 std::vector<int> list; |
268 TestPlatformEventDispatcher dispatcher(10, &list); | 268 TestPlatformEventDispatcher dispatcher(10, &list); |
269 TestPlatformEventObserver observer(15, &list); | 269 TestPlatformEventObserver observer(15, &list); |
270 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 270 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
271 source()->Dispatch(*event); | 271 source()->Dispatch(*event); |
272 ASSERT_EQ(2u, list.size()); | 272 ASSERT_EQ(2u, list.size()); |
273 EXPECT_EQ(15, list[0]); | 273 EXPECT_EQ(15, list[0]); |
274 EXPECT_EQ(10, list[1]); | 274 EXPECT_EQ(10, list[1]); |
275 list.clear(); | 275 list.clear(); |
276 | 276 |
277 TestPlatformEventDispatcher overriding_dispatcher(20, &list); | 277 TestPlatformEventDispatcher overriding_dispatcher(20, &list); |
278 source()->RemovePlatformEventDispatcher(&overriding_dispatcher); | 278 source()->RemovePlatformEventDispatcher(&overriding_dispatcher); |
279 scoped_ptr<ScopedEventDispatcher> handle = | 279 std::unique_ptr<ScopedEventDispatcher> handle = |
280 source()->OverrideDispatcher(&overriding_dispatcher); | 280 source()->OverrideDispatcher(&overriding_dispatcher); |
281 source()->Dispatch(*event); | 281 source()->Dispatch(*event); |
282 ASSERT_EQ(2u, list.size()); | 282 ASSERT_EQ(2u, list.size()); |
283 EXPECT_EQ(15, list[0]); | 283 EXPECT_EQ(15, list[0]); |
284 EXPECT_EQ(20, list[1]); | 284 EXPECT_EQ(20, list[1]); |
285 } | 285 } |
286 | 286 |
287 // Tests that an overridden dispatcher can request that the default dispatchers | 287 // Tests that an overridden dispatcher can request that the default dispatchers |
288 // can dispatch the events. | 288 // can dispatch the events. |
289 TEST_F(PlatformEventTest, OverriddenDispatcherInvokeDefaultDispatcher) { | 289 TEST_F(PlatformEventTest, OverriddenDispatcherInvokeDefaultDispatcher) { |
290 std::vector<int> list; | 290 std::vector<int> list; |
291 TestPlatformEventDispatcher dispatcher(10, &list); | 291 TestPlatformEventDispatcher dispatcher(10, &list); |
292 TestPlatformEventObserver observer(15, &list); | 292 TestPlatformEventObserver observer(15, &list); |
293 TestPlatformEventDispatcher overriding_dispatcher(20, &list); | 293 TestPlatformEventDispatcher overriding_dispatcher(20, &list); |
294 source()->RemovePlatformEventDispatcher(&overriding_dispatcher); | 294 source()->RemovePlatformEventDispatcher(&overriding_dispatcher); |
295 scoped_ptr<ScopedEventDispatcher> handle = | 295 std::unique_ptr<ScopedEventDispatcher> handle = |
296 source()->OverrideDispatcher(&overriding_dispatcher); | 296 source()->OverrideDispatcher(&overriding_dispatcher); |
297 overriding_dispatcher.set_post_dispatch_action(POST_DISPATCH_PERFORM_DEFAULT); | 297 overriding_dispatcher.set_post_dispatch_action(POST_DISPATCH_PERFORM_DEFAULT); |
298 | 298 |
299 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 299 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
300 source()->Dispatch(*event); | 300 source()->Dispatch(*event); |
301 // First the observer, then the overriding dispatcher, then the default | 301 // First the observer, then the overriding dispatcher, then the default |
302 // dispatcher. | 302 // dispatcher. |
303 ASSERT_EQ(3u, list.size()); | 303 ASSERT_EQ(3u, list.size()); |
304 EXPECT_EQ(15, list[0]); | 304 EXPECT_EQ(15, list[0]); |
305 EXPECT_EQ(20, list[1]); | 305 EXPECT_EQ(20, list[1]); |
306 EXPECT_EQ(10, list[2]); | 306 EXPECT_EQ(10, list[2]); |
307 list.clear(); | 307 list.clear(); |
308 | 308 |
309 // Install a second overriding dispatcher. | 309 // Install a second overriding dispatcher. |
310 TestPlatformEventDispatcher second_overriding(50, &list); | 310 TestPlatformEventDispatcher second_overriding(50, &list); |
311 source()->RemovePlatformEventDispatcher(&second_overriding); | 311 source()->RemovePlatformEventDispatcher(&second_overriding); |
312 scoped_ptr<ScopedEventDispatcher> second_override_handle = | 312 std::unique_ptr<ScopedEventDispatcher> second_override_handle = |
313 source()->OverrideDispatcher(&second_overriding); | 313 source()->OverrideDispatcher(&second_overriding); |
314 source()->Dispatch(*event); | 314 source()->Dispatch(*event); |
315 ASSERT_EQ(2u, list.size()); | 315 ASSERT_EQ(2u, list.size()); |
316 EXPECT_EQ(15, list[0]); | 316 EXPECT_EQ(15, list[0]); |
317 EXPECT_EQ(50, list[1]); | 317 EXPECT_EQ(50, list[1]); |
318 list.clear(); | 318 list.clear(); |
319 | 319 |
320 second_overriding.set_post_dispatch_action(POST_DISPATCH_PERFORM_DEFAULT); | 320 second_overriding.set_post_dispatch_action(POST_DISPATCH_PERFORM_DEFAULT); |
321 source()->Dispatch(*event); | 321 source()->Dispatch(*event); |
322 // First the observer, then the second overriding dispatcher, then the default | 322 // First the observer, then the second overriding dispatcher, then the default |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 // continues correctly. | 357 // continues correctly. |
358 TEST_F(PlatformEventTest, DispatcherRemovesNextDispatcherDuringDispatch) { | 358 TEST_F(PlatformEventTest, DispatcherRemovesNextDispatcherDuringDispatch) { |
359 std::vector<int> list; | 359 std::vector<int> list; |
360 TestPlatformEventDispatcher first(10, &list); | 360 TestPlatformEventDispatcher first(10, &list); |
361 RunCallbackDuringDispatch second(15, &list); | 361 RunCallbackDuringDispatch second(15, &list); |
362 TestPlatformEventDispatcher third(20, &list); | 362 TestPlatformEventDispatcher third(20, &list); |
363 TestPlatformEventDispatcher fourth(30, &list); | 363 TestPlatformEventDispatcher fourth(30, &list); |
364 | 364 |
365 second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&third))); | 365 second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&third))); |
366 | 366 |
367 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 367 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
368 source()->Dispatch(*event); | 368 source()->Dispatch(*event); |
369 // |second| removes |third| from the dispatcher list during dispatch. So the | 369 // |second| removes |third| from the dispatcher list during dispatch. So the |
370 // event should only reach |first|, |second|, and |fourth|. | 370 // event should only reach |first|, |second|, and |fourth|. |
371 ASSERT_EQ(3u, list.size()); | 371 ASSERT_EQ(3u, list.size()); |
372 EXPECT_EQ(10, list[0]); | 372 EXPECT_EQ(10, list[0]); |
373 EXPECT_EQ(15, list[1]); | 373 EXPECT_EQ(15, list[1]); |
374 EXPECT_EQ(30, list[2]); | 374 EXPECT_EQ(30, list[2]); |
375 } | 375 } |
376 | 376 |
377 // Tests that if a dispatcher removes itself from the dispatcher list during | 377 // Tests that if a dispatcher removes itself from the dispatcher list during |
378 // dispatching an event, then event dispatching continues correctly. | 378 // dispatching an event, then event dispatching continues correctly. |
379 TEST_F(PlatformEventTest, DispatcherRemovesSelfDuringDispatch) { | 379 TEST_F(PlatformEventTest, DispatcherRemovesSelfDuringDispatch) { |
380 std::vector<int> list; | 380 std::vector<int> list; |
381 TestPlatformEventDispatcher first(10, &list); | 381 TestPlatformEventDispatcher first(10, &list); |
382 RunCallbackDuringDispatch second(15, &list); | 382 RunCallbackDuringDispatch second(15, &list); |
383 TestPlatformEventDispatcher third(20, &list); | 383 TestPlatformEventDispatcher third(20, &list); |
384 | 384 |
385 second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&second))); | 385 second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&second))); |
386 | 386 |
387 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 387 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
388 source()->Dispatch(*event); | 388 source()->Dispatch(*event); |
389 // |second| removes itself from the dispatcher list during dispatch. So the | 389 // |second| removes itself from the dispatcher list during dispatch. So the |
390 // event should reach all three dispatchers in the list. | 390 // event should reach all three dispatchers in the list. |
391 ASSERT_EQ(3u, list.size()); | 391 ASSERT_EQ(3u, list.size()); |
392 EXPECT_EQ(10, list[0]); | 392 EXPECT_EQ(10, list[0]); |
393 EXPECT_EQ(15, list[1]); | 393 EXPECT_EQ(15, list[1]); |
394 EXPECT_EQ(20, list[2]); | 394 EXPECT_EQ(20, list[2]); |
395 } | 395 } |
396 | 396 |
397 // Tests that if a dispatcher removes itself from the dispatcher list during | 397 // Tests that if a dispatcher removes itself from the dispatcher list during |
398 // dispatching an event, and this dispatcher is last in the dispatcher-list, | 398 // dispatching an event, and this dispatcher is last in the dispatcher-list, |
399 // then event dispatching ends correctly. | 399 // then event dispatching ends correctly. |
400 TEST_F(PlatformEventTest, DispatcherRemovesSelfDuringDispatchLast) { | 400 TEST_F(PlatformEventTest, DispatcherRemovesSelfDuringDispatchLast) { |
401 std::vector<int> list; | 401 std::vector<int> list; |
402 TestPlatformEventDispatcher first(10, &list); | 402 TestPlatformEventDispatcher first(10, &list); |
403 RunCallbackDuringDispatch second(15, &list); | 403 RunCallbackDuringDispatch second(15, &list); |
404 | 404 |
405 second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&second))); | 405 second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&second))); |
406 | 406 |
407 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 407 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
408 source()->Dispatch(*event); | 408 source()->Dispatch(*event); |
409 // |second| removes itself during dispatch. So both dispatchers will have | 409 // |second| removes itself during dispatch. So both dispatchers will have |
410 // received the event. | 410 // received the event. |
411 ASSERT_EQ(2u, list.size()); | 411 ASSERT_EQ(2u, list.size()); |
412 EXPECT_EQ(10, list[0]); | 412 EXPECT_EQ(10, list[0]); |
413 EXPECT_EQ(15, list[1]); | 413 EXPECT_EQ(15, list[1]); |
414 } | 414 } |
415 | 415 |
416 // Tests that if a dispatcher removes a single dispatcher that comes before it | 416 // Tests that if a dispatcher removes a single dispatcher that comes before it |
417 // in the dispatcher list, then dispatch continues correctly. | 417 // in the dispatcher list, then dispatch continues correctly. |
418 TEST_F(PlatformEventTest, DispatcherRemovesPrevDispatcherDuringDispatch) { | 418 TEST_F(PlatformEventTest, DispatcherRemovesPrevDispatcherDuringDispatch) { |
419 std::vector<int> list; | 419 std::vector<int> list; |
420 TestPlatformEventDispatcher first(10, &list); | 420 TestPlatformEventDispatcher first(10, &list); |
421 RunCallbackDuringDispatch second(15, &list); | 421 RunCallbackDuringDispatch second(15, &list); |
422 TestPlatformEventDispatcher third(20, &list); | 422 TestPlatformEventDispatcher third(20, &list); |
423 | 423 |
424 second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&first))); | 424 second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&first))); |
425 | 425 |
426 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 426 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
427 source()->Dispatch(*event); | 427 source()->Dispatch(*event); |
428 // |second| removes |first| from the dispatcher list during dispatch. The | 428 // |second| removes |first| from the dispatcher list during dispatch. The |
429 // event should reach all three dispatchers. | 429 // event should reach all three dispatchers. |
430 ASSERT_EQ(3u, list.size()); | 430 ASSERT_EQ(3u, list.size()); |
431 EXPECT_EQ(10, list[0]); | 431 EXPECT_EQ(10, list[0]); |
432 EXPECT_EQ(15, list[1]); | 432 EXPECT_EQ(15, list[1]); |
433 EXPECT_EQ(20, list[2]); | 433 EXPECT_EQ(20, list[2]); |
434 } | 434 } |
435 | 435 |
436 // Tests that if a dispatcher removes multiple dispatchers that comes before it | 436 // Tests that if a dispatcher removes multiple dispatchers that comes before it |
437 // in the dispatcher list, then dispatch continues correctly. | 437 // in the dispatcher list, then dispatch continues correctly. |
438 TEST_F(PlatformEventTest, DispatcherRemovesPrevDispatchersDuringDispatch) { | 438 TEST_F(PlatformEventTest, DispatcherRemovesPrevDispatchersDuringDispatch) { |
439 std::vector<int> list; | 439 std::vector<int> list; |
440 TestPlatformEventDispatcher first(10, &list); | 440 TestPlatformEventDispatcher first(10, &list); |
441 TestPlatformEventDispatcher second(12, &list); | 441 TestPlatformEventDispatcher second(12, &list); |
442 RunCallbackDuringDispatch third(15, &list); | 442 RunCallbackDuringDispatch third(15, &list); |
443 TestPlatformEventDispatcher fourth(20, &list); | 443 TestPlatformEventDispatcher fourth(20, &list); |
444 | 444 |
445 third.set_callback(base::Bind(&RemoveDispatchers, | 445 third.set_callback(base::Bind(&RemoveDispatchers, |
446 base::Unretained(&first), | 446 base::Unretained(&first), |
447 base::Unretained(&second))); | 447 base::Unretained(&second))); |
448 | 448 |
449 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 449 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
450 source()->Dispatch(*event); | 450 source()->Dispatch(*event); |
451 // |third| removes |first| and |second| from the dispatcher list during | 451 // |third| removes |first| and |second| from the dispatcher list during |
452 // dispatch. The event should reach all three dispatchers. | 452 // dispatch. The event should reach all three dispatchers. |
453 ASSERT_EQ(4u, list.size()); | 453 ASSERT_EQ(4u, list.size()); |
454 EXPECT_EQ(10, list[0]); | 454 EXPECT_EQ(10, list[0]); |
455 EXPECT_EQ(12, list[1]); | 455 EXPECT_EQ(12, list[1]); |
456 EXPECT_EQ(15, list[2]); | 456 EXPECT_EQ(15, list[2]); |
457 EXPECT_EQ(20, list[3]); | 457 EXPECT_EQ(20, list[3]); |
458 } | 458 } |
459 | 459 |
460 // Tests that adding a dispatcher during dispatching an event receives that | 460 // Tests that adding a dispatcher during dispatching an event receives that |
461 // event. | 461 // event. |
462 TEST_F(PlatformEventTest, DispatcherAddedDuringDispatchReceivesEvent) { | 462 TEST_F(PlatformEventTest, DispatcherAddedDuringDispatchReceivesEvent) { |
463 std::vector<int> list; | 463 std::vector<int> list; |
464 TestPlatformEventDispatcher first(10, &list); | 464 TestPlatformEventDispatcher first(10, &list); |
465 RunCallbackDuringDispatch second(15, &list); | 465 RunCallbackDuringDispatch second(15, &list); |
466 TestPlatformEventDispatcher third(20, &list); | 466 TestPlatformEventDispatcher third(20, &list); |
467 TestPlatformEventDispatcher fourth(30, &list); | 467 TestPlatformEventDispatcher fourth(30, &list); |
468 RemoveDispatchers(&third, &fourth); | 468 RemoveDispatchers(&third, &fourth); |
469 | 469 |
470 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 470 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
471 source()->Dispatch(*event); | 471 source()->Dispatch(*event); |
472 ASSERT_EQ(2u, list.size()); | 472 ASSERT_EQ(2u, list.size()); |
473 EXPECT_EQ(10, list[0]); | 473 EXPECT_EQ(10, list[0]); |
474 EXPECT_EQ(15, list[1]); | 474 EXPECT_EQ(15, list[1]); |
475 | 475 |
476 second.set_callback(base::Bind(&AddDispatcher, base::Unretained(&third))); | 476 second.set_callback(base::Bind(&AddDispatcher, base::Unretained(&third))); |
477 list.clear(); | 477 list.clear(); |
478 source()->Dispatch(*event); | 478 source()->Dispatch(*event); |
479 ASSERT_EQ(3u, list.size()); | 479 ASSERT_EQ(3u, list.size()); |
480 EXPECT_EQ(10, list[0]); | 480 EXPECT_EQ(10, list[0]); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 : public PlatformEventTestWithMessageLoop { | 528 : public PlatformEventTestWithMessageLoop { |
529 public: | 529 public: |
530 // PlatformEventTestWithMessageLoop: | 530 // PlatformEventTestWithMessageLoop: |
531 void RunTestImpl() override { | 531 void RunTestImpl() override { |
532 std::vector<int> list; | 532 std::vector<int> list; |
533 TestPlatformEventDispatcher dispatcher(10, &list); | 533 TestPlatformEventDispatcher dispatcher(10, &list); |
534 TestPlatformEventObserver observer(15, &list); | 534 TestPlatformEventObserver observer(15, &list); |
535 | 535 |
536 TestPlatformEventDispatcher first_overriding(20, &list); | 536 TestPlatformEventDispatcher first_overriding(20, &list); |
537 source()->RemovePlatformEventDispatcher(&first_overriding); | 537 source()->RemovePlatformEventDispatcher(&first_overriding); |
538 scoped_ptr<ScopedEventDispatcher> first_override_handle = | 538 std::unique_ptr<ScopedEventDispatcher> first_override_handle = |
539 source()->OverrideDispatcher(&first_overriding); | 539 source()->OverrideDispatcher(&first_overriding); |
540 | 540 |
541 // Install a second overriding dispatcher. | 541 // Install a second overriding dispatcher. |
542 TestPlatformEventDispatcher second_overriding(50, &list); | 542 TestPlatformEventDispatcher second_overriding(50, &list); |
543 source()->RemovePlatformEventDispatcher(&second_overriding); | 543 source()->RemovePlatformEventDispatcher(&second_overriding); |
544 scoped_ptr<ScopedEventDispatcher> second_override_handle = | 544 std::unique_ptr<ScopedEventDispatcher> second_override_handle = |
545 source()->OverrideDispatcher(&second_overriding); | 545 source()->OverrideDispatcher(&second_overriding); |
546 | 546 |
547 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 547 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
548 source()->Dispatch(*event); | 548 source()->Dispatch(*event); |
549 ASSERT_EQ(2u, list.size()); | 549 ASSERT_EQ(2u, list.size()); |
550 EXPECT_EQ(15, list[0]); | 550 EXPECT_EQ(15, list[0]); |
551 EXPECT_EQ(50, list[1]); | 551 EXPECT_EQ(50, list[1]); |
552 list.clear(); | 552 list.clear(); |
553 | 553 |
554 second_override_handle.reset(); | 554 second_override_handle.reset(); |
555 source()->Dispatch(*event); | 555 source()->Dispatch(*event); |
556 ASSERT_EQ(2u, list.size()); | 556 ASSERT_EQ(2u, list.size()); |
557 EXPECT_EQ(15, list[0]); | 557 EXPECT_EQ(15, list[0]); |
558 EXPECT_EQ(20, list[1]); | 558 EXPECT_EQ(20, list[1]); |
559 } | 559 } |
560 }; | 560 }; |
561 | 561 |
562 RUN_TEST_IN_MESSAGE_LOOP(ScopedDispatcherRestoresAfterDestroy) | 562 RUN_TEST_IN_MESSAGE_LOOP(ScopedDispatcherRestoresAfterDestroy) |
563 | 563 |
564 // This dispatcher destroys the handle to the ScopedEventDispatcher when | 564 // This dispatcher destroys the handle to the ScopedEventDispatcher when |
565 // dispatching an event. | 565 // dispatching an event. |
566 class DestroyScopedHandleDispatcher : public TestPlatformEventDispatcher { | 566 class DestroyScopedHandleDispatcher : public TestPlatformEventDispatcher { |
567 public: | 567 public: |
568 DestroyScopedHandleDispatcher(int id, std::vector<int>* list) | 568 DestroyScopedHandleDispatcher(int id, std::vector<int>* list) |
569 : TestPlatformEventDispatcher(id, list) {} | 569 : TestPlatformEventDispatcher(id, list) {} |
570 ~DestroyScopedHandleDispatcher() override {} | 570 ~DestroyScopedHandleDispatcher() override {} |
571 | 571 |
572 void SetScopedHandle(scoped_ptr<ScopedEventDispatcher> handler) { | 572 void SetScopedHandle(std::unique_ptr<ScopedEventDispatcher> handler) { |
573 handler_ = std::move(handler); | 573 handler_ = std::move(handler); |
574 } | 574 } |
575 | 575 |
576 void set_callback(const base::Closure& callback) { | 576 void set_callback(const base::Closure& callback) { |
577 callback_ = callback; | 577 callback_ = callback; |
578 } | 578 } |
579 | 579 |
580 private: | 580 private: |
581 // PlatformEventDispatcher: | 581 // PlatformEventDispatcher: |
582 bool CanDispatchEvent(const PlatformEvent& event) override { return true; } | 582 bool CanDispatchEvent(const PlatformEvent& event) override { return true; } |
583 | 583 |
584 uint32_t DispatchEvent(const PlatformEvent& event) override { | 584 uint32_t DispatchEvent(const PlatformEvent& event) override { |
585 handler_.reset(); | 585 handler_.reset(); |
586 uint32_t action = TestPlatformEventDispatcher::DispatchEvent(event); | 586 uint32_t action = TestPlatformEventDispatcher::DispatchEvent(event); |
587 if (!callback_.is_null()) { | 587 if (!callback_.is_null()) { |
588 callback_.Run(); | 588 callback_.Run(); |
589 callback_ = base::Closure(); | 589 callback_ = base::Closure(); |
590 } | 590 } |
591 return action; | 591 return action; |
592 } | 592 } |
593 | 593 |
594 scoped_ptr<ScopedEventDispatcher> handler_; | 594 std::unique_ptr<ScopedEventDispatcher> handler_; |
595 base::Closure callback_; | 595 base::Closure callback_; |
596 | 596 |
597 DISALLOW_COPY_AND_ASSIGN(DestroyScopedHandleDispatcher); | 597 DISALLOW_COPY_AND_ASSIGN(DestroyScopedHandleDispatcher); |
598 }; | 598 }; |
599 | 599 |
600 // Tests that resetting an overridden dispatcher causes the nested message-loop | 600 // Tests that resetting an overridden dispatcher causes the nested message-loop |
601 // iteration to stop and the rest of the events are dispatched in the next | 601 // iteration to stop and the rest of the events are dispatched in the next |
602 // iteration. | 602 // iteration. |
603 class DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration | 603 class DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration |
604 : public PlatformEventTestWithMessageLoop { | 604 : public PlatformEventTestWithMessageLoop { |
605 public: | 605 public: |
606 void NestedTask(std::vector<int>* list, | 606 void NestedTask(std::vector<int>* list, |
607 TestPlatformEventDispatcher* dispatcher) { | 607 TestPlatformEventDispatcher* dispatcher) { |
608 ScopedVector<PlatformEvent> events; | 608 ScopedVector<PlatformEvent> events; |
609 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 609 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
610 events.push_back(std::move(event)); | 610 events.push_back(std::move(event)); |
611 event = CreatePlatformEvent(); | 611 event = CreatePlatformEvent(); |
612 events.push_back(std::move(event)); | 612 events.push_back(std::move(event)); |
613 | 613 |
614 // Attempt to dispatch a couple of events. Dispatching the first event will | 614 // Attempt to dispatch a couple of events. Dispatching the first event will |
615 // have terminated the ScopedEventDispatcher object, which will terminate | 615 // have terminated the ScopedEventDispatcher object, which will terminate |
616 // the current iteration of the message-loop. | 616 // the current iteration of the message-loop. |
617 size_t count = source()->DispatchEventStream(events); | 617 size_t count = source()->DispatchEventStream(events); |
618 EXPECT_EQ(1u, count); | 618 EXPECT_EQ(1u, count); |
619 ASSERT_EQ(2u, list->size()); | 619 ASSERT_EQ(2u, list->size()); |
(...skipping 16 matching lines...) Expand all Loading... |
636 } | 636 } |
637 | 637 |
638 // PlatformEventTestWithMessageLoop: | 638 // PlatformEventTestWithMessageLoop: |
639 void RunTestImpl() override { | 639 void RunTestImpl() override { |
640 std::vector<int> list; | 640 std::vector<int> list; |
641 TestPlatformEventDispatcher dispatcher(10, &list); | 641 TestPlatformEventDispatcher dispatcher(10, &list); |
642 TestPlatformEventObserver observer(15, &list); | 642 TestPlatformEventObserver observer(15, &list); |
643 | 643 |
644 DestroyScopedHandleDispatcher overriding(20, &list); | 644 DestroyScopedHandleDispatcher overriding(20, &list); |
645 source()->RemovePlatformEventDispatcher(&overriding); | 645 source()->RemovePlatformEventDispatcher(&overriding); |
646 scoped_ptr<ScopedEventDispatcher> override_handle = | 646 std::unique_ptr<ScopedEventDispatcher> override_handle = |
647 source()->OverrideDispatcher(&overriding); | 647 source()->OverrideDispatcher(&overriding); |
648 | 648 |
649 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 649 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
650 source()->Dispatch(*event); | 650 source()->Dispatch(*event); |
651 ASSERT_EQ(2u, list.size()); | 651 ASSERT_EQ(2u, list.size()); |
652 EXPECT_EQ(15, list[0]); | 652 EXPECT_EQ(15, list[0]); |
653 EXPECT_EQ(20, list[1]); | 653 EXPECT_EQ(20, list[1]); |
654 list.clear(); | 654 list.clear(); |
655 | 655 |
656 overriding.SetScopedHandle(std::move(override_handle)); | 656 overriding.SetScopedHandle(std::move(override_handle)); |
657 base::RunLoop run_loop; | 657 base::RunLoop run_loop; |
658 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | 658 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
659 base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop); | 659 base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop); |
(...skipping 17 matching lines...) Expand all Loading... |
677 | 677 |
678 RUN_TEST_IN_MESSAGE_LOOP( | 678 RUN_TEST_IN_MESSAGE_LOOP( |
679 DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration) | 679 DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration) |
680 | 680 |
681 // Tests that resetting an overridden dispatcher, and installing another | 681 // Tests that resetting an overridden dispatcher, and installing another |
682 // overridden dispatcher before the nested message-loop completely unwinds | 682 // overridden dispatcher before the nested message-loop completely unwinds |
683 // function correctly. | 683 // function correctly. |
684 class ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration | 684 class ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration |
685 : public PlatformEventTestWithMessageLoop { | 685 : public PlatformEventTestWithMessageLoop { |
686 public: | 686 public: |
687 void NestedTask(scoped_ptr<ScopedEventDispatcher> dispatch_handle, | 687 void NestedTask(std::unique_ptr<ScopedEventDispatcher> dispatch_handle, |
688 std::vector<int>* list) { | 688 std::vector<int>* list) { |
689 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 689 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
690 source()->Dispatch(*event); | 690 source()->Dispatch(*event); |
691 ASSERT_EQ(2u, list->size()); | 691 ASSERT_EQ(2u, list->size()); |
692 EXPECT_EQ(15, (*list)[0]); | 692 EXPECT_EQ(15, (*list)[0]); |
693 EXPECT_EQ(20, (*list)[1]); | 693 EXPECT_EQ(20, (*list)[1]); |
694 list->clear(); | 694 list->clear(); |
695 | 695 |
696 // Reset the override dispatcher. This should restore the default | 696 // Reset the override dispatcher. This should restore the default |
697 // dispatcher. | 697 // dispatcher. |
698 dispatch_handle.reset(); | 698 dispatch_handle.reset(); |
699 source()->Dispatch(*event); | 699 source()->Dispatch(*event); |
700 ASSERT_EQ(2u, list->size()); | 700 ASSERT_EQ(2u, list->size()); |
701 EXPECT_EQ(15, (*list)[0]); | 701 EXPECT_EQ(15, (*list)[0]); |
702 EXPECT_EQ(10, (*list)[1]); | 702 EXPECT_EQ(10, (*list)[1]); |
703 list->clear(); | 703 list->clear(); |
704 | 704 |
705 // Install another override-dispatcher. | 705 // Install another override-dispatcher. |
706 DestroyScopedHandleDispatcher second_overriding(70, list); | 706 DestroyScopedHandleDispatcher second_overriding(70, list); |
707 source()->RemovePlatformEventDispatcher(&second_overriding); | 707 source()->RemovePlatformEventDispatcher(&second_overriding); |
708 scoped_ptr<ScopedEventDispatcher> second_override_handle = | 708 std::unique_ptr<ScopedEventDispatcher> second_override_handle = |
709 source()->OverrideDispatcher(&second_overriding); | 709 source()->OverrideDispatcher(&second_overriding); |
710 | 710 |
711 source()->Dispatch(*event); | 711 source()->Dispatch(*event); |
712 ASSERT_EQ(2u, list->size()); | 712 ASSERT_EQ(2u, list->size()); |
713 EXPECT_EQ(15, (*list)[0]); | 713 EXPECT_EQ(15, (*list)[0]); |
714 EXPECT_EQ(70, (*list)[1]); | 714 EXPECT_EQ(70, (*list)[1]); |
715 list->clear(); | 715 list->clear(); |
716 | 716 |
717 second_overriding.SetScopedHandle(std::move(second_override_handle)); | 717 second_overriding.SetScopedHandle(std::move(second_override_handle)); |
718 second_overriding.set_post_dispatch_action(POST_DISPATCH_NONE); | 718 second_overriding.set_post_dispatch_action(POST_DISPATCH_NONE); |
(...skipping 17 matching lines...) Expand all Loading... |
736 } | 736 } |
737 | 737 |
738 // PlatformEventTestWithMessageLoop: | 738 // PlatformEventTestWithMessageLoop: |
739 void RunTestImpl() override { | 739 void RunTestImpl() override { |
740 std::vector<int> list; | 740 std::vector<int> list; |
741 TestPlatformEventDispatcher dispatcher(10, &list); | 741 TestPlatformEventDispatcher dispatcher(10, &list); |
742 TestPlatformEventObserver observer(15, &list); | 742 TestPlatformEventObserver observer(15, &list); |
743 | 743 |
744 TestPlatformEventDispatcher overriding(20, &list); | 744 TestPlatformEventDispatcher overriding(20, &list); |
745 source()->RemovePlatformEventDispatcher(&overriding); | 745 source()->RemovePlatformEventDispatcher(&overriding); |
746 scoped_ptr<ScopedEventDispatcher> override_handle = | 746 std::unique_ptr<ScopedEventDispatcher> override_handle = |
747 source()->OverrideDispatcher(&overriding); | 747 source()->OverrideDispatcher(&overriding); |
748 | 748 |
749 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); | 749 std::unique_ptr<PlatformEvent> event(CreatePlatformEvent()); |
750 source()->Dispatch(*event); | 750 source()->Dispatch(*event); |
751 ASSERT_EQ(2u, list.size()); | 751 ASSERT_EQ(2u, list.size()); |
752 EXPECT_EQ(15, list[0]); | 752 EXPECT_EQ(15, list[0]); |
753 EXPECT_EQ(20, list[1]); | 753 EXPECT_EQ(20, list[1]); |
754 list.clear(); | 754 list.clear(); |
755 | 755 |
756 // Start a nested message-loop, and destroy |override_handle| in the nested | 756 // Start a nested message-loop, and destroy |override_handle| in the nested |
757 // loop. That should terminate the nested loop, restore the previous | 757 // loop. That should terminate the nested loop, restore the previous |
758 // dispatchers, and return control to this function. | 758 // dispatchers, and return control to this function. |
759 base::RunLoop run_loop; | 759 base::RunLoop run_loop; |
(...skipping 14 matching lines...) Expand all Loading... |
774 ASSERT_EQ(2u, list.size()); | 774 ASSERT_EQ(2u, list.size()); |
775 EXPECT_EQ(15, list[0]); | 775 EXPECT_EQ(15, list[0]); |
776 EXPECT_EQ(10, list[1]); | 776 EXPECT_EQ(10, list[1]); |
777 } | 777 } |
778 }; | 778 }; |
779 | 779 |
780 RUN_TEST_IN_MESSAGE_LOOP( | 780 RUN_TEST_IN_MESSAGE_LOOP( |
781 ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration) | 781 ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration) |
782 | 782 |
783 } // namespace ui | 783 } // namespace ui |
OLD | NEW |