Chromium Code Reviews| Index: services/ui/public/cpp/tests/gpu_unittest.cc |
| diff --git a/services/ui/public/cpp/tests/gpu_unittest.cc b/services/ui/public/cpp/tests/gpu_unittest.cc |
| index 132dbf77cb2e3f687c64d103766aeef43ac7dcdd..dd1e387bea8b461795606e994fcd091dc12a82a5 100644 |
| --- a/services/ui/public/cpp/tests/gpu_unittest.cc |
| +++ b/services/ui/public/cpp/tests/gpu_unittest.cc |
| @@ -33,11 +33,13 @@ class TestGpuImpl : public mojom::Gpu { |
| quit_closure_ = base::Closure(); |
| } |
| - bool RespondToGpuChannelRequests() { |
| + bool RespondToGpuChannelRequests(bool success = false) { |
| if (establish_channel_callback_.is_null()) |
| return false; |
| constexpr int client_id = 1; |
| mojo::ScopedMessagePipeHandle handle; |
| + if (success) |
| + handle = std::move(mojo::MessagePipe().handle0); |
| base::ResetAndReturn(&establish_channel_callback_) |
| .Run(client_id, std::move(handle), gpu::GPUInfo()); |
| return true; |
| @@ -121,4 +123,58 @@ TEST_F(GpuTest, EstablishRequestsQueued) { |
| EXPECT_EQ(0, counter); |
| } |
| +// Tests that a new request for establishing a gpu channel from a callback of a |
| +// previous callback is processed correctly. |
| +TEST_F(GpuTest, EstablishRequestOnFailureOnPreviousRequest) { |
| + base::RunLoop run_loop; |
| + auto callback = base::Bind( |
| + [](const base::Closure& callback, |
| + scoped_refptr<gpu::GpuChannelHost> host) { callback.Run(); }, |
|
piman
2017/07/05 22:16:40
nit: Is there a way to check that the second estab
sadrul
2017/07/05 22:59:56
I have made the second request to succeed, and ver
|
| + run_loop.QuitClosure()); |
| + gpu()->EstablishGpuChannel(base::Bind( |
| + [](ui::Gpu* gpu, const gpu::GpuChannelEstablishedCallback& callback, |
| + scoped_refptr<gpu::GpuChannelHost> host) { |
| + DCHECK(!host); |
| + gpu->EstablishGpuChannel(callback); |
| + }, |
| + gpu(), callback)); |
| + gpu_impl()->WaitUntilChannelRequest(); |
| + EXPECT_TRUE(gpu_impl()->RespondToGpuChannelRequests()); |
| + |
| + // Responding to the first request would issue a second request immediately. |
| + // So wait for that request to reach the TestGpuImpl, and have that respond |
| + // again. That should run quit-closure of |run_loop|. |
| + gpu_impl()->WaitUntilChannelRequest(); |
| + EXPECT_TRUE(gpu_impl()->RespondToGpuChannelRequests()); |
| + run_loop.Run(); |
| +} |
| + |
| +// Tests that if a request for a gpu channel succeeded, then subsequent requests |
| +// are met synchronously. |
| +TEST_F(GpuTest, EstablishRequestResponseSynchronouslyOnSuccess) { |
| + scoped_refptr<gpu::GpuChannelHost> host; |
| + base::RunLoop run_loop; |
| + gpu()->EstablishGpuChannel(base::Bind( |
| + [](scoped_refptr<gpu::GpuChannelHost>* out_host, |
| + const base::Closure& callback, |
| + scoped_refptr<gpu::GpuChannelHost> host) { |
| + *out_host = std::move(host); |
| + callback.Run(); |
| + }, |
| + &host, run_loop.QuitClosure())); |
| + gpu_impl()->WaitUntilChannelRequest(); |
| + EXPECT_TRUE(gpu_impl()->RespondToGpuChannelRequests(true /* success */)); |
| + EXPECT_FALSE(host); |
| + run_loop.Run(); |
| + EXPECT_TRUE(host); |
| + |
| + int counter = 0; |
| + auto callback = |
| + base::Bind([](int* counter, |
| + scoped_refptr<gpu::GpuChannelHost> host) { ++(*counter); }, |
| + &counter); |
| + gpu()->EstablishGpuChannel(callback); |
| + EXPECT_EQ(1, counter); |
| +} |
| + |
| } // namespace ui |