OLD | NEW |
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/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" |
8 #include "content/port/browser/render_widget_host_view_port.h" | 9 #include "content/port/browser/render_widget_host_view_port.h" |
9 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
10 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
11 #include "content/public/common/content_paths.h" | 12 #include "content/public/common/content_paths.h" |
12 #include "content/shell/shell.h" | 13 #include "content/shell/shell.h" |
13 #include "content/test/content_browser_test.h" | 14 #include "content/test/content_browser_test.h" |
14 #include "content/test/content_browser_test_utils.h" | 15 #include "content/test/content_browser_test_utils.h" |
| 16 #include "media/base/video_frame.h" |
15 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
16 #include "skia/ext/platform_canvas.h" | 18 #include "skia/ext/platform_canvas.h" |
17 #include "ui/compositor/compositor_setup.h" | 19 #include "ui/compositor/compositor_setup.h" |
18 #if defined(OS_MACOSX) | 20 #if defined(OS_MACOSX) |
19 #include "ui/surface/io_surface_support_mac.h" | 21 #include "ui/surface/io_surface_support_mac.h" |
20 #endif | 22 #endif |
21 | 23 |
22 namespace content { | 24 namespace content { |
23 | 25 |
24 class RenderWidgetHostViewBrowserTest : public ContentBrowserTest { | 26 class RenderWidgetHostViewBrowserTest : public ContentBrowserTest { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 ASSERT_FALSE(bitmap.empty()); | 70 ASSERT_FALSE(bitmap.empty()); |
69 finish_called_ = true; | 71 finish_called_ = true; |
70 } | 72 } |
71 | 73 |
72 protected: | 74 protected: |
73 base::FilePath test_dir_; | 75 base::FilePath test_dir_; |
74 bool finish_called_; | 76 bool finish_called_; |
75 gfx::Size size_; | 77 gfx::Size size_; |
76 }; | 78 }; |
77 | 79 |
| 80 class FakeFrameSubscriber : public RenderWidgetHostViewFrameSubscriber { |
| 81 public: |
| 82 FakeFrameSubscriber( |
| 83 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback) |
| 84 : callback_(callback) { |
| 85 } |
| 86 |
| 87 virtual bool ShouldCaptureFrame( |
| 88 scoped_refptr<media::VideoFrame>* storage, |
| 89 DeliverFrameCallback* callback) OVERRIDE { |
| 90 *storage = media::VideoFrame::CreateBlackFrame(gfx::Size(100, 100)); |
| 91 *callback = callback_; |
| 92 return true; |
| 93 } |
| 94 |
| 95 private: |
| 96 DeliverFrameCallback callback_; |
| 97 }; |
| 98 |
78 #if defined(OS_MACOSX) | 99 #if defined(OS_MACOSX) |
79 // Tests that the callback passed to CopyFromBackingStore is always called, even | 100 // Tests that the callback passed to CopyFromBackingStore is always called, even |
80 // when the RenderWidgetHost is deleting in the middle of an async copy. | 101 // when the RenderWidgetHost is deleting in the middle of an async copy. |
81 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest, | 102 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest, |
82 MacAsyncCopyFromBackingStoreCallbackTest) { | 103 MacAsyncCopyFromBackingStoreCallbackTest) { |
83 if (!IOSurfaceSupport::Initialize()) | 104 if (!IOSurfaceSupport::Initialize()) |
84 return; | 105 return; |
85 | 106 |
86 SetupCompositingSurface(); | 107 SetupCompositingSurface(); |
87 | 108 |
(...skipping 30 matching lines...) Expand all Loading... |
118 base::RunLoop run_loop; | 139 base::RunLoop run_loop; |
119 shell()->web_contents()->GetRenderViewHost()->CopyFromBackingStore( | 140 shell()->web_contents()->GetRenderViewHost()->CopyFromBackingStore( |
120 gfx::Rect(), | 141 gfx::Rect(), |
121 size_, | 142 size_, |
122 base::Bind(&RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore, | 143 base::Bind(&RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore, |
123 base::Unretained(this), true, run_loop.QuitClosure())); | 144 base::Unretained(this), true, run_loop.QuitClosure())); |
124 run_loop.Run(); | 145 run_loop.Run(); |
125 | 146 |
126 ASSERT_TRUE(finish_called_); | 147 ASSERT_TRUE(finish_called_); |
127 } | 148 } |
| 149 |
| 150 static void DeliverFrameFunc(base::Closure quit_closure, |
| 151 bool* frame_captured_out, |
| 152 base::Time timestamp, |
| 153 bool frame_captured) { |
| 154 *frame_captured_out = frame_captured; |
| 155 quit_closure.Run(); |
| 156 } |
| 157 |
| 158 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest, |
| 159 MacFrameSubscriberTest) { |
| 160 if (!IOSurfaceSupport::Initialize()) |
| 161 return; |
| 162 |
| 163 SetupCompositingSurface(); |
| 164 |
| 165 base::RunLoop run_loop; |
| 166 RenderWidgetHostViewPort* view = RenderWidgetHostViewPort::FromRWHV( |
| 167 shell()->web_contents()->GetRenderViewHost()->GetView()); |
| 168 ASSERT_TRUE(view); |
| 169 |
| 170 EXPECT_TRUE(view->CanSubscribeFrame()); |
| 171 |
| 172 bool frame_captured = false; |
| 173 view->BeginFrameSubscription( |
| 174 new FakeFrameSubscriber(base::Bind(&DeliverFrameFunc, |
| 175 run_loop.QuitClosure(), |
| 176 &frame_captured))); |
| 177 |
| 178 // Do a resize of the window to trigger a repaint and present. |
| 179 SetWindowBounds(shell()->window(), gfx::Rect(size_)); |
| 180 run_loop.Run(); |
| 181 view->EndFrameSubscription(); |
| 182 |
| 183 EXPECT_TRUE(frame_captured); |
| 184 } |
| 185 |
128 #endif | 186 #endif |
129 | 187 |
130 } // namespace content | 188 } // namespace content |
OLD | NEW |