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