Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Unified Diff: services/ui/public/cpp/tests/gpu_unittest.cc

Issue 2968053002: mus-gpu: Fix handling channel establish requests. (Closed)
Patch Set: . Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/ui/public/cpp/gpu/gpu.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « services/ui/public/cpp/gpu/gpu.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698