OLD | NEW |
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 "chrome/browser/multi_process_notification.h" | 5 #include "chrome/browser/multi_process_notification.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/test/multiprocess_test.h" | 12 #include "base/test/multiprocess_test.h" |
13 #include "base/test/test_timeouts.h" | 13 #include "base/test/test_timeouts.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "testing/multiprocess_func_list.h" | 16 #include "testing/multiprocess_func_list.h" |
17 | 17 |
18 #if defined(OS_MACOSX) | 18 #if defined(OS_POSIX) |
19 // TODO(dmaclach): Remove defined(OS_MACOSX) once | 19 // TODO(ajwong): Remove defined(OS_POSIX) restriction once |
20 // MultiProcessNotification is implemented on Win/Linux. | 20 // MultiProcessNotification is implemented on Win. |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 const char kStartedNotificationName[] = "MultiProcessTestStartedNotification"; | 24 const char kStartedNotificationName[] = "MultiProcessTestStartedNotification"; |
25 const char kQuitNotificationName[] = "MultiProcessTestQuitNotification"; | 25 const char kQuitNotificationName[] = "MultiProcessTestQuitNotification"; |
26 | 26 |
27 void SpinRunLoop(int milliseconds) { | 27 void SpinRunLoop(int milliseconds) { |
28 MessageLoop *loop = MessageLoop::current(); | 28 MessageLoop *loop = MessageLoop::current(); |
29 | 29 |
30 // Post a quit task so that this loop eventually ends and we don't hang | 30 // Post a quit task so that this loop eventually ends and we don't hang |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 case multi_process_notification::SystemDomain: | 237 case multi_process_notification::SystemDomain: |
238 ASSERT_FALSE(profile_quitter.WasNotificationReceived()); | 238 ASSERT_FALSE(profile_quitter.WasNotificationReceived()); |
239 ASSERT_FALSE(user_quitter.WasNotificationReceived()); | 239 ASSERT_FALSE(user_quitter.WasNotificationReceived()); |
240 ASSERT_TRUE(system_quitter.WasNotificationReceived()); | 240 ASSERT_TRUE(system_quitter.WasNotificationReceived()); |
241 break; | 241 break; |
242 } | 242 } |
243 } | 243 } |
244 | 244 |
245 TEST_F(MultiProcessNotificationTest, BasicCreationTest) { | 245 TEST_F(MultiProcessNotificationTest, BasicCreationTest) { |
246 QuitterDelegate quitter; | 246 QuitterDelegate quitter; |
| 247 MessageLoop* message_loop = IOMessageLoop(); |
| 248 |
| 249 multi_process_notification::Listener profile_listener( |
| 250 "BasicCreationTest", multi_process_notification::ProfileDomain, &quitter); |
| 251 ASSERT_TRUE(profile_listener.Start(message_loop)); |
| 252 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); |
| 253 ASSERT_TRUE(quitter.WasStartedReceived()); |
| 254 |
247 multi_process_notification::Listener local_listener( | 255 multi_process_notification::Listener local_listener( |
248 "BasicCreationTest", multi_process_notification::UserDomain, &quitter); | 256 "BasicCreationTest", multi_process_notification::UserDomain, &quitter); |
249 MessageLoop* message_loop = IOMessageLoop(); | |
250 ASSERT_TRUE(local_listener.Start(message_loop)); | 257 ASSERT_TRUE(local_listener.Start(message_loop)); |
251 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); | 258 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); |
252 ASSERT_TRUE(quitter.WasStartedReceived()); | 259 ASSERT_TRUE(quitter.WasStartedReceived()); |
| 260 |
253 multi_process_notification::Listener system_listener( | 261 multi_process_notification::Listener system_listener( |
254 "BasicCreationTest", multi_process_notification::SystemDomain, &quitter); | 262 "BasicCreationTest", multi_process_notification::SystemDomain, &quitter); |
255 ASSERT_TRUE(system_listener.Start(message_loop)); | 263 ASSERT_TRUE(system_listener.Start(message_loop)); |
256 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); | 264 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); |
257 ASSERT_TRUE(quitter.WasStartedReceived()); | 265 ASSERT_TRUE(quitter.WasStartedReceived()); |
| 266 } |
258 | 267 |
259 multi_process_notification::Listener local_listener2( | 268 TEST_F(MultiProcessNotificationTest, ListenOnNonIoThread) { |
260 "BasicCreationTest", multi_process_notification::UserDomain, &quitter); | 269 QuitterDelegate quitter; |
| 270 multi_process_notification::Listener local_listener( |
| 271 "ListenOnNonIoThread", multi_process_notification::UserDomain, &quitter); |
261 // Should fail because current message loop should not be an IOMessageLoop. | 272 // Should fail because current message loop should not be an IOMessageLoop. |
262 ASSERT_FALSE(local_listener2.Start(MessageLoop::current())); | 273 ASSERT_FALSE(local_listener.Start(MessageLoop::current())); |
263 } | 274 } |
264 | 275 |
265 TEST_F(MultiProcessNotificationTest, PostInProcessNotification) { | 276 TEST_F(MultiProcessNotificationTest, PostInProcessNotification) { |
266 std::string local_notification("QuitLocalNotification"); | 277 std::string local_notification("QuitLocalNotification"); |
267 QuitterDelegate quitter; | 278 QuitterDelegate quitter; |
| 279 MessageLoop* message_loop = IOMessageLoop(); |
| 280 |
268 multi_process_notification::Listener listener( | 281 multi_process_notification::Listener listener( |
269 local_notification, multi_process_notification::UserDomain, &quitter); | 282 local_notification, multi_process_notification::UserDomain, &quitter); |
270 MessageLoop* message_loop = IOMessageLoop(); | |
271 ASSERT_TRUE(listener.Start(message_loop)); | 283 ASSERT_TRUE(listener.Start(message_loop)); |
272 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); | 284 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); |
273 ASSERT_TRUE(quitter.WasStartedReceived()); | 285 ASSERT_TRUE(quitter.WasStartedReceived()); |
| 286 |
274 ASSERT_TRUE(multi_process_notification::Post( | 287 ASSERT_TRUE(multi_process_notification::Post( |
275 local_notification, multi_process_notification::UserDomain)); | 288 local_notification, multi_process_notification::UserDomain)); |
276 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); | 289 SpinRunLoop(TestTimeouts::action_max_timeout_ms()); |
277 ASSERT_TRUE(quitter.WasNotificationReceived()); | 290 ASSERT_TRUE(quitter.WasNotificationReceived()); |
278 } | 291 } |
279 | 292 |
280 TEST_F(MultiProcessNotificationTest, MultiListener) { | 293 TEST_F(MultiProcessNotificationTest, MultiListener) { |
281 std::string local_notification("LocalNotification"); | 294 std::string local_notification("LocalNotification"); |
282 std::string quit_local_notification("QuitLocalNotification"); | 295 std::string quit_local_notification("QuitLocalNotification"); |
283 | 296 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 } | 357 } |
345 | 358 |
346 MULTIPROCESS_TEST_MAIN(MultiProcessUserNotificationMain) { | 359 MULTIPROCESS_TEST_MAIN(MultiProcessUserNotificationMain) { |
347 return MultiProcessNotificationMain(multi_process_notification::UserDomain); | 360 return MultiProcessNotificationMain(multi_process_notification::UserDomain); |
348 } | 361 } |
349 | 362 |
350 MULTIPROCESS_TEST_MAIN(MultiProcessSystemNotificationMain) { | 363 MULTIPROCESS_TEST_MAIN(MultiProcessSystemNotificationMain) { |
351 return MultiProcessNotificationMain(multi_process_notification::SystemDomain); | 364 return MultiProcessNotificationMain(multi_process_notification::SystemDomain); |
352 } | 365 } |
353 | 366 |
354 #endif // defined(OS_MACOSX) | 367 #endif // defined(OS_POSIX) |
OLD | NEW |