OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 |
11 using base::WaitableEvent; | 11 using base::WaitableEvent; |
12 using base::WaitableEventWatcher; | 12 using base::WaitableEventWatcher; |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 class QuitDelegate : public WaitableEventWatcher::Delegate { | 16 class QuitDelegate : public WaitableEventWatcher::Delegate { |
17 public: | 17 public: |
18 virtual void OnWaitableEventSignaled(WaitableEvent* event) { | 18 virtual void OnWaitableEventSignaled(WaitableEvent* event) { |
19 MessageLoop::current()->Quit(); | 19 MessageLoop::current()->Quit(); |
20 } | 20 } |
21 }; | 21 }; |
22 | 22 |
23 class DecrementCountDelegate : public WaitableEventWatcher::Delegate { | 23 class DecrementCountDelegate : public WaitableEventWatcher::Delegate { |
24 public: | 24 public: |
25 explicit DecrementCountDelegate(int* counter) : counter_(counter) { | 25 DecrementCountDelegate(int* counter) : counter_(counter) { |
26 } | 26 } |
27 virtual void OnWaitableEventSignaled(WaitableEvent* object) { | 27 virtual void OnWaitableEventSignaled(WaitableEvent* object) { |
28 --(*counter_); | 28 --(*counter_); |
29 } | 29 } |
30 private: | 30 private: |
31 int* counter_; | 31 int* counter_; |
32 }; | 32 }; |
33 | 33 |
34 void RunTest_BasicSignal(MessageLoop::Type message_loop_type) { | 34 void RunTest_BasicSignal(MessageLoop::Type message_loop_type) { |
35 MessageLoop message_loop(message_loop_type); | 35 MessageLoop message_loop(message_loop_type); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_DEFAULT); | 149 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_DEFAULT); |
150 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_IO); | 150 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_IO); |
151 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_UI); | 151 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_UI); |
152 } | 152 } |
153 | 153 |
154 TEST(WaitableEventWatcherTest, DeleteUnder) { | 154 TEST(WaitableEventWatcherTest, DeleteUnder) { |
155 RunTest_DeleteUnder(MessageLoop::TYPE_DEFAULT); | 155 RunTest_DeleteUnder(MessageLoop::TYPE_DEFAULT); |
156 RunTest_DeleteUnder(MessageLoop::TYPE_IO); | 156 RunTest_DeleteUnder(MessageLoop::TYPE_IO); |
157 RunTest_DeleteUnder(MessageLoop::TYPE_UI); | 157 RunTest_DeleteUnder(MessageLoop::TYPE_UI); |
158 } | 158 } |
OLD | NEW |