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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_browsertest.cc

Issue 14495016: Fix flaky test: RenderWidgetHostViewBrowserTest.CopyFromBackingStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More clean-up. Fixes for Aura. Disabled tests for Android and IOS platforms. Created 7 years, 7 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 | Annotate | Revision Log
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/message_loop_proxy.h" 6 #include "base/message_loop_proxy.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "content/browser/gpu/gpu_data_manager_impl.h" 9 #include "content/browser/gpu/gpu_data_manager_impl.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h" 10 #include "content/browser/renderer_host/render_widget_host_impl.h"
11 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" 11 #include "content/port/browser/render_widget_host_view_frame_subscriber.h"
12 #include "content/port/browser/render_widget_host_view_port.h" 12 #include "content/port/browser/render_widget_host_view_port.h"
13 #include "content/public/browser/render_view_host.h" 13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/content_paths.h" 15 #include "content/public/common/content_paths.h"
16 #include "content/public/common/content_switches.h"
16 #include "content/shell/shell.h" 17 #include "content/shell/shell.h"
17 #include "content/test/content_browser_test.h" 18 #include "content/test/content_browser_test.h"
18 #include "content/test/content_browser_test_utils.h" 19 #include "content/test/content_browser_test_utils.h"
19 #include "media/base/video_frame.h" 20 #include "media/base/video_frame.h"
20 #include "net/base/net_util.h" 21 #include "net/base/net_util.h"
21 #include "skia/ext/platform_canvas.h"
22 #include "ui/compositor/compositor_setup.h" 22 #include "ui/compositor/compositor_setup.h"
23 #if defined(OS_MACOSX) 23 #if defined(OS_MACOSX)
24 #include "ui/surface/io_surface_support_mac.h" 24 #include "ui/surface/io_surface_support_mac.h"
25 #endif 25 #endif
26 26
27 namespace content { 27 namespace content {
28 namespace {
28 29
30 // Common base class for browser tests. This is subclassed twice: Once to test
31 // the browser in forced-compositing mode, and once to test with compositing
32 // mode disabled.
29 class RenderWidgetHostViewBrowserTest : public ContentBrowserTest { 33 class RenderWidgetHostViewBrowserTest : public ContentBrowserTest {
30 public: 34 public:
31 RenderWidgetHostViewBrowserTest() : finish_called_(false), size_(400, 300) {} 35 RenderWidgetHostViewBrowserTest()
36 : frame_size_(400, 300),
37 callback_invoke_count_(0),
38 frames_captured_(0) {}
32 39
33 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 40 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
41 ui::DisableTestCompositor();
34 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_dir_)); 42 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_dir_));
35 } 43 }
36 44
37 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 45 // Overridden in subclasses to source either a compositing surface or a
38 ui::DisableTestCompositor(); 46 // backing store.
47 virtual void SetUpSourceSurface() = 0;
48 virtual bool IsCopySourceReady() = 0;
49
50 int callback_invoke_count() const {
51 return callback_invoke_count_;
39 } 52 }
40 53
41 bool CheckAcceleratedCompositingActive() { 54 int frames_captured() const {
42 RenderWidgetHostImpl* impl = 55 return frames_captured_;
43 RenderWidgetHostImpl::From(
44 shell()->web_contents()->GetRenderWidgetHostView()->
45 GetRenderWidgetHost());
46 return impl->is_accelerated_compositing_active();
47 } 56 }
48 57
49 bool CheckCompositingSurface() { 58 const gfx::Size& frame_size() const {
50 #if defined(OS_WIN) 59 return frame_size_;
51 if (!GpuDataManagerImpl::GetInstance()->IsUsingAcceleratedSurface())
52 return false;
53 #endif
54
55 RenderViewHost* const rwh =
56 shell()->web_contents()->GetRenderViewHost();
57 RenderWidgetHostViewPort* rwhvp =
58 static_cast<RenderWidgetHostViewPort*>(rwh->GetView());
59 bool ret = !rwhvp->GetCompositingSurface().is_null();
60 #if defined(OS_MACOSX)
61 ret &= rwhvp->HasAcceleratedSurface(gfx::Size());
62 #endif
63 return ret;
64 } 60 }
65 61
66 bool SetupCompositingSurface() { 62 const base::FilePath& test_dir() const {
67 #if defined(OS_MACOSX) 63 return test_dir_;
68 if (!IOSurfaceSupport::Initialize()) 64 }
69 return false;
70 #endif
71 NavigateToURL(shell(), net::FilePathToFileURL(
72 test_dir_.AppendASCII("rwhv_compositing_animation.html")));
73 if (!CheckAcceleratedCompositingActive())
74 return false;
75 65
76 // The page is now accelerated composited but a compositing surface might 66 RenderViewHost* GetRenderViewHost() const {
77 // not be available immediately so wait for it. 67 RenderViewHost* const rvh = shell()->web_contents()->GetRenderViewHost();
78 while (!CheckCompositingSurface()) { 68 CHECK(rvh);
69 return rvh;
70 }
71
72 RenderWidgetHostImpl* GetRenderWidgetHost() const {
73 RenderWidgetHostImpl* const rwh = RenderWidgetHostImpl::From(
74 shell()->web_contents()->GetRenderWidgetHostView()->
75 GetRenderWidgetHost());
76 CHECK(rwh);
77 return rwh;
78 }
79
80 RenderWidgetHostViewPort* GetRenderWidgetHostViewPort() const {
81 RenderWidgetHostViewPort* const view =
82 RenderWidgetHostViewPort::FromRWHV(GetRenderViewHost()->GetView());
83 CHECK(view);
84 return view;
85 }
86
87 // Callback when using CopyFromBackingStore() API.
88 void FinishCopyFromBackingStore(const base::Closure& quit_closure,
89 bool frame_captured,
90 const SkBitmap& bitmap) {
91 ++callback_invoke_count_;
92 if (frame_captured) {
93 ++frames_captured_;
94 EXPECT_FALSE(bitmap.empty());
95 }
96 if (!quit_closure.is_null())
97 quit_closure.Run();
98 }
99
100 // Callback when using CopyFromCompositingSurfaceToVideoFrame() API.
101 void FinishCopyFromCompositingSurface(const base::Closure& quit_closure,
102 bool frame_captured) {
103 ++callback_invoke_count_;
104 if (frame_captured)
105 ++frames_captured_;
106 if (!quit_closure.is_null())
107 quit_closure.Run();
108 }
109
110 // Callback when using frame subscriber API.
111 void FrameDelivered(const scoped_refptr<base::MessageLoopProxy>& loop,
112 base::Closure quit_closure,
113 base::Time timestamp,
114 bool frame_captured) {
115 ++callback_invoke_count_;
116 if (frame_captured)
117 ++frames_captured_;
118 if (!quit_closure.is_null())
119 loop->PostTask(FROM_HERE, quit_closure);
120 }
121
122 // Copy one frame using the CopyFromBackingStore API.
123 void RunBasicCopyFromBackingStoreTest() {
124 SetUpSourceSurface();
125
126 base::RunLoop run_loop;
127 GetRenderViewHost()->CopyFromBackingStore(
128 gfx::Rect(),
129 frame_size(),
130 base::Bind(&RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore,
131 base::Unretained(this), run_loop.QuitClosure()));
132 run_loop.Run();
133
134 EXPECT_EQ(1, callback_invoke_count());
135 EXPECT_EQ(1, frames_captured());
136 }
137
138 protected:
139 // Waits until the source is available for copying.
140 void WaitForCopySourceReady() {
141 while (!IsCopySourceReady()) {
79 base::RunLoop run_loop; 142 base::RunLoop run_loop;
80 MessageLoop::current()->PostDelayedTask( 143 MessageLoop::current()->PostDelayedTask(
81 FROM_HERE, 144 FROM_HERE,
82 run_loop.QuitClosure(), 145 run_loop.QuitClosure(),
83 base::TimeDelta::FromMilliseconds(10)); 146 base::TimeDelta::FromMilliseconds(10));
84 run_loop.Run(); 147 run_loop.Run();
85 } 148 }
86 return true;
87 } 149 }
88 150
89 bool SetupNonCompositing() { 151 private:
90 NavigateToURL(shell(), net::FilePathToFileURL( 152 const gfx::Size frame_size_;
91 test_dir_.AppendASCII("rwhv_compositing_static.html"))); 153 base::FilePath test_dir_;
92 return !CheckCompositingSurface(); 154 int callback_invoke_count_;
155 int frames_captured_;
156 };
157
158 class RenderWidgetHostViewBrowserTest_Compositing
Ken Russell (switch to Gerrit) 2013/04/30 23:23:02 The "_" here and in the subclass below doesn't rea
miu 2013/05/01 00:19:36 Done. Was concerned about what people might try i
159 : public RenderWidgetHostViewBrowserTest {
160 public:
161 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
162 command_line->AppendSwitch(switches::kForceCompositingMode);
93 } 163 }
94 164
95 void FinishCopyFromBackingStore(bool expected_result, 165 virtual void SetUpSourceSurface() OVERRIDE {
96 const base::Closure& quit_closure, 166 #if defined(OS_MACOSX)
97 bool result, 167 ASSERT_TRUE(IOSurfaceSupport::Initialize());
98 const SkBitmap& bitmap) { 168 #endif
99 quit_closure.Run(); 169 NavigateToURL(shell(), net::FilePathToFileURL(
100 EXPECT_EQ(expected_result, result); 170 test_dir().AppendASCII("rwhv_compositing_animation.html")));
101 if (expected_result) 171 #if !defined(USE_AURA)
102 EXPECT_FALSE(bitmap.empty()); 172 ASSERT_TRUE(GetRenderWidgetHost()->is_accelerated_compositing_active());
103 finish_called_ = true; 173 #endif
174
175 // The page is now accelerated composited but a compositing surface might
176 // not be available immediately so wait for it.
177 WaitForCopySourceReady();
104 } 178 }
105 179
106 void FinishCopyFromCompositingSurface(bool expected_result, 180 virtual bool IsCopySourceReady() OVERRIDE {
107 const base::Closure& quit_closure, 181 #if defined(OS_WIN)
108 bool result) { 182 if (!GpuDataManagerImpl::GetInstance()->IsUsingAcceleratedSurface())
109 if (!quit_closure.is_null()) 183 return false;
110 quit_closure.Run(); 184 #endif
111 EXPECT_EQ(expected_result, result); 185
112 finish_called_ = true; 186 RenderWidgetHostViewPort* const view = GetRenderWidgetHostViewPort();
187 bool ret = !view->GetCompositingSurface().is_null();
188 #if defined(OS_MACOSX)
189 ret &= view->HasAcceleratedSurface(gfx::Size());
190 #endif
191 return ret;
192 }
193 };
194
195 class RenderWidgetHostViewBrowserTest_NonCompositing
196 : public RenderWidgetHostViewBrowserTest {
197 public:
198 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
199 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing);
113 } 200 }
114 201
115 protected: 202 virtual void SetUpSourceSurface() OVERRIDE {
116 base::FilePath test_dir_; 203 // Assumption: Browser-internal pages will cause RenderWidget to turn off
117 bool finish_called_; 204 // compositing.
Ken Russell (switch to Gerrit) 2013/04/30 23:23:02 Wasn't the point of the subclass to avoid these as
miu 2013/05/01 00:19:36 Ah! A should have removed the comment. The comma
118 gfx::Size size_; 205 NavigateToURL(shell(), GURL("about:blank"));
206 WaitForCopySourceReady();
207 }
208
209 virtual bool IsCopySourceReady() OVERRIDE {
210 // Note: Passing false to GetBackingStore() asks for the backing store
211 // without forcing its creation. We want to the browser to create it via
212 // its normal mechanism.
213 return GetRenderWidgetHost()->GetBackingStore(false) != NULL;
Ken Russell (switch to Gerrit) 2013/04/30 23:23:02 Do you want to make assertions that the composited
miu 2013/05/01 00:19:36 Good point. Done.
214 }
119 }; 215 };
120 216
121 class FakeFrameSubscriber : public RenderWidgetHostViewFrameSubscriber { 217 class FakeFrameSubscriber : public RenderWidgetHostViewFrameSubscriber {
122 public: 218 public:
123 FakeFrameSubscriber( 219 FakeFrameSubscriber(
124 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback) 220 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback)
125 : callback_(callback) { 221 : callback_(callback) {
126 } 222 }
127 223
128 virtual bool ShouldCaptureFrame( 224 virtual bool ShouldCaptureFrame(
(...skipping 10 matching lines...) Expand all
139 *storage = media::VideoFrame::CreateBlackFrame(gfx::Size(100, 100)); 235 *storage = media::VideoFrame::CreateBlackFrame(gfx::Size(100, 100));
140 *callback = callback_; 236 *callback = callback_;
141 callback_.Reset(); 237 callback_.Reset();
142 return true; 238 return true;
143 } 239 }
144 240
145 private: 241 private:
146 DeliverFrameCallback callback_; 242 DeliverFrameCallback callback_;
147 }; 243 };
148 244
149 #if defined(OS_MACOSX) || defined(OS_WIN) 245 // Disable tests for Android and IOS as these platforms have incomplete
246 // implementation.
247 #if !defined(OS_ANDROID) && !defined(OS_IOS)
150 248
151 static void DeliverFrameFunc(const scoped_refptr<base::MessageLoopProxy>& loop, 249 // The CopyFromBackingStore() API should work on all platforms when compositing
152 base::Closure quit_closure, 250 // is enabled.
153 bool* frame_captured_out, 251 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest_Compositing,
154 base::Time timestamp, 252 CopyFromBackingStore) {
155 bool frame_captured) { 253 RunBasicCopyFromBackingStoreTest();
156 *frame_captured_out = frame_captured;
157 if (!quit_closure.is_null())
158 loop->PostTask(FROM_HERE, quit_closure);
159 } 254 }
160 255
161 #endif 256 // The CopyFromBackingStore() API should work on all platforms when compositing
257 // is disabled.
258 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest_NonCompositing,
259 CopyFromBackingStore) {
260 RunBasicCopyFromBackingStoreTest();
261 }
162 262
163 #if defined(OS_MACOSX) 263 // Tests that the callback passed to CopyFromBackingStore is always called,
164 // Tests that the callback passed to CopyFromBackingStore is always called, even 264 // even when the RenderWidgetHost is deleting in the middle of an async copy.
165 // when the RenderWidgetHost is deleting in the middle of an async copy. 265 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest_Compositing,
166 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest, 266 CopyFromBackingStore_CallbackDespiteDelete) {
167 MacAsyncCopyFromBackingStoreCallbackTest) { 267 SetUpSourceSurface();
168 if (!SetupCompositingSurface()) {
169 LOG(WARNING) << "Accelerated compositing not running.";
170 return;
171 }
172 268
173 base::RunLoop run_loop; 269 base::RunLoop run_loop;
174 RenderViewHost* const rwh = 270 GetRenderViewHost()->CopyFromBackingStore(
175 shell()->web_contents()->GetRenderViewHost();
176 RenderWidgetHostViewPort* rwhvp =
177 static_cast<RenderWidgetHostViewPort*>(rwh->GetView());
178
179 rwh->CopyFromBackingStore(
180 gfx::Rect(), 271 gfx::Rect(),
181 size_, 272 frame_size(),
182 base::Bind(&RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore, 273 base::Bind(&RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore,
183 base::Unretained(this), false, run_loop.QuitClosure())); 274 base::Unretained(this), run_loop.QuitClosure()));
184 275 // Delete the surface before the callback is run.
185 // Delete the surface before the callback is run. This is synchronous until 276 GetRenderWidgetHostViewPort()->AcceleratedSurfaceRelease();
186 // we get to the copy_timer_, so we will always end up in the destructor
187 // before the timer fires.
188 rwhvp->AcceleratedSurfaceRelease();
189 run_loop.Run(); 277 run_loop.Run();
190 278
191 EXPECT_TRUE(finish_called_); 279 EXPECT_EQ(1, callback_invoke_count());
192 } 280 }
193 281
194 // Tests that the callback passed to CopyFromCompositingSurfaceToVideoFrame is 282 // Tests that the callback passed to CopyFromCompositingSurfaceToVideoFrame is
195 // always called, even when the RenderWidgetHost is deleting in the middle of 283 // always called, even when the RenderWidgetHost is deleting in the middle of
196 // an async copy. 284 // an async copy.
197 IN_PROC_BROWSER_TEST_F( 285 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest_Compositing,
198 RenderWidgetHostViewBrowserTest, 286 CopyFromCompositingSurface_CallbackDespiteDelete) {
199 MacAsyncCopyFromCompositingSurfaceToVideoFrameCallbackTest) { 287 SetUpSourceSurface();
200 if (!SetupCompositingSurface()) { 288 RenderWidgetHostViewPort* const view = GetRenderWidgetHostViewPort();
201 LOG(WARNING) << "Accelerated compositing not running."; 289 if (!view->CanCopyToVideoFrame()) {
290 LOG(WARNING) << ("CopyFromCompositingSurfaceToVideoFrame() not supported "
291 "on this platform.");
202 return; 292 return;
203 } 293 }
204 294
205 base::RunLoop run_loop; 295 base::RunLoop run_loop;
206 RenderViewHost* const rwh =
207 shell()->web_contents()->GetRenderViewHost();
208 RenderWidgetHostViewPort* rwhvp =
209 static_cast<RenderWidgetHostViewPort*>(rwh->GetView());
210
211 scoped_refptr<media::VideoFrame> dest = 296 scoped_refptr<media::VideoFrame> dest =
212 media::VideoFrame::CreateBlackFrame(size_); 297 media::VideoFrame::CreateBlackFrame(frame_size());
213 rwhvp->CopyFromCompositingSurfaceToVideoFrame( 298 view->CopyFromCompositingSurfaceToVideoFrame(
214 gfx::Rect(rwhvp->GetViewBounds().size()), dest, base::Bind( 299 gfx::Rect(view->GetViewBounds().size()), dest, base::Bind(
215 &RenderWidgetHostViewBrowserTest::FinishCopyFromCompositingSurface, 300 &RenderWidgetHostViewBrowserTest::FinishCopyFromCompositingSurface,
216 base::Unretained(this), false, run_loop.QuitClosure())); 301 base::Unretained(this), run_loop.QuitClosure()));
217 302 // Delete the surface before the callback is run.
218 // Delete the surface before the callback is run. This is synchronous until 303 view->AcceleratedSurfaceRelease();
219 // we get to the copy_timer_, so we will always end up in the destructor
220 // before the timer fires.
221 rwhvp->AcceleratedSurfaceRelease();
222 run_loop.Run(); 304 run_loop.Run();
223 305
224 ASSERT_TRUE(finish_called_); 306 EXPECT_EQ(1, callback_invoke_count());
225 } 307 }
226 #endif
227 308
228 #if (defined(OS_WIN) && !defined(USE_AURA)) || defined(OS_MACOSX) 309 // With compositing turned off, no platforms should support the
229 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest, 310 // CopyFromCompositingSurfaceToVideoFrame() API.
311 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest_NonCompositing,
312 CopyFromCompositingSurfaceToVideoFrameCallbackTest) {
313 SetUpSourceSurface();
314 EXPECT_FALSE(GetRenderWidgetHostViewPort()->CanCopyToVideoFrame());
315 }
316
317 // Test basic frame subscription functionality. We subscribe, and then run
318 // until at least one DeliverFrameCallback has been invoked.
319 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest_Compositing,
230 FrameSubscriberTest) { 320 FrameSubscriberTest) {
231 if (!SetupCompositingSurface()) { 321 SetUpSourceSurface();
232 LOG(WARNING) << "Accelerated compositing not running."; 322 RenderWidgetHostViewPort* const view = GetRenderWidgetHostViewPort();
323 if (!view->CanSubscribeFrame()) {
324 LOG(WARNING) << "Frame subscription not supported on this platform.";
233 return; 325 return;
ncarter (slow) 2013/05/01 00:04:32 I expect this will happen on XP.
234 } 326 }
235 327
236 base::RunLoop run_loop; 328 base::RunLoop run_loop;
237 RenderWidgetHostViewPort* view = RenderWidgetHostViewPort::FromRWHV(
238 shell()->web_contents()->GetRenderViewHost()->GetView());
239 ASSERT_TRUE(view);
240
241 if (!view->CanSubscribeFrame()) {
242 LOG(WARNING) << "Frame subscription no supported on this platform.";
243 return;
244 }
245
246 bool frame_captured = false;
247 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber( 329 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber(
248 new FakeFrameSubscriber(base::Bind(&DeliverFrameFunc, 330 new FakeFrameSubscriber(
249 base::MessageLoopProxy::current(), 331 base::Bind(&RenderWidgetHostViewBrowserTest::FrameDelivered,
250 run_loop.QuitClosure(), 332 base::Unretained(this),
251 &frame_captured))); 333 base::MessageLoopProxy::current(),
334 run_loop.QuitClosure())));
252 view->BeginFrameSubscription(subscriber.Pass()); 335 view->BeginFrameSubscription(subscriber.Pass());
253 run_loop.Run(); 336 run_loop.Run();
254 view->EndFrameSubscription(); 337 view->EndFrameSubscription();
255 EXPECT_TRUE(frame_captured); 338
339 EXPECT_LE(1, callback_invoke_count());
340 EXPECT_LE(1, frames_captured());
256 } 341 }
257 342
258 // Test copying from backing store when page is non-accelerated-composited.
259 // Flaky. http://crbug.com/224351
260 #if defined(OS_MACOSX) || defined(OS_WIN)
261 #define MAYBE_CopyFromBackingStore DISABLED_CopyFromBackingStore
262 #else
263 #define MAYBE_CopyFromBackingStore CopyFromBackingStore
264 #endif
265 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest,
266 MAYBE_CopyFromBackingStore) {
267 SetupNonCompositing();
268 base::RunLoop run_loop;
269
270 shell()->web_contents()->GetRenderViewHost()->CopyFromBackingStore(
271 gfx::Rect(),
272 size_,
273 base::Bind(&RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore,
274 base::Unretained(this), true, run_loop.QuitClosure()));
275 run_loop.Run();
276
277 EXPECT_TRUE(finish_called_);
278 }
279 #endif
280
281 #if defined(OS_MACOSX)
282 // Test that we can copy twice from an accelerated composited page. 343 // Test that we can copy twice from an accelerated composited page.
283 // This test is only running on Mac because this is the only platform that 344 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest_Compositing, CopyTwice) {
284 // we can reliably detect that accelerated surface is in use. 345 SetUpSourceSurface();
285 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest, CopyTwice) { 346 RenderWidgetHostViewPort* const view = GetRenderWidgetHostViewPort();
286 if (!SetupCompositingSurface()) { 347 if (!view->CanCopyToVideoFrame()) {
287 LOG(WARNING) << "Accelerated compositing not running."; 348 LOG(WARNING) << ("CopyFromCompositingSurfaceToVideoFrame() not supported "
349 "on this platform.");
ncarter (slow) 2013/05/01 00:04:32 I expect this will happen on XP.
288 return; 350 return;
289 } 351 }
290 352
291 base::RunLoop run_loop; 353 base::RunLoop run_loop;
292 RenderViewHost* const rwh = 354 scoped_refptr<media::VideoFrame> first_output =
293 shell()->web_contents()->GetRenderViewHost(); 355 media::VideoFrame::CreateBlackFrame(frame_size());
294 RenderWidgetHostViewPort* rwhvp = 356 ASSERT_TRUE(first_output);
295 static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); 357 scoped_refptr<media::VideoFrame> second_output =
296 scoped_refptr<media::VideoFrame> dest = 358 media::VideoFrame::CreateBlackFrame(frame_size());
297 media::VideoFrame::CreateBlackFrame(size_); 359 ASSERT_TRUE(second_output);
298 360 view->CopyFromCompositingSurfaceToVideoFrame(
299 bool first_frame_captured = false; 361 gfx::Rect(view->GetViewBounds().size()), first_output,
300 bool second_frame_captured = false; 362 base::Bind(&RenderWidgetHostViewBrowserTest::FrameDelivered,
301 rwhvp->CopyFromCompositingSurfaceToVideoFrame( 363 base::Unretained(this),
302 gfx::Rect(rwhvp->GetViewBounds().size()), dest,
303 base::Bind(&DeliverFrameFunc,
304 base::MessageLoopProxy::current(), 364 base::MessageLoopProxy::current(),
305 base::Closure(), 365 base::Closure(),
306 &first_frame_captured,
307 base::Time::Now())); 366 base::Time::Now()));
308 rwhvp->CopyFromCompositingSurfaceToVideoFrame( 367 view->CopyFromCompositingSurfaceToVideoFrame(
309 gfx::Rect(rwhvp->GetViewBounds().size()), dest, 368 gfx::Rect(view->GetViewBounds().size()), second_output,
310 base::Bind(&DeliverFrameFunc, 369 base::Bind(&RenderWidgetHostViewBrowserTest::FrameDelivered,
370 base::Unretained(this),
311 base::MessageLoopProxy::current(), 371 base::MessageLoopProxy::current(),
312 run_loop.QuitClosure(), 372 run_loop.QuitClosure(),
313 &second_frame_captured,
314 base::Time::Now())); 373 base::Time::Now()));
315 run_loop.Run(); 374 run_loop.Run();
316 375
317 EXPECT_TRUE(first_frame_captured); 376 EXPECT_EQ(2, callback_invoke_count());
318 EXPECT_TRUE(second_frame_captured); 377 EXPECT_EQ(2, frames_captured());
319 } 378 }
320 #endif
321 379
380 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
381
382 } // namespace
322 } // namespace content 383 } // namespace content
OLDNEW
« no previous file with comments | « build/android/pylib/gtest/test_runner.py ('k') | content/test/data/rwhv_compositing_static.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698