Skip to content

Commit

Permalink
core(driver): remove unused goOffline/goOnline methods (#12135)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Feb 26, 2021
1 parent a753350 commit 0daa1c3
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 145 deletions.
36 changes: 0 additions & 36 deletions lighthouse-core/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,6 @@ class Driver {
*/
_domainEnabledCounts = new Map();

/**
* Used for monitoring url redirects during gotoURL.
* @type {?string}
* @private
*/
_monitoredUrl = null;

/**
* Used for monitoring frame navigations during gotoURL.
* @type {Array<LH.Crdp.Page.Frame>}
* @private
*/
_monitoredUrlNavigations = [];

/**
* @type {number}
* @private
Expand Down Expand Up @@ -125,8 +111,6 @@ class Driver {
this.on('Target.attachedToTarget', event => {
this._handleTargetAttached(event).catch(this._handleEventError);
});

this.on('Page.frameNavigated', evt => this._monitoredUrlNavigations.push(evt.frame));
this.on('Debugger.paused', () => this.sendCommand('Debugger.resume'));

connection.on('protocolevent', this._handleProtocolEvent.bind(this));
Expand Down Expand Up @@ -805,26 +789,6 @@ class Driver {
await Promise.all([cpuPromise, networkPromise]);
}

/**
* Emulate internet disconnection.
* @return {Promise<void>}
*/
async goOffline() {
await this.sendCommand('Network.enable');
await emulation.goOffline(this);
this.online = false;
}

/**
* Enable internet connection, using emulated mobile settings if applicable.
* @param {{settings: LH.Config.Settings, passConfig: LH.Config.Pass}} options
* @return {Promise<void>}
*/
async goOnline(options) {
await this.setThrottling(options.settings, options.passConfig);
this.online = true;
}

/**
* Clear the network cache on disk and in memory.
* @return {Promise<void>}
Expand Down
17 changes: 0 additions & 17 deletions lighthouse-core/lib/emulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@

/** @typedef {import('../gather/driver.js')} Driver */

const OFFLINE_METRICS = {
offline: true,
// values of 0 remove any active throttling. crbug.com/456324#c9
latency: 0,
downloadThroughput: 0,
uploadThroughput: 0,
};

const NO_THROTTLING_METRICS = {
latency: 0,
downloadThroughput: 0,
Expand Down Expand Up @@ -80,14 +72,6 @@ function clearAllNetworkEmulation(driver) {
return driver.sendCommand('Network.emulateNetworkConditions', NO_THROTTLING_METRICS);
}

/**
* @param {Driver} driver
* @return {Promise<void>}
*/
function goOffline(driver) {
return driver.sendCommand('Network.emulateNetworkConditions', OFFLINE_METRICS);
}

/**
* @param {Driver} driver
* @param {Required<LH.ThrottlingSettings>} throttlingSettings
Expand All @@ -112,5 +96,4 @@ module.exports = {
clearAllNetworkEmulation,
enableCPUThrottling,
disableCPUThrottling,
goOffline,
};
92 changes: 0 additions & 92 deletions lighthouse-core/test/gather/driver-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jest.useFakeTimers();
* @property {ReturnType<typeof createMockOnceFn>} on
* @property {ReturnType<typeof createMockOnceFn>} once
* @property {(...args: RecursivePartial<Parameters<Driver['gotoURL']>>) => ReturnType<Driver['gotoURL']>} gotoURL
* @property {(...args: RecursivePartial<Parameters<Driver['goOnline']>>) => ReturnType<Driver['goOnline']>} goOnline
*/

/** @typedef {Omit<Driver, keyof DriverMockMethods> & DriverMockMethods} TestDriver */
Expand Down Expand Up @@ -227,24 +226,6 @@ describe('.setExtraHTTPHeaders', () => {
});
});

describe('.goOffline', () => {
it('should send offline emulation', async () => {
connectionStub.sendCommand = createMockSendCommandFn()
.mockResponse('Network.enable')
.mockResponse('Network.emulateNetworkConditions');

await driver.goOffline();
const emulateArgs = connectionStub.sendCommand
.findInvocation('Network.emulateNetworkConditions');
expect(emulateArgs).toEqual({
offline: true,
latency: 0,
downloadThroughput: 0,
uploadThroughput: 0,
});
});
});

describe('.gotoURL', () => {
beforeEach(() => {
connectionStub.sendCommand = createMockSendCommandFn()
Expand Down Expand Up @@ -453,79 +434,6 @@ describe('.assertNoSameOriginServiceWorkerClients', () => {
});
});

describe('.goOnline', () => {
beforeEach(() => {
connectionStub.sendCommand = createMockSendCommandFn()
.mockResponse('Network.enable')
.mockResponse('Emulation.setCPUThrottlingRate')
.mockResponse('Network.emulateNetworkConditions');
});

it('re-establishes previous throttling settings', async () => {
await driver.goOnline({
passConfig: {useThrottling: true},
settings: {
throttlingMethod: 'devtools',
throttling: {
requestLatencyMs: 500,
downloadThroughputKbps: 1000,
uploadThroughputKbps: 1000,
},
},
});

const emulateArgs = connectionStub.sendCommand
.findInvocation('Network.emulateNetworkConditions');
expect(emulateArgs).toEqual({
offline: false,
latency: 500,
downloadThroughput: (1000 * 1024) / 8,
uploadThroughput: (1000 * 1024) / 8,
});
});

it('clears network emulation when throttling is not devtools', async () => {
await driver.goOnline({
passConfig: {useThrottling: true},
settings: {
throttlingMethod: 'provided',
},
});

const emulateArgs = connectionStub.sendCommand
.findInvocation('Network.emulateNetworkConditions');
expect(emulateArgs).toEqual({
offline: false,
latency: 0,
downloadThroughput: 0,
uploadThroughput: 0,
});
});

it('clears network emulation when useThrottling is false', async () => {
await driver.goOnline({
passConfig: {useThrottling: false},
settings: {
throttlingMethod: 'devtools',
throttling: {
requestLatencyMs: 500,
downloadThroughputKbps: 1000,
uploadThroughputKbps: 1000,
},
},
});

const emulateArgs = connectionStub.sendCommand
.findInvocation('Network.emulateNetworkConditions');
expect(emulateArgs).toEqual({
offline: false,
latency: 0,
downloadThroughput: 0,
uploadThroughput: 0,
});
});
});

describe('.clearDataForOrigin', () => {
it('only clears data from certain locations', async () => {
let foundStorageTypes;
Expand Down

0 comments on commit 0daa1c3

Please sign in to comment.