Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(driver): remove unused goOffline/goOnline methods #12135

Merged
merged 2 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

@brendankenny brendankenny Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like the only tricky knowledge that could be lost if trying to recreate going offline at a later date, but based on that comment is it still true/useful today?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the immediate followup commit, it looks like future attempts should be fine with just offline: true.

If we ever need to find this again, we know the file to use git history on :)

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