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