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