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 <process.h> | 5 #include <process.h> |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/object_watcher.h" | 8 #include "base/object_watcher.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 private: | 27 private: |
28 int* counter_; | 28 int* counter_; |
29 }; | 29 }; |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 void RunTest_BasicSignal(MessageLoop::Type message_loop_type) { | 33 void RunTest_BasicSignal(MessageLoop::Type message_loop_type) { |
34 MessageLoop message_loop(message_loop_type); | 34 MessageLoop message_loop(message_loop_type); |
35 | 35 |
36 base::ObjectWatcher watcher; | 36 base::ObjectWatcher watcher; |
| 37 EXPECT_EQ(NULL, watcher.GetWatchedObject()); |
37 | 38 |
38 // A manual-reset event that is not yet signaled. | 39 // A manual-reset event that is not yet signaled. |
39 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); | 40 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); |
40 | 41 |
41 QuitDelegate delegate; | 42 QuitDelegate delegate; |
42 bool ok = watcher.StartWatching(event, &delegate); | 43 bool ok = watcher.StartWatching(event, &delegate); |
43 EXPECT_TRUE(ok); | 44 EXPECT_TRUE(ok); |
| 45 EXPECT_EQ(event, watcher.GetWatchedObject()); |
44 | 46 |
45 SetEvent(event); | 47 SetEvent(event); |
46 | 48 |
47 MessageLoop::current()->Run(); | 49 MessageLoop::current()->Run(); |
48 | 50 |
| 51 EXPECT_EQ(NULL, watcher.GetWatchedObject()); |
49 CloseHandle(event); | 52 CloseHandle(event); |
50 } | 53 } |
51 | 54 |
52 void RunTest_BasicCancel(MessageLoop::Type message_loop_type) { | 55 void RunTest_BasicCancel(MessageLoop::Type message_loop_type) { |
53 MessageLoop message_loop(message_loop_type); | 56 MessageLoop message_loop(message_loop_type); |
54 | 57 |
55 base::ObjectWatcher watcher; | 58 base::ObjectWatcher watcher; |
56 | 59 |
57 // A manual-reset event that is not yet signaled. | 60 // A manual-reset event that is not yet signaled. |
58 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); | 61 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 RunTest_CancelAfterSet(MessageLoop::TYPE_DEFAULT); | 134 RunTest_CancelAfterSet(MessageLoop::TYPE_DEFAULT); |
132 RunTest_CancelAfterSet(MessageLoop::TYPE_IO); | 135 RunTest_CancelAfterSet(MessageLoop::TYPE_IO); |
133 RunTest_CancelAfterSet(MessageLoop::TYPE_UI); | 136 RunTest_CancelAfterSet(MessageLoop::TYPE_UI); |
134 } | 137 } |
135 | 138 |
136 TEST(ObjectWatcherTest, OutlivesMessageLoop) { | 139 TEST(ObjectWatcherTest, OutlivesMessageLoop) { |
137 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_DEFAULT); | 140 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_DEFAULT); |
138 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_IO); | 141 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_IO); |
139 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_UI); | 142 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_UI); |
140 } | 143 } |
OLD | NEW |