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

Side by Side Diff: chrome/browser/media/webrtc/webrtc_getmediadevices_browsertest.cc

Issue 2472593004: Reenable media-device enumeration integration test. (Closed)
Patch Set: rebase Created 4 years, 1 month 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 | « no previous file | chrome/test/data/webrtc/media_devices.js » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/json/json_reader.h" 6 #include "base/json/json_reader.h"
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "chrome/browser/media/webrtc/webrtc_browsertest_base.h" 8 #include "chrome/browser/media/webrtc/webrtc_browsertest_base.h"
9 #include "chrome/browser/media/webrtc/webrtc_browsertest_common.h" 9 #include "chrome/browser/media/webrtc/webrtc_browsertest_common.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_tabstrip.h" 11 #include "chrome/browser/ui/browser_tabstrip.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
16 #include "content/public/common/content_switches.h" 16 #include "content/public/common/content_switches.h"
17 #include "content/public/test/browser_test_utils.h" 17 #include "content/public/test/browser_test_utils.h"
18 #include "media/audio/audio_device_description.h"
18 #include "media/audio/audio_manager.h" 19 #include "media/audio/audio_manager.h"
19 #include "media/base/media_switches.h" 20 #include "media/base/media_switches.h"
20 #include "net/test/embedded_test_server/embedded_test_server.h" 21 #include "net/test/embedded_test_server/embedded_test_server.h"
21 22
22 namespace { 23 namespace {
23 24
24 const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html"; 25 const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html";
25 26
26 const char kDeviceKindAudioInput[] = "audioinput"; 27 const char kDeviceKindAudioInput[] = "audioinput";
27 const char kDeviceKindVideoInput[] = "videoinput"; 28 const char kDeviceKindVideoInput[] = "videoinput";
28 const char kDeviceKindAudioOutput[] = "audiooutput"; 29 const char kDeviceKindAudioOutput[] = "audiooutput";
29 30
30 const char kSourceKindAudioInput[] = "audio";
31 const char kSourceKindVideoInput[] = "video";
32
33 } // namespace 31 } // namespace
34 32
35 // Integration test for WebRTC getMediaDevices. It always uses fake devices. 33 // Integration test for WebRTC enumerateDevices. It always uses fake devices.
36 // It needs to be a browser test (and not content browser test) to be able to 34 // It needs to be a browser test (and not content browser test) to be able to
37 // test that labels are cleared or not depending on if access to devices has 35 // test that labels are cleared or not depending on if access to devices has
38 // been granted. 36 // been granted.
39 class WebRtcGetMediaDevicesBrowserTest 37 class WebRtcGetMediaDevicesBrowserTest
40 : public WebRtcTestBase, 38 : public WebRtcTestBase,
41 public testing::WithParamInterface<bool> { 39 public testing::WithParamInterface<bool> {
42 public: 40 public:
43 WebRtcGetMediaDevicesBrowserTest() 41 WebRtcGetMediaDevicesBrowserTest()
44 : has_audio_output_devices_initialized_(false), 42 : has_audio_output_devices_initialized_(false),
45 has_audio_output_devices_(false) {} 43 has_audio_output_devices_(false) {}
(...skipping 12 matching lines...) Expand all
58 56
59 protected: 57 protected:
60 // This is used for media devices and sources. 58 // This is used for media devices and sources.
61 struct MediaDeviceInfo { 59 struct MediaDeviceInfo {
62 std::string device_id; // Domain specific device ID. 60 std::string device_id; // Domain specific device ID.
63 std::string kind; 61 std::string kind;
64 std::string label; 62 std::string label;
65 std::string group_id; 63 std::string group_id;
66 }; 64 };
67 65
68 bool HasOutputDevices() { 66 void EnumerateDevices(content::WebContents* tab,
69 // There's no fake audio output devices supported yet. We can't test audio 67 std::vector<MediaDeviceInfo>* devices) {
70 // output devices on bots with no output devices, so skip testing for that 68 std::string devices_as_json = ExecuteJavascript("enumerateDevices()", tab);
71 // on such bots. We cache the result since querying for devices can take
72 // considerable time.
73 if (!has_audio_output_devices_initialized_) {
74 has_audio_output_devices_ =
75 media::AudioManager::Get()->HasAudioOutputDevices();
76 has_audio_output_devices_initialized_ = true;
77 }
78 return has_audio_output_devices_;
79 }
80
81 // If |get_sources| is true, use getSources API and leave groupId empty,
82 // otherwise use getMediaDevices API.
83 void GetMediaDevicesOrSources(content::WebContents* tab,
84 std::vector<MediaDeviceInfo>* devices,
85 bool get_sources) {
86 std::string devices_as_json =
87 ExecuteJavascript(get_sources ? "getSources()" : "getMediaDevices()",
88 tab);
89 EXPECT_FALSE(devices_as_json.empty()); 69 EXPECT_FALSE(devices_as_json.empty());
90 70
91 int error_code; 71 int error_code;
92 std::string error_message; 72 std::string error_message;
93 std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( 73 std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError(
94 devices_as_json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code, 74 devices_as_json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code,
95 &error_message); 75 &error_message);
96 76
97 ASSERT_TRUE(value.get() != NULL) << error_message; 77 ASSERT_TRUE(value.get() != NULL) << error_message;
98 EXPECT_EQ(value->GetType(), base::Value::TYPE_LIST); 78 EXPECT_EQ(value->GetType(), base::Value::TYPE_LIST);
99 79
100 base::ListValue* values; 80 base::ListValue* values;
101 ASSERT_TRUE(value->GetAsList(&values)); 81 ASSERT_TRUE(value->GetAsList(&values));
102 ASSERT_FALSE(values->empty()); 82 ASSERT_FALSE(values->empty());
103 bool found_audio_input = false; 83 bool found_audio_input = false;
104 bool found_video_input = false; 84 bool found_video_input = false;
105 bool found_audio_output = false; 85 bool found_audio_output = false;
106 86
107 for (base::ListValue::iterator it = values->begin(); 87 for (base::ListValue::iterator it = values->begin();
108 it != values->end(); ++it) { 88 it != values->end(); ++it) {
109 const base::DictionaryValue* dict; 89 const base::DictionaryValue* dict;
110 MediaDeviceInfo device; 90 MediaDeviceInfo device;
111 ASSERT_TRUE((*it)->GetAsDictionary(&dict)); 91 ASSERT_TRUE((*it)->GetAsDictionary(&dict));
112 ASSERT_TRUE(dict->GetString(get_sources ? "id" : "deviceId", 92 ASSERT_TRUE(dict->GetString("deviceId", &device.device_id));
113 &device.device_id));
114 ASSERT_TRUE(dict->GetString("kind", &device.kind)); 93 ASSERT_TRUE(dict->GetString("kind", &device.kind));
115 ASSERT_TRUE(dict->GetString("label", &device.label)); 94 ASSERT_TRUE(dict->GetString("label", &device.label));
116 if (!get_sources) 95 ASSERT_TRUE(dict->GetString("groupId", &device.group_id));
117 ASSERT_TRUE(dict->GetString("groupId", &device.group_id));
118 96
119 // Should be HMAC SHA256. 97 // Should be HMAC SHA256.
120 EXPECT_EQ(64ul, device.device_id.length()); 98 if (!media::AudioDeviceDescription::IsDefaultDevice(device.device_id) &&
121 EXPECT_TRUE(base::ContainsOnlyChars(device.device_id, 99 !(device.device_id ==
122 "0123456789abcdef")); 100 media::AudioDeviceDescription::kCommunicationsDeviceId)) {
101 EXPECT_EQ(64ul, device.device_id.length());
102 EXPECT_TRUE(
103 base::ContainsOnlyChars(device.device_id, "0123456789abcdef"));
104 }
123 105
124 const char* kAudioInputKind = 106 EXPECT_TRUE(device.kind == kDeviceKindAudioInput ||
125 get_sources ? kSourceKindAudioInput : kDeviceKindAudioInput; 107 device.kind == kDeviceKindVideoInput ||
126 const char* kVideoInputKind = 108 device.kind == kDeviceKindAudioOutput);
127 get_sources ? kSourceKindVideoInput : kDeviceKindVideoInput; 109 if (device.kind == kDeviceKindAudioInput) {
128 if (get_sources) {
129 EXPECT_TRUE(device.kind == kAudioInputKind ||
130 device.kind == kVideoInputKind);
131 } else {
132 EXPECT_TRUE(device.kind == kAudioInputKind ||
133 device.kind == kVideoInputKind ||
134 device.kind == kDeviceKindAudioOutput);
135 }
136 if (device.kind == kAudioInputKind) {
137 found_audio_input = true; 110 found_audio_input = true;
138 } else if (device.kind == kVideoInputKind) { 111 } else if (device.kind == kDeviceKindVideoInput) {
139 found_video_input = true; 112 found_video_input = true;
140 } else { 113 } else {
141 found_audio_output = true; 114 found_audio_output = true;
142 } 115 }
143 116
144 // getSources doesn't have group ID support. getMediaDevices doesn't have 117 // enumerateDevices doesn't have group ID support for video input devices.
145 // group ID support for video input devices. 118 // TODO(guidou): remove this once http://crbug.com/627793 is fixed.
146 if (get_sources || device.kind == kDeviceKindVideoInput) { 119 if (device.kind == kDeviceKindVideoInput) {
147 EXPECT_TRUE(device.group_id.empty()); 120 EXPECT_TRUE(device.group_id.empty());
148 } else { 121 } else {
149 EXPECT_FALSE(device.group_id.empty()); 122 EXPECT_FALSE(device.group_id.empty());
150 } 123 }
151 124
152 devices->push_back(device); 125 devices->push_back(device);
153 } 126 }
154 127
155 EXPECT_TRUE(found_audio_input); 128 EXPECT_TRUE(found_audio_input);
156 EXPECT_TRUE(found_video_input); 129 EXPECT_TRUE(found_video_input);
157 if (get_sources) {
158 EXPECT_FALSE(found_audio_output);
159 } else {
160 EXPECT_EQ(HasOutputDevices(), found_audio_output);
161 }
162 }
163
164 void GetMediaDevices(content::WebContents* tab,
165 std::vector<MediaDeviceInfo>* devices) {
166 GetMediaDevicesOrSources(tab, devices, false);
167 }
168
169 void GetSources(content::WebContents* tab,
170 std::vector<MediaDeviceInfo>* sources) {
171 GetMediaDevicesOrSources(tab, sources, true);
172 } 130 }
173 131
174 bool has_audio_output_devices_initialized_; 132 bool has_audio_output_devices_initialized_;
175 bool has_audio_output_devices_; 133 bool has_audio_output_devices_;
176 }; 134 };
177 135
178 static const bool kParamsToRunTestsWith[] = { false, true }; 136 static const bool kParamsToRunTestsWith[] = { false, true };
179 INSTANTIATE_TEST_CASE_P(WebRtcGetMediaDevicesBrowserTests, 137 INSTANTIATE_TEST_CASE_P(WebRtcGetMediaDevicesBrowserTests,
180 WebRtcGetMediaDevicesBrowserTest, 138 WebRtcGetMediaDevicesBrowserTest,
181 testing::ValuesIn(kParamsToRunTestsWith)); 139 testing::ValuesIn(kParamsToRunTestsWith));
182 140
183 // getMediaDevices has been removed and will be replaced
184 // MediaDevices.enumerateDevices. http://crbug.com/388648.
185 IN_PROC_BROWSER_TEST_P(WebRtcGetMediaDevicesBrowserTest, 141 IN_PROC_BROWSER_TEST_P(WebRtcGetMediaDevicesBrowserTest,
186 DISABLED_GetMediaDevicesWithoutAccess) { 142 EnumerateDevicesWithoutAccess) {
187 ASSERT_TRUE(embedded_test_server()->Start()); 143 ASSERT_TRUE(embedded_test_server()->Start());
188 GURL url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); 144 GURL url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage));
189 ui_test_utils::NavigateToURL(browser(), url); 145 ui_test_utils::NavigateToURL(browser(), url);
190 content::WebContents* tab = 146 content::WebContents* tab =
191 browser()->tab_strip_model()->GetActiveWebContents(); 147 browser()->tab_strip_model()->GetActiveWebContents();
192 148
193 std::vector<MediaDeviceInfo> devices; 149 std::vector<MediaDeviceInfo> devices;
194 GetMediaDevices(tab, &devices); 150 EnumerateDevices(tab, &devices);
195 151
196 // Labels should be empty if access has not been allowed. 152 // Labels should be empty if access has not been allowed.
197 for (std::vector<MediaDeviceInfo>::iterator it = devices.begin(); 153 for (std::vector<MediaDeviceInfo>::iterator it = devices.begin();
198 it != devices.end(); ++it) { 154 it != devices.end(); ++it) {
199 EXPECT_TRUE(it->label.empty()); 155 EXPECT_TRUE(it->label.empty());
200 } 156 }
201 } 157 }
202 158
203 // getMediaDevices has been removed and will be replaced
204 // MediaDevices.enumerateDevices. http://crbug.com/388648.
205 // Disabled, fails due to http://crbug.com/382391.
206 IN_PROC_BROWSER_TEST_P(WebRtcGetMediaDevicesBrowserTest, 159 IN_PROC_BROWSER_TEST_P(WebRtcGetMediaDevicesBrowserTest,
207 DISABLED_GetMediaDevicesWithAccess) { 160 EnumerateDevicesWithAccess) {
208 ASSERT_TRUE(embedded_test_server()->Start()); 161 ASSERT_TRUE(embedded_test_server()->Start());
209 GURL url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); 162 GURL url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage));
210 ui_test_utils::NavigateToURL(browser(), url); 163 ui_test_utils::NavigateToURL(browser(), url);
211 content::WebContents* tab = 164 content::WebContents* tab =
212 browser()->tab_strip_model()->GetActiveWebContents(); 165 browser()->tab_strip_model()->GetActiveWebContents();
213 166
214 EXPECT_TRUE(GetUserMediaAndAccept(tab)); 167 EXPECT_TRUE(GetUserMediaAndAccept(tab));
215 168
216 std::vector<MediaDeviceInfo> devices; 169 std::vector<MediaDeviceInfo> devices;
217 GetMediaDevices(tab, &devices); 170 EnumerateDevices(tab, &devices);
218 171
219 // Labels should be non-empty if access has been allowed. 172 // Labels should be non-empty if access has been allowed.
220 for (std::vector<MediaDeviceInfo>::iterator it = devices.begin(); 173 for (std::vector<MediaDeviceInfo>::iterator it = devices.begin();
221 it != devices.end(); ++it) { 174 it != devices.end(); ++it) {
222 EXPECT_TRUE(!it->label.empty()); 175 EXPECT_TRUE(!it->label.empty());
223 } 176 }
224 } 177 }
225
226 // getMediaDevices has been removed and will be replaced
227 // MediaDevices.enumerateDevices. http://crbug.com/388648.
228 IN_PROC_BROWSER_TEST_P(WebRtcGetMediaDevicesBrowserTest,
229 DISABLED_GetMediaDevicesEqualsGetSourcesWithoutAccess) {
230 ASSERT_TRUE(embedded_test_server()->Start());
231 GURL url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage));
232 ui_test_utils::NavigateToURL(browser(), url);
233 content::WebContents* tab =
234 browser()->tab_strip_model()->GetActiveWebContents();
235
236 std::vector<MediaDeviceInfo> devices;
237 GetMediaDevices(tab, &devices);
238
239 std::vector<MediaDeviceInfo> sources;
240 GetSources(tab, &sources);
241
242 std::vector<MediaDeviceInfo>::iterator sources_it = sources.begin();
243 for (std::vector<MediaDeviceInfo>::iterator devices_it = devices.begin();
244 devices_it != devices.end(); ++devices_it) {
245 if (devices_it->kind == kDeviceKindAudioOutput)
246 continue;
247 EXPECT_STREQ(devices_it->device_id.c_str(), sources_it->device_id.c_str());
248 if (devices_it->kind == kDeviceKindAudioInput) {
249 EXPECT_STREQ(kSourceKindAudioInput, sources_it->kind.c_str());
250 } else {
251 EXPECT_STREQ(kSourceKindVideoInput, sources_it->kind.c_str());
252 }
253 EXPECT_TRUE(devices_it->label.empty());
254 EXPECT_TRUE(sources_it->label.empty());
255 ++sources_it;
256 }
257 EXPECT_EQ(sources.end(), sources_it);
258 }
259
260 // getMediaDevices has been removed and will be replaced
261 // MediaDevices.enumerateDevices. http://crbug.com/388648.
262 // Disabled, fails due to http://crbug.com/382391.
263 IN_PROC_BROWSER_TEST_P(WebRtcGetMediaDevicesBrowserTest,
264 DISABLED_GetMediaDevicesEqualsGetSourcesWithAccess) {
265 ASSERT_TRUE(embedded_test_server()->Start());
266 GURL url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage));
267 ui_test_utils::NavigateToURL(browser(), url);
268 content::WebContents* tab =
269 browser()->tab_strip_model()->GetActiveWebContents();
270
271 EXPECT_TRUE(GetUserMediaAndAccept(tab));
272
273 std::vector<MediaDeviceInfo> devices;
274 GetMediaDevices(tab, &devices);
275
276 std::vector<MediaDeviceInfo> sources;
277 GetSources(tab, &sources);
278
279 std::vector<MediaDeviceInfo>::iterator sources_it = sources.begin();
280 for (std::vector<MediaDeviceInfo>::iterator devices_it = devices.begin();
281 devices_it != devices.end(); ++devices_it) {
282 if (devices_it->kind == kDeviceKindAudioOutput)
283 continue;
284 EXPECT_STREQ(devices_it->device_id.c_str(), sources_it->device_id.c_str());
285 if (devices_it->kind == kDeviceKindAudioInput) {
286 EXPECT_STREQ(kSourceKindAudioInput, sources_it->kind.c_str());
287 } else {
288 EXPECT_STREQ(kSourceKindVideoInput, sources_it->kind.c_str());
289 }
290 EXPECT_TRUE(!devices_it->label.empty());
291 EXPECT_STREQ(devices_it->label.c_str(), sources_it->label.c_str());
292 ++sources_it;
293 }
294 EXPECT_EQ(sources.end(), sources_it);
295 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/webrtc/media_devices.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698