Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: device/vr/vr_device_manager_unittest.cc

Issue 2471433002: Implement WebVR presentation pausing for VR Shell Menu Mode (Closed)
Patch Set: Address comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 scoped_refptr<FakeVRDeviceProvider> provider_;
34 std::unique_ptr<VRDeviceManager> device_manager_; 34 std::unique_ptr<VRDeviceManager> device_manager_;
35 35
36 DISALLOW_COPY_AND_ASSIGN(VRDeviceManagerTest); 36 DISALLOW_COPY_AND_ASSIGN(VRDeviceManagerTest);
37 }; 37 };
38 38
39 VRDeviceManagerTest::VRDeviceManagerTest() {} 39 VRDeviceManagerTest::VRDeviceManagerTest() {}
40 40
41 VRDeviceManagerTest::~VRDeviceManagerTest() {} 41 VRDeviceManagerTest::~VRDeviceManagerTest() {}
42 42
43 void VRDeviceManagerTest::SetUp() { 43 void VRDeviceManagerTest::SetUp() {
44 std::unique_ptr<FakeVRDeviceProvider> provider(new FakeVRDeviceProvider()); 44 FakeVRDeviceProvider* provider = new FakeVRDeviceProvider();
45 provider_ = provider.get(); 45 provider_ = provider;
46 device_manager_.reset(new VRDeviceManager(std::move(provider))); 46 device_manager_.reset(new VRDeviceManager(provider));
47 } 47 }
48 48
49 TEST_F(VRDeviceManagerTest, InitializationTest) { 49 TEST_F(VRDeviceManagerTest, InitializationTest) {
50 EXPECT_FALSE(provider_->IsInitialized()); 50 EXPECT_FALSE(provider_->IsInitialized());
51 51
52 // Calling GetDevices should initialize the service if it hasn't been 52 // Calling GetDevices should initialize the service if it hasn't been
53 // initialized yet or the providesr have been released. 53 // initialized yet or the providesr have been released.
54 // The mojom::VRService should initialize each of it's providers upon it's own 54 // The mojom::VRService should initialize each of it's providers upon it's own
55 // initialization. 55 // initialization.
56 mojo::Array<VRDisplayPtr> webvr_devices; 56 mojo::Array<VRDisplayPtr> webvr_devices;
57 webvr_devices = device_manager_->GetVRDevices(); 57 webvr_devices = device_manager_->GetVRDevices();
58 EXPECT_TRUE(provider_->IsInitialized()); 58 EXPECT_TRUE(provider_->IsInitialized());
59 } 59 }
60 60
61 TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) { 61 TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) {
62 mojo::Array<VRDisplayPtr> webvr_devices; 62 mojo::Array<VRDisplayPtr> webvr_devices;
63 webvr_devices = device_manager_->GetVRDevices(); 63 webvr_devices = device_manager_->GetVRDevices();
64 // Calling GetVRDevices should initialize the providers. 64 // Calling GetVRDevices should initialize the providers.
65 EXPECT_TRUE(provider_->IsInitialized()); 65 EXPECT_TRUE(provider_->IsInitialized());
66 // Should successfully return zero devices when none are available. 66 // Should successfully return zero devices when none are available.
67 EXPECT_EQ(0u, webvr_devices.size()); 67 EXPECT_EQ(0u, webvr_devices.size());
68 68
69 // GetDeviceByIndex should return nullptr if an invalid index in queried. 69 // GetDeviceByIndex should return nullptr if an invalid index in queried.
70 VRDevice* queried_device = GetDevice(1); 70 VRDevice* queried_device = GetDevice(1);
71 EXPECT_EQ(nullptr, queried_device); 71 EXPECT_EQ(nullptr, queried_device);
72 72
73 std::unique_ptr<FakeVRDevice> device1(new FakeVRDevice(provider_)); 73 std::unique_ptr<FakeVRDevice> device1(new FakeVRDevice(provider_.get()));
74 provider_->AddDevice(device1.get()); 74 provider_->AddDevice(device1.get());
75 webvr_devices = device_manager_->GetVRDevices(); 75 webvr_devices = device_manager_->GetVRDevices();
76 // Should have successfully returned one device. 76 // Should have successfully returned one device.
77 EXPECT_EQ(1u, webvr_devices.size()); 77 EXPECT_EQ(1u, webvr_devices.size());
78 // The WebVRDevice index should match the device id. 78 // The WebVRDevice index should match the device id.
79 EXPECT_EQ(webvr_devices[0]->index, device1->id()); 79 EXPECT_EQ(webvr_devices[0]->index, device1->id());
80 80
81 std::unique_ptr<FakeVRDevice> device2(new FakeVRDevice(provider_)); 81 std::unique_ptr<FakeVRDevice> device2(new FakeVRDevice(provider_.get()));
82 provider_->AddDevice(device2.get()); 82 provider_->AddDevice(device2.get());
83 webvr_devices = device_manager_->GetVRDevices(); 83 webvr_devices = device_manager_->GetVRDevices();
84 // Should have successfully returned two devices. 84 // Should have successfully returned two devices.
85 EXPECT_EQ(2u, webvr_devices.size()); 85 EXPECT_EQ(2u, webvr_devices.size());
86 // NOTE: Returned WebVRDevices are not required to be in any particular order. 86 // NOTE: Returned WebVRDevices are not required to be in any particular order.
87 87
88 // Querying the WebVRDevice index should return the correct device. 88 // Querying the WebVRDevice index should return the correct device.
89 queried_device = GetDevice(device1->id()); 89 queried_device = GetDevice(device1->id());
90 EXPECT_EQ(device1.get(), queried_device); 90 EXPECT_EQ(device1.get(), queried_device);
91 queried_device = GetDevice(device2->id()); 91 queried_device = GetDevice(device2->id());
92 EXPECT_EQ(device2.get(), queried_device); 92 EXPECT_EQ(device2.get(), queried_device);
93 93
94 provider_->RemoveDevice(device1.get()); 94 provider_->RemoveDevice(device1.get());
95 webvr_devices = device_manager_->GetVRDevices(); 95 webvr_devices = device_manager_->GetVRDevices();
96 // Should have successfully returned one device. 96 // Should have successfully returned one device.
97 EXPECT_EQ(1u, webvr_devices.size()); 97 EXPECT_EQ(1u, webvr_devices.size());
98 // The WebVRDevice index should match the only remaining device id. 98 // The WebVRDevice index should match the only remaining device id.
99 EXPECT_EQ(webvr_devices[0]->index, device2->id()); 99 EXPECT_EQ(webvr_devices[0]->index, device2->id());
100 } 100 }
101 101
102 } // namespace device 102 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698