| 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_loop/message_pump_libevent.h" | 5 #include "base/message_loop/message_pump_libevent.h" |
| 6 | 6 |
| 7 #include <unistd.h> | 7 #include <unistd.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 if (!work_units_) | 283 if (!work_units_) |
| 284 return false; | 284 return false; |
| 285 work_units_--; | 285 work_units_--; |
| 286 return true; | 286 return true; |
| 287 } | 287 } |
| 288 | 288 |
| 289 private: | 289 private: |
| 290 uint32_t work_units_; | 290 uint32_t work_units_; |
| 291 }; | 291 }; |
| 292 | 292 |
| 293 TEST_F(MessagePumpLibeventTest, PollEventSource) { | 293 TEST(MessagePumpLibeventEventSourceTest, Poll) { |
| 294 MessagePumpLibevent* pump = new MessagePumpLibevent; // owned by |loop|. |
| 295 MessageLoop loop(make_scoped_ptr(pump)); |
| 294 FakeEventSource event_source; | 296 FakeEventSource event_source; |
| 295 | 297 |
| 296 // Verify event source gets polled repeatedly until no work remains. | 298 // Verify event source gets polled repeatedly until no work remains. |
| 297 MessageLoopForUI::current()->SetEventSource(&event_source); | 299 pump->SetEventSource(&event_source); |
| 298 event_source.set_work_units(5u); | 300 event_source.set_work_units(5u); |
| 299 ui_loop_->RunUntilIdle(); | 301 loop.RunUntilIdle(); |
| 300 EXPECT_EQ(0u, event_source.work_units()); | 302 EXPECT_EQ(0u, event_source.work_units()); |
| 301 | 303 |
| 302 // After removing the event source, it should no longer be polled. | 304 // After removing the event source, it should no longer be polled. |
| 303 MessageLoopForUI::current()->ClearEventSource(); | 305 pump->ClearEventSource(); |
| 304 event_source.set_work_units(5u); | 306 event_source.set_work_units(5u); |
| 305 ui_loop_->RunUntilIdle(); | 307 loop.RunUntilIdle(); |
| 306 EXPECT_EQ(5u, event_source.work_units()); | 308 EXPECT_EQ(5u, event_source.work_units()); |
| 307 } | 309 } |
| 308 | 310 |
| 309 } // namespace | 311 } // namespace |
| 310 | 312 |
| 311 } // namespace base | 313 } // namespace base |
| OLD | NEW |