OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <glib.h> | 7 #include <glib.h> |
8 #include <math.h> | 8 #include <math.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| 18 #include "base/run_loop.h" |
18 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 #if defined(TOOLKIT_GTK) | 22 #if defined(TOOLKIT_GTK) |
22 #include <gtk/gtk.h> | 23 #include <gtk/gtk.h> |
23 #endif | 24 #endif |
24 | 25 |
| 26 namespace base { |
25 namespace { | 27 namespace { |
26 | 28 |
27 // This class injects dummy "events" into the GLib loop. When "handled" these | 29 // This class injects dummy "events" into the GLib loop. When "handled" these |
28 // events can run tasks. This is intended to mock gtk events (the corresponding | 30 // events can run tasks. This is intended to mock gtk events (the corresponding |
29 // GLib source runs at the same priority). | 31 // GLib source runs at the same priority). |
30 class EventInjector { | 32 class EventInjector { |
31 public: | 33 public: |
32 EventInjector() : processed_events_(0) { | 34 EventInjector() : processed_events_(0) { |
33 source_ = static_cast<Source*>(g_source_new(&SourceFuncs, sizeof(Source))); | 35 source_ = static_cast<Source*>(g_source_new(&SourceFuncs, sizeof(Source))); |
34 source_->injector = this; | 36 source_->injector = this; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 EventInjector* injector_; | 184 EventInjector* injector_; |
183 DISALLOW_COPY_AND_ASSIGN(MessagePumpGLibTest); | 185 DISALLOW_COPY_AND_ASSIGN(MessagePumpGLibTest); |
184 }; | 186 }; |
185 | 187 |
186 } // namespace | 188 } // namespace |
187 | 189 |
188 TEST_F(MessagePumpGLibTest, TestQuit) { | 190 TEST_F(MessagePumpGLibTest, TestQuit) { |
189 // Checks that Quit works and that the basic infrastructure is working. | 191 // Checks that Quit works and that the basic infrastructure is working. |
190 | 192 |
191 // Quit from a task | 193 // Quit from a task |
192 loop()->RunUntilIdle(); | 194 RunLoop().RunUntilIdle(); |
193 EXPECT_EQ(0, injector()->processed_events()); | 195 EXPECT_EQ(0, injector()->processed_events()); |
194 | 196 |
195 injector()->Reset(); | 197 injector()->Reset(); |
196 // Quit from an event | 198 // Quit from an event |
197 injector()->AddEvent(0, MessageLoop::QuitWhenIdleClosure()); | 199 injector()->AddEvent(0, MessageLoop::QuitWhenIdleClosure()); |
198 loop()->Run(); | 200 loop()->Run(); |
199 EXPECT_EQ(1, injector()->processed_events()); | 201 EXPECT_EQ(1, injector()->processed_events()); |
200 } | 202 } |
201 | 203 |
202 TEST_F(MessagePumpGLibTest, TestEventTaskInterleave) { | 204 TEST_F(MessagePumpGLibTest, TestEventTaskInterleave) { |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 TEST_F(MessagePumpGLibTest, TestGtkLoop) { | 569 TEST_F(MessagePumpGLibTest, TestGtkLoop) { |
568 // Tests that events and posted tasks are correctly executed if the message | 570 // Tests that events and posted tasks are correctly executed if the message |
569 // loop is not run by MessageLoop::Run() but by a straight Gtk loop. | 571 // loop is not run by MessageLoop::Run() but by a straight Gtk loop. |
570 // Note that in this case we don't make strong guarantees about niceness | 572 // Note that in this case we don't make strong guarantees about niceness |
571 // between events and posted tasks. | 573 // between events and posted tasks. |
572 loop()->PostTask( | 574 loop()->PostTask( |
573 FROM_HERE, | 575 FROM_HERE, |
574 base::Bind(&TestGtkLoopInternal, base::Unretained(injector()))); | 576 base::Bind(&TestGtkLoopInternal, base::Unretained(injector()))); |
575 loop()->Run(); | 577 loop()->Run(); |
576 } | 578 } |
| 579 |
| 580 } // namespace base |
OLD | NEW |