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