| Index: content/test/test_navigation_observer.cc
|
| diff --git a/content/test/test_navigation_observer.cc b/content/test/test_navigation_observer.cc
|
| index 89ff36fd575feb8ec98c98463596d8c7442c5a2e..92dea533ab041a28332e894049d826a674b7e7f4 100644
|
| --- a/content/test/test_navigation_observer.cc
|
| +++ b/content/test/test_navigation_observer.cc
|
| @@ -14,6 +14,21 @@
|
|
|
| namespace content {
|
|
|
| +namespace {
|
| +
|
| +// Allow some pending tasks and up to |num_deferrals| generations to complete.
|
| +static void DeferQuitWithID(const MessageLoop::RunID& run_id,
|
| + int num_deferrals) {
|
| + if (num_deferrals <= 0) {
|
| + MessageLoop::current()->QuitNowWithID(run_id);
|
| + } else {
|
| + MessageLoop::current()->PostTask(
|
| + FROM_HERE, base::Bind(&DeferQuitWithID, run_id, num_deferrals - 1));
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| // This class observes |render_view_host| and calls OnJsInjectionReady() of
|
| // |js_injection_ready_observer| when the time is right to inject JavaScript
|
| // into the page.
|
| @@ -84,11 +99,13 @@ void TestNavigationObserver::WaitForObservation(
|
| }
|
|
|
| void TestNavigationObserver::Wait() {
|
| + MessageLoop::RunID run_id = MessageLoop::current()->GetRunID();
|
| + // Number of times to repost QuitNow task to allow pending tasks to complete:
|
| + const int num_quit_deferrals = 20;
|
| WaitForObservation(
|
| - base::Bind(&MessageLoop::Run,
|
| - base::Unretained(MessageLoop::current())),
|
| - base::Bind(&MessageLoop::Quit,
|
| - base::Unretained(MessageLoop::current())));
|
| + base::Bind(&MessageLoop::RunWithID,
|
| + base::Unretained(MessageLoop::current()), run_id),
|
| + base::Bind(&DeferQuitWithID, run_id, num_quit_deferrals));
|
| }
|
|
|
| TestNavigationObserver::TestNavigationObserver(
|
| @@ -131,8 +148,10 @@ void TestNavigationObserver::Observe(
|
| ++navigations_completed_ == number_of_navigations_) {
|
| navigation_started_ = false;
|
| done_ = true;
|
| - if (running_)
|
| + if (running_) {
|
| + running_ = false;
|
| done_callback_.Run();
|
| + }
|
| }
|
| break;
|
| case NOTIFICATION_RENDER_VIEW_HOST_CREATED:
|
|
|