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 "content/browser/renderer_host/offscreen_canvas_compositor_frame_sink_m
anager.h" |
| 6 |
5 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
6 #include "cc/surfaces/local_surface_id_allocator.h" | 8 #include "cc/surfaces/local_surface_id_allocator.h" |
7 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 9 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
8 #include "content/browser/renderer_host/offscreen_canvas_compositor_frame_sink_m
anager.h" | |
9 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" | 10 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" |
10 #include "content/public/test/test_browser_thread.h" | 11 #include "content/public/test/test_browser_thread.h" |
11 #include "mojo/public/cpp/bindings/binding.h" | 12 #include "mojo/public/cpp/bindings/binding.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/WebKit/public/platform/modules/offscreencanvas/offscreen_c
anvas_surface.mojom.h" |
13 | 15 |
14 #if defined(OS_ANDROID) | 16 #if defined(OS_ANDROID) |
15 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
16 #else | 18 #else |
17 #include "content/browser/compositor/image_transport_factory.h" | 19 #include "content/browser/compositor/image_transport_factory.h" |
18 #endif | 20 #endif |
19 | 21 |
20 namespace content { | 22 namespace content { |
21 | 23 |
22 class OffscreenCanvasCompositorFrameSinkManagerTest : public testing::Test { | 24 class OffscreenCanvasCompositorFrameSinkManagerTest : public testing::Test { |
(...skipping 29 matching lines...) Expand all Loading... |
52 void OffscreenCanvasCompositorFrameSinkManagerTest::TearDown() { | 54 void OffscreenCanvasCompositorFrameSinkManagerTest::TearDown() { |
53 #if !defined(OS_ANDROID) | 55 #if !defined(OS_ANDROID) |
54 ImageTransportFactory::Terminate(); | 56 ImageTransportFactory::Terminate(); |
55 #endif | 57 #endif |
56 } | 58 } |
57 | 59 |
58 // This test mimics the workflow of OffscreenCanvas.commit() on renderer | 60 // This test mimics the workflow of OffscreenCanvas.commit() on renderer |
59 // process. | 61 // process. |
60 TEST_F(OffscreenCanvasCompositorFrameSinkManagerTest, | 62 TEST_F(OffscreenCanvasCompositorFrameSinkManagerTest, |
61 SingleHTMLCanvasElementTransferToOffscreen) { | 63 SingleHTMLCanvasElementTransferToOffscreen) { |
62 cc::mojom::FrameSinkManagerClientPtr client; | 64 blink::mojom::OffscreenCanvasSurfaceClientPtr client; |
63 cc::FrameSinkId frame_sink_id(3, 3); | 65 cc::FrameSinkId frame_sink_id(3, 3); |
64 cc::LocalSurfaceIdAllocator local_surface_id_allocator; | 66 cc::LocalSurfaceIdAllocator local_surface_id_allocator; |
65 cc::LocalSurfaceId current_local_surface_id( | 67 cc::LocalSurfaceId current_local_surface_id( |
66 local_surface_id_allocator.GenerateId()); | 68 local_surface_id_allocator.GenerateId()); |
67 | 69 |
68 auto surface_impl = base::WrapUnique(new OffscreenCanvasSurfaceImpl( | 70 auto surface_impl = base::WrapUnique(new OffscreenCanvasSurfaceImpl( |
69 cc::FrameSinkId(), frame_sink_id, std::move(client))); | 71 cc::FrameSinkId(), frame_sink_id, std::move(client))); |
70 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); | 72 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); |
71 EXPECT_EQ(surface_impl.get(), | 73 EXPECT_EQ(surface_impl.get(), |
72 OffscreenCanvasCompositorFrameSinkManager::GetInstance() | 74 OffscreenCanvasCompositorFrameSinkManager::GetInstance() |
73 ->GetSurfaceInstance(frame_sink_id)); | 75 ->GetSurfaceInstance(frame_sink_id)); |
74 | 76 |
75 this->OnSurfaceCreated( | 77 this->OnSurfaceCreated( |
76 cc::SurfaceId(frame_sink_id, current_local_surface_id)); | 78 cc::SurfaceId(frame_sink_id, current_local_surface_id)); |
77 EXPECT_EQ(current_local_surface_id, surface_impl->current_local_surface_id()); | 79 EXPECT_EQ(current_local_surface_id, surface_impl->current_local_surface_id()); |
78 | 80 |
79 surface_impl = nullptr; | 81 surface_impl = nullptr; |
80 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); | 82 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); |
81 } | 83 } |
82 | 84 |
83 TEST_F(OffscreenCanvasCompositorFrameSinkManagerTest, | 85 TEST_F(OffscreenCanvasCompositorFrameSinkManagerTest, |
84 MultiHTMLCanvasElementTransferToOffscreen) { | 86 MultiHTMLCanvasElementTransferToOffscreen) { |
85 cc::mojom::FrameSinkManagerClientPtr client_a; | 87 blink::mojom::OffscreenCanvasSurfaceClientPtr client_a; |
86 cc::FrameSinkId dummy_parent_frame_sink_id(0, 0); | 88 cc::FrameSinkId dummy_parent_frame_sink_id(0, 0); |
87 cc::FrameSinkId frame_sink_id_a(3, 3); | 89 cc::FrameSinkId frame_sink_id_a(3, 3); |
88 auto surface_impl_a = base::WrapUnique(new OffscreenCanvasSurfaceImpl( | 90 auto surface_impl_a = base::WrapUnique(new OffscreenCanvasSurfaceImpl( |
89 dummy_parent_frame_sink_id, frame_sink_id_a, std::move(client_a))); | 91 dummy_parent_frame_sink_id, frame_sink_id_a, std::move(client_a))); |
90 | 92 |
91 cc::mojom::FrameSinkManagerClientPtr client_b; | 93 blink::mojom::OffscreenCanvasSurfaceClientPtr client_b; |
92 cc::FrameSinkId frame_sink_id_b(4, 4); | 94 cc::FrameSinkId frame_sink_id_b(4, 4); |
93 | 95 |
94 auto surface_impl_b = base::WrapUnique(new OffscreenCanvasSurfaceImpl( | 96 auto surface_impl_b = base::WrapUnique(new OffscreenCanvasSurfaceImpl( |
95 dummy_parent_frame_sink_id, frame_sink_id_b, std::move(client_b))); | 97 dummy_parent_frame_sink_id, frame_sink_id_b, std::move(client_b))); |
96 | 98 |
97 EXPECT_EQ(2, this->getNumSurfaceImplInstances()); | 99 EXPECT_EQ(2, this->getNumSurfaceImplInstances()); |
98 EXPECT_EQ(surface_impl_a.get(), | 100 EXPECT_EQ(surface_impl_a.get(), |
99 OffscreenCanvasCompositorFrameSinkManager::GetInstance() | 101 OffscreenCanvasCompositorFrameSinkManager::GetInstance() |
100 ->GetSurfaceInstance(frame_sink_id_a)); | 102 ->GetSurfaceInstance(frame_sink_id_a)); |
101 EXPECT_EQ(surface_impl_b.get(), | 103 EXPECT_EQ(surface_impl_b.get(), |
102 OffscreenCanvasCompositorFrameSinkManager::GetInstance() | 104 OffscreenCanvasCompositorFrameSinkManager::GetInstance() |
103 ->GetSurfaceInstance(frame_sink_id_b)); | 105 ->GetSurfaceInstance(frame_sink_id_b)); |
104 | 106 |
105 surface_impl_a = nullptr; | 107 surface_impl_a = nullptr; |
106 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); | 108 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); |
107 surface_impl_b = nullptr; | 109 surface_impl_b = nullptr; |
108 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); | 110 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); |
109 } | 111 } |
110 | 112 |
111 } // namespace content | 113 } // namespace content |
OLD | NEW |