OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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.h" | 5 #include "base/message_loop.h" |
6 #include "base/platform_thread.h" | 6 #include "base/platform_thread.h" |
7 #include "base/waitable_event.h" | 7 #include "base/waitable_event.h" |
8 #include "base/waitable_event_watcher.h" | 8 #include "base/waitable_event_watcher.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 WaitableEventWatcher watcher; | 100 WaitableEventWatcher watcher; |
101 { | 101 { |
102 MessageLoop message_loop(message_loop_type); | 102 MessageLoop message_loop(message_loop_type); |
103 | 103 |
104 QuitDelegate delegate; | 104 QuitDelegate delegate; |
105 watcher.StartWatching(&event, &delegate); | 105 watcher.StartWatching(&event, &delegate); |
106 } | 106 } |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
| 110 void RunTest_DeleteUnder(MessageLoop::Type message_loop_type) { |
| 111 // Delete the WaitableEvent out from under the Watcher. This is explictly |
| 112 // allowed by the interface. |
| 113 |
| 114 MessageLoop message_loop(message_loop_type); |
| 115 |
| 116 { |
| 117 WaitableEventWatcher watcher; |
| 118 |
| 119 WaitableEvent* event = new WaitableEvent(false, false); |
| 120 QuitDelegate delegate; |
| 121 watcher.StartWatching(event, &delegate); |
| 122 delete event; |
| 123 } |
| 124 } |
| 125 |
110 } // namespace | 126 } // namespace |
111 | 127 |
112 //----------------------------------------------------------------------------- | 128 //----------------------------------------------------------------------------- |
113 | 129 |
114 TEST(WaitableEventWatcherTest, BasicSignal) { | 130 TEST(WaitableEventWatcherTest, BasicSignal) { |
115 RunTest_BasicSignal(MessageLoop::TYPE_DEFAULT); | 131 RunTest_BasicSignal(MessageLoop::TYPE_DEFAULT); |
116 RunTest_BasicSignal(MessageLoop::TYPE_IO); | 132 RunTest_BasicSignal(MessageLoop::TYPE_IO); |
117 RunTest_BasicSignal(MessageLoop::TYPE_UI); | 133 RunTest_BasicSignal(MessageLoop::TYPE_UI); |
118 } | 134 } |
119 | 135 |
120 TEST(WaitableEventWatcherTest, BasicCancel) { | 136 TEST(WaitableEventWatcherTest, BasicCancel) { |
121 RunTest_BasicCancel(MessageLoop::TYPE_DEFAULT); | 137 RunTest_BasicCancel(MessageLoop::TYPE_DEFAULT); |
122 RunTest_BasicCancel(MessageLoop::TYPE_IO); | 138 RunTest_BasicCancel(MessageLoop::TYPE_IO); |
123 RunTest_BasicCancel(MessageLoop::TYPE_UI); | 139 RunTest_BasicCancel(MessageLoop::TYPE_UI); |
124 } | 140 } |
125 | 141 |
126 TEST(WaitableEventWatcherTest, CancelAfterSet) { | 142 TEST(WaitableEventWatcherTest, CancelAfterSet) { |
127 RunTest_CancelAfterSet(MessageLoop::TYPE_DEFAULT); | 143 RunTest_CancelAfterSet(MessageLoop::TYPE_DEFAULT); |
128 RunTest_CancelAfterSet(MessageLoop::TYPE_IO); | 144 RunTest_CancelAfterSet(MessageLoop::TYPE_IO); |
129 RunTest_CancelAfterSet(MessageLoop::TYPE_UI); | 145 RunTest_CancelAfterSet(MessageLoop::TYPE_UI); |
130 } | 146 } |
131 | 147 |
132 TEST(WaitableEventWatcherTest, OutlivesMessageLoop) { | 148 TEST(WaitableEventWatcherTest, OutlivesMessageLoop) { |
133 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_DEFAULT); | 149 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_DEFAULT); |
134 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_IO); | 150 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_IO); |
135 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_UI); | 151 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_UI); |
136 } | 152 } |
| 153 |
| 154 TEST(WaitableEventWatcherTest, DeleteUnder) { |
| 155 RunTest_DeleteUnder(MessageLoop::TYPE_DEFAULT); |
| 156 RunTest_DeleteUnder(MessageLoop::TYPE_IO); |
| 157 RunTest_DeleteUnder(MessageLoop::TYPE_UI); |
| 158 } |
OLD | NEW |