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

Side by Side Diff: content/browser/media/webrtc_getusermedia_browsertest.cc

Issue 190563002: Refactored how WebRTC content browser tests talk to their javascript. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed AEC dump tests on Andri Created 6 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/media/webrtc_browsertest.cc ('k') | content/test/data/media/getusermedia.html » ('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/debug/trace_event_impl.h" 5 #include "base/debug/trace_event_impl.h"
6 #include "base/json/json_reader.h" 6 #include "base/json/json_reader.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/test/trace_event_analyzer.h" 8 #include "base/test/trace_event_analyzer.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "content/browser/media/webrtc_internals.h" 10 #include "content/browser/media/webrtc_internals.h"
(...skipping 10 matching lines...) Expand all
21 #include "base/win/windows_version.h" 21 #include "base/win/windows_version.h"
22 #endif 22 #endif
23 23
24 using trace_analyzer::TraceAnalyzer; 24 using trace_analyzer::TraceAnalyzer;
25 using trace_analyzer::Query; 25 using trace_analyzer::Query;
26 using trace_analyzer::TraceEventVector; 26 using trace_analyzer::TraceEventVector;
27 27
28 namespace { 28 namespace {
29 29
30 static const char kGetUserMediaAndStop[] = "getUserMediaAndStop"; 30 static const char kGetUserMediaAndStop[] = "getUserMediaAndStop";
31 static const char kGetUserMediaAndWaitAndStop[] = "getUserMediaAndWaitAndStop"; 31 static const char kGetUserMediaAndGetStreamUp[] = "getUserMediaAndGetStreamUp";
32 static const char kGetUserMediaAndAnalyseAndStop[] = 32 static const char kGetUserMediaAndAnalyseAndStop[] =
33 "getUserMediaAndAnalyseAndStop"; 33 "getUserMediaAndAnalyseAndStop";
34 static const char kGetUserMediaAndExpectFailure[] =
35 "getUserMediaAndExpectFailure";
34 36
35 // Results returned by JS. 37 // Results returned by JS.
36 static const char kOK[] = "OK"; 38 static const char kOK[] = "OK";
37 static const char kGetUserMediaFailed[] =
38 "GetUserMedia call failed with code undefined";
39 39
40 std::string GenerateGetUserMediaWithMandatorySourceID( 40 std::string GenerateGetUserMediaWithMandatorySourceID(
41 const std::string& function_name, 41 const std::string& function_name,
42 const std::string& audio_source_id, 42 const std::string& audio_source_id,
43 const std::string& video_source_id) { 43 const std::string& video_source_id) {
44 const std::string audio_constraint = 44 const std::string audio_constraint =
45 "audio: {mandatory: { sourceId:\"" + audio_source_id + "\"}}, "; 45 "audio: {mandatory: { sourceId:\"" + audio_source_id + "\"}}, ";
46 46
47 const std::string video_constraint = 47 const std::string video_constraint =
48 "video: {mandatory: { sourceId:\"" + video_source_id + "\"}}"; 48 "video: {mandatory: { sourceId:\"" + video_source_id + "\"}}";
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return TraceAnalyzer::Create("[" + recorded_trace_data_->data() + "]"); 102 return TraceAnalyzer::Create("[" + recorded_trace_data_->data() + "]");
103 } 103 }
104 104
105 void RunGetUserMediaAndCollectMeasures(const int time_to_sample_secs, 105 void RunGetUserMediaAndCollectMeasures(const int time_to_sample_secs,
106 const std::string& measure_filter, 106 const std::string& measure_filter,
107 const std::string& graph_name) { 107 const std::string& graph_name) {
108 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 108 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
109 109
110 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); 110 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
111 NavigateToURL(shell(), url); 111 NavigateToURL(shell(), url);
112
112 // Put getUserMedia to work and let it run for a couple of seconds. 113 // Put getUserMedia to work and let it run for a couple of seconds.
113 DCHECK(time_to_sample_secs); 114 DCHECK(time_to_sample_secs);
114 ASSERT_TRUE( 115 ASSERT_EQ("ok-stream-running",
115 ExecuteJavascript(base::StringPrintf("%s({video: true}, %d);", 116 ExecuteJavascriptAndReturnResult(
116 kGetUserMediaAndWaitAndStop, 117 base::StringPrintf("%s({video: true});",
117 time_to_sample_secs))); 118 kGetUserMediaAndGetStreamUp)));
118 119
119 // Make sure the stream is up and running, then start collecting traces. 120 // Now the stream is up and running, start collecting traces.
120 ExpectTitle("Running...");
121 StartTracing(); 121 StartTracing();
122 122
123 // Let the stream run for a while in javascript.
124 ExecuteJavascriptAndWaitForOk(
125 base::StringPrintf("waitAndStopVideoTrack(%d);", time_to_sample_secs));
126
123 // Wait until the page title changes to "OK". Do not sleep() here since that 127 // Wait until the page title changes to "OK". Do not sleep() here since that
124 // would stop both this code and the browser underneath. 128 // would stop both this code and the browser underneath.
125 ExpectTitle("OK");
126 StopTracing(); 129 StopTracing();
127 130
128 scoped_ptr<TraceAnalyzer> analyzer(CreateTraceAnalyzer()); 131 scoped_ptr<TraceAnalyzer> analyzer(CreateTraceAnalyzer());
129 analyzer->AssociateBeginEndEvents(); 132 analyzer->AssociateBeginEndEvents();
130 trace_analyzer::TraceEventVector events; 133 trace_analyzer::TraceEventVector events;
131 DCHECK(measure_filter.size()); 134 DCHECK(measure_filter.size());
132 analyzer->FindEvents( 135 analyzer->FindEvents(
133 Query::EventNameIs(measure_filter), 136 Query::EventNameIs(measure_filter),
134 &events); 137 &events);
135 ASSERT_GT(events.size(), 0u) 138 ASSERT_GT(events.size(), 0u)
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 210
208 // These tests will all make a getUserMedia call with different constraints and 211 // These tests will all make a getUserMedia call with different constraints and
209 // see that the success callback is called. If the error callback is called or 212 // see that the success callback is called. If the error callback is called or
210 // none of the callbacks are called the tests will simply time out and fail. 213 // none of the callbacks are called the tests will simply time out and fail.
211 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, GetVideoStreamAndStop) { 214 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, GetVideoStreamAndStop) {
212 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 215 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
213 216
214 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); 217 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
215 NavigateToURL(shell(), url); 218 NavigateToURL(shell(), url);
216 219
217 ASSERT_TRUE(ExecuteJavascript( 220 ExecuteJavascriptAndWaitForOk(
218 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop))); 221 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop));
219
220 ExpectTitle("OK");
221 } 222 }
222 223
223 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, 224 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
224 GetAudioAndVideoStreamAndStop) { 225 GetAudioAndVideoStreamAndStop) {
225 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 226 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
226 227
227 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); 228 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
228 NavigateToURL(shell(), url); 229 NavigateToURL(shell(), url);
229 230
230 ASSERT_TRUE(ExecuteJavascript(base::StringPrintf( 231 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
231 "%s({video: true, audio: true});", kGetUserMediaAndStop))); 232 "%s({video: true, audio: true});", kGetUserMediaAndStop));
232
233 ExpectTitle("OK");
234 } 233 }
235 234
236 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, 235 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
237 GetAudioAndVideoStreamAndClone) { 236 GetAudioAndVideoStreamAndClone) {
238 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 237 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
239 238
240 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); 239 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
241 NavigateToURL(shell(), url); 240 NavigateToURL(shell(), url);
242 241
243 ASSERT_TRUE(ExecuteJavascript("getUserMediaAndClone();")); 242 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();");
244
245 ExpectTitle("OK");
246 } 243 }
247 244
248 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, 245 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
249 GetUserMediaWithMandatorySourceID) { 246 GetUserMediaWithMandatorySourceID) {
250 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 247 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
251 248
252 std::vector<std::string> audio_ids; 249 std::vector<std::string> audio_ids;
253 std::vector<std::string> video_ids; 250 std::vector<std::string> video_ids;
254 GetSources(&audio_ids, &video_ids); 251 GetSources(&audio_ids, &video_ids);
255 252
(...skipping 19 matching lines...) Expand all
275 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 272 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
276 273
277 std::vector<std::string> audio_ids; 274 std::vector<std::string> audio_ids;
278 std::vector<std::string> video_ids; 275 std::vector<std::string> video_ids;
279 GetSources(&audio_ids, &video_ids); 276 GetSources(&audio_ids, &video_ids);
280 277
281 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); 278 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
282 279
283 // Test with invalid mandatory audio sourceID. 280 // Test with invalid mandatory audio sourceID.
284 NavigateToURL(shell(), url); 281 NavigateToURL(shell(), url);
285 EXPECT_EQ(kGetUserMediaFailed, ExecuteJavascriptAndReturnResult( 282 ExecuteJavascriptAndWaitForOk(
286 GenerateGetUserMediaWithMandatorySourceID( 283 GenerateGetUserMediaWithMandatorySourceID(
287 kGetUserMediaAndStop, 284 kGetUserMediaAndExpectFailure,
288 "something invalid", 285 "something invalid",
289 video_ids[0]))); 286 video_ids[0]));
290 287
291 // Test with invalid mandatory video sourceID. 288 // Test with invalid mandatory video sourceID.
292 EXPECT_EQ(kGetUserMediaFailed, ExecuteJavascriptAndReturnResult( 289 ExecuteJavascriptAndWaitForOk(
293 GenerateGetUserMediaWithMandatorySourceID( 290 GenerateGetUserMediaWithMandatorySourceID(
294 kGetUserMediaAndStop, 291 kGetUserMediaAndExpectFailure,
295 audio_ids[0], 292 audio_ids[0],
296 "something invalid"))); 293 "something invalid"));
297 294
298 // Test with empty mandatory audio sourceID. 295 // Test with empty mandatory audio sourceID.
299 EXPECT_EQ(kGetUserMediaFailed, ExecuteJavascriptAndReturnResult( 296 ExecuteJavascriptAndWaitForOk(
300 GenerateGetUserMediaWithMandatorySourceID( 297 GenerateGetUserMediaWithMandatorySourceID(
301 kGetUserMediaAndStop, 298 kGetUserMediaAndExpectFailure,
302 "", 299 "",
303 video_ids[0]))); 300 video_ids[0]));
304 } 301 }
305 302
306 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, 303 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
307 GetUserMediaWithInvalidOptionalSourceID) { 304 GetUserMediaWithInvalidOptionalSourceID) {
308 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 305 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
309 306
310 std::vector<std::string> audio_ids; 307 std::vector<std::string> audio_ids;
311 std::vector<std::string> video_ids; 308 std::vector<std::string> video_ids;
312 GetSources(&audio_ids, &video_ids); 309 GetSources(&audio_ids, &video_ids);
313 310
(...skipping 21 matching lines...) Expand all
335 "", 332 "",
336 video_ids[0]))); 333 video_ids[0])));
337 } 334 }
338 335
339 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, TwoGetUserMediaAndStop) { 336 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, TwoGetUserMediaAndStop) {
340 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 337 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
341 338
342 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); 339 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
343 NavigateToURL(shell(), url); 340 NavigateToURL(shell(), url);
344 341
345 ASSERT_TRUE(ExecuteJavascript( 342 ExecuteJavascriptAndWaitForOk(
346 "twoGetUserMediaAndStop({video: true, audio: true});")); 343 "twoGetUserMediaAndStop({video: true, audio: true});");
347
348 ExpectTitle("OK");
349 } 344 }
350 345
351 // This test will make a simple getUserMedia page, verify that video is playing 346 // This test will make a simple getUserMedia page, verify that video is playing
352 // in a simple local <video>, and for a couple of seconds, collect some 347 // in a simple local <video>, and for a couple of seconds, collect some
353 // performance traces from VideoCaptureController colorspace conversion and 348 // performance traces from VideoCaptureController colorspace conversion and
354 // potential resizing. 349 // potential resizing.
355 IN_PROC_BROWSER_TEST_F( 350 IN_PROC_BROWSER_TEST_F(
356 WebRtcGetUserMediaBrowserTest, 351 WebRtcGetUserMediaBrowserTest,
357 TraceVideoCaptureControllerPerformanceDuringGetUserMedia) { 352 TraceVideoCaptureControllerPerformanceDuringGetUserMedia) {
358 RunGetUserMediaAndCollectMeasures( 353 RunGetUserMediaAndCollectMeasures(
(...skipping 22 matching lines...) Expand all
381 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 376 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
382 377
383 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); 378 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
384 379
385 std::string constraints_4_3 = GenerateGetUserMediaCall( 380 std::string constraints_4_3 = GenerateGetUserMediaCall(
386 kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 30, 30); 381 kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 30, 30);
387 382
388 // TODO(mcasas): add more aspect ratios, in particular 16:10 crbug.com/275594. 383 // TODO(mcasas): add more aspect ratios, in particular 16:10 crbug.com/275594.
389 384
390 NavigateToURL(shell(), url); 385 NavigateToURL(shell(), url);
391 ASSERT_TRUE(ExecuteJavascript(constraints_4_3)); 386 ASSERT_EQ("4:3 letterbox",
392 ExpectTitle("4:3 letterbox"); 387 ExecuteJavascriptAndReturnResult(constraints_4_3));
393 } 388 }
394 389
395 // This test calls getUserMedia and checks for aspect ratio behavior. 390 // This test calls getUserMedia and checks for aspect ratio behavior.
396 // TODO(perkj): Enable this test as soon as crbug/349450 is fixed. 391 // TODO(perkj): Enable this test as soon as crbug/349450 is fixed.
397 // Currently the render pipeline doesn't support cropping where the new cropped 392 // Currently the render pipeline doesn't support cropping where the new cropped
398 // frame doesn't have the same top left coordinates as the original frame. 393 // frame doesn't have the same top left coordinates as the original frame.
399 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, 394 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
400 DISABLED_TestGetUserMediaAspectRatio16To9) { 395 DISABLED_TestGetUserMediaAspectRatio16To9) {
401 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 396 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
402 397
403 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); 398 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
404 399
405 std::string constraints_16_9 = GenerateGetUserMediaCall( 400 std::string constraints_16_9 = GenerateGetUserMediaCall(
406 kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 30, 30); 401 kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 30, 30);
407 402
408 NavigateToURL(shell(), url); 403 NavigateToURL(shell(), url);
409 ASSERT_TRUE(ExecuteJavascript(constraints_16_9)); 404 ASSERT_EQ("16:9 letterbox",
410 ExpectTitle("16:9 letterbox"); 405 ExecuteJavascriptAndReturnResult(constraints_16_9));
411 } 406 }
412 407
413 namespace { 408 namespace {
414 409
415 struct UserMediaSizes { 410 struct UserMediaSizes {
416 int min_width; 411 int min_width;
417 int max_width; 412 int max_width;
418 int min_height; 413 int min_height;
419 int max_height; 414 int max_height;
420 int min_frame_rate; 415 int min_frame_rate;
(...skipping 21 matching lines...) Expand all
442 437
443 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndStop, 438 std::string call = GenerateGetUserMediaCall(kGetUserMediaAndStop,
444 user_media().min_width, 439 user_media().min_width,
445 user_media().max_width, 440 user_media().max_width,
446 user_media().min_height, 441 user_media().min_height,
447 user_media().max_height, 442 user_media().max_height,
448 user_media().min_frame_rate, 443 user_media().min_frame_rate,
449 user_media().max_frame_rate); 444 user_media().max_frame_rate);
450 DVLOG(1) << "Calling getUserMedia: " << call; 445 DVLOG(1) << "Calling getUserMedia: " << call;
451 NavigateToURL(shell(), url); 446 NavigateToURL(shell(), url);
452 ASSERT_TRUE(ExecuteJavascript(call)); 447 ExecuteJavascriptAndWaitForOk(call);
453 ExpectTitle("OK");
454 } 448 }
455 449
456 static const UserMediaSizes kAllUserMediaSizes[] = { 450 static const UserMediaSizes kAllUserMediaSizes[] = {
457 {320, 320, 180, 180, 30, 30}, 451 {320, 320, 180, 180, 30, 30},
458 {320, 320, 240, 240, 30, 30}, 452 {320, 320, 240, 240, 30, 30},
459 {640, 640, 360, 360, 30, 30}, 453 {640, 640, 360, 360, 30, 30},
460 {640, 640, 480, 480, 30, 30}, 454 {640, 640, 480, 480, 30, 30},
461 {960, 960, 720, 720, 30, 30}, 455 {960, 960, 720, 720, 30, 30},
462 {1280, 1280, 720, 720, 30, 30}, 456 {1280, 1280, 720, 720, 30, 30},
463 {1920, 1920, 1080, 1080, 30, 30}}; 457 {1920, 1920, 1080, 1080, 30, 30}};
464 458
465 INSTANTIATE_TEST_CASE_P(UserMedia, 459 INSTANTIATE_TEST_CASE_P(UserMedia,
466 WebRtcConstraintsBrowserTest, 460 WebRtcConstraintsBrowserTest,
467 testing::ValuesIn(kAllUserMediaSizes)); 461 testing::ValuesIn(kAllUserMediaSizes));
468 462
469 } // namespace content 463 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/webrtc_browsertest.cc ('k') | content/test/data/media/getusermedia.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698