Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Unified Diff: content/browser/renderer_host/render_widget_host_view_browsertest.cc

Issue 2779713002: Add a test checking that compositor works in a reused renderer. (Closed)
Patch Set: Reformat test page Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/renderer_host/delegated_frame_host.cc ('k') | content/test/data/page_with_animation.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/render_widget_host_view_browsertest.cc
diff --git a/content/browser/renderer_host/render_widget_host_view_browsertest.cc b/content/browser/renderer_host/render_widget_host_view_browsertest.cc
index fb74aa1d646c48c1c79c7859fcee99314247875f..2eb79515a7bdbf3ad97403b9954dc4cc6c8f334c 100644
--- a/content/browser/renderer_host/render_widget_host_view_browsertest.cc
+++ b/content/browser/renderer_host/render_widget_host_view_browsertest.cc
@@ -21,6 +21,8 @@
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/browser/renderer_host/render_widget_host_view_frame_subscriber.h"
+#include "content/common/frame_messages.h"
+#include "content/common/view_messages.h"
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
@@ -30,10 +32,12 @@
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
+#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "media/base/video_frame.h"
#include "media/renderers/skcanvas_video_renderer.h"
#include "net/base/filename_util.h"
+#include "net/dns/mock_host_resolver.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "ui/base/layout.h"
@@ -202,6 +206,101 @@ class RenderWidgetHostViewBrowserTest : public ContentBrowserTest {
int frames_captured_;
};
+class SwapCompositorFrameWaiter : public WebContentsObserver {
Saman Sami 2017/04/03 21:51:30 This class is very similar to content::FrameWatche
Alexander Semashko 2017/04/17 18:16:20 Done. Adding timeout to FrameWatcher is not worth
+ public:
+ explicit SwapCompositorFrameWaiter(WebContents* web_contents)
+ : WebContentsObserver(web_contents) {}
+
+ void Wait() { RunThisRunLoop(&run_loop_); }
+
+ void WaitWithTimeout(const base::TimeDelta& timeout) {
+ BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
+ run_loop_.QuitClosure(), timeout);
+ Wait();
+ }
+
+ bool frame_swapped() const { return frame_swapped_; }
+
+ private:
+ void OnSwapCompositorFrame() {
+ frame_swapped_ = true;
+ run_loop_.Quit();
+ }
+
+ bool OnMessageReceived(const IPC::Message& message) override {
+ IPC_BEGIN_MESSAGE_MAP(SwapCompositorFrameWaiter, message)
+ IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_SwapCompositorFrame,
+ OnSwapCompositorFrame())
+ IPC_END_MESSAGE_MAP()
+ return false;
+ }
+
+ base::RunLoop run_loop_;
+ bool frame_swapped_ = false;
+
+ DISALLOW_COPY_AND_ASSIGN(SwapCompositorFrameWaiter);
+};
+
+// Helps to ensure that a navigation is committed after a compositor frame was
+// submitted by the renderer, but before corresponding ACK is sent back.
+class CommitBeforeSwapAckSentHelper : public WebContentsObserver {
+ public:
+ explicit CommitBeforeSwapAckSentHelper(WebContents* web_contents)
+ : WebContentsObserver(web_contents) {}
+
+ private:
+ void WaitForSwapCompositorFrame() {
+ SwapCompositorFrameWaiter(web_contents()).Wait();
+ }
+
+ bool OnMessageReceived(const IPC::Message& message,
+ RenderFrameHost* rfh) override {
+ IPC_BEGIN_MESSAGE_MAP(CommitBeforeSwapAckSentHelper, message)
+ IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad,
+ WaitForSwapCompositorFrame())
+ IPC_END_MESSAGE_MAP()
+ return false;
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(CommitBeforeSwapAckSentHelper);
+};
+
+using RenderWidgetHostViewBrowserTestBase = ContentBrowserTest;
+
+IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTestBase,
+ SendFrameSwapAckOnNavigateAway) {
+ host_resolver()->AddRule("*", "127.0.0.1");
+ ASSERT_TRUE(embedded_test_server()->Start());
+ // Load a page that draws new frames infinitely.
+ NavigateToURL(shell(),
+ embedded_test_server()->GetURL("/page_with_animation.html"));
+
+ // Open a new page in the same renderer to keep it alive.
+ ShellAddedObserver shao;
+ EXPECT_TRUE(
+ ExecuteScript(shell()->web_contents(), "window.open('about:blank');"));
+ EXPECT_TRUE(WaitForLoadStop(shao.GetShell()->web_contents()));
+
+ // Start a cross-process navigation.
+ shell()->LoadURL(embedded_test_server()->GetURL("foo.com", "/title1.html"));
+
+ // When the navigation is about to commit, wait for the next frame to be
+ // submitted by the renderer before proceeding with page load.
+ {
+ CommitBeforeSwapAckSentHelper commit_helper(shell()->web_contents());
+ EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
+ EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(),
+ shao.GetShell()->web_contents()->GetRenderProcessHost());
+ }
+
+ // Go back and verify that the renderer continues to draw new frames.
+ shell()->GoBackOrForward(-1);
+ EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
+ SwapCompositorFrameWaiter frame_waiter(shell()->web_contents());
+ frame_waiter.WaitWithTimeout(base::TimeDelta::FromMilliseconds(500));
+ EXPECT_TRUE(frame_waiter.frame_swapped());
+}
+
enum CompositingMode {
GL_COMPOSITING,
SOFTWARE_COMPOSITING,
« no previous file with comments | « content/browser/renderer_host/delegated_frame_host.cc ('k') | content/test/data/page_with_animation.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698