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

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

Issue 2782063006: Show that ResizeLock is racey with renderer frames in flight. (Closed)
Patch Set: 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
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.h ('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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <tuple> 10 #include <tuple>
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 size_t GetAndResetProcessedTouchEventCount() { 348 size_t GetAndResetProcessedTouchEventCount() {
349 size_t count = processed_touch_event_count_; 349 size_t count = processed_touch_event_count_;
350 processed_touch_event_count_ = 0; 350 processed_touch_event_count_ = 0;
351 return count; 351 return count;
352 } 352 }
353 353
354 private: 354 private:
355 size_t processed_touch_event_count_; 355 size_t processed_touch_event_count_;
356 }; 356 };
357 357
358 class FakeDelegatedFrameHostClientAura : public DelegatedFrameHostClientAura { 358 class FakeDelegatedFrameHostClientAura : public DelegatedFrameHostClientAura,
359 public ui::CompositorLockDelegate {
359 public: 360 public:
360 explicit FakeDelegatedFrameHostClientAura( 361 explicit FakeDelegatedFrameHostClientAura(
361 RenderWidgetHostViewAura* render_widget_host_view) 362 RenderWidgetHostViewAura* render_widget_host_view)
362 : DelegatedFrameHostClientAura(render_widget_host_view) {} 363 : DelegatedFrameHostClientAura(render_widget_host_view),
364 weak_ptr_factory_(this) {}
363 ~FakeDelegatedFrameHostClientAura() override = default; 365 ~FakeDelegatedFrameHostClientAura() override = default;
364 366
365 void DisableResizeLock() { can_create_resize_lock_ = false; } 367 void DisableResizeLock() { can_create_resize_lock_ = false; }
366 368
369 bool resize_locked() const { return resize_locked_; }
370 bool compositor_locked() const { return compositor_locked_; }
371
367 private: 372 private:
368 // DelegatedFrameHostClientAura implementation. 373 // DelegatedFrameHostClientAura implementation.
369 bool DelegatedFrameCanCreateResizeLock() const override { 374 bool DelegatedFrameCanCreateResizeLock() const override {
370 return can_create_resize_lock_; 375 return can_create_resize_lock_;
371 } 376 }
372 377
373 // CompositorResizeLockClient implemention. Overrides from 378 // CompositorResizeLockClient implemention. Overrides from
374 // DelegatedFrameHostClientAura, to prevent the lock from timing out. 379 // DelegatedFrameHostClientAura, to prevent the lock from timing out.
375 std::unique_ptr<ui::CompositorLock> GetCompositorLock( 380 std::unique_ptr<ui::CompositorLock> GetCompositorLock(
376 ui::CompositorLockClient* client) override { 381 ui::CompositorLockClient* client) override {
377 return base::MakeUnique<ui::CompositorLock>(nullptr, nullptr); 382 resize_locked_ = compositor_locked_ = true;
383 return base::MakeUnique<ui::CompositorLock>(nullptr,
384 weak_ptr_factory_.GetWeakPtr());
385 }
386 // CompositorResizeLockClient implemention. Overrides from
387 // // DelegatedFrameHostClientAura.
388 void CompositorResizeLockEnded() override { resize_locked_ = false; }
389
390 // ui::CompositorLockDelegate implemention.
391 void RemoveCompositorLock(ui::CompositorLock*) override {
392 compositor_locked_ = false;
378 } 393 }
379 394
380 bool can_create_resize_lock_ = true; 395 bool can_create_resize_lock_ = true;
396 bool resize_locked_ = false;
397 bool compositor_locked_ = false;
398 base::WeakPtrFactory<FakeDelegatedFrameHostClientAura> weak_ptr_factory_;
381 399
382 DISALLOW_COPY_AND_ASSIGN(FakeDelegatedFrameHostClientAura); 400 DISALLOW_COPY_AND_ASSIGN(FakeDelegatedFrameHostClientAura);
383 }; 401 };
384 402
385 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { 403 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura {
386 public: 404 public:
387 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget, 405 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget,
388 bool is_guest_view_hack) 406 bool is_guest_view_hack)
389 : RenderWidgetHostViewAura(widget, is_guest_view_hack), 407 : RenderWidgetHostViewAura(widget, is_guest_view_hack),
390 delegated_frame_host_client_( 408 delegated_frame_host_client_(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 bool released_front_lock_active() const { 453 bool released_front_lock_active() const {
436 return GetDelegatedFrameHost()->ReleasedFrontLockActiveForTesting(); 454 return GetDelegatedFrameHost()->ReleasedFrontLockActiveForTesting();
437 } 455 }
438 456
439 void ReclaimResources(const cc::ReturnedResourceArray& resources) { 457 void ReclaimResources(const cc::ReturnedResourceArray& resources) {
440 GetDelegatedFrameHost()->ReclaimResources(resources); 458 GetDelegatedFrameHost()->ReclaimResources(resources);
441 } 459 }
442 460
443 void ResetCompositor() { GetDelegatedFrameHost()->ResetCompositor(); } 461 void ResetCompositor() { GetDelegatedFrameHost()->ResetCompositor(); }
444 462
445 const ui::MotionEventAura& pointer_state_for_test() { 463 const ui::MotionEventAura& pointer_state() {
446 return event_handler()->pointer_state(); 464 return event_handler()->pointer_state();
447 } 465 }
448 466
467 bool resize_locked() const {
468 return delegated_frame_host_client_->resize_locked();
469 }
470 bool compositor_locked() const {
471 return delegated_frame_host_client_->compositor_locked();
472 }
473
449 gfx::Size last_frame_size_; 474 gfx::Size last_frame_size_;
450 std::unique_ptr<cc::CopyOutputRequest> last_copy_request_; 475 std::unique_ptr<cc::CopyOutputRequest> last_copy_request_;
451 FakeWindowEventDispatcher* dispatcher_; 476 FakeWindowEventDispatcher* dispatcher_;
452 477
453 private: 478 private:
454 FakeDelegatedFrameHostClientAura* delegated_frame_host_client_; 479 FakeDelegatedFrameHostClientAura* delegated_frame_host_client_;
455 480
456 DISALLOW_COPY_AND_ASSIGN(FakeRenderWidgetHostViewAura); 481 DISALLOW_COPY_AND_ASSIGN(FakeRenderWidgetHostViewAura);
457 }; 482 };
458 483
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 697
673 InputEventDispatchType dispatch_type = std::get<3>(params); 698 InputEventDispatchType dispatch_type = std::get<3>(params);
674 if (dispatch_type == InputEventDispatchType::DISPATCH_TYPE_NON_BLOCKING) 699 if (dispatch_type == InputEventDispatchType::DISPATCH_TYPE_NON_BLOCKING)
675 return; 700 return;
676 701
677 const blink::WebInputEvent* event = std::get<0>(params); 702 const blink::WebInputEvent* event = std::get<0>(params);
678 SendTouchEventACK(event->type(), ack_result, 703 SendTouchEventACK(event->type(), ack_result,
679 WebInputEventTraits::GetUniqueTouchEventId(*event)); 704 WebInputEventTraits::GetUniqueTouchEventId(*event));
680 } 705 }
681 706
682 const ui::MotionEventAura& pointer_state() { 707 const ui::MotionEventAura& pointer_state() { return view_->pointer_state(); }
683 return view_->pointer_state_for_test();
684 }
685 708
686 void EnableRafAlignedTouchInput() { 709 void EnableRafAlignedTouchInput() {
687 feature_list_.InitFromCommandLine( 710 feature_list_.InitFromCommandLine(
688 features::kRafAlignedTouchInputEvents.name, ""); 711 features::kRafAlignedTouchInputEvents.name, "");
689 } 712 }
690 713
691 void DisableRafAlignedTouchInput() { 714 void DisableRafAlignedTouchInput() {
692 feature_list_.InitFromCommandLine( 715 feature_list_.InitFromCommandLine(
693 "", features::kRafAlignedTouchInputEvents.name); 716 "", features::kRafAlignedTouchInputEvents.name);
694 } 717 }
(...skipping 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after
2282 // A partial damage frame. 2305 // A partial damage frame.
2283 gfx::Rect partial_view_rect(30, 30, 20, 20); 2306 gfx::Rect partial_view_rect(30, 30, 20, 20);
2284 EXPECT_CALL(observer, 2307 EXPECT_CALL(observer,
2285 OnDelegatedFrameDamage(view_->window_, partial_view_rect)); 2308 OnDelegatedFrameDamage(view_->window_, partial_view_rect));
2286 view_->OnSwapCompositorFrame( 2309 view_->OnSwapCompositorFrame(
2287 0, kArbitraryLocalSurfaceId, 2310 0, kArbitraryLocalSurfaceId,
2288 MakeDelegatedFrame(1.f, frame_size, partial_view_rect)); 2311 MakeDelegatedFrame(1.f, frame_size, partial_view_rect));
2289 testing::Mock::VerifyAndClearExpectations(&observer); 2312 testing::Mock::VerifyAndClearExpectations(&observer);
2290 view_->RunOnCompositingDidCommit(); 2313 view_->RunOnCompositingDidCommit();
2291 2314
2315 EXPECT_FALSE(view_->resize_locked());
2316 EXPECT_FALSE(view_->compositor_locked());
2317
2292 // Lock the compositor. Now we should drop frames. 2318 // Lock the compositor. Now we should drop frames.
2293 view_rect = gfx::Rect(150, 150); 2319 view_rect = gfx::Rect(150, 150);
2294 view_->SetSize(view_rect.size()); 2320 view_->SetSize(view_rect.size());
2321 EXPECT_TRUE(view_->resize_locked());
2322 EXPECT_TRUE(view_->compositor_locked());
2295 2323
2296 // This frame is dropped. 2324 // This frame is dropped.
2297 gfx::Rect dropped_damage_rect_1(10, 20, 30, 40); 2325 gfx::Rect dropped_damage_rect_1(10, 20, 30, 40);
2298 EXPECT_CALL(observer, OnDelegatedFrameDamage(_, _)).Times(0); 2326 EXPECT_CALL(observer, OnDelegatedFrameDamage(_, _)).Times(0);
2299 view_->OnSwapCompositorFrame( 2327 view_->OnSwapCompositorFrame(
2300 0, kArbitraryLocalSurfaceId, 2328 0, kArbitraryLocalSurfaceId,
2301 MakeDelegatedFrame(1.f, frame_size, dropped_damage_rect_1)); 2329 MakeDelegatedFrame(1.f, frame_size, dropped_damage_rect_1));
2302 testing::Mock::VerifyAndClearExpectations(&observer); 2330 testing::Mock::VerifyAndClearExpectations(&observer);
2303 view_->RunOnCompositingDidCommit(); 2331 view_->RunOnCompositingDidCommit();
2304 2332
2305 gfx::Rect dropped_damage_rect_2(40, 50, 10, 20); 2333 gfx::Rect dropped_damage_rect_2(40, 50, 10, 20);
2306 EXPECT_CALL(observer, OnDelegatedFrameDamage(_, _)).Times(0); 2334 EXPECT_CALL(observer, OnDelegatedFrameDamage(_, _)).Times(0);
2307 view_->OnSwapCompositorFrame( 2335 view_->OnSwapCompositorFrame(
2308 0, kArbitraryLocalSurfaceId, 2336 0, kArbitraryLocalSurfaceId,
2309 MakeDelegatedFrame(1.f, frame_size, dropped_damage_rect_2)); 2337 MakeDelegatedFrame(1.f, frame_size, dropped_damage_rect_2));
2310 testing::Mock::VerifyAndClearExpectations(&observer); 2338 testing::Mock::VerifyAndClearExpectations(&observer);
2311 view_->RunOnCompositingDidCommit(); 2339 view_->RunOnCompositingDidCommit();
2312 2340
2341 EXPECT_TRUE(view_->resize_locked());
2342 EXPECT_TRUE(view_->compositor_locked());
2343
2313 // Unlock the compositor. This frame should damage everything. 2344 // Unlock the compositor. This frame should damage everything.
2314 frame_size = view_rect.size(); 2345 frame_size = view_rect.size();
2315 2346
2316 gfx::Rect new_damage_rect(5, 6, 10, 10); 2347 gfx::Rect new_damage_rect(5, 6, 10, 10);
2317 EXPECT_CALL(observer, 2348 EXPECT_CALL(observer,
2318 OnDelegatedFrameDamage(view_->window_, view_rect)); 2349 OnDelegatedFrameDamage(view_->window_, view_rect));
2319 view_->OnSwapCompositorFrame( 2350 view_->OnSwapCompositorFrame(
2320 0, kArbitraryLocalSurfaceId, 2351 0, kArbitraryLocalSurfaceId,
2321 MakeDelegatedFrame(1.f, frame_size, new_damage_rect)); 2352 MakeDelegatedFrame(1.f, frame_size, new_damage_rect));
2353 // The swap unlocks the compositor.
2354 EXPECT_TRUE(view_->resize_locked());
2355 EXPECT_FALSE(view_->compositor_locked());
2322 testing::Mock::VerifyAndClearExpectations(&observer); 2356 testing::Mock::VerifyAndClearExpectations(&observer);
2357 // The UI commit unlocks for further resize.
2323 view_->RunOnCompositingDidCommit(); 2358 view_->RunOnCompositingDidCommit();
2359 EXPECT_FALSE(view_->resize_locked());
2360 EXPECT_FALSE(view_->compositor_locked());
2324 2361
2325 // A partial damage frame, this should not be dropped. 2362 // A partial damage frame, this should not be dropped.
2326 EXPECT_CALL(observer, 2363 EXPECT_CALL(observer,
2327 OnDelegatedFrameDamage(view_->window_, partial_view_rect)); 2364 OnDelegatedFrameDamage(view_->window_, partial_view_rect));
2328 view_->OnSwapCompositorFrame( 2365 view_->OnSwapCompositorFrame(
2329 0, kArbitraryLocalSurfaceId, 2366 0, kArbitraryLocalSurfaceId,
2330 MakeDelegatedFrame(1.f, frame_size, partial_view_rect)); 2367 MakeDelegatedFrame(1.f, frame_size, partial_view_rect));
2331 testing::Mock::VerifyAndClearExpectations(&observer); 2368 testing::Mock::VerifyAndClearExpectations(&observer);
2332 view_->RunOnCompositingDidCommit(); 2369 view_->RunOnCompositingDidCommit();
2370 EXPECT_FALSE(view_->resize_locked());
2371 EXPECT_FALSE(view_->compositor_locked());
2333 2372
2334 2373 // Resize to something empty. This doesn't lock anything since it's not
2335 // Resize to something empty. 2374 // visible anymore anyways.
2336 view_rect = gfx::Rect(100, 0); 2375 view_rect = gfx::Rect(100, 0);
2337 view_->SetSize(view_rect.size()); 2376 view_->SetSize(view_rect.size());
2377 EXPECT_FALSE(view_->resize_locked());
2378 EXPECT_FALSE(view_->compositor_locked());
2338 2379
2339 // We're never expecting empty frames, resize to something non-empty. 2380 // We're never expecting empty frames, resize to something non-empty.
2340 view_rect = gfx::Rect(100, 100); 2381 view_rect = gfx::Rect(100, 100);
2341 view_->SetSize(view_rect.size()); 2382 view_->SetSize(view_rect.size());
2383 EXPECT_TRUE(view_->resize_locked());
2384 EXPECT_TRUE(view_->compositor_locked());
2342 2385
2343 // This frame should not be dropped. 2386 // This frame should not be dropped.
2344 EXPECT_CALL(observer, OnDelegatedFrameDamage(view_->window_, view_rect)); 2387 EXPECT_CALL(observer, OnDelegatedFrameDamage(view_->window_, view_rect));
2345 view_->OnSwapCompositorFrame( 2388 view_->OnSwapCompositorFrame(
2346 0, kArbitraryLocalSurfaceId, 2389 0, kArbitraryLocalSurfaceId,
2347 MakeDelegatedFrame(1.f, view_rect.size(), view_rect)); 2390 MakeDelegatedFrame(1.f, view_rect.size(), view_rect));
2348 testing::Mock::VerifyAndClearExpectations(&observer); 2391 testing::Mock::VerifyAndClearExpectations(&observer);
2392 EXPECT_TRUE(view_->resize_locked());
2393 EXPECT_FALSE(view_->compositor_locked());
2349 view_->RunOnCompositingDidCommit(); 2394 view_->RunOnCompositingDidCommit();
2395 EXPECT_FALSE(view_->resize_locked());
2396 EXPECT_FALSE(view_->compositor_locked());
2350 2397
2351 view_->window_->RemoveObserver(&observer); 2398 view_->window_->RemoveObserver(&observer);
2352 } 2399 }
2400
2401 // If resize races with a renderer frame, we should lock for the right size.
2402 TEST_F(RenderWidgetHostViewAuraTest, ResizeAfterReceivingFrame) {
2403 gfx::Rect view_rect(100, 100);
2404 gfx::Size frame_size = view_rect.size();
2405
2406 view_->InitAsChild(nullptr);
2407 aura::client::ParentWindowWithContext(
2408 view_->GetNativeView(), parent_view_->GetNativeView()->GetRootWindow(),
2409 gfx::Rect());
2410 view_->SetSize(view_rect.size());
2411
2412 MockWindowObserver observer;
2413 view_->window_->AddObserver(&observer);
2414
2415 // A frame of initial size.
2416 EXPECT_CALL(observer, OnDelegatedFrameDamage(view_->window_, view_rect));
2417 view_->OnSwapCompositorFrame(
2418 0, kArbitraryLocalSurfaceId,
2419 MakeDelegatedFrame(1.f, frame_size, gfx::Rect(frame_size)));
2420 testing::Mock::VerifyAndClearExpectations(&observer);
2421 view_->RunOnCompositingDidCommit();
2422
2423 // A frame of initial size arrives, but we don't commit in the UI yet.
2424 EXPECT_CALL(observer, OnDelegatedFrameDamage(view_->window_, _));
2425 view_->OnSwapCompositorFrame(
2426 0, kArbitraryLocalSurfaceId,
2427 MakeDelegatedFrame(1.f, frame_size, gfx::Rect(frame_size)));
2428 testing::Mock::VerifyAndClearExpectations(&observer);
2429
2430 EXPECT_FALSE(view_->resize_locked());
2431 EXPECT_FALSE(view_->compositor_locked());
2432
2433 // Resize, and lock the compositor. Now we should drop frames of the old size.
2434 view_rect = gfx::Rect(150, 150);
2435 view_->SetSize(view_rect.size());
2436 EXPECT_TRUE(view_->resize_locked());
2437 EXPECT_TRUE(view_->compositor_locked());
2438
2439 EXPECT_CALL(observer, OnDelegatedFrameDamage(_, _)).Times(0);
2440 view_->OnSwapCompositorFrame(
2441 0, kArbitraryLocalSurfaceId,
2442 MakeDelegatedFrame(1.f, frame_size, gfx::Rect(frame_size)));
2443 testing::Mock::VerifyAndClearExpectations(&observer);
2444
2445 // If the CompositorLock times out in the meantime, a commit would happen.
2446 // Verify that if a commit occurs, the lock remains and we reject frames
2447 // of the wrong size still.
2448 view_->RunOnCompositingDidCommit();
2449
2450 EXPECT_TRUE(view_->resize_locked());
2451 // In this case we lied about it and the CompositorLock is still active.
2452 EXPECT_TRUE(view_->compositor_locked());
2453
2454 EXPECT_CALL(observer, OnDelegatedFrameDamage(_, _)).Times(0);
2455 view_->OnSwapCompositorFrame(
2456 0, kArbitraryLocalSurfaceId,
2457 MakeDelegatedFrame(1.f, frame_size, gfx::Rect(frame_size)));
2458 testing::Mock::VerifyAndClearExpectations(&observer);
2459
2460 // A frame arrives of the new size, which will be accepted.
2461 frame_size = view_rect.size();
2462 EXPECT_CALL(observer, OnDelegatedFrameDamage(view_->window_, _));
2463 view_->OnSwapCompositorFrame(
2464 0, kArbitraryLocalSurfaceId,
2465 MakeDelegatedFrame(1.f, frame_size, gfx::Rect(frame_size)));
2466 // Receiving the frame unlocks the compositor so it can commit.
2467 EXPECT_TRUE(view_->resize_locked());
2468 EXPECT_FALSE(view_->compositor_locked());
2469 testing::Mock::VerifyAndClearExpectations(&observer);
2470
2471 // When the frame of the correct size is committed, the CompositorResizeLock
2472 // is released.
2473 view_->RunOnCompositingDidCommit();
2474 EXPECT_FALSE(view_->resize_locked());
2475 EXPECT_FALSE(view_->compositor_locked());
2476
2477 view_->window_->RemoveObserver(&observer);
2478 }
2353 2479
2354 TEST_F(RenderWidgetHostViewAuraTest, OutputSurfaceIdChange) { 2480 TEST_F(RenderWidgetHostViewAuraTest, OutputSurfaceIdChange) {
2355 gfx::Rect view_rect(100, 100); 2481 gfx::Rect view_rect(100, 100);
2356 gfx::Size frame_size = view_rect.size(); 2482 gfx::Size frame_size = view_rect.size();
2357 2483
2358 view_->InitAsChild(nullptr); 2484 view_->InitAsChild(nullptr);
2359 aura::client::ParentWindowWithContext( 2485 aura::client::ParentWindowWithContext(
2360 view_->GetNativeView(), 2486 view_->GetNativeView(),
2361 parent_view_->GetNativeView()->GetRootWindow(), 2487 parent_view_->GetNativeView()->GetRootWindow(),
2362 gfx::Rect()); 2488 gfx::Rect());
(...skipping 2657 matching lines...) Expand 10 before | Expand all | Expand 10 after
5020 // There is no composition in the beginning. 5146 // There is no composition in the beginning.
5021 EXPECT_FALSE(has_composition_text()); 5147 EXPECT_FALSE(has_composition_text());
5022 SetHasCompositionTextToTrue(); 5148 SetHasCompositionTextToTrue();
5023 view->ImeCancelComposition(); 5149 view->ImeCancelComposition();
5024 // The composition must have been canceled. 5150 // The composition must have been canceled.
5025 EXPECT_FALSE(has_composition_text()); 5151 EXPECT_FALSE(has_composition_text());
5026 } 5152 }
5027 } 5153 }
5028 5154
5029 } // namespace content 5155 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698