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

Side by Side Diff: chrome/test/data/extensions/api_test/tab_capture/performance.js

Issue 1076533002: Fix some shutdown problems in tab capture performance tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix fps Created 5 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
« no previous file with comments | « chrome/browser/extensions/api/tab_capture/tab_capture_performancetest.cc ('k') | no next file » | 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 // The tests here cover the end-to-end functionality of tab capturing and 5 // The tests here cover the end-to-end functionality of tab capturing and
6 // playback as video. The page generates a test patter (moving balls) and 6 // playback as video. The page generates a test patter (moving balls) and
7 // the rendering output of the tab is captured into a LocalMediaStream. Then, 7 // the rendering output of the tab is captured into a LocalMediaStream. Then,
8 // the LocalMediaStream is plugged into a video element for playback. 8 // the LocalMediaStream is plugged into a video element for playback.
9 // 9 //
10 10
11 // Global to prevent gc from eating the video tag. 11 // Global to prevent gc from eating the video tag.
12 var video = null; 12 var video = null;
13 var capture_stream = null;
13 14
14 function TestStream(stream) { 15 function TestStream(stream) {
15 // Create video and canvas elements, but no need to append them to the 16 // Create video and canvas elements, but no need to append them to the
16 // DOM. 17 // DOM.
17 video = document.createElement("video"); 18 video = document.createElement("video");
18 video.width = 1920; 19 video.width = 1920;
19 video.height = 1080; 20 video.height = 1080;
20 video.addEventListener("error", chrome.test.fail); 21 video.addEventListener("error", chrome.test.fail);
21 22
22 var canvas = document.createElement("canvas"); 23 var canvas = document.createElement("canvas");
23 canvas.width = video.width; 24 canvas.width = video.width;
24 canvas.height = video.height; 25 canvas.height = video.height;
25 var context = canvas.getContext("2d"); 26 var context = canvas.getContext("2d");
26 document.body.appendChild(canvas); 27 document.body.appendChild(canvas);
27 var start_time = new Date().getTime(); 28 var start_time = new Date().getTime();
28 29
29 // Play the LocalMediaStream in the video element. 30 // Play the LocalMediaStream in the video element.
30 video.src = URL.createObjectURL(stream); 31 video.src = URL.createObjectURL(stream);
31 video.play(); 32 video.play();
32 33
33 var frame = 0; 34 var frame = 0;
34 function draw() { 35 function draw() {
35 // Run for 10 seconds. 36 // Run for 10 seconds.
36 if (new Date().getTime() - start_time > 10000) { 37 if (new Date().getTime() - start_time > 10000) {
37 chrome.test.succeed(); 38 chrome.test.succeed();
38 // Note that the API testing framework might not terminate if we keep 39 // Note that the API testing framework might not terminate if we keep
39 // animating and capturing, so we have to make sure that we stop doing 40 // animating and capturing, so we have to make sure that we stop doing
40 // that here. 41 // that here.
42 if (capture_stream) {
43 capture_stream.stop();
44 }
41 stream.stop(); 45 stream.stop();
42 return; 46 return;
43 } 47 }
44 requestAnimationFrame(draw); 48 requestAnimationFrame(draw);
45 frame = frame + 1; 49 frame = frame + 1;
46 context.fillStyle = 'rgb(255,255,255)'; 50 context.fillStyle = 'rgb(255,255,255)';
47 context.fillRect( 0, 0, canvas.width, canvas.height ); 51 context.fillRect( 0, 0, canvas.width, canvas.height );
48 for (var j = 0; j < 200; j++) { 52 for (var j = 0; j < 200; j++) {
49 var i = (j + frame) % 200; 53 var i = (j + frame) % 200;
50 var t = (frame + 3000) * (0.01 + i / 8000.0); 54 var t = (frame + 3000) * (0.01 + i / 8000.0);
51 var x = (Math.sin( t ) * 0.45 + 0.5) * canvas.width; 55 var x = (Math.sin( t ) * 0.45 + 0.5) * canvas.width;
52 var y = (Math.cos( t * 0.9 ) * 0.45 + 0.5) * canvas.height; 56 var y = (Math.cos( t * 0.9 ) * 0.45 + 0.5) * canvas.height;
53 context.fillStyle = 'rgb(' + (255 - i) + ',' + (155 +i) + ', ' + i + ')'; 57 context.fillStyle = 'rgb(' + (255 - i) + ',' + (155 +i) + ', ' + i + ')';
54 context.beginPath(); 58 context.beginPath();
55 context.arc(x, y, 50, 0, Math.PI * 2, true); 59 context.arc(x, y, 50, 0, Math.PI * 2, true);
56 context.closePath(); 60 context.closePath();
57 context.fill(); 61 context.fill();
58 } 62 }
59 } 63 }
60 64
61 // Kick it off. 65 // Kick it off.
62 draw(); 66 draw();
63 } 67 }
64 68
65 // Set up a WebRTC connection and pipe |stream| through it. 69 // Set up a WebRTC connection and pipe |stream| through it.
66 function testThroughWebRTC(stream) { 70 function testThroughWebRTC(stream) {
71 capture_stream = stream;
67 console.log("Testing through webrtc."); 72 console.log("Testing through webrtc.");
68 var sender = new webkitRTCPeerConnection(null); 73 var sender = new webkitRTCPeerConnection(null);
69 var receiver = new webkitRTCPeerConnection(null); 74 var receiver = new webkitRTCPeerConnection(null);
70 sender.onicecandidate = function (event) { 75 sender.onicecandidate = function (event) {
71 if (event.candidate) { 76 if (event.candidate) {
72 receiver.addIceCandidate(new RTCIceCandidate(event.candidate)); 77 receiver.addIceCandidate(new RTCIceCandidate(event.candidate));
73 } 78 }
74 }; 79 };
75 receiver.onicecandidate = function (event) { 80 receiver.onicecandidate = function (event) {
76 if (event.candidate) { 81 if (event.candidate) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 114 }
110 } 115 }
111 }, 116 },
112 f); 117 f);
113 } 118 }
114 119
115 chrome.test.runTests([ tabCapturePerformanceTest ]); 120 chrome.test.runTests([ tabCapturePerformanceTest ]);
116 121
117 // TODO(hubbe): Consider capturing audio as well, need to figure out how to 122 // TODO(hubbe): Consider capturing audio as well, need to figure out how to
118 // capture relevant statistics for that though. 123 // capture relevant statistics for that though.
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tab_capture/tab_capture_performancetest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698