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

Side by Side Diff: content/browser/vr/vr_device_manager_unittest.cc

Issue 2029703002: Moving VR service from /content/browser to /device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added nogncheck to failing include Created 4 years, 6 months 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 | « content/browser/vr/vr_device_manager.cc ('k') | content/browser/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
(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 "content/browser/vr/vr_device_manager.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "base/macros.h"
11 #include "base/memory/linked_ptr.h"
12 #include "content/browser/vr/test/fake_vr_device.h"
13 #include "content/browser/vr/test/fake_vr_device_provider.h"
14 #include "content/browser/vr/vr_device_provider.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace content {
18
19 class VRDeviceManagerTest : public testing::Test {
20 protected:
21 VRDeviceManagerTest();
22 ~VRDeviceManagerTest() override;
23
24 void SetUp() override;
25
26 bool HasServiceInstance() { return VRDeviceManager::HasInstance(); }
27
28 protected:
29 FakeVRDeviceProvider* provider_;
30 std::unique_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 std::unique_ptr<FakeVRDeviceProvider> provider(new FakeVRDeviceProvider());
43 provider_ = provider.get();
44 device_manager_.reset(new VRDeviceManager(std::move(provider)));
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 mojom::VRService should initialize each of it's providers upon it's own
53 // initialization.
54 mojo::Array<blink::mojom::VRDisplayPtr> webvr_devices;
55 webvr_devices = device_manager_->GetVRDevices();
56 EXPECT_TRUE(provider_->IsInitialized());
57 }
58
59 TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) {
60 mojo::Array<blink::mojom::VRDisplayPtr> 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 std::unique_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 std::unique_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
OLDNEW
« no previous file with comments | « content/browser/vr/vr_device_manager.cc ('k') | content/browser/vr/vr_device_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698