Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(555)

Side by Side Diff: content/browser/renderer_host/offscreen_canvas_compositor_frame_sink_manager_unittest.cc

Issue 2737653005: Rename OffscreenCanvasSurfaceManager to OffscreenCanvasCompositorFrameSinkManager (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
xlai (Olivia) 2017/03/08 16:29:56 I really wonder this CL can pass style check when
boliu 2017/03/08 17:00:57 +1
5 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
6 #include "cc/surfaces/local_surface_id_allocator.h" 7 #include "cc/surfaces/local_surface_id_allocator.h"
7 #include "content/browser/compositor/test/no_transport_image_transport_factory.h " 8 #include "content/browser/compositor/test/no_transport_image_transport_factory.h "
8 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" 9 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h"
9 #include "content/browser/renderer_host/offscreen_canvas_surface_manager.h"
10 #include "content/public/test/test_browser_thread.h" 10 #include "content/public/test/test_browser_thread.h"
11 #include "mojo/public/cpp/bindings/binding.h" 11 #include "mojo/public/cpp/bindings/binding.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 #if defined(OS_ANDROID) 14 #if defined(OS_ANDROID)
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #else 16 #else
17 #include "content/browser/compositor/image_transport_factory.h" 17 #include "content/browser/compositor/image_transport_factory.h"
18 #endif 18 #endif
19 19
20 namespace content { 20 namespace content {
21 21
22 class OffscreenCanvasSurfaceManagerTest : public testing::Test { 22 class OffscreenCanvasCompositorFrameSinkManagerTest : public testing::Test {
23 public: 23 public:
24 int getNumSurfaceImplInstances() { 24 int getNumSurfaceImplInstances() {
25 return OffscreenCanvasSurfaceManager::GetInstance() 25 return OffscreenCanvasCompositorFrameSinkManager::GetInstance()
26 ->registered_surface_instances_.size(); 26 ->registered_surface_instances_.size();
27 } 27 }
28 28
29 void OnSurfaceCreated(const cc::SurfaceId& surface_id) { 29 void OnSurfaceCreated(const cc::SurfaceId& surface_id) {
30 OffscreenCanvasSurfaceManager::GetInstance()->OnSurfaceCreated( 30 OffscreenCanvasCompositorFrameSinkManager::GetInstance()->OnSurfaceCreated(
31 cc::SurfaceInfo(surface_id, 1.0f, gfx::Size(10, 10))); 31 cc::SurfaceInfo(surface_id, 1.0f, gfx::Size(10, 10)));
32 } 32 }
33 33
34 protected: 34 protected:
35 void SetUp() override; 35 void SetUp() override;
36 void TearDown() override; 36 void TearDown() override;
37 37
38 private: 38 private:
39 std::unique_ptr<TestBrowserThread> ui_thread_; 39 std::unique_ptr<TestBrowserThread> ui_thread_;
40 base::MessageLoopForUI message_loop_; 40 base::MessageLoopForUI message_loop_;
41 }; 41 };
42 42
43 void OffscreenCanvasSurfaceManagerTest::SetUp() { 43 void OffscreenCanvasCompositorFrameSinkManagerTest::SetUp() {
44 #if !defined(OS_ANDROID) 44 #if !defined(OS_ANDROID)
45 ImageTransportFactory::InitializeForUnitTests( 45 ImageTransportFactory::InitializeForUnitTests(
46 std::unique_ptr<ImageTransportFactory>( 46 std::unique_ptr<ImageTransportFactory>(
47 new NoTransportImageTransportFactory)); 47 new NoTransportImageTransportFactory));
48 #endif 48 #endif
49 ui_thread_.reset(new TestBrowserThread(BrowserThread::UI, &message_loop_)); 49 ui_thread_.reset(new TestBrowserThread(BrowserThread::UI, &message_loop_));
50 } 50 }
51 51
52 void OffscreenCanvasSurfaceManagerTest::TearDown() { 52 void OffscreenCanvasCompositorFrameSinkManagerTest::TearDown() {
53 #if !defined(OS_ANDROID) 53 #if !defined(OS_ANDROID)
54 ImageTransportFactory::Terminate(); 54 ImageTransportFactory::Terminate();
55 #endif 55 #endif
56 } 56 }
57 57
58 // This test mimics the workflow of OffscreenCanvas.commit() on renderer 58 // This test mimics the workflow of OffscreenCanvas.commit() on renderer
59 // process. 59 // process.
60 TEST_F(OffscreenCanvasSurfaceManagerTest, 60 TEST_F(OffscreenCanvasCompositorFrameSinkManagerTest,
61 SingleHTMLCanvasElementTransferToOffscreen) { 61 SingleHTMLCanvasElementTransferToOffscreen) {
62 cc::mojom::DisplayCompositorClientPtr client; 62 cc::mojom::DisplayCompositorClientPtr client;
63 cc::FrameSinkId frame_sink_id(3, 3); 63 cc::FrameSinkId frame_sink_id(3, 3);
64 cc::LocalSurfaceIdAllocator local_surface_id_allocator; 64 cc::LocalSurfaceIdAllocator local_surface_id_allocator;
65 cc::LocalSurfaceId current_local_surface_id( 65 cc::LocalSurfaceId current_local_surface_id(
66 local_surface_id_allocator.GenerateId()); 66 local_surface_id_allocator.GenerateId());
67 67
68 auto surface_impl = base::WrapUnique(new OffscreenCanvasSurfaceImpl( 68 auto surface_impl = base::WrapUnique(new OffscreenCanvasSurfaceImpl(
69 cc::FrameSinkId(), frame_sink_id, std::move(client))); 69 cc::FrameSinkId(), frame_sink_id, std::move(client)));
70 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); 70 EXPECT_EQ(1, this->getNumSurfaceImplInstances());
71 EXPECT_EQ(surface_impl.get(), 71 EXPECT_EQ(surface_impl.get(),
72 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( 72 OffscreenCanvasCompositorFrameSinkManager::GetInstance()
73 frame_sink_id)); 73 ->GetSurfaceInstance(frame_sink_id));
74 74
75 this->OnSurfaceCreated( 75 this->OnSurfaceCreated(
76 cc::SurfaceId(frame_sink_id, current_local_surface_id)); 76 cc::SurfaceId(frame_sink_id, current_local_surface_id));
77 EXPECT_EQ(current_local_surface_id, surface_impl->current_local_surface_id()); 77 EXPECT_EQ(current_local_surface_id, surface_impl->current_local_surface_id());
78 78
79 surface_impl = nullptr; 79 surface_impl = nullptr;
80 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); 80 EXPECT_EQ(0, this->getNumSurfaceImplInstances());
81 } 81 }
82 82
83 TEST_F(OffscreenCanvasSurfaceManagerTest, 83 TEST_F(OffscreenCanvasCompositorFrameSinkManagerTest,
84 MultiHTMLCanvasElementTransferToOffscreen) { 84 MultiHTMLCanvasElementTransferToOffscreen) {
85 cc::mojom::DisplayCompositorClientPtr client_a; 85 cc::mojom::DisplayCompositorClientPtr client_a;
86 cc::FrameSinkId dummy_parent_frame_sink_id(0, 0); 86 cc::FrameSinkId dummy_parent_frame_sink_id(0, 0);
87 cc::FrameSinkId frame_sink_id_a(3, 3); 87 cc::FrameSinkId frame_sink_id_a(3, 3);
88 auto surface_impl_a = base::WrapUnique(new OffscreenCanvasSurfaceImpl( 88 auto surface_impl_a = base::WrapUnique(new OffscreenCanvasSurfaceImpl(
89 dummy_parent_frame_sink_id, frame_sink_id_a, std::move(client_a))); 89 dummy_parent_frame_sink_id, frame_sink_id_a, std::move(client_a)));
90 90
91 cc::mojom::DisplayCompositorClientPtr client_b; 91 cc::mojom::DisplayCompositorClientPtr client_b;
92 cc::FrameSinkId frame_sink_id_b(4, 4); 92 cc::FrameSinkId frame_sink_id_b(4, 4);
93 93
94 auto surface_impl_b = base::WrapUnique(new OffscreenCanvasSurfaceImpl( 94 auto surface_impl_b = base::WrapUnique(new OffscreenCanvasSurfaceImpl(
95 dummy_parent_frame_sink_id, frame_sink_id_b, std::move(client_b))); 95 dummy_parent_frame_sink_id, frame_sink_id_b, std::move(client_b)));
96 96
97 EXPECT_EQ(2, this->getNumSurfaceImplInstances()); 97 EXPECT_EQ(2, this->getNumSurfaceImplInstances());
98 EXPECT_EQ(surface_impl_a.get(), 98 EXPECT_EQ(surface_impl_a.get(),
99 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( 99 OffscreenCanvasCompositorFrameSinkManager::GetInstance()
100 frame_sink_id_a)); 100 ->GetSurfaceInstance(frame_sink_id_a));
101 EXPECT_EQ(surface_impl_b.get(), 101 EXPECT_EQ(surface_impl_b.get(),
102 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( 102 OffscreenCanvasCompositorFrameSinkManager::GetInstance()
103 frame_sink_id_b)); 103 ->GetSurfaceInstance(frame_sink_id_b));
104 104
105 surface_impl_a = nullptr; 105 surface_impl_a = nullptr;
106 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); 106 EXPECT_EQ(1, this->getNumSurfaceImplInstances());
107 surface_impl_b = nullptr; 107 surface_impl_b = nullptr;
108 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); 108 EXPECT_EQ(0, this->getNumSurfaceImplInstances());
109 } 109 }
110 110
111 } // namespace content 111 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698