| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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) { | 28 VRDevice* GetDevice(unsigned int index) { |
| 29 return device_manager_->GetDevice(index); | 29 return device_manager_->GetDevice(index); |
| 30 } | 30 } |
| 31 | 31 |
| 32 protected: | 32 protected: |
| 33 FakeVRDeviceProvider* provider_; | 33 FakeVRDeviceProvider* provider_ = nullptr; |
| 34 std::unique_ptr<VRDeviceManager> device_manager_; | 34 std::unique_ptr<VRDeviceManager> device_manager_; |
| 35 std::unique_ptr<VRServiceImpl> vr_service_; | 35 std::unique_ptr<VRServiceImpl> vr_service_; |
| 36 | 36 |
| 37 DISALLOW_COPY_AND_ASSIGN(VRDeviceManagerTest); | 37 DISALLOW_COPY_AND_ASSIGN(VRDeviceManagerTest); |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 VRDeviceManagerTest::VRDeviceManagerTest() {} | 40 VRDeviceManagerTest::VRDeviceManagerTest() {} |
| 41 | 41 |
| 42 VRDeviceManagerTest::~VRDeviceManagerTest() {} | 42 VRDeviceManagerTest::~VRDeviceManagerTest() {} |
| 43 | 43 |
| 44 void VRDeviceManagerTest::SetUp() { | 44 void VRDeviceManagerTest::SetUp() { |
| 45 std::unique_ptr<FakeVRDeviceProvider> provider(new FakeVRDeviceProvider()); | 45 provider_ = new FakeVRDeviceProvider(); |
| 46 provider_ = provider.get(); | 46 device_manager_.reset(new VRDeviceManager(base::WrapUnique(provider_))); |
| 47 device_manager_.reset(new VRDeviceManager(std::move(provider))); | |
| 48 vr_service_.reset(new VRServiceImpl()); | 47 vr_service_.reset(new VRServiceImpl()); |
| 49 } | 48 } |
| 50 | 49 |
| 51 TEST_F(VRDeviceManagerTest, InitializationTest) { | 50 TEST_F(VRDeviceManagerTest, InitializationTest) { |
| 52 EXPECT_FALSE(provider_->IsInitialized()); | 51 EXPECT_FALSE(provider_->IsInitialized()); |
| 53 | 52 |
| 54 // Calling GetDevices should initialize the service if it hasn't been | 53 // Calling GetDevices should initialize the service if it hasn't been |
| 55 // initialized yet or the providesr have been released. | 54 // initialized yet or the providesr have been released. |
| 56 // The mojom::VRService should initialize each of it's providers upon it's own | 55 // The mojom::VRService should initialize each of it's providers upon it's own |
| 57 // initialization. | 56 // initialization. |
| 58 device_manager_->GetVRDevices(vr_service_.get()); | 57 device_manager_->GetVRDevices(vr_service_.get()); |
| 59 EXPECT_TRUE(provider_->IsInitialized()); | 58 EXPECT_TRUE(provider_->IsInitialized()); |
| 60 } | 59 } |
| 61 | 60 |
| 62 TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) { | 61 TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) { |
| 63 bool success = device_manager_->GetVRDevices(vr_service_.get()); | 62 bool success = device_manager_->GetVRDevices(vr_service_.get()); |
| 64 // Calling GetVRDevices should initialize the providers. | 63 // Calling GetVRDevices should initialize the providers. |
| 65 EXPECT_TRUE(provider_->IsInitialized()); | 64 EXPECT_TRUE(provider_->IsInitialized()); |
| 66 EXPECT_FALSE(success); | 65 EXPECT_FALSE(success); |
| 67 | 66 |
| 68 // GetDeviceByIndex should return nullptr if an invalid index in queried. | 67 // GetDeviceByIndex should return nullptr if an invalid index in queried. |
| 69 VRDevice* queried_device = GetDevice(1); | 68 VRDevice* queried_device = GetDevice(1); |
| 70 EXPECT_EQ(nullptr, queried_device); | 69 EXPECT_EQ(nullptr, queried_device); |
| 71 | 70 |
| 72 std::unique_ptr<FakeVRDevice> device1(new FakeVRDevice(provider_)); | 71 FakeVRDevice device1; |
| 73 provider_->AddDevice(device1.get()); | 72 provider_->AddDevice(&device1); |
| 74 success = device_manager_->GetVRDevices(vr_service_.get()); | 73 success = device_manager_->GetVRDevices(vr_service_.get()); |
| 75 EXPECT_TRUE(success); | 74 EXPECT_TRUE(success); |
| 76 // Should have successfully returned one device. | 75 // Should have successfully returned one device. |
| 77 EXPECT_EQ(device1.get(), GetDevice(device1->id())); | 76 EXPECT_EQ(&device1, GetDevice(device1.id())); |
| 78 | 77 |
| 79 std::unique_ptr<FakeVRDevice> device2(new FakeVRDevice(provider_)); | 78 FakeVRDevice device2; |
| 80 provider_->AddDevice(device2.get()); | 79 provider_->AddDevice(&device2); |
| 81 success = device_manager_->GetVRDevices(vr_service_.get()); | 80 success = device_manager_->GetVRDevices(vr_service_.get()); |
| 82 EXPECT_TRUE(success); | 81 EXPECT_TRUE(success); |
| 83 | 82 |
| 84 // Querying the WebVRDevice index should return the correct device. | 83 // Querying the WebVRDevice index should return the correct device. |
| 85 VRDevice* queried_device1 = GetDevice(device1->id()); | 84 EXPECT_EQ(&device1, GetDevice(device1.id())); |
| 86 EXPECT_EQ(device1.get(), queried_device1); | 85 EXPECT_EQ(&device2, GetDevice(device2.id())); |
| 87 VRDevice* queried_device2 = GetDevice(device2->id()); | |
| 88 EXPECT_EQ(device2.get(), queried_device2); | |
| 89 } | 86 } |
| 90 | 87 |
| 91 } // namespace device | 88 } // namespace device |
| OLD | NEW |