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

Unified Diff: content/browser/vr/vr_device_manager_unittest.cc

Issue 829803003: Adding Chrome-side WebVR interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed one cardboard reference Created 5 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/vr/vr_device_manager_unittest.cc
diff --git a/content/browser/vr/vr_device_manager_unittest.cc b/content/browser/vr/vr_device_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..873a29670692b2fed58eaad8563c53664efba4c5
--- /dev/null
+++ b/content/browser/vr/vr_device_manager_unittest.cc
@@ -0,0 +1,96 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/memory/linked_ptr.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/browser/vr/test/fake_vr_device.h"
+#include "content/browser/vr/test/fake_vr_device_provider.h"
+#include "content/browser/vr/vr_device_manager.h"
+#include "content/browser/vr/vr_device_provider.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+class VRDeviceManagerTest : public testing::Test {
+ protected:
+ VRDeviceManagerTest();
+ ~VRDeviceManagerTest() override;
+
+ void SetUp() override;
+
+ bool HasServiceInstance() { return VRDeviceManager::HasInstance(); }
+
+ protected:
+ FakeVRDeviceProvider* provider_;
+ scoped_ptr<VRDeviceManager> device_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(VRDeviceManagerTest);
+};
+
+VRDeviceManagerTest::VRDeviceManagerTest() {
+}
+
+VRDeviceManagerTest::~VRDeviceManagerTest() {
+}
+
+void VRDeviceManagerTest::SetUp() {
+ scoped_ptr<FakeVRDeviceProvider> provider(new FakeVRDeviceProvider());
+ provider_ = provider.get();
+ device_manager_.reset(new VRDeviceManager(provider.Pass()));
+}
+
+TEST_F(VRDeviceManagerTest, InitializationTest) {
+ EXPECT_FALSE(provider_->IsInitialized());
+
+ // Calling GetDevices should initialize the service if it hasn't been
+ // initialized yet or the providesr have been released.
+ // The VRService should initialize each of it's providers upon it's own
+ // initialization.
+ mojo::Array<VRDeviceInfoPtr> webvr_devices;
+ webvr_devices = device_manager_->GetVRDevices();
+ EXPECT_TRUE(provider_->IsInitialized());
+}
+
+TEST_F(VRDeviceManagerTest, GetDevicesBasicTest) {
+ mojo::Array<VRDeviceInfoPtr> webvr_devices;
+ webvr_devices = device_manager_->GetVRDevices();
+ // Calling GetVRDevices should initialize the providers.
+ EXPECT_TRUE(provider_->IsInitialized());
+ // Should successfully return zero devices when none are available.
+ EXPECT_EQ(0u, webvr_devices.size());
+
+ // GetDeviceByIndex should return nullptr if an invalid index in queried.
+ VRDevice* queried_device = device_manager_->GetDevice(1);
+ EXPECT_EQ(nullptr, queried_device);
+
+ scoped_ptr<FakeVRDevice> device1(new FakeVRDevice(provider_));
+ provider_->AddDevice(device1.get());
+ webvr_devices = device_manager_->GetVRDevices();
+ // Should have successfully returned one device.
+ EXPECT_EQ(1u, webvr_devices.size());
+ // The WebVRDevice index should match the device id.
+ EXPECT_EQ(webvr_devices[0]->index, device1->id());
+
+ scoped_ptr<FakeVRDevice> device2(new FakeVRDevice(provider_));
+ provider_->AddDevice(device2.get());
+ webvr_devices = device_manager_->GetVRDevices();
+ // Should have successfully returned two devices.
+ EXPECT_EQ(2u, webvr_devices.size());
+ // NOTE: Returned WebVRDevices are not required to be in any particular order.
+
+ // Querying the WebVRDevice index should return the correct device.
+ queried_device = device_manager_->GetDevice(device1->id());
+ EXPECT_EQ(device1.get(), queried_device);
+ queried_device = device_manager_->GetDevice(device2->id());
+ EXPECT_EQ(device2.get(), queried_device);
+
+ provider_->RemoveDevice(device1.get());
+ webvr_devices = device_manager_->GetVRDevices();
+ // Should have successfully returned one device.
+ EXPECT_EQ(1u, webvr_devices.size());
+ // The WebVRDevice index should match the only remaining device id.
+ EXPECT_EQ(webvr_devices[0]->index, device2->id());
+}
+
+} // namespace content
« 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