| 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..9d816a4d43e4fba7ebeefe0c854bfe8e22268c26 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,64 @@ 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;
|
| + scoped_refptr<gpu::GpuChannelHost> host;
|
| + auto callback = base::Bind(
|
| + [](scoped_refptr<gpu::GpuChannelHost>* out_host,
|
| + const base::Closure& callback,
|
| + scoped_refptr<gpu::GpuChannelHost> host) {
|
| + callback.Run();
|
| + *out_host = std::move(host);
|
| + },
|
| + &host, 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(true /* success */));
|
| + run_loop.Run();
|
| + EXPECT_TRUE(host);
|
| +}
|
| +
|
| +// 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
|
|
|