Commit db9f22ca authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[Flaky] Use RunLoop to fix repeated moving

Most likely, `std::move(*quit_task).Run();` could be called twice for
the same |quit_task| at times. By introducing a RunLoop, it doesn't
matter (anymore) how often the loop is quit.

This should fix the flaky crashes of this test as described in the
linked bug.

Bug: 1030275
Change-Id: I9509d474cc950362996f31a879034fb01ca5303c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1948895
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721478}
parent 51431c56
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
...@@ -80,21 +81,20 @@ class BookmarkBrowsertest : public InProcessBrowserTest { ...@@ -80,21 +81,20 @@ class BookmarkBrowsertest : public InProcessBrowserTest {
return browser()->bookmark_bar_state() == BookmarkBar::SHOW; return browser()->bookmark_bar_state() == BookmarkBar::SHOW;
} }
static void CheckAnimation(Browser* browser, base::OnceClosure* quit_task) { static void CheckAnimation(Browser* browser, base::RepeatingClosure quit) {
if (!browser->window()->IsBookmarkBarAnimating()) if (!browser->window()->IsBookmarkBarAnimating())
std::move(*quit_task).Run(); quit.Run();
} }
base::TimeDelta WaitForBookmarkBarAnimationToFinish() { base::TimeDelta WaitForBookmarkBarAnimationToFinish() {
base::Time start(base::Time::Now()); base::Time start(base::Time::Now());
scoped_refptr<content::MessageLoopRunner> runner = base::RunLoop loop;
new content::MessageLoopRunner;
base::OnceClosure quit_closure = runner->QuitClosure();
base::RepeatingTimer timer; base::RepeatingTimer timer;
timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(15), timer.Start(
base::BindRepeating(&CheckAnimation, browser(), &quit_closure)); FROM_HERE, base::TimeDelta::FromMilliseconds(15),
runner->Run(); base::BindRepeating(&CheckAnimation, browser(), loop.QuitClosure()));
loop.Run();
return base::Time::Now() - start; return base::Time::Now() - start;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment