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

Side by Side Diff: device/vr/vr_service_impl_unittest.cc

Issue 2167643003: Refactored VRService interaction and added VRServiceClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Liberal sprinkling of 'u's Created 4 years, 4 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 | « device/vr/vr_service_impl.cc ('k') | third_party/WebKit/Source/modules/modules.gypi » ('j') | 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 2016 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 "device/vr/vr_service_impl.h"
6
7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h"
9 #include "device/vr/test/fake_vr_device.h"
10 #include "device/vr/test/fake_vr_device_provider.h"
11 #include "device/vr/vr_device_manager.h"
12 #include "device/vr/vr_service.mojom.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14
15 using ::testing::_;
16 using ::testing::Mock;
17
18 namespace device {
19
20 class MockVRServiceClient : public VRServiceClient {
21 public:
22 MOCK_METHOD1(OnDisplayChanged, void(const VRDisplay& display));
23 void OnDisplayChanged(VRDisplayPtr display) override {
24 OnDisplayChanged(*display);
25 last_display_ = std::move(display);
26 }
27
28 const VRDisplayPtr& LastDisplay() { return last_display_; }
29
30 private:
31 VRDisplayPtr last_display_;
32 };
33
34 class VRServiceTestBinding {
35 public:
36 VRServiceTestBinding() {
37 auto request = mojo::GetProxy(&service_ptr_);
38 service_impl_.reset(new VRServiceImpl());
39 service_impl_->Bind(std::move(request));
40
41 VRServiceClientPtr client_ptr;
42 client_binding_.reset(new mojo::Binding<VRServiceClient>(
43 &mock_client_, mojo::GetProxy(&client_ptr)));
44 service_impl_->SetClient(std::move(client_ptr));
45 }
46
47 void Close() {
48 service_ptr_.reset();
49 service_impl_.reset();
50 }
51
52 MockVRServiceClient& client() { return mock_client_; }
53
54 private:
55 std::unique_ptr<VRServiceImpl> service_impl_;
56 mojo::InterfacePtr<VRService> service_ptr_;
57
58 MockVRServiceClient mock_client_;
59 std::unique_ptr<mojo::Binding<VRServiceClient>> client_binding_;
60
61 DISALLOW_COPY_AND_ASSIGN(VRServiceTestBinding);
62 };
63
64 class VRServiceImplTest : public testing::Test {
65 public:
66 VRServiceImplTest() {}
67 ~VRServiceImplTest() override {}
68
69 protected:
70 void SetUp() override {
71 std::unique_ptr<FakeVRDeviceProvider> provider(new FakeVRDeviceProvider());
72 provider_ = provider.get();
73 device_manager_.reset(new VRDeviceManager(std::move(provider)));
74 }
75
76 void TearDown() override { base::RunLoop().RunUntilIdle(); }
77
78 std::unique_ptr<VRServiceTestBinding> BindService() {
79 return std::unique_ptr<VRServiceTestBinding>(new VRServiceTestBinding());
80 }
81
82 size_t ServiceCount() { return device_manager_->services_.size(); }
83
84 base::MessageLoop message_loop_;
85 FakeVRDeviceProvider* provider_;
86 std::unique_ptr<VRDeviceManager> device_manager_;
87
88 DISALLOW_COPY_AND_ASSIGN(VRServiceImplTest);
89 };
90
91 // Ensure that services are registered with the device manager as they are
92 // created and removed from the device manager as their connections are closed.
93 TEST_F(VRServiceImplTest, DeviceManagerRegistration) {
94 EXPECT_EQ(0u, ServiceCount());
95
96 std::unique_ptr<VRServiceTestBinding> service_1 = BindService();
97
98 EXPECT_EQ(1u, ServiceCount());
99
100 std::unique_ptr<VRServiceTestBinding> service_2 = BindService();
101
102 EXPECT_EQ(2u, ServiceCount());
103
104 service_1->Close();
105
106 EXPECT_EQ(1u, ServiceCount());
107
108 service_2->Close();
109
110 EXPECT_EQ(0u, ServiceCount());
111 }
112
113 // Ensure that DeviceChanged calls are dispatched to all active services.
114 TEST_F(VRServiceImplTest, DeviceChangedDispatched) {
115 std::unique_ptr<VRServiceTestBinding> service_1 = BindService();
116 std::unique_ptr<VRServiceTestBinding> service_2 = BindService();
117
118 EXPECT_CALL(service_1->client(), OnDisplayChanged(_));
119 EXPECT_CALL(service_2->client(), OnDisplayChanged(_));
120
121 std::unique_ptr<FakeVRDevice> device(new FakeVRDevice(provider_));
122 device_manager_->OnDeviceChanged(device->GetVRDevice());
123
124 base::RunLoop().RunUntilIdle();
125
126 EXPECT_EQ(device->id(), service_1->client().LastDisplay()->index);
127 EXPECT_EQ(device->id(), service_2->client().LastDisplay()->index);
128 }
129 }
OLDNEW
« no previous file with comments | « device/vr/vr_service_impl.cc ('k') | third_party/WebKit/Source/modules/modules.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698