Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: base/win/object_watcher_unittest.cc

Issue 2211473003: Remove calls to deprecated MessageLoop methods on Windows and Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/win/object_watcher.h" 5 #include "base/win/object_watcher.h"
6 6
7 #include <process.h> 7 #include <process.h>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); 42 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL);
43 43
44 QuitDelegate delegate; 44 QuitDelegate delegate;
45 bool ok = watcher.StartWatchingOnce(event, &delegate); 45 bool ok = watcher.StartWatchingOnce(event, &delegate);
46 EXPECT_TRUE(ok); 46 EXPECT_TRUE(ok);
47 EXPECT_TRUE(watcher.IsWatching()); 47 EXPECT_TRUE(watcher.IsWatching());
48 EXPECT_EQ(event, watcher.GetWatchedObject()); 48 EXPECT_EQ(event, watcher.GetWatchedObject());
49 49
50 SetEvent(event); 50 SetEvent(event);
51 51
52 MessageLoop::current()->Run(); 52 RunLoop().Run();
53 53
54 EXPECT_FALSE(watcher.IsWatching()); 54 EXPECT_FALSE(watcher.IsWatching());
55 CloseHandle(event); 55 CloseHandle(event);
56 } 56 }
57 57
58 void RunTest_BasicCancel(MessageLoop::Type message_loop_type) { 58 void RunTest_BasicCancel(MessageLoop::Type message_loop_type) {
59 MessageLoop message_loop(message_loop_type); 59 MessageLoop message_loop(message_loop_type);
60 60
61 ObjectWatcher watcher; 61 ObjectWatcher watcher;
62 62
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 106
107 ObjectWatcher watcher; 107 ObjectWatcher watcher;
108 108
109 // A manual-reset event that is signaled before we begin watching. 109 // A manual-reset event that is signaled before we begin watching.
110 HANDLE event = CreateEvent(NULL, TRUE, TRUE, NULL); 110 HANDLE event = CreateEvent(NULL, TRUE, TRUE, NULL);
111 111
112 QuitDelegate delegate; 112 QuitDelegate delegate;
113 bool ok = watcher.StartWatchingOnce(event, &delegate); 113 bool ok = watcher.StartWatchingOnce(event, &delegate);
114 EXPECT_TRUE(ok); 114 EXPECT_TRUE(ok);
115 115
116 MessageLoop::current()->Run(); 116 RunLoop().Run();
117 117
118 EXPECT_FALSE(watcher.IsWatching()); 118 EXPECT_FALSE(watcher.IsWatching());
119 CloseHandle(event); 119 CloseHandle(event);
120 } 120 }
121 121
122 void RunTest_OutlivesMessageLoop(MessageLoop::Type message_loop_type) { 122 void RunTest_OutlivesMessageLoop(MessageLoop::Type message_loop_type) {
123 // Simulate a MessageLoop that dies before an ObjectWatcher. This ordinarily 123 // Simulate a MessageLoop that dies before an ObjectWatcher. This ordinarily
124 // doesn't happen when people use the Thread class, but it can happen when 124 // doesn't happen when people use the Thread class, but it can happen when
125 // people use the Singleton pattern or atexit. 125 // people use the Singleton pattern or atexit.
126 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); // not signaled 126 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); // not signaled
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 HANDLE event = CreateEvent(NULL, FALSE, FALSE, NULL); 163 HANDLE event = CreateEvent(NULL, FALSE, FALSE, NULL);
164 164
165 QuitAfterMultipleDelegate delegate(event, 2); 165 QuitAfterMultipleDelegate delegate(event, 2);
166 bool ok = watcher.StartWatchingMultipleTimes(event, &delegate); 166 bool ok = watcher.StartWatchingMultipleTimes(event, &delegate);
167 EXPECT_TRUE(ok); 167 EXPECT_TRUE(ok);
168 EXPECT_TRUE(watcher.IsWatching()); 168 EXPECT_TRUE(watcher.IsWatching());
169 EXPECT_EQ(event, watcher.GetWatchedObject()); 169 EXPECT_EQ(event, watcher.GetWatchedObject());
170 170
171 SetEvent(event); 171 SetEvent(event);
172 172
173 MessageLoop::current()->Run(); 173 RunLoop().Run();
174 174
175 EXPECT_TRUE(watcher.IsWatching()); 175 EXPECT_TRUE(watcher.IsWatching());
176 EXPECT_TRUE(watcher.StopWatching()); 176 EXPECT_TRUE(watcher.StopWatching());
177 CloseHandle(event); 177 CloseHandle(event);
178 } 178 }
179 179
180 } // namespace 180 } // namespace
181 181
182 //----------------------------------------------------------------------------- 182 //-----------------------------------------------------------------------------
183 183
(...skipping 28 matching lines...) Expand all
212 } 212 }
213 213
214 TEST(ObjectWatcherTest, ExecuteMultipleTimes) { 214 TEST(ObjectWatcherTest, ExecuteMultipleTimes) {
215 RunTest_ExecuteMultipleTimes(MessageLoop::TYPE_DEFAULT); 215 RunTest_ExecuteMultipleTimes(MessageLoop::TYPE_DEFAULT);
216 RunTest_ExecuteMultipleTimes(MessageLoop::TYPE_IO); 216 RunTest_ExecuteMultipleTimes(MessageLoop::TYPE_IO);
217 RunTest_ExecuteMultipleTimes(MessageLoop::TYPE_UI); 217 RunTest_ExecuteMultipleTimes(MessageLoop::TYPE_UI);
218 } 218 }
219 219
220 } // namespace win 220 } // namespace win
221 } // namespace base 221 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698