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

Side by Side 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, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/barrier_closure.h" 8 #include "base/barrier_closure.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "cc/paint/skia_paint_canvas.h" 17 #include "cc/paint/skia_paint_canvas.h"
18 #include "content/browser/gpu/compositor_util.h" 18 #include "content/browser/gpu/compositor_util.h"
19 #include "content/browser/gpu/gpu_data_manager_impl.h" 19 #include "content/browser/gpu/gpu_data_manager_impl.h"
20 #include "content/browser/renderer_host/dip_util.h" 20 #include "content/browser/renderer_host/dip_util.h"
21 #include "content/browser/renderer_host/render_widget_host_impl.h" 21 #include "content/browser/renderer_host/render_widget_host_impl.h"
22 #include "content/browser/renderer_host/render_widget_host_view_base.h" 22 #include "content/browser/renderer_host/render_widget_host_view_base.h"
23 #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber .h" 23 #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber .h"
24 #include "content/common/frame_messages.h"
25 #include "content/common/view_messages.h"
24 #include "content/public/browser/gpu_data_manager.h" 26 #include "content/public/browser/gpu_data_manager.h"
25 #include "content/public/browser/render_view_host.h" 27 #include "content/public/browser/render_view_host.h"
26 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
27 #include "content/public/common/content_paths.h" 29 #include "content/public/common/content_paths.h"
28 #include "content/public/common/content_switches.h" 30 #include "content/public/common/content_switches.h"
29 #include "content/public/common/url_constants.h" 31 #include "content/public/common/url_constants.h"
30 #include "content/public/test/browser_test_utils.h" 32 #include "content/public/test/browser_test_utils.h"
31 #include "content/public/test/content_browser_test.h" 33 #include "content/public/test/content_browser_test.h"
32 #include "content/public/test/content_browser_test_utils.h" 34 #include "content/public/test/content_browser_test_utils.h"
35 #include "content/public/test/test_utils.h"
33 #include "content/shell/browser/shell.h" 36 #include "content/shell/browser/shell.h"
34 #include "media/base/video_frame.h" 37 #include "media/base/video_frame.h"
35 #include "media/renderers/skcanvas_video_renderer.h" 38 #include "media/renderers/skcanvas_video_renderer.h"
36 #include "net/base/filename_util.h" 39 #include "net/base/filename_util.h"
40 #include "net/dns/mock_host_resolver.h"
37 #include "third_party/skia/include/core/SkBitmap.h" 41 #include "third_party/skia/include/core/SkBitmap.h"
38 #include "third_party/skia/include/core/SkCanvas.h" 42 #include "third_party/skia/include/core/SkCanvas.h"
39 #include "ui/base/layout.h" 43 #include "ui/base/layout.h"
40 #include "ui/base/ui_base_switches.h" 44 #include "ui/base/ui_base_switches.h"
41 #include "ui/display/display_switches.h" 45 #include "ui/display/display_switches.h"
42 #include "ui/gfx/geometry/size_conversions.h" 46 #include "ui/gfx/geometry/size_conversions.h"
43 #include "ui/gl/gl_switches.h" 47 #include "ui/gl/gl_switches.h"
44 48
45 #if defined(OS_WIN) 49 #if defined(OS_WIN)
46 #include "base/win/windows_version.h" 50 #include "base/win/windows_version.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 run_loop.Run(); 199 run_loop.Run();
196 } 200 }
197 201
198 private: 202 private:
199 const gfx::Size frame_size_; 203 const gfx::Size frame_size_;
200 base::FilePath test_dir_; 204 base::FilePath test_dir_;
201 int callback_invoke_count_; 205 int callback_invoke_count_;
202 int frames_captured_; 206 int frames_captured_;
203 }; 207 };
204 208
209 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
210 public:
211 explicit SwapCompositorFrameWaiter(WebContents* web_contents)
212 : WebContentsObserver(web_contents) {}
213
214 void Wait() { RunThisRunLoop(&run_loop_); }
215
216 void WaitWithTimeout(const base::TimeDelta& timeout) {
217 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
218 run_loop_.QuitClosure(), timeout);
219 Wait();
220 }
221
222 bool frame_swapped() const { return frame_swapped_; }
223
224 private:
225 void OnSwapCompositorFrame() {
226 frame_swapped_ = true;
227 run_loop_.Quit();
228 }
229
230 bool OnMessageReceived(const IPC::Message& message) override {
231 IPC_BEGIN_MESSAGE_MAP(SwapCompositorFrameWaiter, message)
232 IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_SwapCompositorFrame,
233 OnSwapCompositorFrame())
234 IPC_END_MESSAGE_MAP()
235 return false;
236 }
237
238 base::RunLoop run_loop_;
239 bool frame_swapped_ = false;
240
241 DISALLOW_COPY_AND_ASSIGN(SwapCompositorFrameWaiter);
242 };
243
244 // Helps to ensure that a navigation is committed after a compositor frame was
245 // submitted by the renderer, but before corresponding ACK is sent back.
246 class CommitBeforeSwapAckSentHelper : public WebContentsObserver {
247 public:
248 explicit CommitBeforeSwapAckSentHelper(WebContents* web_contents)
249 : WebContentsObserver(web_contents) {}
250
251 private:
252 void WaitForSwapCompositorFrame() {
253 SwapCompositorFrameWaiter(web_contents()).Wait();
254 }
255
256 bool OnMessageReceived(const IPC::Message& message,
257 RenderFrameHost* rfh) override {
258 IPC_BEGIN_MESSAGE_MAP(CommitBeforeSwapAckSentHelper, message)
259 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad,
260 WaitForSwapCompositorFrame())
261 IPC_END_MESSAGE_MAP()
262 return false;
263 }
264
265 DISALLOW_COPY_AND_ASSIGN(CommitBeforeSwapAckSentHelper);
266 };
267
268 using RenderWidgetHostViewBrowserTestBase = ContentBrowserTest;
269
270 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTestBase,
271 SendFrameSwapAckOnNavigateAway) {
272 host_resolver()->AddRule("*", "127.0.0.1");
273 ASSERT_TRUE(embedded_test_server()->Start());
274 // Load a page that draws new frames infinitely.
275 NavigateToURL(shell(),
276 embedded_test_server()->GetURL("/page_with_animation.html"));
277
278 // Open a new page in the same renderer to keep it alive.
279 ShellAddedObserver shao;
280 EXPECT_TRUE(
281 ExecuteScript(shell()->web_contents(), "window.open('about:blank');"));
282 EXPECT_TRUE(WaitForLoadStop(shao.GetShell()->web_contents()));
283
284 // Start a cross-process navigation.
285 shell()->LoadURL(embedded_test_server()->GetURL("foo.com", "/title1.html"));
286
287 // When the navigation is about to commit, wait for the next frame to be
288 // submitted by the renderer before proceeding with page load.
289 {
290 CommitBeforeSwapAckSentHelper commit_helper(shell()->web_contents());
291 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
292 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(),
293 shao.GetShell()->web_contents()->GetRenderProcessHost());
294 }
295
296 // Go back and verify that the renderer continues to draw new frames.
297 shell()->GoBackOrForward(-1);
298 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
299 SwapCompositorFrameWaiter frame_waiter(shell()->web_contents());
300 frame_waiter.WaitWithTimeout(base::TimeDelta::FromMilliseconds(500));
301 EXPECT_TRUE(frame_waiter.frame_swapped());
302 }
303
205 enum CompositingMode { 304 enum CompositingMode {
206 GL_COMPOSITING, 305 GL_COMPOSITING,
207 SOFTWARE_COMPOSITING, 306 SOFTWARE_COMPOSITING,
208 }; 307 };
209 308
210 class CompositingRenderWidgetHostViewBrowserTest 309 class CompositingRenderWidgetHostViewBrowserTest
211 : public RenderWidgetHostViewBrowserTest, 310 : public RenderWidgetHostViewBrowserTest,
212 public testing::WithParamInterface<CompositingMode> { 311 public testing::WithParamInterface<CompositingMode> {
213 public: 312 public:
214 CompositingRenderWidgetHostViewBrowserTest() 313 CompositingRenderWidgetHostViewBrowserTest()
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 kTestCompositingModes); 1035 kTestCompositingModes);
937 INSTANTIATE_TEST_CASE_P( 1036 INSTANTIATE_TEST_CASE_P(
938 GLAndSoftwareCompositing, 1037 GLAndSoftwareCompositing,
939 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, 1038 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI,
940 kTestCompositingModes); 1039 kTestCompositingModes);
941 1040
942 #endif // !defined(OS_ANDROID) 1041 #endif // !defined(OS_ANDROID)
943 1042
944 } // namespace 1043 } // namespace
945 } // namespace content 1044 } // namespace content
OLDNEW
« 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