Chromium Code Reviews| Index: content/public/test/test_utils.cc |
| =================================================================== |
| --- content/public/test/test_utils.cc (revision 202993) |
| +++ content/public/test/test_utils.cc (working copy) |
| @@ -5,6 +5,7 @@ |
| #include "content/public/test/test_utils.h" |
| #include "base/bind.h" |
| +#include "base/lazy_instance.h" |
| #include "base/message_loop.h" |
| #include "base/run_loop.h" |
| #include "base/utf_string_conversions.h" |
| @@ -18,6 +19,12 @@ |
| namespace { |
| +base::LazyInstance<std::vector<RunMessageLoopHook> >::Leaky |
| + g_pre_run_message_loop_hooks = LAZY_INSTANCE_INITIALIZER; |
| + |
| +base::LazyInstance<std::vector<RunMessageLoopHook> >::Leaky |
| + g_post_run_message_loop_hooks = LAZY_INSTANCE_INITIALIZER; |
| + |
| // Number of times to repost a Quit task so that the MessageLoop finishes up |
| // pending tasks and tasks posted by those pending tasks without risking the |
| // potential hang behavior of MessageLoop::QuitWhenIdle. |
| @@ -78,19 +85,23 @@ |
| base::MessageLoop::ScopedNestableTaskAllower allow( |
| base::MessageLoop::current()); |
| - // If we're running inside a browser test, we might need to allow the test |
| - // launcher to do extra work before/after running a nested message loop. |
| - TestLauncherDelegate* delegate = NULL; |
| -#if !defined(OS_IOS) |
| - delegate = GetCurrentTestLauncherDelegate(); |
| -#endif |
| - if (delegate) |
| - delegate->PreRunMessageLoop(run_loop); |
| + for (size_t i = 0; i < g_pre_run_message_loop_hooks.Get().size(); i++) |
|
sky
2013/05/31 19:27:03
Should this use ObserverList for the case of the l
Paweł Hajdan Jr.
2013/05/31 19:50:15
Good question.
ObserverList<RunMessageLoopHook>::
|
| + g_pre_run_message_loop_hooks.Get()[i].Run(run_loop); |
| + |
| run_loop->Run(); |
| - if (delegate) |
| - delegate->PostRunMessageLoop(); |
| + |
| + for (size_t i = 0; i < g_pre_run_message_loop_hooks.Get().size(); i++) |
| + g_post_run_message_loop_hooks.Get()[i].Run(run_loop); |
| } |
| +void AddPreRunMessageLoopHook(const RunMessageLoopHook& hook) { |
| + g_pre_run_message_loop_hooks.Get().push_back(hook); |
| +} |
| + |
| +void AddPostRunMessageLoopHook(const RunMessageLoopHook& hook) { |
| + g_post_run_message_loop_hooks.Get().push_back(hook); |
| +} |
| + |
| void RunAllPendingInMessageLoop() { |
| base::MessageLoop::current()->PostTask( |
| FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |