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 "content/renderer/media/media_devices_event_dispatcher.h" | 5 #include "content/renderer/media/media_devices_event_dispatcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 17 matching lines...) Expand all Loading... |
28 public: | 28 public: |
29 MOCK_METHOD2(EventDispatched, | 29 MOCK_METHOD2(EventDispatched, |
30 void(MediaDeviceType, const MediaDeviceInfoArray&)); | 30 void(MediaDeviceType, const MediaDeviceInfoArray&)); |
31 }; | 31 }; |
32 | 32 |
33 class MockMediaDevicesDispatcherHost | 33 class MockMediaDevicesDispatcherHost |
34 : public ::mojom::MediaDevicesDispatcherHost { | 34 : public ::mojom::MediaDevicesDispatcherHost { |
35 public: | 35 public: |
36 MockMediaDevicesDispatcherHost() : binding_(this) {} | 36 MockMediaDevicesDispatcherHost() : binding_(this) {} |
37 | 37 |
38 MOCK_METHOD3(SubscribeDeviceChangeNotifications, | 38 MOCK_METHOD2(SubscribeDeviceChangeNotifications, |
39 void(MediaDeviceType type, | 39 void(MediaDeviceType type, uint32_t subscription_id)); |
40 uint32_t subscription_id, | |
41 const url::Origin& security_origin)); | |
42 MOCK_METHOD2(UnsubscribeDeviceChangeNotifications, | 40 MOCK_METHOD2(UnsubscribeDeviceChangeNotifications, |
43 void(MediaDeviceType type, uint32_t subscription_id)); | 41 void(MediaDeviceType type, uint32_t subscription_id)); |
44 | 42 |
45 void EnumerateDevices(bool request_audio_input, | 43 void EnumerateDevices(bool request_audio_input, |
46 bool request_video_input, | 44 bool request_video_input, |
47 bool request_audio_output, | 45 bool request_audio_output, |
48 const url::Origin& security_origin, | |
49 EnumerateDevicesCallback) override { | 46 EnumerateDevicesCallback) override { |
50 NOTREACHED(); | 47 NOTREACHED(); |
51 } | 48 } |
52 | 49 |
53 void GetVideoInputCapabilities( | 50 void GetVideoInputCapabilities( |
54 const url::Origin& security_origin, | |
55 GetVideoInputCapabilitiesCallback client_callback) override { | 51 GetVideoInputCapabilitiesCallback client_callback) override { |
56 NOTREACHED(); | 52 NOTREACHED(); |
57 } | 53 } |
58 | 54 |
59 ::mojom::MediaDevicesDispatcherHostPtr CreateInterfacePtrAndBind() { | 55 ::mojom::MediaDevicesDispatcherHostPtr CreateInterfacePtrAndBind() { |
60 return binding_.CreateInterfacePtrAndBind(); | 56 return binding_.CreateInterfacePtrAndBind(); |
61 } | 57 } |
62 | 58 |
63 private: | 59 private: |
64 mojo::Binding<::mojom::MediaDevicesDispatcherHost> binding_; | 60 mojo::Binding<::mojom::MediaDevicesDispatcherHost> binding_; |
(...skipping 18 matching lines...) Expand all Loading... |
83 MockMediaDevicesDispatcherHost media_devices_dispatcher_; | 79 MockMediaDevicesDispatcherHost media_devices_dispatcher_; |
84 }; | 80 }; |
85 | 81 |
86 } // namespace | 82 } // namespace |
87 | 83 |
88 TEST_F(MediaDevicesEventDispatcherTest, SubscribeUnsubscribeSingleType) { | 84 TEST_F(MediaDevicesEventDispatcherTest, SubscribeUnsubscribeSingleType) { |
89 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) { | 85 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) { |
90 MediaDeviceType type = static_cast<MediaDeviceType>(i); | 86 MediaDeviceType type = static_cast<MediaDeviceType>(i); |
91 MediaDeviceInfoArray device_infos; | 87 MediaDeviceInfoArray device_infos; |
92 MockMediaDevicesEventSubscriber subscriber1, subscriber2; | 88 MockMediaDevicesEventSubscriber subscriber1, subscriber2; |
93 url::Origin security_origin(GURL("http://localhost")); | |
94 EXPECT_CALL(media_devices_dispatcher_, | 89 EXPECT_CALL(media_devices_dispatcher_, |
95 SubscribeDeviceChangeNotifications(type, _, security_origin)) | 90 SubscribeDeviceChangeNotifications(type, _)) |
96 .Times(2); | 91 .Times(2); |
97 auto subscription_id1 = | 92 auto subscription_id1 = |
98 event_dispatcher_->SubscribeDeviceChangeNotifications( | 93 event_dispatcher_->SubscribeDeviceChangeNotifications( |
99 type, security_origin, | 94 type, base::Bind(&MockMediaDevicesEventSubscriber::EventDispatched, |
100 base::Bind(&MockMediaDevicesEventSubscriber::EventDispatched, | 95 base::Unretained(&subscriber1))); |
101 base::Unretained(&subscriber1))); | |
102 auto subscription_id2 = | 96 auto subscription_id2 = |
103 event_dispatcher_->SubscribeDeviceChangeNotifications( | 97 event_dispatcher_->SubscribeDeviceChangeNotifications( |
104 type, security_origin, | 98 type, base::Bind(&MockMediaDevicesEventSubscriber::EventDispatched, |
105 base::Bind(&MockMediaDevicesEventSubscriber::EventDispatched, | 99 base::Unretained(&subscriber2))); |
106 base::Unretained(&subscriber2))); | |
107 | 100 |
108 // Simulate a device change. | 101 // Simulate a device change. |
109 EXPECT_CALL(subscriber1, EventDispatched(type, _)); | 102 EXPECT_CALL(subscriber1, EventDispatched(type, _)); |
110 EXPECT_CALL(subscriber2, EventDispatched(type, _)); | 103 EXPECT_CALL(subscriber2, EventDispatched(type, _)); |
111 event_dispatcher_->DispatchDevicesChangedEvent(type, device_infos); | 104 event_dispatcher_->DispatchDevicesChangedEvent(type, device_infos); |
112 base::RunLoop().RunUntilIdle(); | 105 base::RunLoop().RunUntilIdle(); |
113 | 106 |
114 // Unsubscribe one of the subscribers. | 107 // Unsubscribe one of the subscribers. |
115 EXPECT_CALL(media_devices_dispatcher_, | 108 EXPECT_CALL(media_devices_dispatcher_, |
116 UnsubscribeDeviceChangeNotifications(type, subscription_id1)); | 109 UnsubscribeDeviceChangeNotifications(type, subscription_id1)); |
(...skipping 11 matching lines...) Expand all Loading... |
128 UnsubscribeDeviceChangeNotifications(type, subscription_id2)); | 121 UnsubscribeDeviceChangeNotifications(type, subscription_id2)); |
129 event_dispatcher_->UnsubscribeDeviceChangeNotifications(type, | 122 event_dispatcher_->UnsubscribeDeviceChangeNotifications(type, |
130 subscription_id2); | 123 subscription_id2); |
131 base::RunLoop().RunUntilIdle(); | 124 base::RunLoop().RunUntilIdle(); |
132 } | 125 } |
133 } | 126 } |
134 | 127 |
135 TEST_F(MediaDevicesEventDispatcherTest, SubscribeUnsubscribeAllTypes) { | 128 TEST_F(MediaDevicesEventDispatcherTest, SubscribeUnsubscribeAllTypes) { |
136 MediaDeviceInfoArray device_infos; | 129 MediaDeviceInfoArray device_infos; |
137 MockMediaDevicesEventSubscriber subscriber1, subscriber2; | 130 MockMediaDevicesEventSubscriber subscriber1, subscriber2; |
138 url::Origin security_origin(GURL("http://localhost")); | 131 EXPECT_CALL(media_devices_dispatcher_, SubscribeDeviceChangeNotifications( |
139 EXPECT_CALL(media_devices_dispatcher_, | 132 MEDIA_DEVICE_TYPE_AUDIO_INPUT, _)) |
140 SubscribeDeviceChangeNotifications(MEDIA_DEVICE_TYPE_AUDIO_INPUT, | |
141 _, security_origin)) | |
142 .Times(2); | 133 .Times(2); |
143 EXPECT_CALL(media_devices_dispatcher_, | 134 EXPECT_CALL(media_devices_dispatcher_, SubscribeDeviceChangeNotifications( |
144 SubscribeDeviceChangeNotifications(MEDIA_DEVICE_TYPE_VIDEO_INPUT, | 135 MEDIA_DEVICE_TYPE_VIDEO_INPUT, _)) |
145 _, security_origin)) | |
146 .Times(2); | 136 .Times(2); |
147 EXPECT_CALL(media_devices_dispatcher_, | 137 EXPECT_CALL(media_devices_dispatcher_, SubscribeDeviceChangeNotifications( |
148 SubscribeDeviceChangeNotifications(MEDIA_DEVICE_TYPE_AUDIO_OUTPUT, | 138 MEDIA_DEVICE_TYPE_AUDIO_OUTPUT, _)) |
149 _, security_origin)) | |
150 .Times(2); | 139 .Times(2); |
151 auto subscription_list_1 = | 140 auto subscription_list_1 = |
152 event_dispatcher_->SubscribeDeviceChangeNotifications( | 141 event_dispatcher_->SubscribeDeviceChangeNotifications( |
153 security_origin, | |
154 base::Bind(&MockMediaDevicesEventSubscriber::EventDispatched, | 142 base::Bind(&MockMediaDevicesEventSubscriber::EventDispatched, |
155 base::Unretained(&subscriber1))); | 143 base::Unretained(&subscriber1))); |
156 auto subscription_list_2 = | 144 auto subscription_list_2 = |
157 event_dispatcher_->SubscribeDeviceChangeNotifications( | 145 event_dispatcher_->SubscribeDeviceChangeNotifications( |
158 security_origin, | |
159 base::Bind(&MockMediaDevicesEventSubscriber::EventDispatched, | 146 base::Bind(&MockMediaDevicesEventSubscriber::EventDispatched, |
160 base::Unretained(&subscriber2))); | 147 base::Unretained(&subscriber2))); |
161 | 148 |
162 // Simulate a device changes for all types. | 149 // Simulate a device changes for all types. |
163 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) { | 150 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) { |
164 MediaDeviceType type = static_cast<MediaDeviceType>(i); | 151 MediaDeviceType type = static_cast<MediaDeviceType>(i); |
165 EXPECT_CALL(subscriber1, EventDispatched(type, _)); | 152 EXPECT_CALL(subscriber1, EventDispatched(type, _)); |
166 EXPECT_CALL(subscriber2, EventDispatched(type, _)); | 153 EXPECT_CALL(subscriber2, EventDispatched(type, _)); |
167 event_dispatcher_->DispatchDevicesChangedEvent(type, device_infos); | 154 event_dispatcher_->DispatchDevicesChangedEvent(type, device_infos); |
168 base::RunLoop().RunUntilIdle(); | 155 base::RunLoop().RunUntilIdle(); |
(...skipping 23 matching lines...) Expand all Loading... |
192 MediaDeviceType type = static_cast<MediaDeviceType>(i); | 179 MediaDeviceType type = static_cast<MediaDeviceType>(i); |
193 EXPECT_CALL( | 180 EXPECT_CALL( |
194 media_devices_dispatcher_, | 181 media_devices_dispatcher_, |
195 UnsubscribeDeviceChangeNotifications(type, subscription_list_2[type])); | 182 UnsubscribeDeviceChangeNotifications(type, subscription_list_2[type])); |
196 } | 183 } |
197 event_dispatcher_->UnsubscribeDeviceChangeNotifications(subscription_list_2); | 184 event_dispatcher_->UnsubscribeDeviceChangeNotifications(subscription_list_2); |
198 base::RunLoop().RunUntilIdle(); | 185 base::RunLoop().RunUntilIdle(); |
199 } | 186 } |
200 | 187 |
201 } // namespace content | 188 } // namespace content |
OLD | NEW |