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

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

Issue 2584643002: Revamp OffscreenCanvas commit flow (Closed)
Patch Set: rebase and fix conflict Created 4 years 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/compositor/test/no_transport_image_transport_factory.h " 5 #include "content/browser/compositor/test/no_transport_image_transport_factory.h "
6 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" 6 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h"
7 #include "content/browser/renderer_host/offscreen_canvas_surface_manager.h" 7 #include "content/browser/renderer_host/offscreen_canvas_surface_manager.h"
8 #include "content/public/test/test_browser_thread.h" 8 #include "content/public/test/test_browser_thread.h"
9 #include "mojo/public/cpp/bindings/binding.h" 9 #include "mojo/public/cpp/bindings/binding.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 #if defined(OS_ANDROID) 12 #if defined(OS_ANDROID)
13 #include "content/browser/renderer_host/context_provider_factory_impl_android.h" 13 #include "content/browser/renderer_host/context_provider_factory_impl_android.h"
14 #include "content/test/mock_gpu_channel_establish_factory.h" 14 #include "content/test/mock_gpu_channel_establish_factory.h"
15 #else 15 #else
16 #include "content/browser/compositor/image_transport_factory.h" 16 #include "content/browser/compositor/image_transport_factory.h"
17 #endif 17 #endif
18 18
19 namespace content { 19 namespace content {
20 20
21 class OffscreenCanvasSurfaceManagerTest : public testing::Test { 21 class OffscreenCanvasSurfaceManagerTest : public testing::Test {
22 public: 22 public:
23 int getNumSurfaceImplInstances() { 23 int getNumSurfaceImplInstances() {
24 return OffscreenCanvasSurfaceManager::GetInstance() 24 return OffscreenCanvasSurfaceManager::GetInstance()
25 ->registered_surface_instances_.size(); 25 ->registered_surface_instances_.size();
26 } 26 }
27 const cc::SurfaceId& getCurrentSurfaceId() const { 27
28 return current_surface_id_; 28 void OnSurfaceCreated(const cc::SurfaceId& surface_id) {
29 } 29 OffscreenCanvasSurfaceManager::GetInstance()->OnSurfaceCreated(
30 void setSurfaceId(const cc::SurfaceId& surface_id) { 30 surface_id, gfx::Size(10, 10), 1.0);
31 current_surface_id_ = surface_id;
32 } 31 }
33 32
34 protected: 33 protected:
35 void SetUp() override; 34 void SetUp() override;
36 void TearDown() override; 35 void TearDown() override;
37 36
38 private: 37 private:
39 cc::SurfaceId current_surface_id_;
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) 40 #if defined(OS_ANDROID)
43 MockGpuChannelEstablishFactory gpu_channel_factory_; 41 MockGpuChannelEstablishFactory gpu_channel_factory_;
44 #endif 42 #endif
45 }; 43 };
46 44
47 void OffscreenCanvasSurfaceManagerTest::SetUp() { 45 void OffscreenCanvasSurfaceManagerTest::SetUp() {
48 #if defined(OS_ANDROID) 46 #if defined(OS_ANDROID)
49 ContextProviderFactoryImpl::Initialize(&gpu_channel_factory_); 47 ContextProviderFactoryImpl::Initialize(&gpu_channel_factory_);
(...skipping 13 matching lines...) Expand all
63 ContextProviderFactoryImpl::Terminate(); 61 ContextProviderFactoryImpl::Terminate();
64 #else 62 #else
65 ImageTransportFactory::Terminate(); 63 ImageTransportFactory::Terminate();
66 #endif 64 #endif
67 } 65 }
68 66
69 // This test mimics the workflow of OffscreenCanvas.commit() on renderer 67 // This test mimics the workflow of OffscreenCanvas.commit() on renderer
70 // process. 68 // process.
71 TEST_F(OffscreenCanvasSurfaceManagerTest, 69 TEST_F(OffscreenCanvasSurfaceManagerTest,
72 SingleHTMLCanvasElementTransferToOffscreen) { 70 SingleHTMLCanvasElementTransferToOffscreen) {
73 // Assume that HTMLCanvasElement.transferControlToOffscreen() is triggered and 71 blink::mojom::OffscreenCanvasSurfaceClientPtr client;
74 // it will invoke GetSurfaceId function on OffscreenCanvasSurfaceImpl to 72 cc::FrameSinkId frame_sink_id(3, 3);
75 // obtain a unique SurfaceId from browser. 73 cc::SurfaceIdAllocator surface_id_allocator;
76 auto surface_impl = base::WrapUnique(new OffscreenCanvasSurfaceImpl()); 74 cc::LocalFrameId current_local_frame_id(surface_id_allocator.GenerateId());
77 surface_impl->GetSurfaceId(
78 base::Bind(&OffscreenCanvasSurfaceManagerTest::setSurfaceId,
79 base::Unretained(this)));
80 75
81 EXPECT_TRUE(this->getCurrentSurfaceId().is_valid()); 76 auto surface_impl = base::WrapUnique(
77 new OffscreenCanvasSurfaceImpl(frame_sink_id, std::move(client)));
82 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); 78 EXPECT_EQ(1, this->getNumSurfaceImplInstances());
83 cc::FrameSinkId frame_sink_id = surface_impl.get()->frame_sink_id();
84 EXPECT_EQ(frame_sink_id, this->getCurrentSurfaceId().frame_sink_id());
85 EXPECT_EQ(surface_impl.get(), 79 EXPECT_EQ(surface_impl.get(),
86 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( 80 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance(
87 frame_sink_id)); 81 frame_sink_id));
88 82
83 this->OnSurfaceCreated(cc::SurfaceId(frame_sink_id, current_local_frame_id));
84 EXPECT_EQ(current_local_frame_id, surface_impl->current_local_frame_id());
85
89 surface_impl = nullptr; 86 surface_impl = nullptr;
90 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); 87 EXPECT_EQ(0, this->getNumSurfaceImplInstances());
91 } 88 }
92 89
93 TEST_F(OffscreenCanvasSurfaceManagerTest, 90 TEST_F(OffscreenCanvasSurfaceManagerTest,
94 MultiHTMLCanvasElementTransferToOffscreen) { 91 MultiHTMLCanvasElementTransferToOffscreen) {
95 // Same scenario as above test except that now we have two HTMLCanvasElement 92 blink::mojom::OffscreenCanvasSurfaceClientPtr client_a;
96 // transferControlToOffscreen at the same time. 93 cc::FrameSinkId frame_sink_id_a(3, 3);
97 auto surface_impl_a = base::WrapUnique(new OffscreenCanvasSurfaceImpl()); 94 cc::SurfaceIdAllocator surface_id_allocator;
98 surface_impl_a->GetSurfaceId( 95 auto surface_impl_a = base::WrapUnique(
99 base::Bind(&OffscreenCanvasSurfaceManagerTest::setSurfaceId, 96 new OffscreenCanvasSurfaceImpl(frame_sink_id_a, std::move(client_a)));
100 base::Unretained(this)));
101 cc::SurfaceId surface_id_a = this->getCurrentSurfaceId();
102 97
103 EXPECT_TRUE(surface_id_a.is_valid()); 98 blink::mojom::OffscreenCanvasSurfaceClientPtr client_b;
99 cc::FrameSinkId frame_sink_id_b(4, 4);
104 100
105 auto surface_impl_b = base::WrapUnique(new OffscreenCanvasSurfaceImpl()); 101 auto surface_impl_b = base::WrapUnique(
106 surface_impl_b->GetSurfaceId( 102 new OffscreenCanvasSurfaceImpl(frame_sink_id_b, std::move(client_b)));
107 base::Bind(&OffscreenCanvasSurfaceManagerTest::setSurfaceId,
108 base::Unretained(this)));
109 cc::SurfaceId surface_id_b = this->getCurrentSurfaceId();
110
111 EXPECT_TRUE(surface_id_b.is_valid());
112 EXPECT_NE(surface_id_a, surface_id_b);
113 103
114 EXPECT_EQ(2, this->getNumSurfaceImplInstances()); 104 EXPECT_EQ(2, this->getNumSurfaceImplInstances());
115 EXPECT_EQ(surface_impl_a.get(), 105 EXPECT_EQ(surface_impl_a.get(),
116 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( 106 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance(
117 surface_id_a.frame_sink_id())); 107 frame_sink_id_a));
118 EXPECT_EQ(surface_impl_b.get(), 108 EXPECT_EQ(surface_impl_b.get(),
119 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( 109 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance(
120 surface_id_b.frame_sink_id())); 110 frame_sink_id_b));
121 111
122 surface_impl_a = nullptr; 112 surface_impl_a = nullptr;
123 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); 113 EXPECT_EQ(1, this->getNumSurfaceImplInstances());
124 surface_impl_b = nullptr; 114 surface_impl_b = nullptr;
125 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); 115 EXPECT_EQ(0, this->getNumSurfaceImplInstances());
126 } 116 }
127 117
128 } // namespace content 118 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698