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

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

Issue 2488273002: Revert of mojo VR interface simplified (Closed)
Patch Set: 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_;
36 35
37 DISALLOW_COPY_AND_ASSIGN(VRDeviceManagerTest); 36 DISALLOW_COPY_AND_ASSIGN(VRDeviceManagerTest);
38 }; 37 };
39 38
40 VRDeviceManagerTest::VRDeviceManagerTest() {} 39 VRDeviceManagerTest::VRDeviceManagerTest() {}
41 40
42 VRDeviceManagerTest::~VRDeviceManagerTest() {} 41 VRDeviceManagerTest::~VRDeviceManagerTest() {}
43 42
44 void VRDeviceManagerTest::SetUp() { 43 void VRDeviceManagerTest::SetUp() {
45 std::unique_ptr<FakeVRDeviceProvider> provider(new FakeVRDeviceProvider()); 44 std::unique_ptr<FakeVRDeviceProvider> provider(new FakeVRDeviceProvider());
46 provider_ = provider.get(); 45 provider_ = provider.get();
47 device_manager_.reset(new VRDeviceManager(std::move(provider))); 46 device_manager_.reset(new VRDeviceManager(std::move(provider)));
48 vr_service_.reset(new VRServiceImpl());
49 } 47 }
50 48
51 TEST_F(VRDeviceManagerTest, InitializationTest) { 49 TEST_F(VRDeviceManagerTest, InitializationTest) {
52 EXPECT_FALSE(provider_->IsInitialized()); 50 EXPECT_FALSE(provider_->IsInitialized());
53 51
54 // Calling GetDevices should initialize the service if it hasn't been 52 // Calling GetDevices should initialize the service if it hasn't been
55 // initialized yet or the providesr have been released. 53 // initialized yet or the providesr have been released.
56 // 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
57 // initialization. 55 // initialization.
58 device_manager_->GetVRDevices(vr_service_.get()); 56 mojo::Array<VRDisplayPtr> webvr_devices;
57 webvr_devices = device_manager_->GetVRDevices();
59 EXPECT_TRUE(provider_->IsInitialized()); 58 EXPECT_TRUE(provider_->IsInitialized());
60 } 59 }
61 60
62 TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) { 61 TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) {
63 bool success = device_manager_->GetVRDevices(vr_service_.get()); 62 mojo::Array<VRDisplayPtr> webvr_devices;
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 EXPECT_FALSE(success); 66 // Should successfully return zero devices when none are available.
67 EXPECT_EQ(0u, webvr_devices.size());
67 68
68 // GetDeviceByIndex should return nullptr if an invalid index in queried. 69 // GetDeviceByIndex should return nullptr if an invalid index in queried.
69 VRDevice* queried_device = GetDevice(1); 70 VRDevice* queried_device = GetDevice(1);
70 EXPECT_EQ(nullptr, queried_device); 71 EXPECT_EQ(nullptr, queried_device);
71 72
72 std::unique_ptr<FakeVRDevice> device1(new FakeVRDevice(provider_)); 73 std::unique_ptr<FakeVRDevice> device1(new FakeVRDevice(provider_));
73 provider_->AddDevice(device1.get()); 74 provider_->AddDevice(device1.get());
74 success = device_manager_->GetVRDevices(vr_service_.get()); 75 webvr_devices = device_manager_->GetVRDevices();
75 EXPECT_TRUE(success);
76 // Should have successfully returned one device. 76 // Should have successfully returned one device.
77 EXPECT_EQ(device1.get(), GetDevice(device1->id())); 77 EXPECT_EQ(1u, webvr_devices.size());
78 // The WebVRDevice index should match the device id.
79 EXPECT_EQ(webvr_devices[0]->index, device1->id());
78 80
79 std::unique_ptr<FakeVRDevice> device2(new FakeVRDevice(provider_)); 81 std::unique_ptr<FakeVRDevice> device2(new FakeVRDevice(provider_));
80 provider_->AddDevice(device2.get()); 82 provider_->AddDevice(device2.get());
81 success = device_manager_->GetVRDevices(vr_service_.get()); 83 webvr_devices = device_manager_->GetVRDevices();
82 EXPECT_TRUE(success); 84 // Should have successfully returned two devices.
85 EXPECT_EQ(2u, webvr_devices.size());
86 // NOTE: Returned WebVRDevices are not required to be in any particular order.
83 87
84 // Querying the WebVRDevice index should return the correct device. 88 // Querying the WebVRDevice index should return the correct device.
85 VRDevice* queried_device1 = GetDevice(device1->id()); 89 queried_device = GetDevice(device1->id());
86 EXPECT_EQ(device1.get(), queried_device1); 90 EXPECT_EQ(device1.get(), queried_device);
87 VRDevice* queried_device2 = GetDevice(device2->id()); 91 queried_device = GetDevice(device2->id());
88 EXPECT_EQ(device2.get(), queried_device2); 92 EXPECT_EQ(device2.get(), queried_device);
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());
89 } 100 }
90 101
91 } // namespace device 102 } // 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