Chromium Code Reviews| Index: components/viz/common/server_gpu_memory_buffer_manager_unittest.cc |
| diff --git a/components/viz/common/server_gpu_memory_buffer_manager_unittest.cc b/components/viz/common/server_gpu_memory_buffer_manager_unittest.cc |
| index 766852975f9059487ab968c0a6d023ed16969dc5..5d7feafeffb92a4a75c9cbb5d2c114d7aff0464c 100644 |
| --- a/components/viz/common/server_gpu_memory_buffer_manager_unittest.cc |
| +++ b/components/viz/common/server_gpu_memory_buffer_manager_unittest.cc |
| @@ -208,4 +208,49 @@ TEST_F(ServerGpuMemoryBufferManagerTest, AllocationRequestsForDestroyedClient) { |
| #endif |
| } |
| +TEST_F(ServerGpuMemoryBufferManagerTest, |
| + RequestsFromUntrustedClientsValidated) { |
| + gfx::ClientNativePixmapFactory::ResetInstance(); |
| + TestGpuService gpu_service; |
| + ServerGpuMemoryBufferManager manager(&gpu_service, 1); |
| + const auto buffer_id = static_cast<gfx::GpuMemoryBufferId>(1); |
| + const int client_id = 2; |
| + const gfx::Size size(10, 20); |
| + // SCANOUT cannot be used if native gpu memory buffer is not supported. |
| + struct { |
| + gfx::BufferUsage usage; |
| + gfx::BufferFormat format; |
| + bool expect_null_handle; |
| + } configs[] = { |
| + {gfx::BufferUsage::SCANOUT, gfx::BufferFormat::YVU_420, true}, |
| + {gfx::BufferUsage::GPU_READ, gfx::BufferFormat::YVU_420, false}, |
| + }; |
| + for (const auto& config : configs) { |
| + gfx::GpuMemoryBufferHandle allocated_handle; |
| + base::RunLoop runloop; |
| + manager.AllocateGpuMemoryBuffer( |
| + buffer_id, client_id, size, config.format, config.usage, |
| + gpu::kNullSurfaceHandle, |
| + base::BindOnce( |
| + [](gfx::GpuMemoryBufferHandle* allocated_handle, |
| + const base::Closure& callback, |
| + const gfx::GpuMemoryBufferHandle& handle) { |
| + *allocated_handle = handle; |
| + callback.Run(); |
| + }, |
| + &allocated_handle, runloop.QuitClosure())); |
| + // Since native gpu memory buffers are not supported, the mojom.GpuService |
| + // should not receive any allocation requests. |
| + EXPECT_FALSE(gpu_service.HasAllocationRequest(buffer_id, client_id)); |
| + runloop.Run(); |
| + if (config.expect_null_handle) { |
| + EXPECT_TRUE(allocated_handle.is_null()); |
| + } else { |
| + EXPECT_FALSE(allocated_handle.is_null()); |
| + EXPECT_EQ(gfx::GpuMemoryBufferType::SHARED_MEMORY_BUFFER, |
| + allocated_handle.type); |
| + } |
| + } |
|
danakj
2017/06/26 15:43:42
Can you add something that shows we actually hit b
sadrul
2017/06/26 21:48:58
Good point. Done.
|
| +} |
| + |
| } // namespace viz |