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

Side by Side Diff: base/message_loop/message_pump_io_ios_unittest.cc

Issue 2695593009: Use the location where FileDescriptorWatcher is created to track the libevent handlers (Closed)
Patch Set: fix mac. Created 3 years, 10 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 | « base/message_loop/message_pump_io_ios.cc ('k') | base/message_loop/message_pump_libevent.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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_io_ios.h" 5 #include "base/message_loop/message_pump_io_ios.h"
6 6
7 #include <unistd.h> 7 #include <unistd.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 ~StupidWatcher() override {} 69 ~StupidWatcher() override {}
70 70
71 // base:MessagePumpIOSForIO::Watcher interface 71 // base:MessagePumpIOSForIO::Watcher interface
72 void OnFileCanReadWithoutBlocking(int fd) override {} 72 void OnFileCanReadWithoutBlocking(int fd) override {}
73 void OnFileCanWriteWithoutBlocking(int fd) override {} 73 void OnFileCanWriteWithoutBlocking(int fd) override {}
74 }; 74 };
75 75
76 // Test to make sure that we catch calling WatchFileDescriptor off of the wrong 76 // Test to make sure that we catch calling WatchFileDescriptor off of the wrong
77 // thread. 77 // thread.
78 TEST_F(MessagePumpIOSForIOTest, TestWatchingFromBadThread) { 78 TEST_F(MessagePumpIOSForIOTest, TestWatchingFromBadThread) {
79 MessagePumpIOSForIO::FileDescriptorWatcher watcher; 79 MessagePumpIOSForIO::FileDescriptorWatcher watcher(FROM_HERE);
80 StupidWatcher delegate; 80 StupidWatcher delegate;
81 81
82 ASSERT_DCHECK_DEATH( 82 ASSERT_DCHECK_DEATH(
83 io_loop()->WatchFileDescriptor(STDOUT_FILENO, false, 83 io_loop()->WatchFileDescriptor(STDOUT_FILENO, false,
84 MessageLoopForIO::WATCH_READ, &watcher, 84 MessageLoopForIO::WATCH_READ, &watcher,
85 &delegate)); 85 &delegate));
86 } 86 }
87 87
88 class BaseWatcher : public MessagePumpIOSForIO::Watcher { 88 class BaseWatcher : public MessagePumpIOSForIO::Watcher {
89 public: 89 public:
(...skipping 23 matching lines...) Expand all
113 void OnFileCanWriteWithoutBlocking(int /* fd */) override { 113 void OnFileCanWriteWithoutBlocking(int /* fd */) override {
114 DCHECK(controller_); 114 DCHECK(controller_);
115 delete controller_; 115 delete controller_;
116 controller_ = NULL; 116 controller_ = NULL;
117 } 117 }
118 }; 118 };
119 119
120 TEST_F(MessagePumpIOSForIOTest, DeleteWatcher) { 120 TEST_F(MessagePumpIOSForIOTest, DeleteWatcher) {
121 std::unique_ptr<MessagePumpIOSForIO> pump(new MessagePumpIOSForIO); 121 std::unique_ptr<MessagePumpIOSForIO> pump(new MessagePumpIOSForIO);
122 MessagePumpIOSForIO::FileDescriptorWatcher* watcher = 122 MessagePumpIOSForIO::FileDescriptorWatcher* watcher =
123 new MessagePumpIOSForIO::FileDescriptorWatcher; 123 new MessagePumpIOSForIO::FileDescriptorWatcher(FROM_HERE);
124 DeleteWatcher delegate(watcher); 124 DeleteWatcher delegate(watcher);
125 pump->WatchFileDescriptor(pipefds_[1], 125 pump->WatchFileDescriptor(pipefds_[1],
126 false, MessagePumpIOSForIO::WATCH_READ_WRITE, watcher, &delegate); 126 false, MessagePumpIOSForIO::WATCH_READ_WRITE, watcher, &delegate);
127 127
128 // Spoof a callback. 128 // Spoof a callback.
129 HandleFdIOEvent(watcher); 129 HandleFdIOEvent(watcher);
130 } 130 }
131 131
132 class StopWatcher : public BaseWatcher { 132 class StopWatcher : public BaseWatcher {
133 public: 133 public:
(...skipping 14 matching lines...) Expand all
148 } 148 }
149 } 149 }
150 150
151 private: 151 private:
152 MessagePumpIOSForIO* pump_; 152 MessagePumpIOSForIO* pump_;
153 int fd_to_start_watching_; 153 int fd_to_start_watching_;
154 }; 154 };
155 155
156 TEST_F(MessagePumpIOSForIOTest, StopWatcher) { 156 TEST_F(MessagePumpIOSForIOTest, StopWatcher) {
157 std::unique_ptr<MessagePumpIOSForIO> pump(new MessagePumpIOSForIO); 157 std::unique_ptr<MessagePumpIOSForIO> pump(new MessagePumpIOSForIO);
158 MessagePumpIOSForIO::FileDescriptorWatcher watcher; 158 MessagePumpIOSForIO::FileDescriptorWatcher watcher(FROM_HERE);
159 StopWatcher delegate(&watcher, pump.get()); 159 StopWatcher delegate(&watcher, pump.get());
160 pump->WatchFileDescriptor(pipefds_[1], 160 pump->WatchFileDescriptor(pipefds_[1],
161 false, MessagePumpIOSForIO::WATCH_READ_WRITE, &watcher, &delegate); 161 false, MessagePumpIOSForIO::WATCH_READ_WRITE, &watcher, &delegate);
162 162
163 // Spoof a callback. 163 // Spoof a callback.
164 HandleFdIOEvent(&watcher); 164 HandleFdIOEvent(&watcher);
165 } 165 }
166 166
167 TEST_F(MessagePumpIOSForIOTest, StopWatcherAndWatchSomethingElse) { 167 TEST_F(MessagePumpIOSForIOTest, StopWatcherAndWatchSomethingElse) {
168 std::unique_ptr<MessagePumpIOSForIO> pump(new MessagePumpIOSForIO); 168 std::unique_ptr<MessagePumpIOSForIO> pump(new MessagePumpIOSForIO);
169 MessagePumpIOSForIO::FileDescriptorWatcher watcher; 169 MessagePumpIOSForIO::FileDescriptorWatcher watcher(FROM_HERE);
170 StopWatcher delegate(&watcher, pump.get(), alternate_pipefds_[1]); 170 StopWatcher delegate(&watcher, pump.get(), alternate_pipefds_[1]);
171 pump->WatchFileDescriptor(pipefds_[1], 171 pump->WatchFileDescriptor(pipefds_[1],
172 false, MessagePumpIOSForIO::WATCH_READ_WRITE, &watcher, &delegate); 172 false, MessagePumpIOSForIO::WATCH_READ_WRITE, &watcher, &delegate);
173 173
174 // Spoof a callback. 174 // Spoof a callback.
175 HandleFdIOEvent(&watcher); 175 HandleFdIOEvent(&watcher);
176 } 176 }
177 177
178 } // namespace 178 } // namespace
179 179
180 } // namespace base 180 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_pump_io_ios.cc ('k') | base/message_loop/message_pump_libevent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698