Index: services/ui/ws/gpu_host_unittest.cc |
diff --git a/services/ui/ws/gpu_host_unittest.cc b/services/ui/ws/gpu_host_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bbc28002c6806ff89d993d23549c864b7df08510 |
--- /dev/null |
+++ b/services/ui/ws/gpu_host_unittest.cc |
@@ -0,0 +1,138 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "services/ui/ws/gpu_host.h" |
+ |
+#include "base/macros.h" |
+#include "base/memory/ptr_util.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/message_loop/message_loop.h" |
+#include "base/run_loop.h" |
+#include "base/test/test_simple_task_runner.h" |
+#include "base/threading/thread_task_runner_handle.h" |
+#include "gpu/config/gpu_info.h" |
+#include "gpu/ipc/service/gpu_watchdog_thread.h" |
+#include "services/ui/gpu/gpu_service.h" |
+#include "services/ui/public/interfaces/gpu.mojom.h" |
+#include "services/ui/ws/gpu_host_delegate.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace ui { |
+namespace ws { |
+namespace test { |
+namespace { |
+ |
+class TestGpuHostDelegate : public GpuHostDelegate { |
+ public: |
+ TestGpuHostDelegate() {} |
+ ~TestGpuHostDelegate() override {} |
+ |
+ void OnGpuServiceInitialized() override; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(TestGpuHostDelegate); |
+}; |
+ |
+void TestGpuHostDelegate::OnGpuServiceInitialized() {} |
+ |
+class TestGpuService : public GpuService { |
+ public: |
+ TestGpuService(scoped_refptr<base::TestSimpleTaskRunner> task_runner, |
+ base::Closure host_deletion_callback); |
+ ~TestGpuService() override {} |
+ |
+ void EstablishGpuChannel( |
+ int32_t client_id, |
+ uint64_t client_tracing_id, |
+ bool is_gpu_host, |
+ const EstablishGpuChannelCallback& callback) override; |
+ |
+ private: |
+ base::Closure host_deletion_callback_; |
+ DISALLOW_COPY_AND_ASSIGN(TestGpuService); |
+}; |
+ |
+TestGpuService::TestGpuService( |
+ scoped_refptr<base::TestSimpleTaskRunner> task_runner, |
+ base::Closure host_deletion_callback) |
+ : GpuService(gpu::GPUInfo(), |
+ gpu::GpuWatchdogThread::Create(), |
+ nullptr, |
+ task_runner, |
+ gpu::GpuFeatureInfo()), |
+ host_deletion_callback_(host_deletion_callback) {} |
+ |
+void TestGpuService::EstablishGpuChannel( |
+ int32_t client_id, |
+ uint64_t client_tracing_id, |
+ bool is_gpu_host, |
+ const EstablishGpuChannelCallback& callback) { |
+ LOG(ERROR) << "JR EstablishGpuChannel!\n"; |
+ // host_deletion_callback_.Run(); |
jonross
2017/03/20 22:09:02
With this turned on the callback doesn't run.
|
+ // LOG(ERROR)<<"JR post nuke\n"; |
+ callback.Run(mojo::ScopedMessagePipeHandle()); |
+} |
+ |
+void TestEstablishGpuChannelCallback( |
+ int32_t client_id, |
+ mojo::ScopedMessagePipeHandle channel_handle, |
+ const gpu::GPUInfo& gpu_info) { |
+ LOG(ERROR) << "JR Callback!!!\n"; |
+} |
+ |
+} // namespace |
+ |
+class GpuHostTest : public testing::Test { |
+ public: |
+ GpuHostTest(); |
+ ~GpuHostTest() override {} |
+ |
+ GpuHost* gpu_host() { return gpu_host_.get(); } |
+ void KillHost(); |
+ |
+ // testing::Test |
+ void SetUp() override; |
+ |
+ private: |
+ base::MessageLoop message_loop_; |
+ scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
+ |
+ TestGpuHostDelegate gpu_host_delegate_; |
+ TestGpuService gpu_service_; |
+ ui::mojom::GpuServicePtr gpu_service_ptr_; |
+ std::unique_ptr<GpuHost> gpu_host_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(GpuHostTest); |
+}; |
+ |
+GpuHostTest::GpuHostTest() |
+ : task_runner_(new base::TestSimpleTaskRunner), |
sadrul
2017/03/20 22:28:22
Don't you need to actually install the task-runner
|
+ gpu_service_(task_runner_, |
+ base::Bind(&GpuHostTest::KillHost, base::Unretained(this))) { |
+} |
+ |
+void GpuHostTest::KillHost() { |
+ gpu_host_.reset(); |
+} |
+ |
+void GpuHostTest::SetUp() { |
+ testing::Test::SetUp(); |
+ gpu_host_ = base::MakeUnique<GpuHost>(&gpu_host_delegate_); |
+ |
+ ui::mojom::GpuServiceRequest request(&gpu_service_ptr_); |
+ gpu_service_.Bind(std::move(request)); |
+ gpu_host_->gpu_service_ = std::move(gpu_service_ptr_); |
+} |
+ |
+TEST_F(GpuHostTest, Basic) { |
+ mojom::GpuRequest request; |
+ mojom::Gpu* gpu = gpu_host()->Add(std::move(request)); |
+ gpu->EstablishGpuChannel(base::Bind(&TestEstablishGpuChannelCallback)); |
+ base::RunLoop().RunUntilIdle(); |
+ LOG(ERROR) << "JR end test\n"; |
+} |
+ |
+} // namespace test |
+} // namespace ws |
+} // namespace ui |