Commit 6c26f334 authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

[TaskScheduler] Handle early first paint in NoBackgroundTasksTest.

NoBackgroundTasksTest.FirstNonEmptyPaintWithoutBackgroundTasks is a
test that verifies that the first paint in a tab can happen when
TaskPriority::BEST_EFFORT tasks don't run.

Before this CL, the test's body ran a RunLoop until
WebContentsObserver::DidFirstVisuallyNonEmptyPaint() was invoked.
A timeout occured if the first paint occured before the test's body
was entered. Having the first paint before the test's body is
possible, because InProcessBrowserTest::PreRunTestOnMainThread()
runs tasks before jumping to the test's body (see
https://cs.chromium.org/chromium/src/chrome/test/base/in_process_browser_test.cc?l=486&rcl=8edfdb37ebe40b1ba4dae27a23d8edaeac09a0ee).

This CL fixes the issue by skipping running the RunLoop if
WebContents::CompletedFirstVisuallyNonEmptyPaint() is already
true at the beginning of the test's body.

This is one of multiple fixes that will allow us to enable the
test on ChromeOS.

Bug: 833989
Change-Id: I0ce024bda351059c4e0ba8648e1f0f0459eb19ac
Reviewed-on: https://chromium-review.googlesource.com/1187131Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585884}
parent b9264ba9
......@@ -25,7 +25,11 @@ class RunLoopUntilNonEmptyPaint : public content::WebContentsObserver {
// Runs a RunLoop on the main thread until the first non-empty frame is
// painted for the WebContents provided to the constructor.
void RunUntilIdle() { run_loop_.Run(); }
void RunUntilNonEmptyPaint() {
if (web_contents()->CompletedFirstVisuallyNonEmptyPaint())
return;
run_loop_.Run();
}
private:
// content::WebContentsObserver:
......@@ -70,5 +74,5 @@ IN_PROC_BROWSER_TEST_F(NoBackgroundTasksTest,
MAYBE_FirstNonEmptyPaintWithoutBackgroundTasks) {
RunLoopUntilNonEmptyPaint run_loop_until_non_empty_paint(
browser()->tab_strip_model()->GetActiveWebContents());
run_loop_until_non_empty_paint.RunUntilIdle();
run_loop_until_non_empty_paint.RunUntilNonEmptyPaint();
}
......@@ -6143,12 +6143,12 @@ bool WebContentsImpl::GetAllowOtherViews() {
return view_->GetAllowOtherViews();
}
#endif
bool WebContentsImpl::CompletedFirstVisuallyNonEmptyPaint() const {
return did_first_visually_non_empty_paint_;
}
#endif
void WebContentsImpl::OnDidDownloadImage(
ImageDownloadCallback callback,
int id,
......
......@@ -455,6 +455,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
void SetShowingContextMenu(bool showing) override;
void PausePageScheduledTasks(bool paused) override;
BrowserPluginGuest* GetBrowserPluginGuest() const override;
bool CompletedFirstVisuallyNonEmptyPaint() const override;
#if defined(OS_ANDROID)
base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents() override;
......@@ -465,7 +466,6 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
#elif defined(OS_MACOSX)
void SetAllowOtherViews(bool allow) override;
bool GetAllowOtherViews() override;
bool CompletedFirstVisuallyNonEmptyPaint() const override;
#endif
bool HasRecentInteractiveInputEvent() const override;
......
......@@ -916,10 +916,11 @@ class WebContents : public PageNavigator,
// Returns true if other views are allowed, false otherwise.
virtual bool GetAllowOtherViews() = 0;
#endif // OS_ANDROID
// Returns true if the WebContents has completed its first meaningful paint.
// Returns true if the WebContents has completed its first meaningful paint
// since the last navigation.
virtual bool CompletedFirstVisuallyNonEmptyPaint() const = 0;
#endif // OS_ANDROID
// TODO(https://crbug.com/826293): This is a simple mitigation to validate
// that an action that requires a user gesture actually has one in the
......
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