| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/message_loop/message_loop.h" | |
| 6 #include "cc/surfaces/local_surface_id_allocator.h" | |
| 7 #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_manager.h" | |
| 10 #include "content/public/test/test_browser_thread.h" | |
| 11 #include "mojo/public/cpp/bindings/binding.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 #if defined(OS_ANDROID) | |
| 15 #include "base/memory/ptr_util.h" | |
| 16 #else | |
| 17 #include "content/browser/compositor/image_transport_factory.h" | |
| 18 #endif | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 class OffscreenCanvasSurfaceManagerTest : public testing::Test { | |
| 23 public: | |
| 24 int getNumSurfaceImplInstances() { | |
| 25 return OffscreenCanvasSurfaceManager::GetInstance() | |
| 26 ->registered_surface_instances_.size(); | |
| 27 } | |
| 28 | |
| 29 void OnSurfaceCreated(const cc::SurfaceId& surface_id) { | |
| 30 OffscreenCanvasSurfaceManager::GetInstance()->OnSurfaceCreated( | |
| 31 cc::SurfaceInfo(surface_id, 1.0f, gfx::Size(10, 10))); | |
| 32 } | |
| 33 | |
| 34 protected: | |
| 35 void SetUp() override; | |
| 36 void TearDown() override; | |
| 37 | |
| 38 private: | |
| 39 std::unique_ptr<TestBrowserThread> ui_thread_; | |
| 40 base::MessageLoopForUI message_loop_; | |
| 41 }; | |
| 42 | |
| 43 void OffscreenCanvasSurfaceManagerTest::SetUp() { | |
| 44 #if !defined(OS_ANDROID) | |
| 45 ImageTransportFactory::InitializeForUnitTests( | |
| 46 std::unique_ptr<ImageTransportFactory>( | |
| 47 new NoTransportImageTransportFactory)); | |
| 48 #endif | |
| 49 ui_thread_.reset(new TestBrowserThread(BrowserThread::UI, &message_loop_)); | |
| 50 } | |
| 51 | |
| 52 void OffscreenCanvasSurfaceManagerTest::TearDown() { | |
| 53 #if !defined(OS_ANDROID) | |
| 54 ImageTransportFactory::Terminate(); | |
| 55 #endif | |
| 56 } | |
| 57 | |
| 58 // This test mimics the workflow of OffscreenCanvas.commit() on renderer | |
| 59 // process. | |
| 60 TEST_F(OffscreenCanvasSurfaceManagerTest, | |
| 61 SingleHTMLCanvasElementTransferToOffscreen) { | |
| 62 cc::mojom::DisplayCompositorClientPtr client; | |
| 63 cc::FrameSinkId frame_sink_id(3, 3); | |
| 64 cc::LocalSurfaceIdAllocator local_surface_id_allocator; | |
| 65 cc::LocalSurfaceId current_local_surface_id( | |
| 66 local_surface_id_allocator.GenerateId()); | |
| 67 | |
| 68 auto surface_impl = base::WrapUnique(new OffscreenCanvasSurfaceImpl( | |
| 69 cc::FrameSinkId(), frame_sink_id, std::move(client))); | |
| 70 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); | |
| 71 EXPECT_EQ(surface_impl.get(), | |
| 72 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( | |
| 73 frame_sink_id)); | |
| 74 | |
| 75 this->OnSurfaceCreated( | |
| 76 cc::SurfaceId(frame_sink_id, current_local_surface_id)); | |
| 77 EXPECT_EQ(current_local_surface_id, surface_impl->current_local_surface_id()); | |
| 78 | |
| 79 surface_impl = nullptr; | |
| 80 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); | |
| 81 } | |
| 82 | |
| 83 TEST_F(OffscreenCanvasSurfaceManagerTest, | |
| 84 MultiHTMLCanvasElementTransferToOffscreen) { | |
| 85 cc::mojom::DisplayCompositorClientPtr client_a; | |
| 86 cc::FrameSinkId dummy_parent_frame_sink_id(0, 0); | |
| 87 cc::FrameSinkId frame_sink_id_a(3, 3); | |
| 88 auto surface_impl_a = base::WrapUnique(new OffscreenCanvasSurfaceImpl( | |
| 89 dummy_parent_frame_sink_id, frame_sink_id_a, std::move(client_a))); | |
| 90 | |
| 91 cc::mojom::DisplayCompositorClientPtr client_b; | |
| 92 cc::FrameSinkId frame_sink_id_b(4, 4); | |
| 93 | |
| 94 auto surface_impl_b = base::WrapUnique(new OffscreenCanvasSurfaceImpl( | |
| 95 dummy_parent_frame_sink_id, frame_sink_id_b, std::move(client_b))); | |
| 96 | |
| 97 EXPECT_EQ(2, this->getNumSurfaceImplInstances()); | |
| 98 EXPECT_EQ(surface_impl_a.get(), | |
| 99 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( | |
| 100 frame_sink_id_a)); | |
| 101 EXPECT_EQ(surface_impl_b.get(), | |
| 102 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( | |
| 103 frame_sink_id_b)); | |
| 104 | |
| 105 surface_impl_a = nullptr; | |
| 106 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); | |
| 107 surface_impl_b = nullptr; | |
| 108 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); | |
| 109 } | |
| 110 | |
| 111 } // namespace content | |
| OLD | NEW |