OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "services/ui/ws/gpu_host.h" | |
6 | |
7 #include "base/macros.h" | |
8 #include "base/memory/ptr_util.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/message_loop/message_loop.h" | |
11 #include "base/run_loop.h" | |
12 #include "base/test/test_simple_task_runner.h" | |
13 #include "base/threading/thread_task_runner_handle.h" | |
14 #include "gpu/config/gpu_info.h" | |
15 #include "gpu/ipc/service/gpu_watchdog_thread.h" | |
16 #include "services/ui/gpu/gpu_service.h" | |
17 #include "services/ui/public/interfaces/gpu.mojom.h" | |
18 #include "services/ui/ws/gpu_host_delegate.h" | |
19 #include "testing/gtest/include/gtest/gtest.h" | |
20 | |
21 namespace ui { | |
22 namespace ws { | |
23 namespace test { | |
24 namespace { | |
25 | |
26 class TestGpuHostDelegate : public GpuHostDelegate { | |
27 public: | |
28 TestGpuHostDelegate() {} | |
29 ~TestGpuHostDelegate() override {} | |
30 | |
31 void OnGpuServiceInitialized() override; | |
32 | |
33 private: | |
34 DISALLOW_COPY_AND_ASSIGN(TestGpuHostDelegate); | |
35 }; | |
36 | |
37 void TestGpuHostDelegate::OnGpuServiceInitialized() {} | |
38 | |
39 class TestGpuService : public GpuService { | |
40 public: | |
41 TestGpuService(scoped_refptr<base::TestSimpleTaskRunner> task_runner, | |
42 base::Closure host_deletion_callback); | |
43 ~TestGpuService() override {} | |
44 | |
45 void EstablishGpuChannel( | |
46 int32_t client_id, | |
47 uint64_t client_tracing_id, | |
48 bool is_gpu_host, | |
49 const EstablishGpuChannelCallback& callback) override; | |
50 | |
51 private: | |
52 base::Closure host_deletion_callback_; | |
53 DISALLOW_COPY_AND_ASSIGN(TestGpuService); | |
54 }; | |
55 | |
56 TestGpuService::TestGpuService( | |
57 scoped_refptr<base::TestSimpleTaskRunner> task_runner, | |
58 base::Closure host_deletion_callback) | |
59 : GpuService(gpu::GPUInfo(), | |
60 gpu::GpuWatchdogThread::Create(), | |
61 nullptr, | |
62 task_runner, | |
63 gpu::GpuFeatureInfo()), | |
64 host_deletion_callback_(host_deletion_callback) {} | |
65 | |
66 void TestGpuService::EstablishGpuChannel( | |
67 int32_t client_id, | |
68 uint64_t client_tracing_id, | |
69 bool is_gpu_host, | |
70 const EstablishGpuChannelCallback& callback) { | |
71 LOG(ERROR) << "JR EstablishGpuChannel!\n"; | |
72 // host_deletion_callback_.Run(); | |
jonross
2017/03/20 22:09:02
With this turned on the callback doesn't run.
| |
73 // LOG(ERROR)<<"JR post nuke\n"; | |
74 callback.Run(mojo::ScopedMessagePipeHandle()); | |
75 } | |
76 | |
77 void TestEstablishGpuChannelCallback( | |
78 int32_t client_id, | |
79 mojo::ScopedMessagePipeHandle channel_handle, | |
80 const gpu::GPUInfo& gpu_info) { | |
81 LOG(ERROR) << "JR Callback!!!\n"; | |
82 } | |
83 | |
84 } // namespace | |
85 | |
86 class GpuHostTest : public testing::Test { | |
87 public: | |
88 GpuHostTest(); | |
89 ~GpuHostTest() override {} | |
90 | |
91 GpuHost* gpu_host() { return gpu_host_.get(); } | |
92 void KillHost(); | |
93 | |
94 // testing::Test | |
95 void SetUp() override; | |
96 | |
97 private: | |
98 base::MessageLoop message_loop_; | |
99 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | |
100 | |
101 TestGpuHostDelegate gpu_host_delegate_; | |
102 TestGpuService gpu_service_; | |
103 ui::mojom::GpuServicePtr gpu_service_ptr_; | |
104 std::unique_ptr<GpuHost> gpu_host_; | |
105 | |
106 DISALLOW_COPY_AND_ASSIGN(GpuHostTest); | |
107 }; | |
108 | |
109 GpuHostTest::GpuHostTest() | |
110 : task_runner_(new base::TestSimpleTaskRunner), | |
sadrul
2017/03/20 22:28:22
Don't you need to actually install the task-runner
| |
111 gpu_service_(task_runner_, | |
112 base::Bind(&GpuHostTest::KillHost, base::Unretained(this))) { | |
113 } | |
114 | |
115 void GpuHostTest::KillHost() { | |
116 gpu_host_.reset(); | |
117 } | |
118 | |
119 void GpuHostTest::SetUp() { | |
120 testing::Test::SetUp(); | |
121 gpu_host_ = base::MakeUnique<GpuHost>(&gpu_host_delegate_); | |
122 | |
123 ui::mojom::GpuServiceRequest request(&gpu_service_ptr_); | |
124 gpu_service_.Bind(std::move(request)); | |
125 gpu_host_->gpu_service_ = std::move(gpu_service_ptr_); | |
126 } | |
127 | |
128 TEST_F(GpuHostTest, Basic) { | |
129 mojom::GpuRequest request; | |
130 mojom::Gpu* gpu = gpu_host()->Add(std::move(request)); | |
131 gpu->EstablishGpuChannel(base::Bind(&TestEstablishGpuChannelCallback)); | |
132 base::RunLoop().RunUntilIdle(); | |
133 LOG(ERROR) << "JR end test\n"; | |
134 } | |
135 | |
136 } // namespace test | |
137 } // namespace ws | |
138 } // namespace ui | |
OLD | NEW |