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 "content/browser/vr/vr_device_manager.h" |
| 6 |
| 7 #include <memory> |
5 #include <utility> | 8 #include <utility> |
6 | 9 |
7 #include "base/macros.h" | 10 #include "base/macros.h" |
8 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "content/browser/vr/test/fake_vr_device.h" | 12 #include "content/browser/vr/test/fake_vr_device.h" |
11 #include "content/browser/vr/test/fake_vr_device_provider.h" | 13 #include "content/browser/vr/test/fake_vr_device_provider.h" |
12 #include "content/browser/vr/vr_device_manager.h" | |
13 #include "content/browser/vr/vr_device_provider.h" | 14 #include "content/browser/vr/vr_device_provider.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 class VRDeviceManagerTest : public testing::Test { | 19 class VRDeviceManagerTest : public testing::Test { |
19 protected: | 20 protected: |
20 VRDeviceManagerTest(); | 21 VRDeviceManagerTest(); |
21 ~VRDeviceManagerTest() override; | 22 ~VRDeviceManagerTest() override; |
22 | 23 |
23 void SetUp() override; | 24 void SetUp() override; |
24 | 25 |
25 bool HasServiceInstance() { return VRDeviceManager::HasInstance(); } | 26 bool HasServiceInstance() { return VRDeviceManager::HasInstance(); } |
26 | 27 |
27 protected: | 28 protected: |
28 FakeVRDeviceProvider* provider_; | 29 FakeVRDeviceProvider* provider_; |
29 scoped_ptr<VRDeviceManager> device_manager_; | 30 std::unique_ptr<VRDeviceManager> device_manager_; |
30 | 31 |
31 DISALLOW_COPY_AND_ASSIGN(VRDeviceManagerTest); | 32 DISALLOW_COPY_AND_ASSIGN(VRDeviceManagerTest); |
32 }; | 33 }; |
33 | 34 |
34 VRDeviceManagerTest::VRDeviceManagerTest() { | 35 VRDeviceManagerTest::VRDeviceManagerTest() { |
35 } | 36 } |
36 | 37 |
37 VRDeviceManagerTest::~VRDeviceManagerTest() { | 38 VRDeviceManagerTest::~VRDeviceManagerTest() { |
38 } | 39 } |
39 | 40 |
40 void VRDeviceManagerTest::SetUp() { | 41 void VRDeviceManagerTest::SetUp() { |
41 scoped_ptr<FakeVRDeviceProvider> provider(new FakeVRDeviceProvider()); | 42 std::unique_ptr<FakeVRDeviceProvider> provider(new FakeVRDeviceProvider()); |
42 provider_ = provider.get(); | 43 provider_ = provider.get(); |
43 device_manager_.reset(new VRDeviceManager(std::move(provider))); | 44 device_manager_.reset(new VRDeviceManager(std::move(provider))); |
44 } | 45 } |
45 | 46 |
46 TEST_F(VRDeviceManagerTest, InitializationTest) { | 47 TEST_F(VRDeviceManagerTest, InitializationTest) { |
47 EXPECT_FALSE(provider_->IsInitialized()); | 48 EXPECT_FALSE(provider_->IsInitialized()); |
48 | 49 |
49 // Calling GetDevices should initialize the service if it hasn't been | 50 // Calling GetDevices should initialize the service if it hasn't been |
50 // initialized yet or the providesr have been released. | 51 // initialized yet or the providesr have been released. |
51 // The mojom::VRService should initialize each of it's providers upon it's own | 52 // The mojom::VRService should initialize each of it's providers upon it's own |
52 // initialization. | 53 // initialization. |
53 mojo::Array<mojom::VRDeviceInfoPtr> webvr_devices; | 54 mojo::Array<mojom::VRDeviceInfoPtr> webvr_devices; |
54 webvr_devices = device_manager_->GetVRDevices(); | 55 webvr_devices = device_manager_->GetVRDevices(); |
55 EXPECT_TRUE(provider_->IsInitialized()); | 56 EXPECT_TRUE(provider_->IsInitialized()); |
56 } | 57 } |
57 | 58 |
58 TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) { | 59 TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) { |
59 mojo::Array<mojom::VRDeviceInfoPtr> webvr_devices; | 60 mojo::Array<mojom::VRDeviceInfoPtr> webvr_devices; |
60 webvr_devices = device_manager_->GetVRDevices(); | 61 webvr_devices = device_manager_->GetVRDevices(); |
61 // Calling GetVRDevices should initialize the providers. | 62 // Calling GetVRDevices should initialize the providers. |
62 EXPECT_TRUE(provider_->IsInitialized()); | 63 EXPECT_TRUE(provider_->IsInitialized()); |
63 // Should successfully return zero devices when none are available. | 64 // Should successfully return zero devices when none are available. |
64 EXPECT_EQ(0u, webvr_devices.size()); | 65 EXPECT_EQ(0u, webvr_devices.size()); |
65 | 66 |
66 // GetDeviceByIndex should return nullptr if an invalid index in queried. | 67 // GetDeviceByIndex should return nullptr if an invalid index in queried. |
67 VRDevice* queried_device = device_manager_->GetDevice(1); | 68 VRDevice* queried_device = device_manager_->GetDevice(1); |
68 EXPECT_EQ(nullptr, queried_device); | 69 EXPECT_EQ(nullptr, queried_device); |
69 | 70 |
70 scoped_ptr<FakeVRDevice> device1(new FakeVRDevice(provider_)); | 71 std::unique_ptr<FakeVRDevice> device1(new FakeVRDevice(provider_)); |
71 provider_->AddDevice(device1.get()); | 72 provider_->AddDevice(device1.get()); |
72 webvr_devices = device_manager_->GetVRDevices(); | 73 webvr_devices = device_manager_->GetVRDevices(); |
73 // Should have successfully returned one device. | 74 // Should have successfully returned one device. |
74 EXPECT_EQ(1u, webvr_devices.size()); | 75 EXPECT_EQ(1u, webvr_devices.size()); |
75 // The WebVRDevice index should match the device id. | 76 // The WebVRDevice index should match the device id. |
76 EXPECT_EQ(webvr_devices[0]->index, device1->id()); | 77 EXPECT_EQ(webvr_devices[0]->index, device1->id()); |
77 | 78 |
78 scoped_ptr<FakeVRDevice> device2(new FakeVRDevice(provider_)); | 79 std::unique_ptr<FakeVRDevice> device2(new FakeVRDevice(provider_)); |
79 provider_->AddDevice(device2.get()); | 80 provider_->AddDevice(device2.get()); |
80 webvr_devices = device_manager_->GetVRDevices(); | 81 webvr_devices = device_manager_->GetVRDevices(); |
81 // Should have successfully returned two devices. | 82 // Should have successfully returned two devices. |
82 EXPECT_EQ(2u, webvr_devices.size()); | 83 EXPECT_EQ(2u, webvr_devices.size()); |
83 // NOTE: Returned WebVRDevices are not required to be in any particular order. | 84 // NOTE: Returned WebVRDevices are not required to be in any particular order. |
84 | 85 |
85 // Querying the WebVRDevice index should return the correct device. | 86 // Querying the WebVRDevice index should return the correct device. |
86 queried_device = device_manager_->GetDevice(device1->id()); | 87 queried_device = device_manager_->GetDevice(device1->id()); |
87 EXPECT_EQ(device1.get(), queried_device); | 88 EXPECT_EQ(device1.get(), queried_device); |
88 queried_device = device_manager_->GetDevice(device2->id()); | 89 queried_device = device_manager_->GetDevice(device2->id()); |
89 EXPECT_EQ(device2.get(), queried_device); | 90 EXPECT_EQ(device2.get(), queried_device); |
90 | 91 |
91 provider_->RemoveDevice(device1.get()); | 92 provider_->RemoveDevice(device1.get()); |
92 webvr_devices = device_manager_->GetVRDevices(); | 93 webvr_devices = device_manager_->GetVRDevices(); |
93 // Should have successfully returned one device. | 94 // Should have successfully returned one device. |
94 EXPECT_EQ(1u, webvr_devices.size()); | 95 EXPECT_EQ(1u, webvr_devices.size()); |
95 // The WebVRDevice index should match the only remaining device id. | 96 // The WebVRDevice index should match the only remaining device id. |
96 EXPECT_EQ(webvr_devices[0]->index, device2->id()); | 97 EXPECT_EQ(webvr_devices[0]->index, device2->id()); |
97 } | 98 } |
98 | 99 |
99 } // namespace content | 100 } // namespace content |
OLD | NEW |