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: chrome/test/media_router/telemetry/benchmarks/pagesets/common.js

Issue 1843063004: Add new Telemetry tests to get CPU and memory usage for idle and flinging two test scenarios. Mirro… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unused code Created 4 years, 8 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 /** 1 /**
2 * Copyright 2016 The Chromium Authors. All rights reserved. 2 * Copyright 2016 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 * 5 *
6 * @fileoverview Common APIs for presentation integration tests. 6 * @fileoverview Common APIs for media router performance tests.
7 * 7 *
8 */ 8 */
9 9
10 var startSessionPromise = null; 10 var initialized = false;
11 var startedSession = null; 11 var currentSession = null;
12 var reconnectedSession = null; 12 var currentMedia = null;
13 var presentationUrl = "http://www.google.com/#__testprovider__=true";
14 var startSessionRequest = new PresentationRequest(presentationUrl);
15 var defaultRequestSessionId = null;
16 13
17 window.navigator.presentation.defaultRequest = startSessionRequest; 14
18 window.navigator.presentation.defaultRequest.onconnectionavailable = function(e) 15 window['__onGCastApiAvailable'] = function(loaded, errorInfo) {
19 { 16 if (loaded) {
20 defaultRequestSessionId = e.connection.id; 17 initializeCastApi();
21 }; 18 } else {
19 console.log(errorInfo);
20 }
21 }
22 22
23 /** 23 /**
24 * Waits until one device is available. 24 * Initialize Cast APIs.
25 */ 25 */
26 function waitUntilDeviceAvailable() { 26 function initializeCastApi() {
27 startSessionRequest.getAvailability(presentationUrl).then( 27 // Load Cast APIs
28 function(availability) { 28 console.info('Initializing API');
29 console.log('availability ' + availability.value + '\n'); 29 var sessionRequest = new chrome.cast.SessionRequest(
30 if (availability.value) { 30 chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID);
31 console.log('device available'); 31 var apiConfig = new chrome.cast.ApiConfig(
32 } else { 32 sessionRequest,
33 availability.onchange = function(newAvailability) { 33 null, // session listener
34 if (newAvailability) 34 function(availability) { // receiver listener
35 console.log('got new availability'); 35 console.info('Recevier listener: ' + JSON.stringify(availability));
mark a. foltz 2016/04/13 20:20:03 Consider using the console format specifier %O for
Lei Lei 2016/04/14 01:55:13 Thanks for the suggestion, I didn't know I can for
36 } 36 initialized = true;
37 } 37 });
38 }).catch(function(){ 38 chrome.cast.initialize(
39 console.log('error'); 39 apiConfig,
40 function() { // Successful callback
41 console.info('Initialize successfully');
42 },
43 function(error) { // Error callback
44 console.info('Initialize failed, error: ' + JSON.stringify(error));
40 }); 45 });
41 } 46 }
42 47
43 /** 48 /**
44 * Starts session. 49 * Start a new session for flinging scenario.
45 */ 50 */
46 function startSession() { 51 function startFlingingSession() {
47 startSessionPromise = startSessionRequest.start(); 52 console.info('Starting Session');
48 console.log('start session'); 53 chrome.cast.requestSession(
54 function(session) { // Request session successful callback
55 console.info('Request session successfully');
56 currentSession = session;
57 },
58 function(error) { // Request session Error callback
59 console.info('Request session failed, error: ' + JSON.stringify(error));
60 });
49 } 61 }
50 62
51 /** 63 /**
52 * Checks if the session has been started successfully. 64 * Loads the specific video on Chromecast.
mark a. foltz 2016/04/13 20:20:03 Mention that the URL must point to a video/mp4 fil
Lei Lei 2016/04/14 01:55:13 Done.
53 */ 65 */
54 function checkSession() { 66 function loadMedia(mediaUrl) {
55 if (!startSessionPromise) { 67 if (!currentSession) {
56 sendResult(false, 'Did not attempt to start session'); 68 console.warn('Cannot load media without a live session');
57 } else {
58 startSessionPromise.then(function(session) {
59 if(!session) {
60 console.log('Failed to start session');
61 } else {
62 // set the new session
63 startedSession = session;
64 console.log('Session has been started');
65 }
66 }).catch(function() {
67 // terminate old session if exists
68 terminateSession();
69 console.log('Failed to start session');
70 })
71 } 69 }
70 console.info('loading ' + mediaUrl);
71 var mediaInfo = new chrome.cast.media.MediaInfo(mediaUrl, 'video/mp4');
72 var request = new chrome.cast.media.LoadRequest(mediaInfo);
73 request.autoplay = true;
74 request.currentTime = 0;
75 currentSession.loadMedia(request,
76 function(media) {
77 console.info('Load media successfully');
78 currentMedia = media;
79 },
80 function(error) { // Error callback
81 console.info('Load media failed, error: ' + JSON.stringify(error));
82 });
72 } 83 }
73 84
74 /** 85 /**
75 * Terminates current session. 86 * Stops current session.
76 */ 87 */
77 function terminateSession() { 88 function stopSession() {
78 if (startedSession) { 89 if (currentSession) {
79 startedSession.terminate(); 90 currentSession.stop(
91 function() {
92 console.info('Stop session successfully');
93 currentSession = null;
94 },
95 function(error) { // Error callback
96 console.info('Stop session failed, error: ' + JSON.stringify(error));
97 });
80 } 98 }
81 } 99 }
82
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698