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

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

Issue 2866943002: Give performance_browser_tests lots of love and attention. (Closed)
Patch Set: fix compile error Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/tab_capture/performance.js
diff --git a/chrome/test/data/extensions/api_test/tab_capture/performance.js b/chrome/test/data/extensions/api_test/tab_capture/performance.js
index 4d6025d03fb197bfe40aae23990ec74a77d3b816..edc9ec15f6095743cddac081ea238631848348cb 100644
--- a/chrome/test/data/extensions/api_test/tab_capture/performance.js
+++ b/chrome/test/data/extensions/api_test/tab_capture/performance.js
@@ -10,16 +10,32 @@
// Global to prevent gc from eating the video tag.
var video = null;
-var capture_stream = null;
+var captureStream = null;
-function TestStream(stream) {
- // Create video and canvas elements, but no need to append them to the
- // DOM.
+function stopStream(stream) {
+ const tracks = stream.getTracks();
+ for (let i = 0; i < tracks.length; ++i) {
+ tracks[i].stop();
+ }
+ chrome.test.assertFalse(stream.active);
+}
+
+function connectToVideoAndRunTest(stream) {
+ if (!stream) {
+ chrome.test.fail(chrome.runtime.lastError.message || 'null stream');
+ return;
+ }
+
+ // Create the video element, to play out the captured video; but there's no
+ // need to append it to the DOM.
video = document.createElement("video");
video.width = 1920;
video.height = 1080;
video.addEventListener("error", chrome.test.fail);
+ // Create a canvas and add it to the test page being captured. The draw()
+ // function below will update the canvas's content, triggering tab capture for
+ // each animation frame.
var canvas = document.createElement("canvas");
canvas.width = video.width;
canvas.height = video.height;
@@ -33,22 +49,23 @@ function TestStream(stream) {
var frame = 0;
function draw() {
- // Run for 10 seconds.
- if (new Date().getTime() - start_time > 10000) {
+ // Run for 15 seconds.
+ if (new Date().getTime() - start_time > 15000) {
chrome.test.succeed();
// Note that the API testing framework might not terminate if we keep
// animating and capturing, so we have to make sure that we stop doing
// that here.
- if (capture_stream) {
- capture_stream.stop();
+ if (captureStream) {
+ stopStream(captureStream);
+ captureStream = null;
}
- stream.stop();
+ stopStream(stream);
return;
}
requestAnimationFrame(draw);
frame = frame + 1;
context.fillStyle = 'rgb(255,255,255)';
- context.fillRect( 0, 0, canvas.width, canvas.height );
+ context.fillRect(0, 0, canvas.width, canvas.height );
for (var j = 0; j < 200; j++) {
var i = (j + frame) % 200;
var t = (frame + 3000) * (0.01 + i / 8000.0);
@@ -68,7 +85,7 @@ function TestStream(stream) {
// Set up a WebRTC connection and pipe |stream| through it.
function testThroughWebRTC(stream) {
- capture_stream = stream;
+ captureStream = stream;
console.log("Testing through webrtc.");
var sender = new RTCPeerConnection();
var receiver = new RTCPeerConnection();
@@ -83,7 +100,7 @@ function testThroughWebRTC(stream) {
}
};
receiver.onaddstream = function (event) {
- TestStream(event.stream);
+ connectToVideoAndRunTest(event.stream);
};
sender.addStream(stream);
sender.createOffer(function (sender_description) {
@@ -99,7 +116,7 @@ function testThroughWebRTC(stream) {
}
function tabCapturePerformanceTest() {
- var f = TestStream;
+ var f = connectToVideoAndRunTest;
if (parseInt(window.location.href.split('?WebRTC=')[1])) {
f = testThroughWebRTC;
}

Powered by Google App Engine
This is Rietveld 408576698