OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/frame_host/render_widget_host_view_guest.h" | 5 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
25 #include "content/public/browser/browser_plugin_guest_delegate.h" | 25 #include "content/public/browser/browser_plugin_guest_delegate.h" |
26 #include "content/public/browser/render_widget_host_view.h" | 26 #include "content/public/browser/render_widget_host_view.h" |
27 #include "content/public/test/mock_render_process_host.h" | 27 #include "content/public/test/mock_render_process_host.h" |
28 #include "content/public/test/test_browser_context.h" | 28 #include "content/public/test/test_browser_context.h" |
29 #include "content/test/test_render_view_host.h" | 29 #include "content/test/test_render_view_host.h" |
30 #include "content/test/test_web_contents.h" | 30 #include "content/test/test_web_contents.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 #include "ui/compositor/compositor.h" | 32 #include "ui/compositor/compositor.h" |
33 | 33 |
34 #if defined(OS_ANDROID) | |
35 #include "content/browser/renderer_host/context_provider_factory_impl_android.h" | |
36 #include "content/test/mock_gpu_channel_establish_factory.h" | |
37 #endif | |
38 | |
39 namespace content { | 34 namespace content { |
40 namespace { | 35 namespace { |
41 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { | 36 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { |
42 public: | 37 public: |
43 MockRenderWidgetHostDelegate() {} | 38 MockRenderWidgetHostDelegate() {} |
44 ~MockRenderWidgetHostDelegate() override {} | 39 ~MockRenderWidgetHostDelegate() override {} |
45 | 40 |
46 private: | 41 private: |
47 // RenderWidgetHostDelegate: | 42 // RenderWidgetHostDelegate: |
48 void Cut() override {} | 43 void Cut() override {} |
49 void Copy() override {} | 44 void Copy() override {} |
50 void Paste() override {} | 45 void Paste() override {} |
51 void SelectAll() override {} | 46 void SelectAll() override {} |
52 }; | 47 }; |
53 | 48 |
54 class RenderWidgetHostViewGuestTest : public testing::Test { | 49 class RenderWidgetHostViewGuestTest : public testing::Test { |
55 public: | 50 public: |
56 RenderWidgetHostViewGuestTest() {} | 51 RenderWidgetHostViewGuestTest() {} |
57 | 52 |
58 void SetUp() override { | 53 void SetUp() override { |
59 #if !defined(OS_ANDROID) | 54 #if !defined(OS_ANDROID) |
60 ImageTransportFactory::InitializeForUnitTests( | 55 ImageTransportFactory::InitializeForUnitTests( |
61 std::unique_ptr<ImageTransportFactory>( | 56 std::unique_ptr<ImageTransportFactory>( |
62 new NoTransportImageTransportFactory)); | 57 new NoTransportImageTransportFactory)); |
63 #else | |
64 ContextProviderFactoryImpl::Initialize(&gpu_channel_factory_); | |
65 ui::ContextProviderFactory::SetInstance( | |
66 ContextProviderFactoryImpl::GetInstance()); | |
67 #endif | 58 #endif |
68 browser_context_.reset(new TestBrowserContext); | 59 browser_context_.reset(new TestBrowserContext); |
69 MockRenderProcessHost* process_host = | 60 MockRenderProcessHost* process_host = |
70 new MockRenderProcessHost(browser_context_.get()); | 61 new MockRenderProcessHost(browser_context_.get()); |
71 int32_t routing_id = process_host->GetNextRoutingID(); | 62 int32_t routing_id = process_host->GetNextRoutingID(); |
72 widget_host_ = | 63 widget_host_ = |
73 new RenderWidgetHostImpl(&delegate_, process_host, routing_id, false); | 64 new RenderWidgetHostImpl(&delegate_, process_host, routing_id, false); |
74 view_ = RenderWidgetHostViewGuest::Create( | 65 view_ = RenderWidgetHostViewGuest::Create( |
75 widget_host_, NULL, | 66 widget_host_, NULL, |
76 (new TestRenderWidgetHostView(widget_host_))->GetWeakPtr()); | 67 (new TestRenderWidgetHostView(widget_host_))->GetWeakPtr()); |
77 } | 68 } |
78 | 69 |
79 void TearDown() override { | 70 void TearDown() override { |
80 if (view_) | 71 if (view_) |
81 view_->Destroy(); | 72 view_->Destroy(); |
82 delete widget_host_; | 73 delete widget_host_; |
83 | 74 |
84 browser_context_.reset(); | 75 browser_context_.reset(); |
85 | 76 |
86 message_loop_.task_runner()->DeleteSoon(FROM_HERE, | 77 message_loop_.task_runner()->DeleteSoon(FROM_HERE, |
87 browser_context_.release()); | 78 browser_context_.release()); |
88 base::RunLoop().RunUntilIdle(); | 79 base::RunLoop().RunUntilIdle(); |
89 #if !defined(OS_ANDROID) | 80 #if !defined(OS_ANDROID) |
90 ImageTransportFactory::Terminate(); | 81 ImageTransportFactory::Terminate(); |
91 #else | |
92 ui::ContextProviderFactory::SetInstance(nullptr); | |
93 ContextProviderFactoryImpl::Terminate(); | |
94 #endif | 82 #endif |
95 } | 83 } |
96 | 84 |
97 protected: | 85 protected: |
98 base::MessageLoopForUI message_loop_; | 86 base::MessageLoopForUI message_loop_; |
99 std::unique_ptr<BrowserContext> browser_context_; | 87 std::unique_ptr<BrowserContext> browser_context_; |
100 MockRenderWidgetHostDelegate delegate_; | 88 MockRenderWidgetHostDelegate delegate_; |
101 | 89 |
102 // Tests should set these to NULL if they've already triggered their | 90 // Tests should set these to NULL if they've already triggered their |
103 // destruction. | 91 // destruction. |
104 RenderWidgetHostImpl* widget_host_; | 92 RenderWidgetHostImpl* widget_host_; |
105 RenderWidgetHostViewGuest* view_; | 93 RenderWidgetHostViewGuest* view_; |
106 | 94 |
107 #if defined(OS_ANDROID) | |
108 MockGpuChannelEstablishFactory gpu_channel_factory_; | |
109 #endif | |
110 | |
111 private: | 95 private: |
112 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuestTest); | 96 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuestTest); |
113 }; | 97 }; |
114 | 98 |
115 } // namespace | 99 } // namespace |
116 | 100 |
117 TEST_F(RenderWidgetHostViewGuestTest, VisibilityTest) { | 101 TEST_F(RenderWidgetHostViewGuestTest, VisibilityTest) { |
118 view_->Show(); | 102 view_->Show(); |
119 ASSERT_TRUE(view_->IsShowing()); | 103 ASSERT_TRUE(view_->IsShowing()); |
120 | 104 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 : public testing::Test { | 141 : public testing::Test { |
158 public: | 142 public: |
159 RenderWidgetHostViewGuestSurfaceTest() | 143 RenderWidgetHostViewGuestSurfaceTest() |
160 : widget_host_(nullptr), view_(nullptr) {} | 144 : widget_host_(nullptr), view_(nullptr) {} |
161 | 145 |
162 void SetUp() override { | 146 void SetUp() override { |
163 #if !defined(OS_ANDROID) | 147 #if !defined(OS_ANDROID) |
164 ImageTransportFactory::InitializeForUnitTests( | 148 ImageTransportFactory::InitializeForUnitTests( |
165 std::unique_ptr<ImageTransportFactory>( | 149 std::unique_ptr<ImageTransportFactory>( |
166 new NoTransportImageTransportFactory)); | 150 new NoTransportImageTransportFactory)); |
167 #else | |
168 ContextProviderFactoryImpl::Initialize(&gpu_channel_factory_); | |
169 ui::ContextProviderFactory::SetInstance( | |
170 ContextProviderFactoryImpl::GetInstance()); | |
171 #endif | 151 #endif |
172 browser_context_.reset(new TestBrowserContext); | 152 browser_context_.reset(new TestBrowserContext); |
173 MockRenderProcessHost* process_host = | 153 MockRenderProcessHost* process_host = |
174 new MockRenderProcessHost(browser_context_.get()); | 154 new MockRenderProcessHost(browser_context_.get()); |
175 web_contents_.reset( | 155 web_contents_.reset( |
176 TestWebContents::Create(browser_context_.get(), nullptr)); | 156 TestWebContents::Create(browser_context_.get(), nullptr)); |
177 // We don't own the BPG, the WebContents does. | 157 // We don't own the BPG, the WebContents does. |
178 browser_plugin_guest_ = new TestBrowserPluginGuest( | 158 browser_plugin_guest_ = new TestBrowserPluginGuest( |
179 web_contents_.get(), &browser_plugin_guest_delegate_); | 159 web_contents_.get(), &browser_plugin_guest_delegate_); |
180 | 160 |
181 int32_t routing_id = process_host->GetNextRoutingID(); | 161 int32_t routing_id = process_host->GetNextRoutingID(); |
182 widget_host_ = | 162 widget_host_ = |
183 new RenderWidgetHostImpl(&delegate_, process_host, routing_id, false); | 163 new RenderWidgetHostImpl(&delegate_, process_host, routing_id, false); |
184 view_ = RenderWidgetHostViewGuest::Create( | 164 view_ = RenderWidgetHostViewGuest::Create( |
185 widget_host_, browser_plugin_guest_, | 165 widget_host_, browser_plugin_guest_, |
186 (new TestRenderWidgetHostView(widget_host_))->GetWeakPtr()); | 166 (new TestRenderWidgetHostView(widget_host_))->GetWeakPtr()); |
187 } | 167 } |
188 | 168 |
189 void TearDown() override { | 169 void TearDown() override { |
190 if (view_) | 170 if (view_) |
191 view_->Destroy(); | 171 view_->Destroy(); |
192 delete widget_host_; | 172 delete widget_host_; |
193 | 173 |
194 // It's important to make sure that the view finishes destructing before | 174 // It's important to make sure that the view finishes destructing before |
195 // we hit the destructor for the TestBrowserThreadBundle, so run the message | 175 // we hit the destructor for the TestBrowserThreadBundle, so run the message |
196 // loop here. | 176 // loop here. |
197 base::RunLoop().RunUntilIdle(); | 177 base::RunLoop().RunUntilIdle(); |
198 #if !defined(OS_ANDROID) | 178 #if !defined(OS_ANDROID) |
199 ImageTransportFactory::Terminate(); | 179 ImageTransportFactory::Terminate(); |
200 #else | |
201 ui::ContextProviderFactory::SetInstance(nullptr); | |
202 ContextProviderFactoryImpl::Terminate(); | |
203 #endif | 180 #endif |
204 } | 181 } |
205 | 182 |
206 cc::SurfaceId GetSurfaceId() const { | 183 cc::SurfaceId GetSurfaceId() const { |
207 DCHECK(view_); | 184 DCHECK(view_); |
208 RenderWidgetHostViewChildFrame* rwhvcf = | 185 RenderWidgetHostViewChildFrame* rwhvcf = |
209 static_cast<RenderWidgetHostViewChildFrame*>(view_); | 186 static_cast<RenderWidgetHostViewChildFrame*>(view_); |
210 if (!rwhvcf->local_surface_id_.is_valid()) | 187 if (!rwhvcf->local_surface_id_.is_valid()) |
211 return cc::SurfaceId(); | 188 return cc::SurfaceId(); |
212 return cc::SurfaceId(rwhvcf->frame_sink_id_, rwhvcf->local_surface_id_); | 189 return cc::SurfaceId(rwhvcf->frame_sink_id_, rwhvcf->local_surface_id_); |
213 } | 190 } |
214 | 191 |
215 protected: | 192 protected: |
216 TestBrowserThreadBundle thread_bundle_; | 193 TestBrowserThreadBundle thread_bundle_; |
217 std::unique_ptr<BrowserContext> browser_context_; | 194 std::unique_ptr<BrowserContext> browser_context_; |
218 MockRenderWidgetHostDelegate delegate_; | 195 MockRenderWidgetHostDelegate delegate_; |
219 BrowserPluginGuestDelegate browser_plugin_guest_delegate_; | 196 BrowserPluginGuestDelegate browser_plugin_guest_delegate_; |
220 std::unique_ptr<TestWebContents> web_contents_; | 197 std::unique_ptr<TestWebContents> web_contents_; |
221 TestBrowserPluginGuest* browser_plugin_guest_; | 198 TestBrowserPluginGuest* browser_plugin_guest_; |
222 | 199 |
223 #if defined(OS_ANDROID) | |
224 MockGpuChannelEstablishFactory gpu_channel_factory_; | |
225 #endif | |
226 | |
227 // Tests should set these to NULL if they've already triggered their | 200 // Tests should set these to NULL if they've already triggered their |
228 // destruction. | 201 // destruction. |
229 RenderWidgetHostImpl* widget_host_; | 202 RenderWidgetHostImpl* widget_host_; |
230 RenderWidgetHostViewGuest* view_; | 203 RenderWidgetHostViewGuest* view_; |
231 | 204 |
232 private: | 205 private: |
233 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuestSurfaceTest); | 206 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuestSurfaceTest); |
234 }; | 207 }; |
235 | 208 |
236 namespace { | 209 namespace { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 276 |
304 browser_plugin_guest_->set_attached(false); | 277 browser_plugin_guest_->set_attached(false); |
305 browser_plugin_guest_->ResetTestData(); | 278 browser_plugin_guest_->ResetTestData(); |
306 | 279 |
307 view_->OnSwapCompositorFrame( | 280 view_->OnSwapCompositorFrame( |
308 0, CreateDelegatedFrame(scale_factor, view_size, view_rect)); | 281 0, CreateDelegatedFrame(scale_factor, view_size, view_rect)); |
309 EXPECT_FALSE(GetSurfaceId().is_valid()); | 282 EXPECT_FALSE(GetSurfaceId().is_valid()); |
310 } | 283 } |
311 | 284 |
312 } // namespace content | 285 } // namespace content |
OLD | NEW |