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_libevent.h" | 5 #include "base/message_pump_libevent.h" |
6 | 6 |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 delete controller_; | 122 delete controller_; |
123 controller_ = NULL; | 123 controller_ = NULL; |
124 } | 124 } |
125 }; | 125 }; |
126 | 126 |
127 TEST_F(MessagePumpLibeventTest, DeleteWatcher) { | 127 TEST_F(MessagePumpLibeventTest, DeleteWatcher) { |
128 scoped_refptr<MessagePumpLibevent> pump(new MessagePumpLibevent); | 128 scoped_refptr<MessagePumpLibevent> pump(new MessagePumpLibevent); |
129 MessagePumpLibevent::FileDescriptorWatcher* watcher = | 129 MessagePumpLibevent::FileDescriptorWatcher* watcher = |
130 new MessagePumpLibevent::FileDescriptorWatcher; | 130 new MessagePumpLibevent::FileDescriptorWatcher; |
131 DeleteWatcher delegate(watcher); | 131 DeleteWatcher delegate(watcher); |
132 pump->WatchFileDescriptor(pipefds_[1], | 132 pump->WatchFileDescriptor(pipefds_[1], false, |
133 false, MessagePumpLibevent::WATCH_READ_WRITE, watcher, &delegate); | 133 MessagePumpLibevent::WATCH_READ | MessagePumpLibevent::WATCH_WRITE, |
wtc
2012/11/21 18:48:42
This is very long. I think we can still define the
blundell
2012/11/26 16:02:23
Done.
| |
134 watcher, &delegate); | |
134 | 135 |
135 // Spoof a libevent notification. | 136 // Spoof a libevent notification. |
136 OnLibeventNotification(pump, watcher); | 137 OnLibeventNotification(pump, watcher); |
137 } | 138 } |
138 | 139 |
139 class StopWatcher : public BaseWatcher { | 140 class StopWatcher : public BaseWatcher { |
140 public: | 141 public: |
141 explicit StopWatcher( | 142 explicit StopWatcher( |
142 MessagePumpLibevent::FileDescriptorWatcher* controller) | 143 MessagePumpLibevent::FileDescriptorWatcher* controller) |
143 : BaseWatcher(controller) {} | 144 : BaseWatcher(controller) {} |
144 | 145 |
145 virtual ~StopWatcher() {} | 146 virtual ~StopWatcher() {} |
146 | 147 |
147 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE { | 148 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE { |
148 controller_->StopWatchingFileDescriptor(); | 149 controller_->StopWatchingFileDescriptor(); |
149 } | 150 } |
150 }; | 151 }; |
151 | 152 |
152 TEST_F(MessagePumpLibeventTest, StopWatcher) { | 153 TEST_F(MessagePumpLibeventTest, StopWatcher) { |
153 scoped_refptr<MessagePumpLibevent> pump(new MessagePumpLibevent); | 154 scoped_refptr<MessagePumpLibevent> pump(new MessagePumpLibevent); |
154 MessagePumpLibevent::FileDescriptorWatcher watcher; | 155 MessagePumpLibevent::FileDescriptorWatcher watcher; |
155 StopWatcher delegate(&watcher); | 156 StopWatcher delegate(&watcher); |
156 pump->WatchFileDescriptor(pipefds_[1], | 157 pump->WatchFileDescriptor(pipefds_[1], false, |
157 false, MessagePumpLibevent::WATCH_READ_WRITE, &watcher, &delegate); | 158 MessagePumpLibevent::WATCH_READ | MessagePumpLibevent::WATCH_WRITE, |
159 &watcher, &delegate); | |
158 | 160 |
159 // Spoof a libevent notification. | 161 // Spoof a libevent notification. |
160 OnLibeventNotification(pump, &watcher); | 162 OnLibeventNotification(pump, &watcher); |
161 } | 163 } |
162 | 164 |
163 } // namespace | 165 } // namespace |
164 | 166 |
165 } // namespace base | 167 } // namespace base |
OLD | NEW |