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

Side by Side Diff: message_loop/message_pump_libevent_unittest.cc

Issue 1921183002: Add a mechanism to extend a libevent based message pump. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/domokit/base@master
Patch Set: added test case Created 4 years, 7 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 | « message_loop/message_pump_libevent.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 loop.PostTask(FROM_HERE, Bind(&WaitableEvent::Signal, Unretained(&event))); 264 loop.PostTask(FROM_HERE, Bind(&WaitableEvent::Signal, Unretained(&event)));
265 265
266 // Now run the MessageLoop. 266 // Now run the MessageLoop.
267 run_loop.Run(); 267 run_loop.Run();
268 268
269 // StartWatching can move |watcher| to IO thread. Release on IO thread. 269 // StartWatching can move |watcher| to IO thread. Release on IO thread.
270 io_loop()->PostTask(FROM_HERE, Bind(&WaitableEventWatcher::StopWatching, 270 io_loop()->PostTask(FROM_HERE, Bind(&WaitableEventWatcher::StopWatching,
271 Owned(watcher.release()))); 271 Owned(watcher.release())));
272 } 272 }
273 273
274 class FakeEventSource : public MessagePumpLibevent::EventSource {
275 public:
276 FakeEventSource() : work_units_(0u) {}
277 ~FakeEventSource() override {}
278
279 void set_work_units(uint32_t work_units) { work_units_ = work_units; }
280 uint32_t work_units() const { return work_units_; }
281
282 bool Poll() override {
283 if (!work_units_)
284 return false;
285 work_units_--;
286 return true;
287 }
288
289 private:
290 uint32_t work_units_;
291 };
292
293 TEST_F(MessagePumpLibeventTest, PollEventSource) {
294 FakeEventSource event_source;
295
296 // Verify event source gets polled repeatedly until no work remains.
297 MessageLoopForUI::current()->SetEventSource(&event_source);
298 event_source.set_work_units(5u);
299 ui_loop_->RunUntilIdle();
300 EXPECT_EQ(0u, event_source.work_units());
301
302 // After removing the event source, it should no longer be polled.
303 MessageLoopForUI::current()->ClearEventSource();
304 event_source.set_work_units(5u);
305 ui_loop_->RunUntilIdle();
306 EXPECT_EQ(5u, event_source.work_units());
307 }
308
274 } // namespace 309 } // namespace
275 310
276 } // namespace base 311 } // namespace base
OLDNEW
« no previous file with comments | « message_loop/message_pump_libevent.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698