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

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

Issue 2741343003: Update liftetime management of GpuClient (Closed)
Patch Set: Update Deps. Remove Test Filter 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 "gpu/ipc/service/gpu_watchdog_thread.h"
13 #include "services/ui/gpu/gpu_service.h"
14 #include "services/ui/public/interfaces/gpu.mojom.h"
15 #include "services/ui/ws/gpu_client.h"
16 #include "services/ui/ws/gpu_host_delegate.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace ui {
20 namespace ws {
21 namespace test {
22 namespace {
23
24 // No-opt implementation of GpuHostDelegate.
25 class TestGpuHostDelegate : public GpuHostDelegate {
26 public:
27 TestGpuHostDelegate() {}
28 ~TestGpuHostDelegate() override {}
29
30 // GpuHostDelegate:
31 void OnGpuServiceInitialized() override {}
32
33 private:
34 DISALLOW_COPY_AND_ASSIGN(TestGpuHostDelegate);
35 };
36
37 // Test implementation of GpuService. For testing behaviour of calls made by
38 // GpuClient
39 class TestGpuService : public GpuService {
40 public:
41 TestGpuService();
42 ~TestGpuService() override {}
43
44 private:
45 DISALLOW_COPY_AND_ASSIGN(TestGpuService);
46 };
47
48 TestGpuService::TestGpuService()
49 : GpuService(gpu::GPUInfo(),
50 gpu::GpuWatchdogThread::Create(),
sadrul 2017/03/23 20:00:20 Just use nullptr here?
jonross 2017/03/23 20:09:50 Actually now yeah. At one point a part of the test
51 nullptr,
52 base::ThreadTaskRunnerHandle::Get(),
53 gpu::GpuFeatureInfo()) {}
54
55 } // namespace
56
57 class GpuHostTest : public testing::Test {
58 public:
59 GpuHostTest() {}
60 ~GpuHostTest() override {}
61
62 GpuHost* gpu_host() { return gpu_host_.get(); }
63
64 base::WeakPtr<GpuClient> AddGpuClient();
65 void DestroyHost();
66
67 // testing::Test
68 void SetUp() override;
69
70 private:
71 base::MessageLoop message_loop_;
72
73 base::WeakPtr<GpuClient> client_ref_;
74
75 TestGpuHostDelegate gpu_host_delegate_;
76 TestGpuService gpu_service_;
77 ui::mojom::GpuServicePtr gpu_service_ptr_;
78 std::unique_ptr<GpuHost> gpu_host_;
79
80 DISALLOW_COPY_AND_ASSIGN(GpuHostTest);
81 };
82
83 base::WeakPtr<GpuClient> GpuHostTest::AddGpuClient() {
84 mojom::GpuRequest request;
85 GpuClient* client = gpu_host_->AddInternal(std::move(request));
86 return client->weak_factory_.GetWeakPtr();
87 }
88
89 void GpuHostTest::DestroyHost() {
90 gpu_host_.reset();
91 }
92
93 void GpuHostTest::SetUp() {
94 testing::Test::SetUp();
95 gpu_host_ = base::MakeUnique<GpuHost>(&gpu_host_delegate_);
96
97 ui::mojom::GpuServiceRequest request(&gpu_service_ptr_);
98 gpu_service_.Bind(std::move(request));
99 gpu_host_->gpu_service_ = std::move(gpu_service_ptr_);
100 }
101
102 // Tests to verify, that if a GpuHost is deleted before GpuClient receives a
103 // callback, that GpuClient is torn down and does not attempt to use GpuInfo
104 // after deletion. This should not crash on asan-builds.
105 TEST_F(GpuHostTest, GpuClientDestructionOrder) {
106 base::WeakPtr<GpuClient> client_ref = AddGpuClient();
107 EXPECT_NE(nullptr, client_ref);
108 DestroyHost();
109 EXPECT_EQ(nullptr, client_ref);
110 }
111
112 } // namespace test
113 } // namespace ws
114 } // 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