fix: navigator.connection not working as intended (#38491)

* fix: navigator.connection not working as intended

* chore: make network quality methods private
This commit is contained in:
Shelley Vohr 2023-05-31 17:06:25 +02:00 committed by GitHub
parent 67f273a6d6
commit 57147d1b8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 0 deletions

View file

@ -1970,6 +1970,30 @@ describe('chromium features', () => {
});
});
// https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation
describe('navigator.connection', () => {
it('returns the correct value', async () => {
const w = new BrowserWindow({ show: false });
w.webContents.session.enableNetworkEmulation({
latency: 500,
downloadThroughput: 6400,
uploadThroughput: 6400
});
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const rtt = await w.webContents.executeJavaScript('navigator.connection.rtt');
expect(rtt).to.be.a('number');
const downlink = await w.webContents.executeJavaScript('navigator.connection.downlink');
expect(downlink).to.be.a('number');
const effectiveTypes = ['slow-2g', '2g', '3g', '4g'];
const effectiveType = await w.webContents.executeJavaScript('navigator.connection.effectiveType');
expect(effectiveTypes).to.include(effectiveType);
});
});
describe('navigator.userAgentData', () => {
// These tests are done on an http server because navigator.userAgentData
// requires a secure context.