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

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

Issue 2317483002: Add support of vrdisplayconnect and vrdisplaydisconnect event (Closed)
Patch Set: fix missing brace Created 4 years, 3 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.mojom ('k') | third_party/WebKit/Source/modules/vr/NavigatorVR.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/vr/vr_service_impl.h" 5 #include "device/vr/vr_service_impl.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "device/vr/test/fake_vr_device.h" 9 #include "device/vr/test/fake_vr_device.h"
10 #include "device/vr/test/fake_vr_device_provider.h" 10 #include "device/vr/test/fake_vr_device_provider.h"
11 #include "device/vr/vr_device_manager.h" 11 #include "device/vr/vr_device_manager.h"
12 #include "device/vr/vr_service.mojom.h" 12 #include "device/vr/vr_service.mojom.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 14
15 using ::testing::_; 15 using ::testing::_;
16 using ::testing::Mock; 16 using ::testing::Mock;
17 17
18 namespace device { 18 namespace device {
19 19
20 class MockVRServiceClient : public VRServiceClient { 20 class MockVRServiceClient : public VRServiceClient {
21 public: 21 public:
22 MOCK_METHOD1(OnDisplayChanged, void(const VRDisplay& display)); 22 MOCK_METHOD1(OnDisplayChanged, void(const VRDisplay& display));
23 void OnDisplayChanged(VRDisplayPtr display) override { 23 void OnDisplayChanged(VRDisplayPtr display) override {
24 OnDisplayChanged(*display); 24 OnDisplayChanged(*display);
25 last_display_ = std::move(display); 25 last_display_ = std::move(display);
26 } 26 }
27 27
28 MOCK_METHOD1(OnExitPresent, void(uint32_t index)); 28 MOCK_METHOD1(OnExitPresent, void(uint32_t index));
29 29
30 MOCK_METHOD1(OnDisplayConnected, void(const VRDisplay& display));
31 void OnDisplayConnected(VRDisplayPtr display) override {
32 OnDisplayConnected(*display);
33 last_display_ = std::move(display);
34 }
35 void OnDisplayDisconnected(unsigned index) override {}
36
30 const VRDisplayPtr& LastDisplay() { return last_display_; } 37 const VRDisplayPtr& LastDisplay() { return last_display_; }
31 38
32 private: 39 private:
33 VRDisplayPtr last_display_; 40 VRDisplayPtr last_display_;
34 }; 41 };
35 42
36 class VRServiceTestBinding { 43 class VRServiceTestBinding {
37 public: 44 public:
38 VRServiceTestBinding() { 45 VRServiceTestBinding() {
39 auto request = mojo::GetProxy(&service_ptr_); 46 auto request = mojo::GetProxy(&service_ptr_);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // Service 1 should be able to exit the presentation it initiated. 180 // Service 1 should be able to exit the presentation it initiated.
174 device_manager_->ExitPresent(service_1->service(), device->id()); 181 device_manager_->ExitPresent(service_1->service(), device->id());
175 EXPECT_FALSE(presenting()); 182 EXPECT_FALSE(presenting());
176 183
177 // Once presention had ended both services should be able to access the device 184 // Once presention had ended both services should be able to access the device
178 EXPECT_EQ(device.get(), VRDeviceManager::GetAllowedDevice( 185 EXPECT_EQ(device.get(), VRDeviceManager::GetAllowedDevice(
179 service_1->service(), device->id())); 186 service_1->service(), device->id()));
180 EXPECT_EQ(device.get(), VRDeviceManager::GetAllowedDevice( 187 EXPECT_EQ(device.get(), VRDeviceManager::GetAllowedDevice(
181 service_2->service(), device->id())); 188 service_2->service(), device->id()));
182 } 189 }
190
191 // Ensure that DeviceChanged calls are dispatched to all active services.
192 TEST_F(VRServiceImplTest, DeviceConnectedDispatched) {
193 std::unique_ptr<VRServiceTestBinding> service_1 = BindService();
194 std::unique_ptr<VRServiceTestBinding> service_2 = BindService();
195
196 EXPECT_CALL(service_1->client(), OnDisplayConnected(_));
197 EXPECT_CALL(service_2->client(), OnDisplayConnected(_));
198
199 std::unique_ptr<FakeVRDevice> device(new FakeVRDevice(provider_));
200 device_manager_->OnDeviceConnectionStatusChanged(device.get(), true);
201
202 base::RunLoop().RunUntilIdle();
203
204 EXPECT_EQ(device->id(), service_1->client().LastDisplay()->index);
205 EXPECT_EQ(device->id(), service_2->client().LastDisplay()->index);
183 } 206 }
207 }
OLDNEW
« no previous file with comments | « device/vr/vr_service.mojom ('k') | third_party/WebKit/Source/modules/vr/NavigatorVR.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698