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

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

Issue 2487943002: Revert of Reenable media-device enumeration integration test. (Closed)
Patch Set: 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"
19 #include "media/audio/audio_manager.h" 18 #include "media/audio/audio_manager.h"
20 #include "media/base/media_switches.h" 19 #include "media/base/media_switches.h"
21 #include "net/test/embedded_test_server/embedded_test_server.h" 20 #include "net/test/embedded_test_server/embedded_test_server.h"
22 21
23 namespace { 22 namespace {
24 23
25 const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html"; 24 const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html";
26 25
27 const char kDeviceKindAudioInput[] = "audioinput"; 26 const char kDeviceKindAudioInput[] = "audioinput";
28 const char kDeviceKindVideoInput[] = "videoinput"; 27 const char kDeviceKindVideoInput[] = "videoinput";
29 const char kDeviceKindAudioOutput[] = "audiooutput"; 28 const char kDeviceKindAudioOutput[] = "audiooutput";
30 29
30 const char kSourceKindAudioInput[] = "audio";
31 const char kSourceKindVideoInput[] = "video";
32
31 } // namespace 33 } // namespace
32 34
33 // Integration test for WebRTC enumerateDevices. It always uses fake devices. 35 // Integration test for WebRTC getMediaDevices. It always uses fake devices.
34 // It needs to be a browser test (and not content browser test) to be able to 36 // It needs to be a browser test (and not content browser test) to be able to
35 // test that labels are cleared or not depending on if access to devices has 37 // test that labels are cleared or not depending on if access to devices has
36 // been granted. 38 // been granted.
37 class WebRtcGetMediaDevicesBrowserTest 39 class WebRtcGetMediaDevicesBrowserTest
38 : public WebRtcTestBase, 40 : public WebRtcTestBase,
39 public testing::WithParamInterface<bool> { 41 public testing::WithParamInterface<bool> {
40 public: 42 public:
41 WebRtcGetMediaDevicesBrowserTest() 43 WebRtcGetMediaDevicesBrowserTest()
42 : has_audio_output_devices_initialized_(false), 44 : has_audio_output_devices_initialized_(false),
43 has_audio_output_devices_(false) {} 45 has_audio_output_devices_(false) {}
(...skipping 12 matching lines...) Expand all
56 58
57 protected: 59 protected:
58 // This is used for media devices and sources. 60 // This is used for media devices and sources.
59 struct MediaDeviceInfo { 61 struct MediaDeviceInfo {
60 std::string device_id; // Domain specific device ID. 62 std::string device_id; // Domain specific device ID.
61 std::string kind; 63 std::string kind;
62 std::string label; 64 std::string label;
63 std::string group_id; 65 std::string group_id;
64 }; 66 };
65 67
66 void EnumerateDevices(content::WebContents* tab, 68 bool HasOutputDevices() {
67 std::vector<MediaDeviceInfo>* devices) { 69 // There's no fake audio output devices supported yet. We can't test audio
68 std::string devices_as_json = ExecuteJavascript("enumerateDevices()", tab); 70 // output devices on bots with no output devices, so skip testing for that
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);
69 EXPECT_FALSE(devices_as_json.empty()); 89 EXPECT_FALSE(devices_as_json.empty());
70 90
71 int error_code; 91 int error_code;
72 std::string error_message; 92 std::string error_message;
73 std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( 93 std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError(
74 devices_as_json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code, 94 devices_as_json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code,
75 &error_message); 95 &error_message);
76 96
77 ASSERT_TRUE(value.get() != NULL) << error_message; 97 ASSERT_TRUE(value.get() != NULL) << error_message;
78 EXPECT_EQ(value->GetType(), base::Value::TYPE_LIST); 98 EXPECT_EQ(value->GetType(), base::Value::TYPE_LIST);
79 99
80 base::ListValue* values; 100 base::ListValue* values;
81 ASSERT_TRUE(value->GetAsList(&values)); 101 ASSERT_TRUE(value->GetAsList(&values));
82 ASSERT_FALSE(values->empty()); 102 ASSERT_FALSE(values->empty());
83 bool found_audio_input = false; 103 bool found_audio_input = false;
84 bool found_video_input = false; 104 bool found_video_input = false;
85 bool found_audio_output = false; 105 bool found_audio_output = false;
86 106
87 for (base::ListValue::iterator it = values->begin(); 107 for (base::ListValue::iterator it = values->begin();
88 it != values->end(); ++it) { 108 it != values->end(); ++it) {
89 const base::DictionaryValue* dict; 109 const base::DictionaryValue* dict;
90 MediaDeviceInfo device; 110 MediaDeviceInfo device;
91 ASSERT_TRUE((*it)->GetAsDictionary(&dict)); 111 ASSERT_TRUE((*it)->GetAsDictionary(&dict));
92 ASSERT_TRUE(dict->GetString("deviceId", &device.device_id)); 112 ASSERT_TRUE(dict->GetString(get_sources ? "id" : "deviceId",
113 &device.device_id));
93 ASSERT_TRUE(dict->GetString("kind", &device.kind)); 114 ASSERT_TRUE(dict->GetString("kind", &device.kind));
94 ASSERT_TRUE(dict->GetString("label", &device.label)); 115 ASSERT_TRUE(dict->GetString("label", &device.label));
95 ASSERT_TRUE(dict->GetString("groupId", &device.group_id)); 116 if (!get_sources)
117 ASSERT_TRUE(dict->GetString("groupId", &device.group_id));
96 118
97 // Should be HMAC SHA256. 119 // Should be HMAC SHA256.
98 if (!media::AudioDeviceDescription::IsDefaultDevice(device.device_id) && 120 EXPECT_EQ(64ul, device.device_id.length());
99 !(device.device_id == 121 EXPECT_TRUE(base::ContainsOnlyChars(device.device_id,
100 media::AudioDeviceDescription::kCommunicationsDeviceId)) { 122 "0123456789abcdef"));
101 EXPECT_EQ(64ul, device.device_id.length()); 123
102 EXPECT_TRUE( 124 const char* kAudioInputKind =
103 base::ContainsOnlyChars(device.device_id, "0123456789abcdef")); 125 get_sources ? kSourceKindAudioInput : kDeviceKindAudioInput;
126 const char* kVideoInputKind =
127 get_sources ? kSourceKindVideoInput : kDeviceKindVideoInput;
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);
104 } 135 }
105 136 if (device.kind == kAudioInputKind) {
106 EXPECT_TRUE(device.kind == kDeviceKindAudioInput ||
107 device.kind == kDeviceKindVideoInput ||
108 device.kind == kDeviceKindAudioOutput);
109 if (device.kind == kDeviceKindAudioInput) {
110 found_audio_input = true; 137 found_audio_input = true;
111 } else if (device.kind == kDeviceKindVideoInput) { 138 } else if (device.kind == kVideoInputKind) {
112 found_video_input = true; 139 found_video_input = true;
113 } else { 140 } else {
114 found_audio_output = true; 141 found_audio_output = true;
115 } 142 }
116 143
117 // enumerateDevices doesn't have group ID support for video input devices. 144 // getSources doesn't have group ID support. getMediaDevices doesn't have
118 // TODO(guidou): remove this once http://crbug.com/627793 is fixed. 145 // group ID support for video input devices.
119 if (device.kind == kDeviceKindVideoInput) { 146 if (get_sources || device.kind == kDeviceKindVideoInput) {
120 EXPECT_TRUE(device.group_id.empty()); 147 EXPECT_TRUE(device.group_id.empty());
121 } else { 148 } else {
122 EXPECT_FALSE(device.group_id.empty()); 149 EXPECT_FALSE(device.group_id.empty());
123 } 150 }
124 151
125 devices->push_back(device); 152 devices->push_back(device);
126 } 153 }
127 154
128 EXPECT_TRUE(found_audio_input); 155 EXPECT_TRUE(found_audio_input);
129 EXPECT_TRUE(found_video_input); 156 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);
130 } 172 }
131 173
132 bool has_audio_output_devices_initialized_; 174 bool has_audio_output_devices_initialized_;
133 bool has_audio_output_devices_; 175 bool has_audio_output_devices_;
134 }; 176 };
135 177
136 static const bool kParamsToRunTestsWith[] = { false, true }; 178 static const bool kParamsToRunTestsWith[] = { false, true };
137 INSTANTIATE_TEST_CASE_P(WebRtcGetMediaDevicesBrowserTests, 179 INSTANTIATE_TEST_CASE_P(WebRtcGetMediaDevicesBrowserTests,
138 WebRtcGetMediaDevicesBrowserTest, 180 WebRtcGetMediaDevicesBrowserTest,
139 testing::ValuesIn(kParamsToRunTestsWith)); 181 testing::ValuesIn(kParamsToRunTestsWith));
140 182
183 // getMediaDevices has been removed and will be replaced
184 // MediaDevices.enumerateDevices. http://crbug.com/388648.
141 IN_PROC_BROWSER_TEST_P(WebRtcGetMediaDevicesBrowserTest, 185 IN_PROC_BROWSER_TEST_P(WebRtcGetMediaDevicesBrowserTest,
142 EnumerateDevicesWithoutAccess) { 186 DISABLED_GetMediaDevicesWithoutAccess) {
143 ASSERT_TRUE(embedded_test_server()->Start()); 187 ASSERT_TRUE(embedded_test_server()->Start());
144 GURL url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); 188 GURL url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage));
145 ui_test_utils::NavigateToURL(browser(), url); 189 ui_test_utils::NavigateToURL(browser(), url);
146 content::WebContents* tab = 190 content::WebContents* tab =
147 browser()->tab_strip_model()->GetActiveWebContents(); 191 browser()->tab_strip_model()->GetActiveWebContents();
148 192
149 std::vector<MediaDeviceInfo> devices; 193 std::vector<MediaDeviceInfo> devices;
150 EnumerateDevices(tab, &devices); 194 GetMediaDevices(tab, &devices);
151 195
152 // Labels should be empty if access has not been allowed. 196 // Labels should be empty if access has not been allowed.
153 for (std::vector<MediaDeviceInfo>::iterator it = devices.begin(); 197 for (std::vector<MediaDeviceInfo>::iterator it = devices.begin();
154 it != devices.end(); ++it) { 198 it != devices.end(); ++it) {
155 EXPECT_TRUE(it->label.empty()); 199 EXPECT_TRUE(it->label.empty());
156 } 200 }
157 } 201 }
158 202
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.
159 IN_PROC_BROWSER_TEST_P(WebRtcGetMediaDevicesBrowserTest, 206 IN_PROC_BROWSER_TEST_P(WebRtcGetMediaDevicesBrowserTest,
160 EnumerateDevicesWithAccess) { 207 DISABLED_GetMediaDevicesWithAccess) {
161 ASSERT_TRUE(embedded_test_server()->Start()); 208 ASSERT_TRUE(embedded_test_server()->Start());
162 GURL url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); 209 GURL url(embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage));
163 ui_test_utils::NavigateToURL(browser(), url); 210 ui_test_utils::NavigateToURL(browser(), url);
164 content::WebContents* tab = 211 content::WebContents* tab =
165 browser()->tab_strip_model()->GetActiveWebContents(); 212 browser()->tab_strip_model()->GetActiveWebContents();
166 213
167 EXPECT_TRUE(GetUserMediaAndAccept(tab)); 214 EXPECT_TRUE(GetUserMediaAndAccept(tab));
168 215
169 std::vector<MediaDeviceInfo> devices; 216 std::vector<MediaDeviceInfo> devices;
170 EnumerateDevices(tab, &devices); 217 GetMediaDevices(tab, &devices);
171 218
172 // Labels should be non-empty if access has been allowed. 219 // Labels should be non-empty if access has been allowed.
173 for (std::vector<MediaDeviceInfo>::iterator it = devices.begin(); 220 for (std::vector<MediaDeviceInfo>::iterator it = devices.begin();
174 it != devices.end(); ++it) { 221 it != devices.end(); ++it) {
175 EXPECT_TRUE(!it->label.empty()); 222 EXPECT_TRUE(!it->label.empty());
176 } 223 }
177 } 224 }
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