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

Unified Diff: device/vr/vr_service_impl_unittest.cc

Issue 2329893002: Isolate a presenting VR device from pages other than the one presenting. (Closed)
Patch Set: Unit tests Created 4 years, 3 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 | « device/vr/vr_service_impl.cc ('k') | third_party/WebKit/Source/modules/vr/VRController.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/vr/vr_service_impl_unittest.cc
diff --git a/device/vr/vr_service_impl_unittest.cc b/device/vr/vr_service_impl_unittest.cc
index 499e2beb2135f1a2c432d816a30c9e67ea65bdb6..cefe287a661f1805245efc6e7dec30ab39aca2dc 100644
--- a/device/vr/vr_service_impl_unittest.cc
+++ b/device/vr/vr_service_impl_unittest.cc
@@ -25,6 +25,8 @@ class MockVRServiceClient : public VRServiceClient {
last_display_ = std::move(display);
}
+ MOCK_METHOD1(OnExitPresent, void(uint32_t index));
+
const VRDisplayPtr& LastDisplay() { return last_display_; }
private:
@@ -50,6 +52,7 @@ class VRServiceTestBinding {
}
MockVRServiceClient& client() { return mock_client_; }
+ VRServiceImpl* service() { return service_impl_.get(); }
private:
std::unique_ptr<VRServiceImpl> service_impl_;
@@ -81,6 +84,8 @@ class VRServiceImplTest : public testing::Test {
size_t ServiceCount() { return device_manager_->services_.size(); }
+ bool presenting() { return !!device_manager_->presenting_service_; }
+
base::MessageLoop message_loop_;
FakeVRDeviceProvider* provider_;
std::unique_ptr<VRDeviceManager> device_manager_;
@@ -126,4 +131,53 @@ TEST_F(VRServiceImplTest, DeviceChangedDispatched) {
EXPECT_EQ(device->id(), service_1->client().LastDisplay()->index);
EXPECT_EQ(device->id(), service_2->client().LastDisplay()->index);
}
+
+// Ensure that presenting devices cannot be accessed by other services
+TEST_F(VRServiceImplTest, DevicePresentationIsolation) {
+ std::unique_ptr<VRServiceTestBinding> service_1 = BindService();
+ std::unique_ptr<VRServiceTestBinding> service_2 = BindService();
+
+ std::unique_ptr<FakeVRDevice> device(new FakeVRDevice(provider_));
+ provider_->AddDevice(device.get());
+
+ // Ensure the device manager has seen the fake device
+ device_manager_->GetVRDevices();
+
+ // When not presenting either service should be able to access the device
+ EXPECT_EQ(device.get(), VRDeviceManager::GetAllowedDevice(
+ service_1->service(), device->id()));
+ EXPECT_EQ(device.get(), VRDeviceManager::GetAllowedDevice(
+ service_2->service(), device->id()));
+
+ // Begin presenting to the fake device with service 1
+ EXPECT_TRUE(
+ device_manager_->RequestPresent(service_1->service(), device->id()));
+
+ EXPECT_TRUE(presenting());
+
+ // Service 2 should not be able to present to the device while service 1
+ // is still presenting.
+ EXPECT_FALSE(
+ device_manager_->RequestPresent(service_2->service(), device->id()));
+
+ // Only the presenting service should be able to access the device
+ EXPECT_EQ(device.get(), VRDeviceManager::GetAllowedDevice(
+ service_1->service(), device->id()));
+ EXPECT_EQ(nullptr, VRDeviceManager::GetAllowedDevice(service_2->service(),
+ device->id()));
+
+ // Service 2 should not be able to exit presentation to the device
+ device_manager_->ExitPresent(service_2->service(), device->id());
+ EXPECT_TRUE(presenting());
+
+ // Service 1 should be able to exit the presentation it initiated.
+ device_manager_->ExitPresent(service_1->service(), device->id());
+ EXPECT_FALSE(presenting());
+
+ // Once presention had ended both services should be able to access the device
+ EXPECT_EQ(device.get(), VRDeviceManager::GetAllowedDevice(
+ service_1->service(), device->id()));
+ EXPECT_EQ(device.get(), VRDeviceManager::GetAllowedDevice(
+ service_2->service(), device->id()));
+}
}
« no previous file with comments | « device/vr/vr_service_impl.cc ('k') | third_party/WebKit/Source/modules/vr/VRController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698