| OLD | NEW |
| 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_service_impl.h" | 5 #include "device/vr/vr_service_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" |
| 7 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 9 #include "device/vr/test/fake_vr_device.h" | 10 #include "device/vr/test/fake_vr_device.h" |
| 10 #include "device/vr/test/fake_vr_device_provider.h" | 11 #include "device/vr/test/fake_vr_device_provider.h" |
| 11 #include "device/vr/vr_device_manager.h" | 12 #include "device/vr/vr_device_manager.h" |
| 12 #include "device/vr/vr_service.mojom.h" | 13 #include "device/vr/vr_service.mojom.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 14 | 15 |
| 15 using ::testing::_; | 16 using ::testing::_; |
| 16 using ::testing::Mock; | 17 using ::testing::Mock; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 DISALLOW_COPY_AND_ASSIGN(VRServiceTestBinding); | 63 DISALLOW_COPY_AND_ASSIGN(VRServiceTestBinding); |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 class VRServiceImplTest : public testing::Test { | 66 class VRServiceImplTest : public testing::Test { |
| 66 public: | 67 public: |
| 67 VRServiceImplTest() {} | 68 VRServiceImplTest() {} |
| 68 ~VRServiceImplTest() override {} | 69 ~VRServiceImplTest() override {} |
| 69 | 70 |
| 70 protected: | 71 protected: |
| 71 void SetUp() override { | 72 void SetUp() override { |
| 72 std::unique_ptr<FakeVRDeviceProvider> provider(new FakeVRDeviceProvider()); | 73 provider_ = new FakeVRDeviceProvider(); |
| 73 provider_ = provider.get(); | 74 device_manager_.reset(new VRDeviceManager(base::WrapUnique(provider_))); |
| 74 device_manager_.reset(new VRDeviceManager(std::move(provider))); | |
| 75 } | 75 } |
| 76 | 76 |
| 77 void TearDown() override { base::RunLoop().RunUntilIdle(); } | 77 void TearDown() override { base::RunLoop().RunUntilIdle(); } |
| 78 | 78 |
| 79 std::unique_ptr<VRServiceTestBinding> BindService() { | 79 std::unique_ptr<VRServiceTestBinding> BindService() { |
| 80 auto test_binding = base::WrapUnique(new VRServiceTestBinding()); | 80 auto test_binding = base::WrapUnique(new VRServiceTestBinding()); |
| 81 test_binding->SetClient(); | 81 test_binding->SetClient(); |
| 82 return test_binding; | 82 return test_binding; |
| 83 } | 83 } |
| 84 | 84 |
| 85 size_t ServiceCount() { return device_manager_->services_.size(); } | 85 size_t ServiceCount() { return device_manager_->services_.size(); } |
| 86 | 86 |
| 87 base::MessageLoop message_loop_; | 87 base::MessageLoop message_loop_; |
| 88 FakeVRDeviceProvider* provider_; | 88 FakeVRDeviceProvider* provider_ = nullptr; |
| 89 std::unique_ptr<VRDeviceManager> device_manager_; | 89 std::unique_ptr<VRDeviceManager> device_manager_; |
| 90 | 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(VRServiceImplTest); | 91 DISALLOW_COPY_AND_ASSIGN(VRServiceImplTest); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 // Ensure that services are registered with the device manager as they are | 94 // Ensure that services are registered with the device manager as they are |
| 95 // created and removed from the device manager as their connections are closed. | 95 // created and removed from the device manager as their connections are closed. |
| 96 TEST_F(VRServiceImplTest, DeviceManagerRegistration) { | 96 TEST_F(VRServiceImplTest, DeviceManagerRegistration) { |
| 97 EXPECT_EQ(0u, ServiceCount()); | 97 EXPECT_EQ(0u, ServiceCount()); |
| 98 | 98 |
| 99 std::unique_ptr<VRServiceTestBinding> service_1 = BindService(); | 99 std::unique_ptr<VRServiceTestBinding> service_1 = BindService(); |
| 100 | 100 |
| 101 EXPECT_EQ(1u, ServiceCount()); | 101 EXPECT_EQ(1u, ServiceCount()); |
| 102 | 102 |
| 103 std::unique_ptr<VRServiceTestBinding> service_2 = BindService(); | 103 std::unique_ptr<VRServiceTestBinding> service_2 = BindService(); |
| 104 | 104 |
| 105 EXPECT_EQ(2u, ServiceCount()); | 105 EXPECT_EQ(2u, ServiceCount()); |
| 106 | 106 |
| 107 service_1->Close(); | 107 service_1->Close(); |
| 108 | 108 |
| 109 EXPECT_EQ(1u, ServiceCount()); | 109 EXPECT_EQ(1u, ServiceCount()); |
| 110 | 110 |
| 111 service_2->Close(); | 111 service_2->Close(); |
| 112 | 112 |
| 113 EXPECT_EQ(0u, ServiceCount()); | 113 EXPECT_EQ(0u, ServiceCount()); |
| 114 } | 114 } |
| 115 | 115 |
| 116 } | 116 } |
| OLD | NEW |