Commit 4ca68f95 authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

Test loading and painting a page from the network without BEST_EFFORT tasks.

We want to experiment with scheduling features that can increase the
completion time of BEST_EFFORT tasks a lot. Before we do this, we want
to make sure that BEST_EFFORT tasks are not required to complete
important user actions (navigation, scrolling, omnibox).

Bug: 831835
Change-Id: I5b935172e0349b7f74fd6120109e1e50cb8d1653
Reviewed-on: https://chromium-review.googlesource.com/c/1307834
Commit-Queue: François Doray <fdoray@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604255}
parent b718554b
...@@ -12,32 +12,47 @@ ...@@ -12,32 +12,47 @@
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace { namespace {
class RunLoopUntilNonEmptyPaint : public content::WebContentsObserver { class RunLoopUntilLoadedAndPainted : public content::WebContentsObserver {
public: public:
explicit RunLoopUntilNonEmptyPaint(content::WebContents* web_contents) explicit RunLoopUntilLoadedAndPainted(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {} : content::WebContentsObserver(web_contents) {}
~RunLoopUntilNonEmptyPaint() override = default; ~RunLoopUntilLoadedAndPainted() override = default;
// Runs a RunLoop on the main thread until the first non-empty frame is // Runs a RunLoop on the main thread until the first non-empty frame is
// painted for the WebContents provided to the constructor. // painted and the load is complete for the WebContents provided to the
void RunUntilNonEmptyPaint() { // constructor.
if (web_contents()->CompletedFirstVisuallyNonEmptyPaint()) void Run() {
if (LoadedAndPainted())
return; return;
run_loop_.Run(); run_loop_.Run();
} }
private: private:
bool LoadedAndPainted() {
return web_contents()->CompletedFirstVisuallyNonEmptyPaint() &&
!web_contents()->IsLoading();
}
// content::WebContentsObserver: // content::WebContentsObserver:
void DidFirstVisuallyNonEmptyPaint() override { run_loop_.Quit(); } void DidFirstVisuallyNonEmptyPaint() override {
if (LoadedAndPainted())
run_loop_.Quit();
}
void DidStopLoading() override {
if (LoadedAndPainted())
run_loop_.Quit();
}
base::RunLoop run_loop_; base::RunLoop run_loop_;
DISALLOW_COPY_AND_ASSIGN(RunLoopUntilNonEmptyPaint); DISALLOW_COPY_AND_ASSIGN(RunLoopUntilLoadedAndPainted);
}; };
class NoBestEffortTasksTest : public InProcessBrowserTest { class NoBestEffortTasksTest : public InProcessBrowserTest {
...@@ -55,22 +70,39 @@ class NoBestEffortTasksTest : public InProcessBrowserTest { ...@@ -55,22 +70,39 @@ class NoBestEffortTasksTest : public InProcessBrowserTest {
} // namespace } // namespace
// Verify that it is possible to get the first non-empty paint without running // Verify that it is possible to load and paint the initial about:blank page
// BEST_EFFORT tasks. // without running BEST_EFFORT tasks.
// //
// TODO(fdoray) https://crbug.com/833989: // TODO(fdoray) https://crbug.com/833989: Times out on Win and ChromeOS ASAN.
// - Flaky timeout on ChromeOS ASAN
// - Consistent timeout on Win ASAN
#if defined(ADDRESS_SANITIZER) && (defined(OS_CHROMEOS) || defined(OS_WIN)) #if defined(ADDRESS_SANITIZER) && (defined(OS_CHROMEOS) || defined(OS_WIN))
#define MAYBE_FirstNonEmptyPaintWithoutBestEffortTasks \ #define MAYBE_LoadAndPaintAboutBlank DISABLED_LoadAndPaintAboutBlank
DISABLED_FirstNonEmptyPaintWithoutBestEffortTasks
#else #else
#define MAYBE_FirstNonEmptyPaintWithoutBestEffortTasks \ #define MAYBE_LoadAndPaintAboutBlank LoadAndPaintAboutBlank
FirstNonEmptyPaintWithoutBestEffortTasks
#endif #endif
IN_PROC_BROWSER_TEST_F(NoBestEffortTasksTest, IN_PROC_BROWSER_TEST_F(NoBestEffortTasksTest, MAYBE_LoadAndPaintAboutBlank) {
MAYBE_FirstNonEmptyPaintWithoutBestEffortTasks) { content::WebContents* const web_contents =
RunLoopUntilNonEmptyPaint run_loop_until_non_empty_paint( browser()->tab_strip_model()->GetActiveWebContents();
browser()->tab_strip_model()->GetActiveWebContents()); EXPECT_TRUE(web_contents->GetLastCommittedURL().IsAboutBlank());
run_loop_until_non_empty_paint.RunUntilNonEmptyPaint();
RunLoopUntilLoadedAndPainted run_until_loaded_and_painted(web_contents);
run_until_loaded_and_painted.Run();
}
// Verify that it is possible to load and paint a page from the network without
// running BEST_EFFORT tasks.
//
// This test has more dependencies than LoadAndPaintAboutBlank, including
// loading cookies.
IN_PROC_BROWSER_TEST_F(NoBestEffortTasksTest, LoadAndPaintFromNetwork) {
ASSERT_TRUE(embedded_test_server()->Start());
content::OpenURLParams open(
embedded_test_server()->GetURL("a.com", "/empty.html"),
content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB,
ui::PAGE_TRANSITION_TYPED, false);
content::WebContents* const web_contents = browser()->OpenURL(open);
EXPECT_TRUE(web_contents->IsLoading());
RunLoopUntilLoadedAndPainted run_until_loaded_and_painted(web_contents);
run_until_loaded_and_painted.Run();
} }
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