Do not announce robot account token before account ID is available
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / cast_streaming / performance.js
blob2f938fb42276ccd6a1e5ec1104350dfd75aca64f
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
3 // found in the LICENSE file.
5 // Run a cast v2 mirroring session for 10 seconds.
7 chrome.test.runTests([
8   function sendTestPatterns() {
9     // The receive port changes between browser_test invocations, and is passed
10     // as an query parameter in the URL.
11     var recvPort;
12     try {
13       recvPort = parseInt(window.location.search.substring("?port=".length));
14       chrome.test.assertTrue(recvPort > 0);
15     } catch (err) {
16       chrome.test.fail("Error parsing ?port=### -- " + err.message);
17       return;
18     }
20     var width = 1920;
21     var height = 1080;
22     var frameRate = 30;
24     chrome.tabCapture.capture(
25         { video: true,
26           audio: true,
27           videoConstraints: {
28             mandatory: {
29               minWidth: width,
30               minHeight: height,
31               maxWidth: width,
32               maxHeight: height,
33               maxFrameRate: frameRate,
34             }
35           }
36         },
37         function startStreamingTestPatterns(captureStream) {
38           chrome.test.assertTrue(!!captureStream);
39           chrome.cast.streaming.session.create(
40               captureStream.getAudioTracks()[0],
41               captureStream.getVideoTracks()[0],
42               function (audioId, videoId, udpId) {
43                 chrome.cast.streaming.udpTransport.setDestination(
44                     udpId, { address: "127.0.0.1", port: recvPort } );
45                 var rtpStream = chrome.cast.streaming.rtpStream;
46                 rtpStream.start(audioId,
47                                 rtpStream.getSupportedParams(audioId)[0]);
48                 var videoParams = rtpStream.getSupportedParams(videoId)[0];
49                 videoParams.payload.width = width;
50                 videoParams.payload.height = height;
51                 videoParams.payload.clockRate = frameRate;
52                 rtpStream.start(videoId, videoParams);
53                 setTimeout(function () {
54                   chrome.test.succeed();
55                   rtpStream.stop(audioId);
56                   rtpStream.stop(videoId);
57                 }, 20000);  // 20 seconds
58               });
59         });
60   }
61 ]);