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. | 15 // The message loops on which each waitable event timer should be tested. |
16 const MessageLoop::Type testing_message_loops[] = { | 16 const MessageLoop::Type testing_message_loops[] = { |
17 MessageLoop::TYPE_DEFAULT, | 17 MessageLoop::TYPE_DEFAULT, |
18 MessageLoop::TYPE_IO, | 18 MessageLoop::TYPE_IO, |
19 #if !defined(OS_IOS) // iOS does not allow direct running of the UI loop. | 19 #if !defined(OS_IOS) // iOS does not allow direct running of the UI loop. |
20 MessageLoop::TYPE_UI, | 20 MessageLoop::TYPE_UI, |
21 #endif | 21 #endif |
22 }; | 22 }; |
23 | 23 |
24 const int kNumTestingMessageLoops = arraysize(testing_message_loops); | 24 const int kNumTestingMessageLoops = arraysize(testing_message_loops); |
25 | 25 |
26 class QuitDelegate : public WaitableEventWatcher::Delegate { | 26 class QuitDelegate : public WaitableEventWatcher::Delegate { |
27 public: | 27 public: |
28 virtual void OnWaitableEventSignaled(WaitableEvent* event) OVERRIDE { | 28 virtual void OnWaitableEventSignaled(WaitableEvent* event) OVERRIDE { |
29 MessageLoop::current()->Quit(); | 29 MessageLoop::current()->QuitWhenIdle(); |
30 } | 30 } |
31 }; | 31 }; |
32 | 32 |
33 class DecrementCountDelegate : public WaitableEventWatcher::Delegate { | 33 class DecrementCountDelegate : public WaitableEventWatcher::Delegate { |
34 public: | 34 public: |
35 explicit DecrementCountDelegate(int* counter) : counter_(counter) { | 35 explicit DecrementCountDelegate(int* counter) : counter_(counter) { |
36 } | 36 } |
37 virtual void OnWaitableEventSignaled(WaitableEvent* object) OVERRIDE { | 37 virtual void OnWaitableEventSignaled(WaitableEvent* object) OVERRIDE { |
38 --(*counter_); | 38 --(*counter_); |
39 } | 39 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 #else | 167 #else |
168 #define MAYBE_DeleteUnder DeleteUnder | 168 #define MAYBE_DeleteUnder DeleteUnder |
169 #endif | 169 #endif |
170 TEST(WaitableEventWatcherTest, MAYBE_DeleteUnder) { | 170 TEST(WaitableEventWatcherTest, MAYBE_DeleteUnder) { |
171 for (int i = 0; i < kNumTestingMessageLoops; i++) { | 171 for (int i = 0; i < kNumTestingMessageLoops; i++) { |
172 RunTest_DeleteUnder(testing_message_loops[i]); | 172 RunTest_DeleteUnder(testing_message_loops[i]); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 } // namespace base | 176 } // namespace base |
OLD | NEW |