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