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

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

Issue 120913004: aura: Ensure OwnedMailbox not used with invalid or destroyed GLHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ownedmailbox: test Created 6 years, 11 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
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "cc/output/compositor_frame.h" 12 #include "cc/output/compositor_frame.h"
12 #include "cc/output/compositor_frame_metadata.h" 13 #include "cc/output/compositor_frame_metadata.h"
14 #include "cc/output/copy_output_request.h"
13 #include "cc/output/gl_frame_data.h" 15 #include "cc/output/gl_frame_data.h"
14 #include "content/browser/aura/resize_lock.h" 16 #include "content/browser/aura/resize_lock.h"
15 #include "content/browser/browser_thread_impl.h" 17 #include "content/browser/browser_thread_impl.h"
16 #include "content/browser/renderer_host/render_widget_host_delegate.h" 18 #include "content/browser/renderer_host/render_widget_host_delegate.h"
17 #include "content/browser/renderer_host/render_widget_host_impl.h" 19 #include "content/browser/renderer_host/render_widget_host_impl.h"
18 #include "content/common/gpu/gpu_messages.h" 20 #include "content/common/gpu/gpu_messages.h"
19 #include "content/common/input_messages.h" 21 #include "content/common/input_messages.h"
20 #include "content/common/view_messages.h" 22 #include "content/common/view_messages.h"
23 #include "content/port/browser/render_widget_host_view_frame_subscriber.h"
21 #include "content/public/browser/render_widget_host_view.h" 24 #include "content/public/browser/render_widget_host_view.h"
22 #include "content/public/test/mock_render_process_host.h" 25 #include "content/public/test/mock_render_process_host.h"
23 #include "content/public/test/test_browser_context.h" 26 #include "content/public/test/test_browser_context.h"
24 #include "ipc/ipc_test_sink.h" 27 #include "ipc/ipc_test_sink.h"
25 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/aura/client/aura_constants.h" 30 #include "ui/aura/client/aura_constants.h"
28 #include "ui/aura/client/screen_position_client.h" 31 #include "ui/aura/client/screen_position_client.h"
29 #include "ui/aura/client/window_tree_client.h" 32 #include "ui/aura/client/window_tree_client.h"
30 #include "ui/aura/env.h" 33 #include "ui/aura/env.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 private: 109 private:
107 // Window that we're observing, or NULL if it's been destroyed. 110 // Window that we're observing, or NULL if it's been destroyed.
108 aura::Window* window_; 111 aura::Window* window_;
109 112
110 // Was |window_| destroyed? 113 // Was |window_| destroyed?
111 bool destroyed_; 114 bool destroyed_;
112 115
113 DISALLOW_COPY_AND_ASSIGN(TestWindowObserver); 116 DISALLOW_COPY_AND_ASSIGN(TestWindowObserver);
114 }; 117 };
115 118
119 class FakeFrameSubscriber : public RenderWidgetHostViewFrameSubscriber {
120 public:
121 FakeFrameSubscriber(gfx::Size size, base::Callback<void(bool)> callback)
122 : size_(size), callback_(callback) {}
123
124 virtual bool ShouldCaptureFrame(base::TimeTicks present_time,
125 scoped_refptr<media::VideoFrame>* storage,
126 DeliverFrameCallback* callback) OVERRIDE {
127 *storage = media::VideoFrame::CreateFrame(media::VideoFrame::YV12,
128 size_,
129 gfx::Rect(size_),
130 size_,
131 base::TimeDelta());
132 *callback = base::Bind(&FakeFrameSubscriber::CallbackMethod, callback_);
133 return true;
134 }
135
136 static void CallbackMethod(base::Callback<void(bool)> callback,
137 base::TimeTicks timestamp,
138 bool success) {
139 callback.Run(success);
140 }
141
142 private:
143 gfx::Size size_;
144 base::Callback<void(bool)> callback_;
145 };
146
116 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { 147 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura {
117 public: 148 public:
118 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget) 149 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget)
119 : RenderWidgetHostViewAura(widget), has_resize_lock_(false) {} 150 : RenderWidgetHostViewAura(widget), has_resize_lock_(false) {}
120 151
121 virtual ~FakeRenderWidgetHostViewAura() {} 152 virtual ~FakeRenderWidgetHostViewAura() {}
122 153
123 virtual bool ShouldCreateResizeLock() OVERRIDE { 154 virtual bool ShouldCreateResizeLock() OVERRIDE {
124 gfx::Size desired_size = window()->bounds().size(); 155 gfx::Size desired_size = window()->bounds().size();
125 return desired_size != current_frame_size(); 156 return desired_size != current_frame_size();
126 } 157 }
127 158
128 virtual scoped_ptr<ResizeLock> CreateResizeLock(bool defer_compositor_lock) 159 virtual scoped_ptr<ResizeLock> CreateResizeLock(bool defer_compositor_lock)
129 OVERRIDE { 160 OVERRIDE {
130 gfx::Size desired_size = window()->bounds().size(); 161 gfx::Size desired_size = window()->bounds().size();
131 return scoped_ptr<ResizeLock>( 162 return scoped_ptr<ResizeLock>(
132 new FakeResizeLock(desired_size, defer_compositor_lock)); 163 new FakeResizeLock(desired_size, defer_compositor_lock));
133 } 164 }
134 165
166 virtual void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request)
167 OVERRIDE {
168 last_copy_request_ = request.Pass();
169 }
170
135 void RunOnCompositingDidCommit() { 171 void RunOnCompositingDidCommit() {
136 OnCompositingDidCommit(window()->GetDispatcher()->host()->compositor()); 172 OnCompositingDidCommit(window()->GetDispatcher()->host()->compositor());
137 } 173 }
138 174
139 // A lock that doesn't actually do anything to the compositor, and does not 175 // A lock that doesn't actually do anything to the compositor, and does not
140 // time out. 176 // time out.
141 class FakeResizeLock : public ResizeLock { 177 class FakeResizeLock : public ResizeLock {
142 public: 178 public:
143 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock) 179 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock)
144 : ResizeLock(new_size, defer_compositor_lock) {} 180 : ResizeLock(new_size, defer_compositor_lock) {}
145 }; 181 };
146 182
147 bool has_resize_lock_; 183 bool has_resize_lock_;
148 gfx::Size last_frame_size_; 184 gfx::Size last_frame_size_;
185 scoped_ptr<cc::CopyOutputRequest> last_copy_request_;
149 }; 186 };
150 187
151 class RenderWidgetHostViewAuraTest : public testing::Test { 188 class RenderWidgetHostViewAuraTest : public testing::Test {
152 public: 189 public:
153 RenderWidgetHostViewAuraTest() 190 RenderWidgetHostViewAuraTest()
154 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} 191 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {}
155 192
156 virtual void SetUp() { 193 void SetUpEnvironment() {
157 ImageTransportFactory::InitializeForUnitTests( 194 ImageTransportFactory::InitializeForUnitTests(
158 scoped_ptr<ui::ContextFactory>(new ui::TestContextFactory)); 195 scoped_ptr<ui::ContextFactory>(new ui::TestContextFactory));
159 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); 196 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
160 aura_test_helper_->SetUp(); 197 aura_test_helper_->SetUp();
161 198
162 browser_context_.reset(new TestBrowserContext); 199 browser_context_.reset(new TestBrowserContext);
163 process_host_ = new MockRenderProcessHost(browser_context_.get()); 200 process_host_ = new MockRenderProcessHost(browser_context_.get());
164 201
165 sink_ = &process_host_->sink(); 202 sink_ = &process_host_->sink();
166 203
167 parent_host_ = new RenderWidgetHostImpl( 204 parent_host_ = new RenderWidgetHostImpl(
168 &delegate_, process_host_, MSG_ROUTING_NONE, false); 205 &delegate_, process_host_, MSG_ROUTING_NONE, false);
169 parent_view_ = static_cast<RenderWidgetHostViewAura*>( 206 parent_view_ = static_cast<RenderWidgetHostViewAura*>(
170 RenderWidgetHostView::CreateViewForWidget(parent_host_)); 207 RenderWidgetHostView::CreateViewForWidget(parent_host_));
171 parent_view_->InitAsChild(NULL); 208 parent_view_->InitAsChild(NULL);
172 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(), 209 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(),
173 aura_test_helper_->root_window(), 210 aura_test_helper_->root_window(),
174 gfx::Rect()); 211 gfx::Rect());
175 212
176 widget_host_ = new RenderWidgetHostImpl( 213 widget_host_ = new RenderWidgetHostImpl(
177 &delegate_, process_host_, MSG_ROUTING_NONE, false); 214 &delegate_, process_host_, MSG_ROUTING_NONE, false);
178 widget_host_->Init(); 215 widget_host_->Init();
179 widget_host_->OnMessageReceived( 216 widget_host_->OnMessageReceived(
180 ViewHostMsg_DidActivateAcceleratedCompositing(0, true)); 217 ViewHostMsg_DidActivateAcceleratedCompositing(0, true));
181 view_ = new FakeRenderWidgetHostViewAura(widget_host_); 218 view_ = new FakeRenderWidgetHostViewAura(widget_host_);
182 } 219 }
183 220
184 virtual void TearDown() { 221 void TearDownEnvironment() {
185 sink_ = NULL; 222 sink_ = NULL;
186 process_host_ = NULL; 223 process_host_ = NULL;
187 if (view_) 224 if (view_)
188 view_->Destroy(); 225 view_->Destroy();
189 delete widget_host_; 226 delete widget_host_;
190 227
191 parent_view_->Destroy(); 228 parent_view_->Destroy();
192 delete parent_host_; 229 delete parent_host_;
193 230
194 browser_context_.reset(); 231 browser_context_.reset();
195 aura_test_helper_->TearDown(); 232 aura_test_helper_->TearDown();
196 233
197 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); 234 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release());
198 message_loop_.RunUntilIdle(); 235 message_loop_.RunUntilIdle();
199 ImageTransportFactory::Terminate(); 236 ImageTransportFactory::Terminate();
200 } 237 }
201 238
239 virtual void SetUp() { SetUpEnvironment(); }
240
241 virtual void TearDown() { TearDownEnvironment(); }
242
202 protected: 243 protected:
203 base::MessageLoopForUI message_loop_; 244 base::MessageLoopForUI message_loop_;
204 BrowserThreadImpl browser_thread_for_ui_; 245 BrowserThreadImpl browser_thread_for_ui_;
205 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; 246 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
206 scoped_ptr<BrowserContext> browser_context_; 247 scoped_ptr<BrowserContext> browser_context_;
207 MockRenderWidgetHostDelegate delegate_; 248 MockRenderWidgetHostDelegate delegate_;
208 MockRenderProcessHost* process_host_; 249 MockRenderProcessHost* process_host_;
209 250
210 // Tests should set these to NULL if they've already triggered their 251 // Tests should set these to NULL if they've already triggered their
211 // destruction. 252 // destruction.
212 RenderWidgetHostImpl* parent_host_; 253 RenderWidgetHostImpl* parent_host_;
213 RenderWidgetHostViewAura* parent_view_; 254 RenderWidgetHostViewAura* parent_view_;
214 255
215 // Tests should set these to NULL if they've already triggered their 256 // Tests should set these to NULL if they've already triggered their
216 // destruction. 257 // destruction.
217 RenderWidgetHostImpl* widget_host_; 258 RenderWidgetHostImpl* widget_host_;
218 FakeRenderWidgetHostViewAura* view_; 259 FakeRenderWidgetHostViewAura* view_;
219 260
220 IPC::TestSink* sink_; 261 IPC::TestSink* sink_;
221 262
222 private: 263 private:
223 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); 264 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest);
224 }; 265 };
225 266
267 class RenderWidgetHostViewAuraShutdownTest
268 : public RenderWidgetHostViewAuraTest {
269 public:
270 RenderWidgetHostViewAuraShutdownTest() {}
271
272 virtual void TearDown() OVERRIDE {
273 // No TearDownEnvironment here, we do this explicitly during the test.
274 }
275
276 private:
277 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraShutdownTest);
278 };
279
226 // A layout manager that always resizes a child to the root window size. 280 // A layout manager that always resizes a child to the root window size.
227 class FullscreenLayoutManager : public aura::LayoutManager { 281 class FullscreenLayoutManager : public aura::LayoutManager {
228 public: 282 public:
229 explicit FullscreenLayoutManager(aura::Window* owner) 283 explicit FullscreenLayoutManager(aura::Window* owner)
230 : owner_(owner) {} 284 : owner_(owner) {}
231 virtual ~FullscreenLayoutManager() {} 285 virtual ~FullscreenLayoutManager() {}
232 286
233 // Overridden from aura::LayoutManager: 287 // Overridden from aura::LayoutManager:
234 virtual void OnWindowResized() OVERRIDE { 288 virtual void OnWindowResized() OVERRIDE {
235 aura::Window::Windows::const_iterator i; 289 aura::Window::Windows::const_iterator i;
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 // scale on it. 1264 // scale on it.
1211 view_->OnSwapCompositorFrame( 1265 view_->OnSwapCompositorFrame(
1212 1, MakeDelegatedFrame(2.f, frame_size, gfx::Rect(frame_size))); 1266 1, MakeDelegatedFrame(2.f, frame_size, gfx::Rect(frame_size)));
1213 1267
1214 // When we get a new frame with the same frame size in physical pixels, but a 1268 // When we get a new frame with the same frame size in physical pixels, but a
1215 // different scale, we should generate a new frame provider, as the final 1269 // different scale, we should generate a new frame provider, as the final
1216 // result will need to be scaled differently to the screen. 1270 // result will need to be scaled differently to the screen.
1217 EXPECT_NE(frame_provider.get(), view_->frame_provider_.get()); 1271 EXPECT_NE(frame_provider.get(), view_->frame_provider_.get());
1218 } 1272 }
1219 1273
1274 class RenderWidgetHostViewAuraCopyRequestTest
1275 : public RenderWidgetHostViewAuraShutdownTest {
1276 public:
1277 RenderWidgetHostViewAuraCopyRequestTest()
1278 : callback_count_(0), result_(false) {}
1279
1280 void CallbackMethod(bool result) {
1281 result_ = result;
1282 callback_count_++;
1283 }
1284
1285 int callback_count_;
1286 bool result_;
1287
1288 private:
1289 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraCopyRequestTest);
1290 };
1291
1292 TEST_F(RenderWidgetHostViewAuraCopyRequestTest, DestroyedAfterCopyRequest) {
1293 gfx::Rect view_rect(100, 100);
1294 scoped_ptr<cc::CopyOutputRequest> request;
1295
1296 view_->InitAsChild(NULL);
1297 aura::client::ParentWindowWithContext(
1298 view_->GetNativeView(),
1299 parent_view_->GetNativeView()->GetRootWindow(),
1300 gfx::Rect());
1301 view_->SetSize(view_rect.size());
1302 view_->WasShown();
1303
1304 scoped_ptr<FakeFrameSubscriber> frame_subscriber(new FakeFrameSubscriber(
1305 view_rect.size(),
1306 base::Bind(&RenderWidgetHostViewAuraCopyRequestTest::CallbackMethod,
1307 base::Unretained(this))));
1308
1309 EXPECT_EQ(0, callback_count_);
1310 EXPECT_FALSE(view_->last_copy_request_);
1311
1312 view_->BeginFrameSubscription(
1313 frame_subscriber.PassAs<RenderWidgetHostViewFrameSubscriber>());
1314 view_->OnSwapCompositorFrame(
1315 1, MakeDelegatedFrame(1.f, view_rect.size(), gfx::Rect(view_rect)));
1316
1317 EXPECT_EQ(0, callback_count_);
1318 EXPECT_TRUE(view_->last_copy_request_);
1319 EXPECT_TRUE(view_->last_copy_request_->has_texture_mailbox());
1320 request = view_->last_copy_request_.Pass();
1321
1322 // There should be one subscriber texture in flight.
1323 EXPECT_EQ(1u, view_->active_frame_subscriber_textures_.size());
1324
1325 // Send back the mailbox included in the request. There's no release callback
1326 // since the mailbox came from the RWHVA originally.
1327 request->SendTextureResult(view_rect.size(),
1328 request->texture_mailbox(),
1329 scoped_ptr<cc::SingleReleaseCallback>());
1330
1331 while (callback_count_ == 0) {
1332 // LOG(ERROR)<<"Running";
piman 2014/01/09 00:23:29 nit: remove.
danakj 2014/01/09 00:34:55 oops, thanks. doesn't need the while either.
1333 base::RunLoop run_loop;
1334 run_loop.RunUntilIdle();
1335 }
1336
1337 // The callback should succeed.
1338 EXPECT_EQ(0u, view_->active_frame_subscriber_textures_.size());
1339 EXPECT_EQ(1, callback_count_);
1340 EXPECT_EQ(true, result_);
1341
1342 view_->OnSwapCompositorFrame(
1343 1, MakeDelegatedFrame(1.f, view_rect.size(), gfx::Rect(view_rect)));
1344
1345 EXPECT_EQ(1, callback_count_);
1346 request = view_->last_copy_request_.Pass();
1347
1348 // There should be one subscriber texture in flight again.
1349 EXPECT_EQ(1u, view_->active_frame_subscriber_textures_.size());
1350
1351 // Destroy the RenderWidgetHostViewAura.
1352 TearDownEnvironment();
1353
1354 // Send back the mailbox included in the request. There's no release callback
1355 // since the mailbox came from the RWHVA originally.
1356 request->SendTextureResult(view_rect.size(),
1357 request->texture_mailbox(),
1358 scoped_ptr<cc::SingleReleaseCallback>());
1359
1360 // Because the copy request callback may be holding state within it, that
1361 // state must handle the RWHVA and ImageTransportFactory going away before the
1362 // callback is called. This test passes if it does not crash as a result of
1363 // these things being destroyed.
1364 EXPECT_EQ(2, callback_count_);
1365 EXPECT_EQ(false, result_);
1366 }
1367
1220 } // namespace content 1368 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698