OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/message_pump_glib.h" | 5 #include "base/message_pump_glib.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 #include <math.h> | 8 #include <math.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 EXPECT_EQ(12, injector()->processed_events()); | 289 EXPECT_EQ(12, injector()->processed_events()); |
290 } | 290 } |
291 | 291 |
292 namespace { | 292 namespace { |
293 | 293 |
294 // This class is a helper for the concurrent events / posted tasks test below. | 294 // This class is a helper for the concurrent events / posted tasks test below. |
295 // It will quit the main loop once enough tasks and events have been processed, | 295 // It will quit the main loop once enough tasks and events have been processed, |
296 // while making sure there is always work to do and events in the queue. | 296 // while making sure there is always work to do and events in the queue. |
297 class ConcurrentHelper : public base::RefCounted<ConcurrentHelper> { | 297 class ConcurrentHelper : public base::RefCounted<ConcurrentHelper> { |
298 public: | 298 public: |
299 ConcurrentHelper(EventInjector* injector) | 299 explicit ConcurrentHelper(EventInjector* injector) |
300 : injector_(injector), | 300 : injector_(injector), |
301 event_count_(kStartingEventCount), | 301 event_count_(kStartingEventCount), |
302 task_count_(kStartingTaskCount) { | 302 task_count_(kStartingTaskCount) { |
303 } | 303 } |
304 | 304 |
305 void FromTask() { | 305 void FromTask() { |
306 if (task_count_ > 0) { | 306 if (task_count_ > 0) { |
307 --task_count_; | 307 --task_count_; |
308 } | 308 } |
309 if (task_count_ == 0 && event_count_ == 0) { | 309 if (task_count_ == 0 && event_count_ == 0) { |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 | 542 |
543 TEST_F(MessagePumpGLibTest, TestGtkLoop) { | 543 TEST_F(MessagePumpGLibTest, TestGtkLoop) { |
544 // Tests that events and posted tasks are correctly exectuted if the message | 544 // Tests that events and posted tasks are correctly exectuted if the message |
545 // loop is not run by MessageLoop::Run() but by a straight Gtk loop. | 545 // loop is not run by MessageLoop::Run() but by a straight Gtk loop. |
546 // Note that in this case we don't make strong guarantees about niceness | 546 // Note that in this case we don't make strong guarantees about niceness |
547 // between events and posted tasks. | 547 // between events and posted tasks. |
548 loop()->PostTask(FROM_HERE, | 548 loop()->PostTask(FROM_HERE, |
549 NewRunnableFunction(TestGtkLoopInternal, injector())); | 549 NewRunnableFunction(TestGtkLoopInternal, injector())); |
550 loop()->Run(); | 550 loop()->Run(); |
551 } | 551 } |
OLD | NEW |