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

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

Issue 43193002: Aura/ÜC: Drop frames on background tabs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CONTENT_EXPORT Created 7 years, 1 month 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) 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/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 public: 121 public:
122 RenderWidgetHostViewAuraTest() 122 RenderWidgetHostViewAuraTest()
123 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} 123 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {}
124 124
125 virtual void SetUp() { 125 virtual void SetUp() {
126 ImageTransportFactory::InitializeForUnitTests(); 126 ImageTransportFactory::InitializeForUnitTests();
127 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); 127 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
128 aura_test_helper_->SetUp(); 128 aura_test_helper_->SetUp();
129 129
130 browser_context_.reset(new TestBrowserContext); 130 browser_context_.reset(new TestBrowserContext);
131 MockRenderProcessHost* process_host = 131 process_host_ = new MockRenderProcessHost(browser_context_.get());
132 new MockRenderProcessHost(browser_context_.get());
133 132
134 sink_ = &process_host->sink(); 133 sink_ = &process_host_->sink();
135 134
136 parent_host_ = new RenderWidgetHostImpl( 135 parent_host_ = new RenderWidgetHostImpl(
137 &delegate_, process_host, MSG_ROUTING_NONE, false); 136 &delegate_, process_host_, MSG_ROUTING_NONE, false);
138 parent_view_ = static_cast<RenderWidgetHostViewAura*>( 137 parent_view_ = static_cast<RenderWidgetHostViewAura*>(
139 RenderWidgetHostView::CreateViewForWidget(parent_host_)); 138 RenderWidgetHostView::CreateViewForWidget(parent_host_));
140 parent_view_->InitAsChild(NULL); 139 parent_view_->InitAsChild(NULL);
141 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(), 140 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(),
142 aura_test_helper_->root_window(), 141 aura_test_helper_->root_window(),
143 gfx::Rect()); 142 gfx::Rect());
144 143
145 widget_host_ = new RenderWidgetHostImpl( 144 widget_host_ = new RenderWidgetHostImpl(
146 &delegate_, process_host, MSG_ROUTING_NONE, false); 145 &delegate_, process_host_, MSG_ROUTING_NONE, false);
147 widget_host_->Init(); 146 widget_host_->Init();
148 widget_host_->OnMessageReceived( 147 widget_host_->OnMessageReceived(
149 ViewHostMsg_DidActivateAcceleratedCompositing(0, true)); 148 ViewHostMsg_DidActivateAcceleratedCompositing(0, true));
150 view_ = new FakeRenderWidgetHostViewAura(widget_host_); 149 view_ = new FakeRenderWidgetHostViewAura(widget_host_);
151 } 150 }
152 151
153 virtual void TearDown() { 152 virtual void TearDown() {
154 sink_ = NULL; 153 sink_ = NULL;
154 process_host_ = NULL;
155 if (view_) 155 if (view_)
156 view_->Destroy(); 156 view_->Destroy();
157 delete widget_host_; 157 delete widget_host_;
158 158
159 parent_view_->Destroy(); 159 parent_view_->Destroy();
160 delete parent_host_; 160 delete parent_host_;
161 161
162 browser_context_.reset(); 162 browser_context_.reset();
163 aura_test_helper_->TearDown(); 163 aura_test_helper_->TearDown();
164 164
165 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); 165 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release());
166 message_loop_.RunUntilIdle(); 166 message_loop_.RunUntilIdle();
167 ImageTransportFactory::Terminate(); 167 ImageTransportFactory::Terminate();
168 } 168 }
169 169
170 protected: 170 protected:
171 base::MessageLoopForUI message_loop_; 171 base::MessageLoopForUI message_loop_;
172 BrowserThreadImpl browser_thread_for_ui_; 172 BrowserThreadImpl browser_thread_for_ui_;
173 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; 173 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
174 scoped_ptr<BrowserContext> browser_context_; 174 scoped_ptr<BrowserContext> browser_context_;
175 MockRenderWidgetHostDelegate delegate_; 175 MockRenderWidgetHostDelegate delegate_;
176 MockRenderProcessHost* process_host_;
176 177
177 // Tests should set these to NULL if they've already triggered their 178 // Tests should set these to NULL if they've already triggered their
178 // destruction. 179 // destruction.
179 RenderWidgetHostImpl* parent_host_; 180 RenderWidgetHostImpl* parent_host_;
180 RenderWidgetHostViewAura* parent_view_; 181 RenderWidgetHostViewAura* parent_view_;
181 182
182 // Tests should set these to NULL if they've already triggered their 183 // Tests should set these to NULL if they've already triggered their
183 // destruction. 184 // destruction.
184 RenderWidgetHostImpl* widget_host_; 185 RenderWidgetHostImpl* widget_host_;
185 FakeRenderWidgetHostViewAura* view_; 186 FakeRenderWidgetHostViewAura* view_;
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 // Swap another frame, with a different surface id. 902 // Swap another frame, with a different surface id.
902 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect)); 903 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, view_rect));
903 view_->OnSwapCompositorFrame( 904 view_->OnSwapCompositorFrame(
904 3, MakeDelegatedFrame(1.f, frame_size, view_rect)); 905 3, MakeDelegatedFrame(1.f, frame_size, view_rect));
905 testing::Mock::VerifyAndClearExpectations(&observer); 906 testing::Mock::VerifyAndClearExpectations(&observer);
906 view_->RunOnCompositingDidCommit(); 907 view_->RunOnCompositingDidCommit();
907 908
908 view_->window_->RemoveObserver(&observer); 909 view_->window_->RemoveObserver(&observer);
909 } 910 }
910 911
912 TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFrames) {
913 size_t max_renderer_frames =
914 RendererFrameManager::GetInstance()->max_number_of_saved_frames();
915 ASSERT_LE(2u, max_renderer_frames);
916 size_t renderer_count = max_renderer_frames + 1;
917 gfx::Rect view_rect(100, 100);
918 gfx::Size frame_size = view_rect.size();
919
920 scoped_ptr<RenderWidgetHostImpl * []> hosts(
921 new RenderWidgetHostImpl* [renderer_count]);
922 scoped_ptr<FakeRenderWidgetHostViewAura * []> views(
923 new FakeRenderWidgetHostViewAura* [renderer_count]);
924
925 // Create a bunch of renderers.
926 for (size_t i = 0; i < renderer_count; ++i) {
927 hosts[i] = new RenderWidgetHostImpl(
928 &delegate_, process_host_, MSG_ROUTING_NONE, false);
929 hosts[i]->Init();
930 hosts[i]->OnMessageReceived(
931 ViewHostMsg_DidActivateAcceleratedCompositing(0, true));
932 views[i] = new FakeRenderWidgetHostViewAura(hosts[i]);
933 views[i]->InitAsChild(NULL);
934 aura::client::ParentWindowWithContext(
935 views[i]->GetNativeView(),
936 parent_view_->GetNativeView()->GetRootWindow(),
937 gfx::Rect());
938 views[i]->SetSize(view_rect.size());
939 }
940
941 // Make each renderer visible, and swap a frame on it, then make it invisible.
942 for (size_t i = 0; i < renderer_count; ++i) {
943 views[i]->WasShown();
944 views[i]->OnSwapCompositorFrame(
945 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
946 EXPECT_TRUE(views[i]->frame_provider_);
947 views[i]->WasHidden();
948 }
949
950 // There should be max_renderer_frames with a frame in it, and one without it.
951 // Since the logic is LRU eviction, the first one should be without.
952 EXPECT_FALSE(views[0]->frame_provider_);
953 for (size_t i = 1; i < renderer_count; ++i)
954 EXPECT_TRUE(views[i]->frame_provider_);
955
956 // LRU renderer is [0], make it visible, it shouldn't evict anything yet.
957 views[0]->WasShown();
958 EXPECT_FALSE(views[0]->frame_provider_);
959 EXPECT_TRUE(views[1]->frame_provider_);
960
961 // Swap a frame on it, it should evict the next LRU [1].
962 views[0]->OnSwapCompositorFrame(
963 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
964 EXPECT_TRUE(views[0]->frame_provider_);
965 EXPECT_FALSE(views[1]->frame_provider_);
966 views[0]->WasHidden();
967
968 // LRU renderer is [1], still hidden. Swap a frame on it, it should evict
969 // the next LRU [2].
970 views[1]->OnSwapCompositorFrame(
971 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
972 EXPECT_TRUE(views[0]->frame_provider_);
973 EXPECT_TRUE(views[1]->frame_provider_);
974 EXPECT_FALSE(views[2]->frame_provider_);
975 for (size_t i = 3; i < renderer_count; ++i)
976 EXPECT_TRUE(views[i]->frame_provider_);
977
978 // Make all renderers but [0] visible and swap a frame on them, keep [0]
979 // hidden, it becomes the LRU.
980 for (size_t i = 1; i < renderer_count; ++i) {
981 views[i]->WasShown();
982 views[i]->OnSwapCompositorFrame(
983 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
984 EXPECT_TRUE(views[i]->frame_provider_);
985 }
986 EXPECT_FALSE(views[0]->frame_provider_);
987
988 // Swap a frame on [0], it should be evicted immediately.
989 views[0]->OnSwapCompositorFrame(
990 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
991 EXPECT_FALSE(views[0]->frame_provider_);
992
993 // Make [0] visible, and swap a frame on it. Nothing should be evicted
994 // although we're above the limit.
995 views[0]->WasShown();
996 views[0]->OnSwapCompositorFrame(
997 1, MakeDelegatedFrame(1.f, frame_size, view_rect));
998 for (size_t i = 0; i < renderer_count; ++i)
999 EXPECT_TRUE(views[i]->frame_provider_);
1000
1001 // Make [0] hidden, it should evict its frame.
1002 views[0]->WasHidden();
1003 EXPECT_FALSE(views[0]->frame_provider_);
1004
1005 for (size_t i = 0; i < renderer_count; ++i) {
1006 views[i]->Destroy();
1007 delete hosts[i];
1008 }
1009 }
1010
911 } // namespace content 1011 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.cc ('k') | content/browser/renderer_host/renderer_frame_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698