| OLD | NEW |
| 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" |
| 11 #include "base/posix/eintr_wrapper.h" | 11 #include "base/posix/eintr_wrapper.h" |
| 12 #include "base/test/gtest_util.h" |
| 12 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 | 17 |
| 17 class MessagePumpIOSForIOTest : public testing::Test { | 18 class MessagePumpIOSForIOTest : public testing::Test { |
| 18 protected: | 19 protected: |
| 19 MessagePumpIOSForIOTest() | 20 MessagePumpIOSForIOTest() |
| 20 : ui_loop_(MessageLoop::TYPE_UI), | 21 : ui_loop_(MessageLoop::TYPE_UI), |
| 21 io_thread_("MessagePumpIOSForIOTestIOThread") {} | 22 io_thread_("MessagePumpIOSForIOTestIOThread") {} |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // nothing useful. | 66 // nothing useful. |
| 66 class StupidWatcher : public MessagePumpIOSForIO::Watcher { | 67 class StupidWatcher : public MessagePumpIOSForIO::Watcher { |
| 67 public: | 68 public: |
| 68 ~StupidWatcher() override {} | 69 ~StupidWatcher() override {} |
| 69 | 70 |
| 70 // base:MessagePumpIOSForIO::Watcher interface | 71 // base:MessagePumpIOSForIO::Watcher interface |
| 71 void OnFileCanReadWithoutBlocking(int fd) override {} | 72 void OnFileCanReadWithoutBlocking(int fd) override {} |
| 72 void OnFileCanWriteWithoutBlocking(int fd) override {} | 73 void OnFileCanWriteWithoutBlocking(int fd) override {} |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 #if GTEST_HAS_DEATH_TEST && !defined(NDEBUG) | 76 // Test to make sure that we catch calling WatchFileDescriptor off of the wrong |
| 76 | 77 // thread. |
| 77 // Test to make sure that we catch calling WatchFileDescriptor off of the | |
| 78 // wrong thread. | |
| 79 TEST_F(MessagePumpIOSForIOTest, TestWatchingFromBadThread) { | 78 TEST_F(MessagePumpIOSForIOTest, TestWatchingFromBadThread) { |
| 80 MessagePumpIOSForIO::FileDescriptorWatcher watcher; | 79 MessagePumpIOSForIO::FileDescriptorWatcher watcher; |
| 81 StupidWatcher delegate; | 80 StupidWatcher delegate; |
| 82 | 81 |
| 83 ASSERT_DEBUG_DEATH(io_loop()->WatchFileDescriptor( | 82 ASSERT_DCHECK_DEATH( |
| 84 STDOUT_FILENO, false, MessageLoopForIO::WATCH_READ, &watcher, &delegate), | 83 io_loop()->WatchFileDescriptor(STDOUT_FILENO, false, |
| 84 MessageLoopForIO::WATCH_READ, &watcher, |
| 85 &delegate), |
| 85 "Check failed: " | 86 "Check failed: " |
| 86 "watch_file_descriptor_caller_checker_.CalledOnValidThread\\(\\)"); | 87 "watch_file_descriptor_caller_checker_.CalledOnValidThread\\(\\)"); |
| 87 } | 88 } |
| 88 | 89 |
| 89 #endif // GTEST_HAS_DEATH_TEST && !defined(NDEBUG) | |
| 90 | |
| 91 class BaseWatcher : public MessagePumpIOSForIO::Watcher { | 90 class BaseWatcher : public MessagePumpIOSForIO::Watcher { |
| 92 public: | 91 public: |
| 93 BaseWatcher(MessagePumpIOSForIO::FileDescriptorWatcher* controller) | 92 BaseWatcher(MessagePumpIOSForIO::FileDescriptorWatcher* controller) |
| 94 : controller_(controller) { | 93 : controller_(controller) { |
| 95 DCHECK(controller_); | 94 DCHECK(controller_); |
| 96 } | 95 } |
| 97 ~BaseWatcher() override {} | 96 ~BaseWatcher() override {} |
| 98 | 97 |
| 99 // MessagePumpIOSForIO::Watcher interface | 98 // MessagePumpIOSForIO::Watcher interface |
| 100 void OnFileCanReadWithoutBlocking(int /* fd */) override { NOTREACHED(); } | 99 void OnFileCanReadWithoutBlocking(int /* fd */) override { NOTREACHED(); } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 pump->WatchFileDescriptor(pipefds_[1], | 173 pump->WatchFileDescriptor(pipefds_[1], |
| 175 false, MessagePumpIOSForIO::WATCH_READ_WRITE, &watcher, &delegate); | 174 false, MessagePumpIOSForIO::WATCH_READ_WRITE, &watcher, &delegate); |
| 176 | 175 |
| 177 // Spoof a callback. | 176 // Spoof a callback. |
| 178 HandleFdIOEvent(&watcher); | 177 HandleFdIOEvent(&watcher); |
| 179 } | 178 } |
| 180 | 179 |
| 181 } // namespace | 180 } // namespace |
| 182 | 181 |
| 183 } // namespace base | 182 } // namespace base |
| OLD | NEW |