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_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/synchronization/waitable_event.h" | 6 #include "base/synchronization/waitable_event.h" |
7 #include "base/synchronization/waitable_event_watcher.h" | 7 #include "base/synchronization/waitable_event_watcher.h" |
8 #include "base/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
| 15 // The message loops on which each waitable event timer should be tested. |
| 16 const MessageLoop::Type testing_message_loops[] = { |
| 17 MessageLoop::TYPE_DEFAULT, |
| 18 MessageLoop::TYPE_IO, |
| 19 #if !defined(OS_IOS) // iOS does not allow direct running of the UI loop. |
| 20 MessageLoop::TYPE_UI, |
| 21 #endif |
| 22 }; |
| 23 |
| 24 const int kNumTestingMessageLoops = arraysize(testing_message_loops); |
| 25 |
15 class QuitDelegate : public WaitableEventWatcher::Delegate { | 26 class QuitDelegate : public WaitableEventWatcher::Delegate { |
16 public: | 27 public: |
17 virtual void OnWaitableEventSignaled(WaitableEvent* event) OVERRIDE { | 28 virtual void OnWaitableEventSignaled(WaitableEvent* event) OVERRIDE { |
18 MessageLoop::current()->Quit(); | 29 MessageLoop::current()->Quit(); |
19 } | 30 } |
20 }; | 31 }; |
21 | 32 |
22 class DecrementCountDelegate : public WaitableEventWatcher::Delegate { | 33 class DecrementCountDelegate : public WaitableEventWatcher::Delegate { |
23 public: | 34 public: |
24 explicit DecrementCountDelegate(int* counter) : counter_(counter) { | 35 explicit DecrementCountDelegate(int* counter) : counter_(counter) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 watcher.StartWatching(event, &delegate); | 131 watcher.StartWatching(event, &delegate); |
121 delete event; | 132 delete event; |
122 } | 133 } |
123 } | 134 } |
124 | 135 |
125 } // namespace | 136 } // namespace |
126 | 137 |
127 //----------------------------------------------------------------------------- | 138 //----------------------------------------------------------------------------- |
128 | 139 |
129 TEST(WaitableEventWatcherTest, BasicSignal) { | 140 TEST(WaitableEventWatcherTest, BasicSignal) { |
130 RunTest_BasicSignal(MessageLoop::TYPE_DEFAULT); | 141 for (int i = 0; i < kNumTestingMessageLoops; i++) { |
131 RunTest_BasicSignal(MessageLoop::TYPE_IO); | 142 RunTest_BasicSignal(testing_message_loops[i]); |
132 RunTest_BasicSignal(MessageLoop::TYPE_UI); | 143 } |
133 } | 144 } |
134 | 145 |
135 TEST(WaitableEventWatcherTest, BasicCancel) { | 146 TEST(WaitableEventWatcherTest, BasicCancel) { |
136 RunTest_BasicCancel(MessageLoop::TYPE_DEFAULT); | 147 for (int i = 0; i < kNumTestingMessageLoops; i++) { |
137 RunTest_BasicCancel(MessageLoop::TYPE_IO); | 148 RunTest_BasicCancel(testing_message_loops[i]); |
138 RunTest_BasicCancel(MessageLoop::TYPE_UI); | 149 } |
139 } | 150 } |
140 | 151 |
141 TEST(WaitableEventWatcherTest, CancelAfterSet) { | 152 TEST(WaitableEventWatcherTest, CancelAfterSet) { |
142 RunTest_CancelAfterSet(MessageLoop::TYPE_DEFAULT); | 153 for (int i = 0; i < kNumTestingMessageLoops; i++) { |
143 RunTest_CancelAfterSet(MessageLoop::TYPE_IO); | 154 RunTest_CancelAfterSet(testing_message_loops[i]); |
144 RunTest_CancelAfterSet(MessageLoop::TYPE_UI); | 155 } |
145 } | 156 } |
146 | 157 |
147 TEST(WaitableEventWatcherTest, OutlivesMessageLoop) { | 158 TEST(WaitableEventWatcherTest, OutlivesMessageLoop) { |
148 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_DEFAULT); | 159 for (int i = 0; i < kNumTestingMessageLoops; i++) { |
149 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_IO); | 160 RunTest_OutlivesMessageLoop(testing_message_loops[i]); |
150 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_UI); | 161 } |
151 } | 162 } |
152 | 163 |
153 #if defined(OS_WIN) | 164 #if defined(OS_WIN) |
154 // Crashes sometimes on vista. http://crbug.com/62119 | 165 // Crashes sometimes on vista. http://crbug.com/62119 |
155 #define MAYBE_DeleteUnder DISABLED_DeleteUnder | 166 #define MAYBE_DeleteUnder DISABLED_DeleteUnder |
156 #else | 167 #else |
157 #define MAYBE_DeleteUnder DeleteUnder | 168 #define MAYBE_DeleteUnder DeleteUnder |
158 #endif | 169 #endif |
159 TEST(WaitableEventWatcherTest, MAYBE_DeleteUnder) { | 170 TEST(WaitableEventWatcherTest, MAYBE_DeleteUnder) { |
160 RunTest_DeleteUnder(MessageLoop::TYPE_DEFAULT); | 171 for (int i = 0; i < kNumTestingMessageLoops; i++) { |
161 RunTest_DeleteUnder(MessageLoop::TYPE_IO); | 172 RunTest_DeleteUnder(testing_message_loops[i]); |
162 RunTest_DeleteUnder(MessageLoop::TYPE_UI); | 173 } |
163 } | 174 } |
164 | 175 |
165 } // namespace base | 176 } // namespace base |
OLD | NEW |