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

Side by Side Diff: chrome/test/data/extensions/api_test/cast_streaming/basics.js

Issue 170063006: Cast: Add JS API to get raw events logs from cast extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 var rtpStream = chrome.cast.streaming.rtpStream; 5 var rtpStream = chrome.cast.streaming.rtpStream;
6 var tabCapture = chrome.tabCapture; 6 var tabCapture = chrome.tabCapture;
7 var udpTransport = chrome.cast.streaming.udpTransport; 7 var udpTransport = chrome.cast.streaming.udpTransport;
8 var createSession = chrome.cast.streaming.session.create; 8 var createSession = chrome.cast.streaming.session.create;
9 var pass = chrome.test.callbackPass; 9 var pass = chrome.test.callbackPass;
10 10
11 function TestStateMachine(stream, audioId, videoId, udpId) {
12 this.stream = stream;
13 this.audioId = audioId;
14 this.videoId = videoId;
15 this.udpId = udpId;
16 this.audioStarted = false;
17 this.videoStarted = false;
18 this.audioStopped = false;
19 this.videoStopped = false;
20 }
21
22 TestStateMachine.prototype.onStarted = function(id) {
23 if (id == this.audioId)
24 this.audioStarted = true;
25 if (id == this.videoId)
26 this.videoStarted = true;
27 if (this.audioStarted && this.videoStarted)
28 this.onAllStarted();
29 }
30
31 TestStateMachine.prototype.onStopped = function(id) {
32 if (id == this.audioId)
33 this.audioStopped = true;
34 if (id == this.videoId)
35 this.videoStopped = true;
36 if (this.audioStopped && this.videoStopped)
37 this.onAllStopped();
38 }
39
40 chrome.test.runTests([ 11 chrome.test.runTests([
41 function rtpStreamStart() { 12 function rtpStreamStart() {
42 console.log("[TEST] rtpStreamStart"); 13 console.log("[TEST] rtpStreamStart");
43 tabCapture.capture({audio: true, video: true}, 14 tabCapture.capture({audio: true, video: true},
44 pass(function(stream) { 15 pass(function(stream) {
45 console.log("Got MediaStream."); 16 console.log("Got MediaStream.");
46 chrome.test.assertTrue(!!stream); 17 chrome.test.assertTrue(!!stream);
47 createSession(stream.getAudioTracks()[0], 18 createSession(stream.getAudioTracks()[0],
48 stream.getVideoTracks()[0], 19 stream.getVideoTracks()[0],
49 pass(function(stream, audioId, videoId, udpId) { 20 pass(function(stream, audioId, videoId, udpId) {
50 console.log("Starting."); 21 console.log("Starting.");
51 var stateMachine = new TestStateMachine(stream, 22 var stateMachine = new TestStateMachine(stream,
52 audioId, 23 audioId,
53 videoId, 24 videoId,
54 udpId); 25 udpId);
55 var audioParams = rtpStream.getSupportedParams(audioId)[0]; 26 var audioParams = rtpStream.getSupportedParams(audioId)[0];
56 var videoParams = rtpStream.getSupportedParams(videoId)[0]; 27 var videoParams = rtpStream.getSupportedParams(videoId)[0];
57 chrome.test.assertEq(audioParams.payload.codecName, "OPUS"); 28 chrome.test.assertEq(audioParams.payload.codecName, "OPUS");
58 chrome.test.assertEq(videoParams.payload.codecName, "VP8"); 29 chrome.test.assertEq(videoParams.payload.codecName, "VP8");
59 udpTransport.setDestination(udpId, 30 udpTransport.setDestination(udpId,
60 {address: "127.0.0.1", port: 2344}); 31 {address: "127.0.0.1", port: 2344});
61 rtpStream.onStarted.addListener( 32 rtpStream.onStarted.addListener(
62 stateMachine.onStarted.bind(stateMachine)); 33 stateMachine.onStarted.bind(stateMachine));
63 stateMachine.onAllStarted = 34 stateMachine.onAllStarted =
64 pass(function(audioId, videoId) { 35 pass(function(audioId, videoId) {
36 console.log("Enabling logging.");
37 rtpStream.toggleLogging(audioId, true);
38 rtpStream.toggleLogging(videoId, true);
65 console.log("Stopping."); 39 console.log("Stopping.");
66 rtpStream.stop(audioId); 40 rtpStream.stop(audioId);
67 rtpStream.stop(videoId); 41 rtpStream.stop(videoId);
68 }.bind(null, audioId, videoId)); 42 }.bind(null, audioId, videoId));
69 rtpStream.onStopped.addListener( 43 rtpStream.onStopped.addListener(
70 stateMachine.onStopped.bind(stateMachine)); 44 stateMachine.onStopped.bind(stateMachine));
71 stateMachine.onAllStopped = 45 stateMachine.onAllStopped =
46 pass(function(audioId, videoId) {
47 rtpStream.getRawEvents(audioId,
48 stateMachine.onGotRawEvents.bind(stateMachine, audioId));
49 rtpStream.getRawEvents(videoId,
50 stateMachine.onGotRawEvents.bind(stateMachine, videoId));
51 }.bind(null, audioId, videoId));
52 stateMachine.onGotAllRawEvents =
72 pass(function(stream, audioId, videoId, udpId) { 53 pass(function(stream, audioId, videoId, udpId) {
54 console.log("Disabling logging.");
55 rtpStream.toggleLogging(audioId, false);
56 rtpStream.toggleLogging(videoId, false);
73 console.log("Destroying."); 57 console.log("Destroying.");
74 rtpStream.destroy(audioId); 58 rtpStream.destroy(audioId);
75 rtpStream.destroy(videoId); 59 rtpStream.destroy(videoId);
76 udpTransport.destroy(udpId); 60 udpTransport.destroy(udpId);
77 chrome.test.assertEq(audioParams.payload.codecName, "OPUS"); 61 chrome.test.assertEq(audioParams.payload.codecName, "OPUS");
78 chrome.test.assertEq(videoParams.payload.codecName, "VP8"); 62 chrome.test.assertEq(videoParams.payload.codecName, "VP8");
79 chrome.test.succeed(); 63 chrome.test.succeed();
80 }.bind(null, stream, audioId, videoId, udpId)); 64 }.bind(null, stream, audioId, videoId, udpId));
81 rtpStream.start(audioId, audioParams); 65 rtpStream.start(audioId, audioParams);
82 rtpStream.start(videoId, videoParams); 66 rtpStream.start(videoId, videoParams);
83 }.bind(null, stream))); 67 }.bind(null, stream)));
84 })); 68 }));
85 }, 69 },
86 ]); 70 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698