Skip to content

Commit

Permalink
Merge pull request webrtc#1543 from fippo/moar-e2e-tests
Browse files Browse the repository at this point in the history
test: add e2e tests for change-codecs and negotiate-timing
  • Loading branch information
fippo authored Apr 25, 2022
2 parents d5bf80b + 2c8e9fe commit 2098bf3
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/content/peerconnection/change-codecs/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ remoteVideo.addEventListener('resize', () => {
}
});

const codecPreferences = document.querySelector('#codecPreferences');
const codecPreferences = document.getElementById('codecPreferences');
const supportsSetCodecPreferences = window.RTCRtpTransceiver &&
'setCodecPreferences' in window.RTCRtpTransceiver.prototype;

Expand Down Expand Up @@ -214,7 +214,7 @@ async function onCreateAnswerSuccess(desc) {
}
const codec = stats.get(stat.codecId);
document.getElementById('actualCodec').innerText = 'Using ' + codec.mimeType +
' ' + (codec.sdpFmtpLine ? codec.sdpFmtpLine + ' ' : '') +
(codec.sdpFmtpLine ? ' ' + codec.sdpFmtpLine + ' ' : '') +
', payloadType=' + codec.payloadType + '. Encoder: ' + stat.encoderImplementation;
});
}, 1000);
Expand Down
68 changes: 68 additions & 0 deletions src/content/peerconnection/change-codecs/js/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree.
*/
/* eslint-env node, mocha */

'use strict';
const webdriver = require('selenium-webdriver');
const seleniumHelpers = require('../../../../../test/webdriver');
const {expect} = require('chai');

let driver;
const path = '/src/content/peerconnection/change-codecs/index.html';
const url = `${process.env.BASEURL ? process.env.BASEURL : ('file://' + process.cwd())}${path}`;

describe('peerconnection with setCodecPreferences', () => {
before(() => {
driver = seleniumHelpers.buildDriver();
});
after(() => {
return driver.quit();
});

beforeEach(() => {
return driver.get(url);
});

['video/VP8'].forEach(codec => {
it('establishes a connection', async () => {
await driver.findElement(webdriver.By.id('startButton')).click();

await driver.wait(() => driver.executeScript(() => {
return localStream !== null; // eslint-disable-line no-undef
}));
await driver.wait(() => driver.executeScript(() => {
return codecPreferences.disabled === false; // eslint-disable-line no-undef
}));
await driver.findElement(webdriver.By.id('codecPreferences')).click();
await driver.findElement(webdriver.By.css('option[value=\'video/VP8\']')).click();

await driver.wait(() => driver.findElement(webdriver.By.id('callButton')).isEnabled());
await driver.findElement(webdriver.By.id('callButton')).click();

await Promise.all([
await driver.wait(() => driver.executeScript(() => {
return pc1 && pc1.connectionState === 'connected'; // eslint-disable-line no-undef
})),
await driver.wait(() => driver.executeScript(() => {
return pc2 && pc2.connectionState === 'connected'; // eslint-disable-line no-undef
})),
]);

await driver.wait(() => driver.executeScript(() => {
return document.getElementById('remoteVideo').readyState === HTMLMediaElement.HAVE_ENOUGH_DATA;
}));

await driver.wait(() => driver.executeScript(() => {
return document.getElementById('actualCodec').innerText !== '';
}));
const actualCodec = await driver.findElement(webdriver.By.id('actualCodec')).getAttribute('innerText');
expect(actualCodec.startsWith('Using ' + codec)).to.be.true;
});
});
});

70 changes: 70 additions & 0 deletions src/content/peerconnection/negotiate-timing/js/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree.
*/
/* eslint-env node, mocha */

'use strict';
const webdriver = require('selenium-webdriver');
const seleniumHelpers = require('../../../../../test/webdriver');
const {expect} = require('chai');

let driver;
const path = '/src/content/peerconnection/negotiate-timing/index.html';
const url = `${process.env.BASEURL ? process.env.BASEURL : ('file://' + process.cwd())}${path}`;

describe('peerconnection with negotiation timing', () => {
before(() => {
driver = seleniumHelpers.buildDriver();
});
after(() => {
return driver.quit();
});

beforeEach(() => {
return driver.get(url);
});

it('establishes a connection, renegotiates and hangs up', async () => {
await driver.findElement(webdriver.By.id('startButton')).click();

await driver.wait(() => driver.executeScript(() => {
return localStream !== null; // eslint-disable-line no-undef
}));

await driver.wait(() => driver.findElement(webdriver.By.id('callButton')).isEnabled());
await driver.findElement(webdriver.By.id('callButton')).click();

await Promise.all([
await driver.wait(() => driver.executeScript(() => {
return pc1 && pc1.connectionState === 'connected'; // eslint-disable-line no-undef
})),
await driver.wait(() => driver.executeScript(() => {
return pc2 && pc2.connectionState === 'connected'; // eslint-disable-line no-undef
})),
]);

await driver.wait(() => driver.executeScript(() => {
return document.getElementById('remoteVideo').readyState === HTMLMediaElement.HAVE_ENOUGH_DATA;
}));

await driver.wait(() => driver.findElement(webdriver.By.id('renegotiateButton')).isEnabled());
await driver.findElement(webdriver.By.id('renegotiateButton')).click();

await driver.wait(() => driver.executeScript(() => {
return document.getElementById('log').innerText !== 'Log goes here';
}));
const logText = await driver.findElement(webdriver.By.id('log')).getAttribute('innerText');
expect(logText.split('\n')).to.have.lengthOf(2);

await driver.findElement(webdriver.By.id('hangupButton')).click();

await driver.wait(() => driver.executeScript(() => {
return pc1 === null; // eslint-disable-line no-undef
}));
});
});

0 comments on commit 2098bf3

Please sign in to comment.