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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « services/ui/public/cpp/gpu/gpu.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/ui/public/cpp/gpu/gpu.h" 5 #include "services/ui/public/cpp/gpu/gpu.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/test/scoped_task_environment.h" 8 #include "base/test/scoped_task_environment.h"
9 #include "gpu/config/gpu_info.h" 9 #include "gpu/config/gpu_info.h"
10 #include "mojo/public/cpp/bindings/binding_set.h" 10 #include "mojo/public/cpp/bindings/binding_set.h"
(...skipping 15 matching lines...) Expand all
26 } 26 }
27 27
28 void WaitUntilChannelRequest() { 28 void WaitUntilChannelRequest() {
29 DCHECK(quit_closure_.is_null()); 29 DCHECK(quit_closure_.is_null());
30 base::RunLoop run_loop; 30 base::RunLoop run_loop;
31 quit_closure_ = run_loop.QuitClosure(); 31 quit_closure_ = run_loop.QuitClosure();
32 run_loop.Run(); 32 run_loop.Run();
33 quit_closure_ = base::Closure(); 33 quit_closure_ = base::Closure();
34 } 34 }
35 35
36 bool RespondToGpuChannelRequests() { 36 bool RespondToGpuChannelRequests(bool success = false) {
37 if (establish_channel_callback_.is_null()) 37 if (establish_channel_callback_.is_null())
38 return false; 38 return false;
39 constexpr int client_id = 1; 39 constexpr int client_id = 1;
40 mojo::ScopedMessagePipeHandle handle; 40 mojo::ScopedMessagePipeHandle handle;
41 if (success)
42 handle = std::move(mojo::MessagePipe().handle0);
41 base::ResetAndReturn(&establish_channel_callback_) 43 base::ResetAndReturn(&establish_channel_callback_)
42 .Run(client_id, std::move(handle), gpu::GPUInfo()); 44 .Run(client_id, std::move(handle), gpu::GPUInfo());
43 return true; 45 return true;
44 } 46 }
45 47
46 // ui::mojom::Gpu overrides: 48 // ui::mojom::Gpu overrides:
47 void EstablishGpuChannel( 49 void EstablishGpuChannel(
48 const EstablishGpuChannelCallback& callback) override { 50 const EstablishGpuChannelCallback& callback) override {
49 establish_channel_callback_ = callback; 51 establish_channel_callback_ = callback;
50 if (!quit_closure_.is_null()) 52 if (!quit_closure_.is_null())
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 gpu()->EstablishGpuChannel(callback); 116 gpu()->EstablishGpuChannel(callback);
115 gpu()->EstablishGpuChannel(callback); 117 gpu()->EstablishGpuChannel(callback);
116 EXPECT_EQ(2, counter); 118 EXPECT_EQ(2, counter);
117 gpu_impl()->WaitUntilChannelRequest(); 119 gpu_impl()->WaitUntilChannelRequest();
118 120
119 EXPECT_TRUE(gpu_impl()->RespondToGpuChannelRequests()); 121 EXPECT_TRUE(gpu_impl()->RespondToGpuChannelRequests());
120 run_loop.Run(); 122 run_loop.Run();
121 EXPECT_EQ(0, counter); 123 EXPECT_EQ(0, counter);
122 } 124 }
123 125
126 // Tests that a new request for establishing a gpu channel from a callback of a
127 // previous callback is processed correctly.
128 TEST_F(GpuTest, EstablishRequestOnFailureOnPreviousRequest) {
129 base::RunLoop run_loop;
130 auto callback = base::Bind(
131 [](const base::Closure& callback,
132 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
133 run_loop.QuitClosure());
134 gpu()->EstablishGpuChannel(base::Bind(
135 [](ui::Gpu* gpu, const gpu::GpuChannelEstablishedCallback& callback,
136 scoped_refptr<gpu::GpuChannelHost> host) {
137 DCHECK(!host);
138 gpu->EstablishGpuChannel(callback);
139 },
140 gpu(), callback));
141 gpu_impl()->WaitUntilChannelRequest();
142 EXPECT_TRUE(gpu_impl()->RespondToGpuChannelRequests());
143
144 // Responding to the first request would issue a second request immediately.
145 // So wait for that request to reach the TestGpuImpl, and have that respond
146 // again. That should run quit-closure of |run_loop|.
147 gpu_impl()->WaitUntilChannelRequest();
148 EXPECT_TRUE(gpu_impl()->RespondToGpuChannelRequests());
149 run_loop.Run();
150 }
151
152 // Tests that if a request for a gpu channel succeeded, then subsequent requests
153 // are met synchronously.
154 TEST_F(GpuTest, EstablishRequestResponseSynchronouslyOnSuccess) {
155 scoped_refptr<gpu::GpuChannelHost> host;
156 base::RunLoop run_loop;
157 gpu()->EstablishGpuChannel(base::Bind(
158 [](scoped_refptr<gpu::GpuChannelHost>* out_host,
159 const base::Closure& callback,
160 scoped_refptr<gpu::GpuChannelHost> host) {
161 *out_host = std::move(host);
162 callback.Run();
163 },
164 &host, run_loop.QuitClosure()));
165 gpu_impl()->WaitUntilChannelRequest();
166 EXPECT_TRUE(gpu_impl()->RespondToGpuChannelRequests(true /* success */));
167 EXPECT_FALSE(host);
168 run_loop.Run();
169 EXPECT_TRUE(host);
170
171 int counter = 0;
172 auto callback =
173 base::Bind([](int* counter,
174 scoped_refptr<gpu::GpuChannelHost> host) { ++(*counter); },
175 &counter);
176 gpu()->EstablishGpuChannel(callback);
177 EXPECT_EQ(1, counter);
178 }
179
124 } // namespace ui 180 } // namespace ui
OLDNEW
« 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