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

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

Issue 2494733002: Reland of mojo VR interface simpified. (Closed)
Patch Set: Fix Werror 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
« no previous file with comments | « device/vr/vr_device_manager.cc ('k') | device/vr/vr_device_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 14 matching lines...) Expand all
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_;
34 std::unique_ptr<VRDeviceManager> device_manager_; 34 std::unique_ptr<VRDeviceManager> device_manager_;
35 std::unique_ptr<VRServiceImpl> vr_service_;
35 36
36 DISALLOW_COPY_AND_ASSIGN(VRDeviceManagerTest); 37 DISALLOW_COPY_AND_ASSIGN(VRDeviceManagerTest);
37 }; 38 };
38 39
39 VRDeviceManagerTest::VRDeviceManagerTest() {} 40 VRDeviceManagerTest::VRDeviceManagerTest() {}
40 41
41 VRDeviceManagerTest::~VRDeviceManagerTest() {} 42 VRDeviceManagerTest::~VRDeviceManagerTest() {}
42 43
43 void VRDeviceManagerTest::SetUp() { 44 void VRDeviceManagerTest::SetUp() {
44 std::unique_ptr<FakeVRDeviceProvider> provider(new FakeVRDeviceProvider()); 45 std::unique_ptr<FakeVRDeviceProvider> provider(new FakeVRDeviceProvider());
45 provider_ = provider.get(); 46 provider_ = provider.get();
46 device_manager_.reset(new VRDeviceManager(std::move(provider))); 47 device_manager_.reset(new VRDeviceManager(std::move(provider)));
48 vr_service_.reset(new VRServiceImpl());
47 } 49 }
48 50
49 TEST_F(VRDeviceManagerTest, InitializationTest) { 51 TEST_F(VRDeviceManagerTest, InitializationTest) {
50 EXPECT_FALSE(provider_->IsInitialized()); 52 EXPECT_FALSE(provider_->IsInitialized());
51 53
52 // Calling GetDevices should initialize the service if it hasn't been 54 // Calling GetDevices should initialize the service if it hasn't been
53 // initialized yet or the providesr have been released. 55 // initialized yet or the providesr have been released.
54 // The mojom::VRService should initialize each of it's providers upon it's own 56 // The mojom::VRService should initialize each of it's providers upon it's own
55 // initialization. 57 // initialization.
56 mojo::Array<VRDisplayPtr> webvr_devices; 58 device_manager_->GetVRDevices(vr_service_.get());
57 webvr_devices = device_manager_->GetVRDevices();
58 EXPECT_TRUE(provider_->IsInitialized()); 59 EXPECT_TRUE(provider_->IsInitialized());
59 } 60 }
60 61
61 TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) { 62 TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) {
62 mojo::Array<VRDisplayPtr> webvr_devices; 63 bool success = device_manager_->GetVRDevices(vr_service_.get());
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 EXPECT_FALSE(success);
67 EXPECT_EQ(0u, webvr_devices.size());
68 67
69 // GetDeviceByIndex should return nullptr if an invalid index in queried. 68 // GetDeviceByIndex should return nullptr if an invalid index in queried.
70 VRDevice* queried_device = GetDevice(1); 69 VRDevice* queried_device = GetDevice(1);
71 EXPECT_EQ(nullptr, queried_device); 70 EXPECT_EQ(nullptr, queried_device);
72 71
73 std::unique_ptr<FakeVRDevice> device1(new FakeVRDevice(provider_)); 72 std::unique_ptr<FakeVRDevice> device1(new FakeVRDevice(provider_));
74 provider_->AddDevice(device1.get()); 73 provider_->AddDevice(device1.get());
75 webvr_devices = device_manager_->GetVRDevices(); 74 success = device_manager_->GetVRDevices(vr_service_.get());
75 EXPECT_TRUE(success);
76 // Should have successfully returned one device. 76 // Should have successfully returned one device.
77 EXPECT_EQ(1u, webvr_devices.size()); 77 EXPECT_EQ(device1.get(), GetDevice(device1->id()));
78 // The WebVRDevice index should match the device id.
79 EXPECT_EQ(webvr_devices[0]->index, device1->id());
80 78
81 std::unique_ptr<FakeVRDevice> device2(new FakeVRDevice(provider_)); 79 std::unique_ptr<FakeVRDevice> device2(new FakeVRDevice(provider_));
82 provider_->AddDevice(device2.get()); 80 provider_->AddDevice(device2.get());
83 webvr_devices = device_manager_->GetVRDevices(); 81 success = device_manager_->GetVRDevices(vr_service_.get());
84 // Should have successfully returned two devices. 82 EXPECT_TRUE(success);
85 EXPECT_EQ(2u, webvr_devices.size());
86 // NOTE: Returned WebVRDevices are not required to be in any particular order.
87 83
88 // Querying the WebVRDevice index should return the correct device. 84 // Querying the WebVRDevice index should return the correct device.
89 queried_device = GetDevice(device1->id()); 85 VRDevice* queried_device1 = GetDevice(device1->id());
90 EXPECT_EQ(device1.get(), queried_device); 86 EXPECT_EQ(device1.get(), queried_device1);
91 queried_device = GetDevice(device2->id()); 87 VRDevice* queried_device2 = GetDevice(device2->id());
92 EXPECT_EQ(device2.get(), queried_device); 88 EXPECT_EQ(device2.get(), queried_device2);
93
94 provider_->RemoveDevice(device1.get());
95 webvr_devices = device_manager_->GetVRDevices();
96 // Should have successfully returned one device.
97 EXPECT_EQ(1u, webvr_devices.size());
98 // The WebVRDevice index should match the only remaining device id.
99 EXPECT_EQ(webvr_devices[0]->index, device2->id());
100 } 89 }
101 90
102 } // namespace device 91 } // namespace device
OLDNEW
« no previous file with comments | « device/vr/vr_device_manager.cc ('k') | device/vr/vr_device_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698