| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 TEST_F(VRDeviceManagerTest, InitializationTest) { | 70 TEST_F(VRDeviceManagerTest, InitializationTest) { |
| 71 EXPECT_FALSE(provider_->IsInitialized()); | 71 EXPECT_FALSE(provider_->IsInitialized()); |
| 72 | 72 |
| 73 // Calling GetDevices should initialize the service if it hasn't been | 73 // Calling GetDevices should initialize the service if it hasn't been |
| 74 // initialized yet or the providesr have been released. | 74 // initialized yet or the providesr have been released. |
| 75 // The mojom::VRService should initialize each of it's providers upon it's own | 75 // The mojom::VRService should initialize each of it's providers upon it's own |
| 76 // initialization. And SetClient method in VRService class will invoke | 76 // initialization. And SetClient method in VRService class will invoke |
| 77 // GetVRDevices too. | 77 // GetVRDevices too. |
| 78 auto service = BindService(); | 78 auto service = BindService(); |
| 79 device_manager_->GetVRDevices(service.get()); | 79 device_manager_->AddService(service.get()); |
| 80 EXPECT_TRUE(provider_->IsInitialized()); | 80 EXPECT_TRUE(provider_->IsInitialized()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) { | 83 TEST_F(VRDeviceManagerTest, GetDevicesTest) { |
| 84 auto service = BindService(); | 84 auto service = BindService(); |
| 85 | 85 device_manager_->AddService(service.get()); |
| 86 bool success = device_manager_->GetVRDevices(service.get()); | |
| 87 // Calling GetVRDevices should initialize the providers. | 86 // Calling GetVRDevices should initialize the providers. |
| 88 EXPECT_TRUE(provider_->IsInitialized()); | 87 EXPECT_TRUE(provider_->IsInitialized()); |
| 89 EXPECT_FALSE(success); | |
| 90 | 88 |
| 91 // GetDeviceByIndex should return nullptr if an invalid index in queried. | 89 // GetDeviceByIndex should return nullptr if an invalid index in queried. |
| 92 VRDevice* queried_device = GetDevice(1); | 90 VRDevice* queried_device = GetDevice(1); |
| 93 EXPECT_EQ(nullptr, queried_device); | 91 EXPECT_EQ(nullptr, queried_device); |
| 94 | 92 |
| 95 FakeVRDevice* device1 = new FakeVRDevice(); | 93 FakeVRDevice* device1 = new FakeVRDevice(); |
| 96 provider_->AddDevice(base::WrapUnique(device1)); | 94 provider_->AddDevice(base::WrapUnique(device1)); |
| 97 success = device_manager_->GetVRDevices(service.get()); | 95 // VRDeviceManager will query devices as a side effect. |
| 98 EXPECT_TRUE(success); | 96 service = BindService(); |
| 99 // Should have successfully returned one device. | 97 // Should have successfully returned one device. |
| 100 EXPECT_EQ(device1, GetDevice(device1->id())); | 98 EXPECT_EQ(device1, GetDevice(device1->id())); |
| 101 | 99 |
| 102 FakeVRDevice* device2 = new FakeVRDevice(); | 100 FakeVRDevice* device2 = new FakeVRDevice(); |
| 103 provider_->AddDevice(base::WrapUnique(device2)); | 101 provider_->AddDevice(base::WrapUnique(device2)); |
| 104 success = device_manager_->GetVRDevices(service.get()); | 102 // VRDeviceManager will query devices as a side effect. |
| 105 EXPECT_TRUE(success); | 103 service = BindService(); |
| 106 | |
| 107 // Querying the WebVRDevice index should return the correct device. | 104 // Querying the WebVRDevice index should return the correct device. |
| 108 EXPECT_EQ(device1, GetDevice(device1->id())); | 105 EXPECT_EQ(device1, GetDevice(device1->id())); |
| 109 EXPECT_EQ(device2, GetDevice(device2->id())); | 106 EXPECT_EQ(device2, GetDevice(device2->id())); |
| 110 } | 107 } |
| 111 | 108 |
| 112 } // namespace device | 109 } // namespace device |
| OLD | NEW |