Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "base/threading/thread_checker.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 #if defined(USE_SYSTEM_LIBEVENT) | 14 #if defined(USE_SYSTEM_LIBEVENT) |
| 14 #include <event.h> | 15 #include <event.h> |
| 15 #else | 16 #else |
| 16 #include "third_party/libevent/event.h" | 17 #include "third_party/libevent/event.h" |
| 17 #endif | 18 #endif |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 | 21 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 #if GTEST_HAS_DEATH_TEST | 63 #if GTEST_HAS_DEATH_TEST |
| 63 | 64 |
| 64 // Test to make sure that we catch calling WatchFileDescriptor off of the | 65 // Test to make sure that we catch calling WatchFileDescriptor off of the |
| 65 // wrong thread. | 66 // wrong thread. |
| 66 TEST_F(MessagePumpLibeventTest, TestWatchingFromBadThread) { | 67 TEST_F(MessagePumpLibeventTest, TestWatchingFromBadThread) { |
| 67 MessagePumpLibevent::FileDescriptorWatcher watcher; | 68 MessagePumpLibevent::FileDescriptorWatcher watcher; |
| 68 StupidWatcher delegate; | 69 StupidWatcher delegate; |
| 69 | 70 |
| 70 ASSERT_DEBUG_DEATH(io_loop()->WatchFileDescriptor( | 71 if (base::ThreadChecker::IsEnabled()) { |
|
Nico
2011/12/21 18:10:11
How is ASSERT_DEBUG_DEATH a useful test? I think w
| |
| 71 STDOUT_FILENO, false, MessageLoopForIO::WATCH_READ, &watcher, &delegate), | 72 ASSERT_DEATH( |
| 72 "Check failed: " | 73 io_loop()->WatchFileDescriptor(STDOUT_FILENO, |
| 73 "watch_file_descriptor_caller_checker_.CalledOnValidThread()"); | 74 false, |
| 75 MessageLoopForIO::WATCH_READ, | |
| 76 &watcher, | |
| 77 &delegate), | |
| 78 "Check failed: " | |
| 79 "watch_file_descriptor_caller_checker_.CalledOnValidThread()"); | |
| 80 } | |
| 74 } | 81 } |
| 75 | 82 |
| 76 #endif // GTEST_HAS_DEATH_TEST | 83 #endif // GTEST_HAS_DEATH_TEST |
| 77 | 84 |
| 78 class DeleteWatcher : public MessagePumpLibevent::Watcher { | 85 class DeleteWatcher : public MessagePumpLibevent::Watcher { |
| 79 public: | 86 public: |
| 80 explicit DeleteWatcher( | 87 explicit DeleteWatcher( |
| 81 MessagePumpLibevent::FileDescriptorWatcher* controller) | 88 MessagePumpLibevent::FileDescriptorWatcher* controller) |
| 82 : controller_(controller) { | 89 : controller_(controller) { |
| 83 DCHECK(controller_); | 90 DCHECK(controller_); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 pump->WatchFileDescriptor( | 143 pump->WatchFileDescriptor( |
| 137 0, false, MessagePumpLibevent::WATCH_READ_WRITE, &watcher, &delegate); | 144 0, false, MessagePumpLibevent::WATCH_READ_WRITE, &watcher, &delegate); |
| 138 | 145 |
| 139 // Spoof a libevent notification. | 146 // Spoof a libevent notification. |
| 140 OnLibeventNotification(pump, &watcher); | 147 OnLibeventNotification(pump, &watcher); |
| 141 } | 148 } |
| 142 | 149 |
| 143 } // namespace | 150 } // namespace |
| 144 | 151 |
| 145 } // namespace base | 152 } // namespace base |
| OLD | NEW |