OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_device_manager.h" | 5 #include "device/vr/vr_device_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
12 #include "device/vr/test/fake_vr_device.h" | 12 #include "device/vr/test/fake_vr_device.h" |
13 #include "device/vr/test/fake_vr_device_provider.h" | 13 #include "device/vr/test/fake_vr_device_provider.h" |
14 #include "device/vr/vr_device_provider.h" | 14 #include "device/vr/vr_device_provider.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace device { | 17 namespace device { |
18 | 18 |
19 class VRDeviceManagerTest : public testing::Test { | 19 class VRDeviceManagerTest : public testing::Test { |
20 protected: | 20 protected: |
21 VRDeviceManagerTest(); | 21 VRDeviceManagerTest(); |
22 ~VRDeviceManagerTest() override; | 22 ~VRDeviceManagerTest() override; |
23 | 23 |
24 void SetUp() override; | 24 void SetUp() override; |
25 | 25 |
26 bool HasServiceInstance() { return VRDeviceManager::HasInstance(); } | 26 bool HasServiceInstance() { return VRDeviceManager::HasInstance(); } |
27 | 27 |
| 28 VRDevice* GetDevice(unsigned int index) { |
| 29 return device_manager_->GetDevice(index); |
| 30 } |
| 31 |
28 protected: | 32 protected: |
29 FakeVRDeviceProvider* provider_; | 33 FakeVRDeviceProvider* provider_; |
30 std::unique_ptr<VRDeviceManager> device_manager_; | 34 std::unique_ptr<VRDeviceManager> device_manager_; |
31 | 35 |
32 DISALLOW_COPY_AND_ASSIGN(VRDeviceManagerTest); | 36 DISALLOW_COPY_AND_ASSIGN(VRDeviceManagerTest); |
33 }; | 37 }; |
34 | 38 |
35 VRDeviceManagerTest::VRDeviceManagerTest() {} | 39 VRDeviceManagerTest::VRDeviceManagerTest() {} |
36 | 40 |
37 VRDeviceManagerTest::~VRDeviceManagerTest() {} | 41 VRDeviceManagerTest::~VRDeviceManagerTest() {} |
(...skipping 18 matching lines...) Expand all Loading... |
56 | 60 |
57 TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) { | 61 TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) { |
58 mojo::Array<VRDisplayPtr> webvr_devices; | 62 mojo::Array<VRDisplayPtr> webvr_devices; |
59 webvr_devices = device_manager_->GetVRDevices(); | 63 webvr_devices = device_manager_->GetVRDevices(); |
60 // Calling GetVRDevices should initialize the providers. | 64 // Calling GetVRDevices should initialize the providers. |
61 EXPECT_TRUE(provider_->IsInitialized()); | 65 EXPECT_TRUE(provider_->IsInitialized()); |
62 // Should successfully return zero devices when none are available. | 66 // Should successfully return zero devices when none are available. |
63 EXPECT_EQ(0u, webvr_devices.size()); | 67 EXPECT_EQ(0u, webvr_devices.size()); |
64 | 68 |
65 // GetDeviceByIndex should return nullptr if an invalid index in queried. | 69 // GetDeviceByIndex should return nullptr if an invalid index in queried. |
66 VRDevice* queried_device = device_manager_->GetDevice(1); | 70 VRDevice* queried_device = GetDevice(1); |
67 EXPECT_EQ(nullptr, queried_device); | 71 EXPECT_EQ(nullptr, queried_device); |
68 | 72 |
69 std::unique_ptr<FakeVRDevice> device1(new FakeVRDevice(provider_)); | 73 std::unique_ptr<FakeVRDevice> device1(new FakeVRDevice(provider_)); |
70 provider_->AddDevice(device1.get()); | 74 provider_->AddDevice(device1.get()); |
71 webvr_devices = device_manager_->GetVRDevices(); | 75 webvr_devices = device_manager_->GetVRDevices(); |
72 // Should have successfully returned one device. | 76 // Should have successfully returned one device. |
73 EXPECT_EQ(1u, webvr_devices.size()); | 77 EXPECT_EQ(1u, webvr_devices.size()); |
74 // The WebVRDevice index should match the device id. | 78 // The WebVRDevice index should match the device id. |
75 EXPECT_EQ(webvr_devices[0]->index, device1->id()); | 79 EXPECT_EQ(webvr_devices[0]->index, device1->id()); |
76 | 80 |
77 std::unique_ptr<FakeVRDevice> device2(new FakeVRDevice(provider_)); | 81 std::unique_ptr<FakeVRDevice> device2(new FakeVRDevice(provider_)); |
78 provider_->AddDevice(device2.get()); | 82 provider_->AddDevice(device2.get()); |
79 webvr_devices = device_manager_->GetVRDevices(); | 83 webvr_devices = device_manager_->GetVRDevices(); |
80 // Should have successfully returned two devices. | 84 // Should have successfully returned two devices. |
81 EXPECT_EQ(2u, webvr_devices.size()); | 85 EXPECT_EQ(2u, webvr_devices.size()); |
82 // NOTE: Returned WebVRDevices are not required to be in any particular order. | 86 // NOTE: Returned WebVRDevices are not required to be in any particular order. |
83 | 87 |
84 // Querying the WebVRDevice index should return the correct device. | 88 // Querying the WebVRDevice index should return the correct device. |
85 queried_device = device_manager_->GetDevice(device1->id()); | 89 queried_device = GetDevice(device1->id()); |
86 EXPECT_EQ(device1.get(), queried_device); | 90 EXPECT_EQ(device1.get(), queried_device); |
87 queried_device = device_manager_->GetDevice(device2->id()); | 91 queried_device = GetDevice(device2->id()); |
88 EXPECT_EQ(device2.get(), queried_device); | 92 EXPECT_EQ(device2.get(), queried_device); |
89 | 93 |
90 provider_->RemoveDevice(device1.get()); | 94 provider_->RemoveDevice(device1.get()); |
91 webvr_devices = device_manager_->GetVRDevices(); | 95 webvr_devices = device_manager_->GetVRDevices(); |
92 // Should have successfully returned one device. | 96 // Should have successfully returned one device. |
93 EXPECT_EQ(1u, webvr_devices.size()); | 97 EXPECT_EQ(1u, webvr_devices.size()); |
94 // The WebVRDevice index should match the only remaining device id. | 98 // The WebVRDevice index should match the only remaining device id. |
95 EXPECT_EQ(webvr_devices[0]->index, device2->id()); | 99 EXPECT_EQ(webvr_devices[0]->index, device2->id()); |
96 } | 100 } |
97 | 101 |
98 } // namespace device | 102 } // namespace device |
OLD | NEW |