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

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

Issue 1759323003: Add resize gutter layers to DelegatedFrameHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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) 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 #include <utility> 9 #include <utility>
10 10
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 270
271 private: 271 private:
272 size_t processed_touch_event_count_; 272 size_t processed_touch_event_count_;
273 }; 273 };
274 274
275 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { 275 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura {
276 public: 276 public:
277 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget, 277 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget,
278 bool is_guest_view_hack) 278 bool is_guest_view_hack)
279 : RenderWidgetHostViewAura(widget, is_guest_view_hack), 279 : RenderWidgetHostViewAura(widget, is_guest_view_hack),
280 has_resize_lock_(false) {} 280 can_create_resize_lock_(true) {}
281 281
282 void UseFakeDispatcher() { 282 void UseFakeDispatcher() {
283 dispatcher_ = new FakeWindowEventDispatcher(window()->GetHost()); 283 dispatcher_ = new FakeWindowEventDispatcher(window()->GetHost());
284 scoped_ptr<aura::WindowEventDispatcher> dispatcher(dispatcher_); 284 scoped_ptr<aura::WindowEventDispatcher> dispatcher(dispatcher_);
285 aura::test::SetHostDispatcher(window()->GetHost(), std::move(dispatcher)); 285 aura::test::SetHostDispatcher(window()->GetHost(), std::move(dispatcher));
286 } 286 }
287 287
288 ~FakeRenderWidgetHostViewAura() override {} 288 ~FakeRenderWidgetHostViewAura() override {}
289 289
290 scoped_ptr<ResizeLock> DelegatedFrameHostCreateResizeLock( 290 scoped_ptr<ResizeLock> DelegatedFrameHostCreateResizeLock(
291 bool defer_compositor_lock) override { 291 bool defer_compositor_lock) override {
292 gfx::Size desired_size = window()->bounds().size(); 292 gfx::Size desired_size = window()->bounds().size();
293 return scoped_ptr<ResizeLock>( 293 return scoped_ptr<ResizeLock>(
294 new FakeResizeLock(desired_size, defer_compositor_lock)); 294 new FakeResizeLock(desired_size, defer_compositor_lock));
295 } 295 }
296 296
297 bool DelegatedFrameCanCreateResizeLock() const override { return true; } 297 bool DelegatedFrameCanCreateResizeLock() const override {
298 return can_create_resize_lock_;
299 }
298 300
299 void RunOnCompositingDidCommit() { 301 void RunOnCompositingDidCommit() {
300 GetDelegatedFrameHost()->OnCompositingDidCommitForTesting( 302 GetDelegatedFrameHost()->OnCompositingDidCommitForTesting(
301 window()->GetHost()->compositor()); 303 window()->GetHost()->compositor());
302 } 304 }
303 305
304 void InterceptCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request) { 306 void InterceptCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request) {
305 last_copy_request_ = std::move(request); 307 last_copy_request_ = std::move(request);
306 if (last_copy_request_->has_texture_mailbox()) { 308 if (last_copy_request_->has_texture_mailbox()) {
307 // Give the resulting texture a size. 309 // Give the resulting texture a size.
(...skipping 23 matching lines...) Expand all
331 class FakeResizeLock : public ResizeLock { 333 class FakeResizeLock : public ResizeLock {
332 public: 334 public:
333 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock) 335 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock)
334 : ResizeLock(new_size, defer_compositor_lock) {} 336 : ResizeLock(new_size, defer_compositor_lock) {}
335 }; 337 };
336 338
337 const ui::MotionEventAura& pointer_state_for_test() { 339 const ui::MotionEventAura& pointer_state_for_test() {
338 return pointer_state(); 340 return pointer_state();
339 } 341 }
340 342
341 bool has_resize_lock_; 343 bool can_create_resize_lock_;
342 gfx::Size last_frame_size_; 344 gfx::Size last_frame_size_;
343 scoped_ptr<cc::CopyOutputRequest> last_copy_request_; 345 scoped_ptr<cc::CopyOutputRequest> last_copy_request_;
344 FakeWindowEventDispatcher* dispatcher_; 346 FakeWindowEventDispatcher* dispatcher_;
345 }; 347 };
346 348
347 // A layout manager that always resizes a child to the root window size. 349 // A layout manager that always resizes a child to the root window size.
348 class FullscreenLayoutManager : public aura::LayoutManager { 350 class FullscreenLayoutManager : public aura::LayoutManager {
349 public: 351 public:
350 explicit FullscreenLayoutManager(aura::Window* owner) : owner_(owner) {} 352 explicit FullscreenLayoutManager(aura::Window* owner) : owner_(owner) {}
351 ~FullscreenLayoutManager() override {} 353 ~FullscreenLayoutManager() override {}
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 if (!id.is_null()) { 1681 if (!id.is_null()) {
1680 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 1682 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
1681 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 1683 cc::SurfaceManager* manager = factory->GetSurfaceManager();
1682 cc::Surface* surface = manager->GetSurfaceForId(id); 1684 cc::Surface* surface = manager->GetSurfaceForId(id);
1683 EXPECT_TRUE(surface); 1685 EXPECT_TRUE(surface);
1684 // Should be a SurfaceSequence for both the original and new layers. 1686 // Should be a SurfaceSequence for both the original and new layers.
1685 EXPECT_EQ(2u, surface->GetDestructionDependencyCount()); 1687 EXPECT_EQ(2u, surface->GetDestructionDependencyCount());
1686 } 1688 }
1687 } 1689 }
1688 1690
1691 // If the view size is larger than the compositor frame then extra layers
1692 // should be created to fill the gap.
1693 TEST_F(RenderWidgetHostViewAuraTest, DelegatedFrameGutter) {
1694 gfx::Size view_size(100, 100);
danakj 2016/03/08 00:09:44 nit: large_size
jbauman 2016/03/08 01:45:29 Done.
1695 gfx::Size small_size(40, 45);
1696 gfx::Size medium_size(40, 95);
1697
1698 // Prevent the DelegatedFrameHost from skipping frames.
1699 view_->can_create_resize_lock_ = false;
1700
1701 view_->InitAsChild(NULL);
1702 aura::client::ParentWindowWithContext(
1703 view_->GetNativeView(), parent_view_->GetNativeView()->GetRootWindow(),
1704 gfx::Rect());
1705 view_->SetSize(view_size);
1706 view_->Show();
1707 scoped_ptr<cc::CompositorFrame> frame =
1708 MakeDelegatedFrame(1.f, small_size, gfx::Rect(small_size));
1709 frame->metadata.root_background_color = SK_ColorRED;
1710 view_->OnSwapCompositorFrame(0, std::move(frame));
1711
1712 ui::Layer* parent_layer = view_->GetNativeView()->layer();
1713
1714 ASSERT_EQ(2u, parent_layer->children().size());
1715 EXPECT_EQ(gfx::Rect(40, 0, 60, 100), parent_layer->children()[0]->bounds());
1716 EXPECT_EQ(SK_ColorRED, parent_layer->children()[0]->background_color());
1717 EXPECT_EQ(gfx::Rect(0, 45, 40, 55), parent_layer->children()[1]->bounds());
1718 EXPECT_EQ(SK_ColorRED, parent_layer->children()[1]->background_color());
1719
1720 view_->SetSize(medium_size);
1721
1722 // Right gutter is unnecessary.
1723 ASSERT_EQ(1u, parent_layer->children().size());
1724 EXPECT_EQ(gfx::Rect(0, 45, 40, 50), parent_layer->children()[0]->bounds());
1725
1726 frame = MakeDelegatedFrame(1.f, medium_size, gfx::Rect(medium_size));
1727 view_->OnSwapCompositorFrame(0, std::move(frame));
1728 EXPECT_EQ(0u, parent_layer->children().size());
1729
1730 view_->SetSize(view_size);
1731 ASSERT_EQ(2u, parent_layer->children().size());
1732
1733 // This should evict the frame and remove the gutter layers.
1734 view_->Hide();
1735 view_->SetSize(small_size);
1736 ASSERT_EQ(0u, parent_layer->children().size());
1737 }
1738
1689 TEST_F(RenderWidgetHostViewAuraTest, Resize) { 1739 TEST_F(RenderWidgetHostViewAuraTest, Resize) {
1690 gfx::Size size1(100, 100); 1740 gfx::Size size1(100, 100);
1691 gfx::Size size2(200, 200); 1741 gfx::Size size2(200, 200);
1692 gfx::Size size3(300, 300); 1742 gfx::Size size3(300, 300);
1693 1743
1694 aura::Window* root_window = parent_view_->GetNativeView()->GetRootWindow(); 1744 aura::Window* root_window = parent_view_->GetNativeView()->GetRootWindow();
1695 view_->InitAsChild(NULL); 1745 view_->InitAsChild(NULL);
1696 aura::client::ParentWindowWithContext( 1746 aura::client::ParentWindowWithContext(
1697 view_->GetNativeView(), root_window, gfx::Rect(size1)); 1747 view_->GetNativeView(), root_window, gfx::Rect(size1));
1698 view_->Show(); 1748 view_->Show();
(...skipping 2720 matching lines...) Expand 10 before | Expand all | Expand 10 after
4419 view()->OnGestureEvent(&gesture_event); 4469 view()->OnGestureEvent(&gesture_event);
4420 4470
4421 EXPECT_TRUE(delegate->context_menu_request_received()); 4471 EXPECT_TRUE(delegate->context_menu_request_received());
4422 EXPECT_EQ(delegate->context_menu_source_type(), ui::MENU_SOURCE_TOUCH); 4472 EXPECT_EQ(delegate->context_menu_source_type(), ui::MENU_SOURCE_TOUCH);
4423 #endif 4473 #endif
4424 4474
4425 RenderViewHostFactory::set_is_real_render_view_host(false); 4475 RenderViewHostFactory::set_is_real_render_view_host(false);
4426 } 4476 }
4427 4477
4428 } // namespace content 4478 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698