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

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

Issue 2537723002: Refine VRDevice Class (Closed)
Patch Set: Rebase Created 4 years 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_display_impl.cc ('k') | device/vr/vr_service_impl.cc » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_display_impl.h" 5 #include "device/vr/vr_display_impl.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "device/vr/test/fake_vr_device.h" 9 #include "device/vr/test/fake_vr_device.h"
10 #include "device/vr/test/fake_vr_device_provider.h" 10 #include "device/vr/test/fake_vr_device_provider.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 true, base::Bind(&VRDisplayImplTest::onPresentComplete, 50 true, base::Bind(&VRDisplayImplTest::onPresentComplete,
51 base::Unretained(this))); 51 base::Unretained(this)));
52 } 52 }
53 53
54 void ExitPresent(VRDisplayImpl* display_impl) { display_impl->ExitPresent(); } 54 void ExitPresent(VRDisplayImpl* display_impl) { display_impl->ExitPresent(); }
55 55
56 void TearDown() override { base::RunLoop().RunUntilIdle(); } 56 void TearDown() override { base::RunLoop().RunUntilIdle(); }
57 57
58 VRDevice* device() { return device_; } 58 VRDevice* device() { return device_; }
59 59
60 bool presenting() { return !!device_->presenting_service_; } 60 bool presenting() { return !!device_->presenting_display_; }
61 61
62 base::MessageLoop message_loop_; 62 base::MessageLoop message_loop_;
63 bool is_request_presenting_success_ = false; 63 bool is_request_presenting_success_ = false;
64 FakeVRDeviceProvider* provider_; 64 FakeVRDeviceProvider* provider_;
65 FakeVRDevice* device_; 65 FakeVRDevice* device_;
66 std::vector<FakeVRServiceClient*> clients_; 66 std::vector<FakeVRServiceClient*> clients_;
67 std::unique_ptr<VRDeviceManager> device_manager_; 67 std::unique_ptr<VRDeviceManager> device_manager_;
68 68
69 DISALLOW_COPY_AND_ASSIGN(VRDisplayImplTest); 69 DISALLOW_COPY_AND_ASSIGN(VRDisplayImplTest);
70 }; 70 };
71 71
72 TEST_F(VRDisplayImplTest, DevicePresentationIsolation) { 72 TEST_F(VRDisplayImplTest, DevicePresentationIsolation) {
73 auto service_1 = BindService(); 73 auto service_1 = BindService();
74 auto service_2 = BindService(); 74 auto service_2 = BindService();
75 75
76 // When not presenting either service should be able to access the device.
77 EXPECT_TRUE(device()->IsAccessAllowed(service_1.get()));
78 EXPECT_TRUE(device()->IsAccessAllowed(service_2.get()));
79
80 VRDisplayImpl* display_1 = service_1->GetVRDisplayImpl(device()); 76 VRDisplayImpl* display_1 = service_1->GetVRDisplayImpl(device());
81 VRDisplayImpl* display_2 = service_2->GetVRDisplayImpl(device()); 77 VRDisplayImpl* display_2 = service_2->GetVRDisplayImpl(device());
82 78
79 // When not presenting either service should be able to access the device.
80 EXPECT_TRUE(device()->IsAccessAllowed(display_1));
81 EXPECT_TRUE(device()->IsAccessAllowed(display_2));
82
83 // Begin presenting to the fake device with service 1. 83 // Begin presenting to the fake device with service 1.
84 RequestPresent(display_1); 84 RequestPresent(display_1);
85 EXPECT_TRUE(is_request_presenting_success_); 85 EXPECT_TRUE(is_request_presenting_success_);
86 EXPECT_TRUE(presenting()); 86 EXPECT_TRUE(presenting());
87 87
88 // Service 2 should not be able to present to the device while service 1 88 // Service 2 should not be able to present to the device while service 1
89 // is still presenting. 89 // is still presenting.
90 RequestPresent(display_2); 90 RequestPresent(display_2);
91 EXPECT_FALSE(is_request_presenting_success_); 91 EXPECT_FALSE(is_request_presenting_success_);
92 EXPECT_TRUE(device()->IsAccessAllowed(service_1.get())); 92 EXPECT_TRUE(device()->IsAccessAllowed(display_1));
93 EXPECT_FALSE(device()->IsAccessAllowed(service_2.get())); 93 EXPECT_FALSE(device()->IsAccessAllowed(display_2));
94 94
95 // Service 2 should not be able to exit presentation to the device. 95 // Service 2 should not be able to exit presentation to the device.
96 ExitPresent(display_2); 96 ExitPresent(display_2);
97 EXPECT_TRUE(presenting()); 97 EXPECT_TRUE(presenting());
98 98
99 // Service 1 should be able to exit the presentation it initiated. 99 // Service 1 should be able to exit the presentation it initiated.
100 ExitPresent(display_1); 100 ExitPresent(display_1);
101 EXPECT_FALSE(presenting()); 101 EXPECT_FALSE(presenting());
102 102
103 // Once presentation had ended both services should be able to access the 103 // Once presentation had ended both services should be able to access the
104 // device. 104 // device.
105 EXPECT_TRUE(device()->IsAccessAllowed(service_1.get())); 105 EXPECT_TRUE(device()->IsAccessAllowed(display_1));
106 EXPECT_TRUE(device()->IsAccessAllowed(service_2.get())); 106 EXPECT_TRUE(device()->IsAccessAllowed(display_2));
107 } 107 }
108 108
109 // This test case tests VRDevice class default behaviour when it 109 // This test case tests VRDevice class default behaviour when it
110 // dispatch "vrdevicechanged" event. The expected behaviour is all 110 // dispatch "vrdevicechanged" event. The expected behaviour is all
111 // of the services related with this device will receive "vrdevicechanged" 111 // of the services related with this device will receive "vrdevicechanged"
112 // event. 112 // event.
113 TEST_F(VRDisplayImplTest, DeviceChangedDispatched) { 113 TEST_F(VRDisplayImplTest, DeviceChangedDispatched) {
114 auto service_1 = BindService(); 114 auto service_1 = BindService();
115 auto service_2 = BindService(); 115 auto service_2 = BindService();
116 116
117 device()->OnChanged(); 117 device()->OnChanged();
118 118
119 base::RunLoop().RunUntilIdle(); 119 base::RunLoop().RunUntilIdle();
120 120
121 for (auto client : clients_) 121 for (auto client : clients_)
122 EXPECT_TRUE(client->CheckDeviceId(device()->id())); 122 EXPECT_TRUE(client->CheckDeviceId(device()->id()));
123 } 123 }
124 } 124 }
OLDNEW
« no previous file with comments | « device/vr/vr_display_impl.cc ('k') | device/vr/vr_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698