Skip to content

Commit

Permalink
port tests to mocha
Browse files Browse the repository at this point in the history
can be run with
  node_modules/.bin/mocha 'src/content/**/js/test.js'
  • Loading branch information
fippo committed Mar 15, 2022
1 parent e5cd1dc commit 515beeb
Show file tree
Hide file tree
Showing 18 changed files with 1,002 additions and 822 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
"'**/third_party/*.js'"
],
"devDependencies": {
"chai": "^4.3.6",
"chromedriver": "^98.0.1",
"eslint": "^8.9.0",
"eslint-config-google": "^0.14.0",
"geckodriver": "^3.0.1",
"http-server": "^14.1.0",
"mocha": "^9.2.1",
"selenium-webdriver": "^3.6.0",
"stylelint": "^14.5.3",
"stylelint-config-recommended": "^7.0.0",
"tape": "^5.5.2"
}
"stylelint-config-recommended": "^7.0.0"
},
"dependencies": {}
}
74 changes: 49 additions & 25 deletions src/content/datachannel/basic/js/test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
* Copyright (c) 2015 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.
*/
export default {
'It should transfer text over data channel': (browser) => {
const path = '/src/content/datachannel/basic/index.html';
const url = 'file://' + process.cwd() + path;

browser
.url(url)
.click('#startButton')
.expect.element('#sendButton').to.be.enabled.before(50);
browser.expect.element('#dataChannelSend').to.be.enabled.before(50);

browser.setValue('#dataChannelSend', 'HELLO, WORLD!');
browser
.click('#sendButton')
.pause(50)
.assert.value('#dataChannelReceive', 'HELLO, WORLD!');

browser
.click('#closeButton')
.expect.element('#sendButton').to.not.be.enabled.before(50);

browser.end();
}
};
/* 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/datachannel/basic/index.html';
const url = `${process.env.BASEURL ? process.env.BASEURL : ('file://' + process.cwd())}${path}`;

describe('datachannel basic', () => {
before(() => {
driver = seleniumHelpers.buildDriver();
});
after(() => {
return driver.quit();
});

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

it('transfers text', async () => {
const text = 'Hello world';
await driver.findElement(webdriver.By.id('startButton')).click();

await Promise.all([
driver.wait(() => driver.executeScript(() => {
return localConnection && localConnection.connectionState === 'connected'; // eslint-disable-line no-undef
})),
await driver.wait(() => driver.executeScript(() => {
return remoteConnection && remoteConnection.connectionState === 'connected'; // eslint-disable-line no-undef
})),
]);
await driver.wait(() => driver.findElement(webdriver.By.id('sendButton')).isEnabled());

await driver.findElement(webdriver.By.id('dataChannelSend'))
.sendKeys(text);
await driver.findElement(webdriver.By.id('sendButton')).click();
await driver.wait(() => driver.executeScript(() => {
return document.getElementById('dataChannelReceive').value.length > 0;
}));

const value = await driver.findElement(webdriver.By.id('dataChannelReceive')).getAttribute('value');
expect(value).to.equal(text);
});
});
65 changes: 51 additions & 14 deletions src/content/datachannel/datatransfer/js/test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,57 @@
/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
* Copyright (c) 2015 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.
*/
export default {
'It should transfer data over data channel': (browser) => {
const path = '/src/content/datachannel/datatransfer/index.html';
const url = 'file://' + process.cwd() + path;

browser
.url(url)
.click('#sendTheData')
.pause(1000)
.assert.value('#receiveProgress', '16777200')
.end();
}
};
/* 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/datachannel/datatransfer/index.html';
const url = `${process.env.BASEURL ? process.env.BASEURL : ('file://' + process.cwd())}${path}`;

describe('datachannel datatransfer', () => {
before(() => {
driver = seleniumHelpers.buildDriver();
});
after(() => {
return driver.quit();
});

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

it('transfers data', async () => {
const megsToSend = 4;
await driver.findElement(webdriver.By.id('megsToSend'))
.clear();
await driver.findElement(webdriver.By.id('megsToSend'))
.sendKeys(megsToSend + '\n');

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

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

// the remote connection gets closed when it is done.
await driver.wait(() => driver.executeScript(() => {
return remoteConnection === null; // eslint-disable-line no-undef
}));

const transferred = await driver.findElement(webdriver.By.id('receiveProgress')).getAttribute('value');
expect(transferred >>> 0).to.equal(megsToSend * 1024 * 1024);
});
});
49 changes: 35 additions & 14 deletions src/content/datachannel/filetransfer/js/test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
* Copyright (c) 2015 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 */

export default {
'It should transfer a file over a datachannel': (browser) => {
const path = '/src/content/datachannel/filetransfer/index.html';
const url = 'file://' + process.cwd() + path;
'use strict';
const webdriver = require('selenium-webdriver');
const seleniumHelpers = require('../../../../../test/webdriver');

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

describe('datachannel basic', () => {
before(() => {
driver = seleniumHelpers.buildDriver();
});
after(() => {
return driver.quit();
});

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

it('transfers a file', async () => {
await driver.findElement(webdriver.By.id('fileInput'))
.sendKeys(process.cwd() + '/src/content/devices/multi/images/poster.jpg');
await driver.wait(() => driver.findElement(webdriver.By.id('sendFile')).isEnabled());
await driver.findElement(webdriver.By.id('sendFile')).click();

// the remote connection gets closed when it is done.
await driver.wait(() => driver.executeScript(() => {
return remoteConnection === null; // eslint-disable-line no-undef
}));
await driver.wait(() => driver.findElement(webdriver.By.id('download')).isEnabled());
});
});

browser
.url(url)
.waitForElementNotVisible('#download', 100, 'File download link is not visible')
.waitForElementVisible('#fileInput', 1000)
.setValue('#fileInput', process.cwd() + '/src/content/devices/multi/images/poster.jpg')
.waitForElementVisible('#download', 10000, 'File download link is visible')
.end();
}
};
67 changes: 54 additions & 13 deletions src/content/devices/input-output/js/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,57 @@
* that can be found in the LICENSE file in the root of the source
* tree.
*/
export default {
'It should have select elements for each media device': (browser) => {
const path = '/src/content/devices/input-output/index.html';
const url = 'file://' + process.cwd() + path;

browser
.url(url)
.waitForElementVisible('#audioSource option:nth-of-type(1)', 1000, 'Check that there is at least one audio source')
.waitForElementVisible('#audioOutput option:nth-of-type(1)', 1000, 'Check that there is at least one audio output')
.waitForElementVisible('#videoSource option:nth-of-type(1)', 1000, 'Check that there is at least one video source')
.end();
}
};
/* 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/devices/input-output/index.html';
const url = `${process.env.BASEURL ? process.env.BASEURL : ('file://' + process.cwd())}${path}`;

describe('input-output', () => {
before(() => {
driver = seleniumHelpers.buildDriver();
});
after(() => {
return driver.quit();
});

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

it('shows at least one audio input device', async () => {
await driver.wait(driver.executeScript(() => {
window.stream !== undefined; // eslint-disable-line no-undef
}));
const numberOfSources = await driver.findElement(webdriver.By.id('audioSource'))
.getAttribute('childElementCount');
expect(numberOfSources >>> 0).to.be.above(0);
});

it('shows at least one video input device', async () => {
await driver.wait(driver.executeScript(() => {
window.stream !== undefined; // eslint-disable-line no-undef
}));
const numberOfSources = await driver.findElement(webdriver.By.id('videoSource'))
.getAttribute('childElementCount');
expect(numberOfSources >>> 0).to.be.above(0);
});

it('shows at least one audio output device device', async function() {
if (process.env.BROWSER === 'firefox') {
this.skip();
}
await driver.wait(driver.executeScript(() => {
window.stream !== undefined; // eslint-disable-line no-undef
}));
const numberOfSinks = await driver.findElement(webdriver.By.id('audioOutput'))
.getAttribute('childElementCount');
expect(numberOfSinks >>> 0).to.be.above(0);
});
});

43 changes: 32 additions & 11 deletions src/content/getusermedia/gum/js/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,36 @@
* that can be found in the LICENSE file in the root of the source
* tree.
*/
export default {
'It should have a video element': (browser) => {
const path = '/src/content/getusermedia/gum/index.html';
const url = 'file://' + process.cwd() + path;
/* 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/getusermedia/gum/index.html';
const url = `${process.env.BASEURL ? process.env.BASEURL : ('file://' + process.cwd())}${path}`;

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

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

it('opens a camera', async () => {
await driver.findElement(webdriver.By.css('button')).click();
await driver.wait(() => driver.executeScript(() =>
document.querySelector('video').readyState === HTMLMediaElement.HAVE_ENOUGH_DATA)
);
const width = await driver.findElement(webdriver.By.css('video')).getAttribute('videoWidth');
expect(width >>> 0).to.be.at.least(320);
});
});

browser
.url(url)
.waitForElementVisible('video', 5000)
.waitForClientConnected('video', 5000)
.end();
}
};
Loading

0 comments on commit 515beeb

Please sign in to comment.