OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 6 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
7 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" | 7 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" |
8 #include "content/browser/renderer_host/offscreen_canvas_surface_manager.h" | 8 #include "content/browser/renderer_host/offscreen_canvas_surface_manager.h" |
9 #include "content/public/test/test_browser_thread.h" | 9 #include "content/public/test/test_browser_thread.h" |
10 #include "mojo/public/cpp/bindings/binding.h" | 10 #include "mojo/public/cpp/bindings/binding.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 #if defined(OS_ANDROID) | 13 #if defined(OS_ANDROID) |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "content/browser/renderer_host/context_provider_factory_impl_android.h" | |
16 #include "content/test/mock_gpu_channel_establish_factory.h" | |
17 #else | 15 #else |
18 #include "content/browser/compositor/image_transport_factory.h" | 16 #include "content/browser/compositor/image_transport_factory.h" |
19 #endif | 17 #endif |
20 | 18 |
21 namespace content { | 19 namespace content { |
22 | 20 |
23 class OffscreenCanvasSurfaceManagerTest : public testing::Test { | 21 class OffscreenCanvasSurfaceManagerTest : public testing::Test { |
24 public: | 22 public: |
25 int getNumSurfaceImplInstances() { | 23 int getNumSurfaceImplInstances() { |
26 return OffscreenCanvasSurfaceManager::GetInstance() | 24 return OffscreenCanvasSurfaceManager::GetInstance() |
27 ->registered_surface_instances_.size(); | 25 ->registered_surface_instances_.size(); |
28 } | 26 } |
29 | 27 |
30 void OnSurfaceCreated(const cc::SurfaceId& surface_id) { | 28 void OnSurfaceCreated(const cc::SurfaceId& surface_id) { |
31 OffscreenCanvasSurfaceManager::GetInstance()->OnSurfaceCreated( | 29 OffscreenCanvasSurfaceManager::GetInstance()->OnSurfaceCreated( |
32 cc::SurfaceInfo(surface_id, 1.0f, gfx::Size(10, 10))); | 30 cc::SurfaceInfo(surface_id, 1.0f, gfx::Size(10, 10))); |
33 } | 31 } |
34 | 32 |
35 protected: | 33 protected: |
36 void SetUp() override; | 34 void SetUp() override; |
37 void TearDown() override; | 35 void TearDown() override; |
38 | 36 |
39 private: | 37 private: |
40 std::unique_ptr<TestBrowserThread> ui_thread_; | 38 std::unique_ptr<TestBrowserThread> ui_thread_; |
41 base::MessageLoopForUI message_loop_; | 39 base::MessageLoopForUI message_loop_; |
42 #if defined(OS_ANDROID) | |
43 MockGpuChannelEstablishFactory gpu_channel_factory_; | |
44 #endif | |
45 }; | 40 }; |
46 | 41 |
47 void OffscreenCanvasSurfaceManagerTest::SetUp() { | 42 void OffscreenCanvasSurfaceManagerTest::SetUp() { |
48 #if defined(OS_ANDROID) | 43 #if !defined(OS_ANDROID) |
49 ContextProviderFactoryImpl::Initialize(&gpu_channel_factory_); | |
50 ui::ContextProviderFactory::SetInstance( | |
51 ContextProviderFactoryImpl::GetInstance()); | |
52 #else | |
53 ImageTransportFactory::InitializeForUnitTests( | 44 ImageTransportFactory::InitializeForUnitTests( |
54 std::unique_ptr<ImageTransportFactory>( | 45 std::unique_ptr<ImageTransportFactory>( |
55 new NoTransportImageTransportFactory)); | 46 new NoTransportImageTransportFactory)); |
56 #endif | 47 #endif |
57 ui_thread_.reset(new TestBrowserThread(BrowserThread::UI, &message_loop_)); | 48 ui_thread_.reset(new TestBrowserThread(BrowserThread::UI, &message_loop_)); |
58 } | 49 } |
59 | 50 |
60 void OffscreenCanvasSurfaceManagerTest::TearDown() { | 51 void OffscreenCanvasSurfaceManagerTest::TearDown() { |
61 #if defined(OS_ANDROID) | 52 #if !defined(OS_ANDROID) |
62 ui::ContextProviderFactory::SetInstance(nullptr); | |
63 ContextProviderFactoryImpl::Terminate(); | |
64 #else | |
65 ImageTransportFactory::Terminate(); | 53 ImageTransportFactory::Terminate(); |
66 #endif | 54 #endif |
67 } | 55 } |
68 | 56 |
69 // This test mimics the workflow of OffscreenCanvas.commit() on renderer | 57 // This test mimics the workflow of OffscreenCanvas.commit() on renderer |
70 // process. | 58 // process. |
71 TEST_F(OffscreenCanvasSurfaceManagerTest, | 59 TEST_F(OffscreenCanvasSurfaceManagerTest, |
72 SingleHTMLCanvasElementTransferToOffscreen) { | 60 SingleHTMLCanvasElementTransferToOffscreen) { |
73 blink::mojom::OffscreenCanvasSurfaceClientPtr client; | 61 blink::mojom::OffscreenCanvasSurfaceClientPtr client; |
74 cc::FrameSinkId frame_sink_id(3, 3); | 62 cc::FrameSinkId frame_sink_id(3, 3); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( | 102 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( |
115 frame_sink_id_b)); | 103 frame_sink_id_b)); |
116 | 104 |
117 surface_impl_a = nullptr; | 105 surface_impl_a = nullptr; |
118 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); | 106 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); |
119 surface_impl_b = nullptr; | 107 surface_impl_b = nullptr; |
120 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); | 108 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); |
121 } | 109 } |
122 | 110 |
123 } // namespace content | 111 } // namespace content |
OLD | NEW |