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

Side by Side Diff: services/ui/ws/gpu_host_unittest.cc

Issue 2741343003: Update liftetime management of GpuClient (Closed)
Patch Set: fix x11 re-definition Created 3 years, 9 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/ws/gpu_host.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
(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/weak_ptr.h"
10 #include "base/message_loop/message_loop.h"
11 #include "gpu/config/gpu_info.h"
12 #include "services/ui/gpu/gpu_service.h"
13 #include "services/ui/public/interfaces/gpu.mojom.h"
14 #include "services/ui/ws/gpu_client.h"
15 #include "services/ui/ws/gpu_host_delegate.h"
16
17 #if defined(USE_X11)
18 #include <X11/Xlib.h>
19 #undef None
20 #undef Bool
21 #endif // USE_X11
22
23 #include "testing/gtest/include/gtest/gtest.h"
24
25 namespace ui {
26 namespace ws {
27 namespace test {
28 namespace {
29
30 // No-opt implementation of GpuHostDelegate.
31 class TestGpuHostDelegate : public GpuHostDelegate {
32 public:
33 TestGpuHostDelegate() {}
34 ~TestGpuHostDelegate() override {}
35
36 // GpuHostDelegate:
37 void OnGpuServiceInitialized() override {}
38
39 private:
40 DISALLOW_COPY_AND_ASSIGN(TestGpuHostDelegate);
41 };
42
43 // Test implementation of GpuService. For testing behaviour of calls made by
44 // GpuClient
45 class TestGpuService : public GpuService {
46 public:
47 TestGpuService();
48 ~TestGpuService() override {}
49
50 private:
51 DISALLOW_COPY_AND_ASSIGN(TestGpuService);
52 };
53
54 TestGpuService::TestGpuService()
55 : GpuService(gpu::GPUInfo(),
56 nullptr,
57 nullptr,
58 base::ThreadTaskRunnerHandle::Get(),
59 gpu::GpuFeatureInfo()) {}
60
61 } // namespace
62
63 class GpuHostTest : public testing::Test {
64 public:
65 GpuHostTest() {}
66 ~GpuHostTest() override {}
67
68 GpuHost* gpu_host() { return gpu_host_.get(); }
69
70 base::WeakPtr<GpuClient> AddGpuClient();
71 void DestroyHost();
72
73 // testing::Test
74 void SetUp() override;
75
76 private:
77 base::MessageLoop message_loop_;
78
79 base::WeakPtr<GpuClient> client_ref_;
80
81 TestGpuHostDelegate gpu_host_delegate_;
82 TestGpuService gpu_service_;
83 ui::mojom::GpuServicePtr gpu_service_ptr_;
84 std::unique_ptr<GpuHost> gpu_host_;
85
86 DISALLOW_COPY_AND_ASSIGN(GpuHostTest);
87 };
88
89 base::WeakPtr<GpuClient> GpuHostTest::AddGpuClient() {
90 mojom::GpuRequest request;
91 GpuClient* client = gpu_host_->AddInternal(std::move(request));
92 return client->weak_factory_.GetWeakPtr();
93 }
94
95 void GpuHostTest::DestroyHost() {
96 gpu_host_.reset();
97 }
98
99 void GpuHostTest::SetUp() {
100 testing::Test::SetUp();
101 gpu_host_ = base::MakeUnique<GpuHost>(&gpu_host_delegate_);
102
103 ui::mojom::GpuServiceRequest request(&gpu_service_ptr_);
104 gpu_service_.Bind(std::move(request));
105 gpu_host_->gpu_service_ = std::move(gpu_service_ptr_);
106 }
107
108 // Tests to verify, that if a GpuHost is deleted before GpuClient receives a
109 // callback, that GpuClient is torn down and does not attempt to use GpuInfo
110 // after deletion. This should not crash on asan-builds.
111 TEST_F(GpuHostTest, GpuClientDestructionOrder) {
112 base::WeakPtr<GpuClient> client_ref = AddGpuClient();
113 EXPECT_NE(nullptr, client_ref);
114 DestroyHost();
115 EXPECT_EQ(nullptr, client_ref);
116 }
117
118 } // namespace test
119 } // namespace ws
120 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/gpu_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698