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(fr): fix main-document-content #12632

Merged
merged 2 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions lighthouse-core/gather/driver/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ async function prepareNetworkForNavigation(session, settings, navigation) {
* @param {LH.Config.Settings} settings
*/
async function prepareTargetForNavigationMode(driver, settings) {
// Enable network domain here so future calls to `emulate()` don't clear cache (#12631)
driver.defaultSession.sendCommand('Network.enable');
adamraine marked this conversation as resolved.
Show resolved Hide resolved

// Emulate our target device screen and user agent.
await emulation.emulate(driver.defaultSession, settings);

Expand Down
2 changes: 0 additions & 2 deletions lighthouse-core/gather/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ class Fetcher {
* @return {Promise<{stream: LH.Crdp.IO.StreamHandle|null, status: number|null}>}
*/
async _loadNetworkResource(url) {
await this.session.sendCommand('Network.enable');
const frameTreeResponse = await this.session.sendCommand('Page.getFrameTree');
const networkResponse = await this.session.sendCommand('Network.loadNetworkResource', {
frameId: frameTreeResponse.frameTree.frame.id,
Expand All @@ -156,7 +155,6 @@ class Fetcher {
includeCredentials: true,
},
});
await this.session.sendCommand('Network.disable');

return {
stream: networkResponse.resource.success ? (networkResponse.resource.stream || null) : null,
Expand Down
2 changes: 0 additions & 2 deletions lighthouse-core/lib/emulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const NO_CPU_THROTTLE_METRICS = {
*/
async function emulate(session, settings) {
if (settings.emulatedUserAgent !== false) {
// Network.enable must be called for UA overriding to work
await session.sendCommand('Network.enable');
await session.sendCommand('Network.setUserAgentOverride', {
userAgent: /** @type {string} */ (settings.emulatedUserAgent),
});
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/fraggle-rock/api-test-pptr.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('Fraggle Rock API', () => {
const {auditResults, failedAudits, erroredAudits} = getAuditsBreakdown(lhr);
// TODO(FR-COMPAT): This assertion can be removed when full compatibility is reached.
expect(auditResults.length).toMatchInlineSnapshot(`151`);
expect(erroredAudits).toHaveLength(1); // FIXME: MainDocumentContent broken from merge
expect(erroredAudits).toHaveLength(0);

const failedAuditIds = failedAudits.map(audit => audit.id);
expect(failedAuditIds).toContain('label');
Expand Down
16 changes: 4 additions & 12 deletions lighthouse-core/test/gather/fetcher-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,51 +125,43 @@ describe('._fetchResourceOverProtocol', () => {

it('fetches a file', async () => {
connectionStub.sendCommand = createMockSendCommandFn()
.mockResponse('Network.enable')
.mockResponse('Page.getFrameTree', {frameTree: {frame: {id: 'FRAME'}}})
.mockResponse('Network.loadNetworkResource', {
resource: {success: true, httpStatusCode: 200, stream: '1'},
})
.mockResponse('Network.disable');
});

const data = await fetcher._fetchResourceOverProtocol('https://example.com', {timeout: 500});
expect(data).toEqual({content: streamContents, status: 200});
});

it('returns null when resource could not be fetched', async () => {
connectionStub.sendCommand = createMockSendCommandFn()
.mockResponse('Network.enable')
.mockResponse('Page.getFrameTree', {frameTree: {frame: {id: 'FRAME'}}})
.mockResponse('Network.loadNetworkResource', {
resource: {success: false, httpStatusCode: 404},
})
.mockResponse('Network.disable');
});

const data = await fetcher._fetchResourceOverProtocol('https://example.com', {timeout: 500});
expect(data).toEqual({content: null, status: 404});
});

it('throws on timeout', async () => {
connectionStub.sendCommand = createMockSendCommandFn()
.mockResponse('Network.enable')
.mockResponse('Page.getFrameTree', {frameTree: {frame: {id: 'FRAME'}}})
.mockResponse('Network.loadNetworkResource', {
resource: {success: false, httpStatusCode: 404},
}, 100)
.mockResponse('Network.disable');
}, 100);

const dataPromise = fetcher._fetchResourceOverProtocol('https://example.com', {timeout: 50});
await expect(dataPromise).rejects.toThrowError(/Timed out fetching resource/);
});

it('uses remaining time on _readIOStream', async () => {
connectionStub.sendCommand = createMockSendCommandFn()
.mockResponse('Network.enable')
.mockResponse('Page.getFrameTree', {frameTree: {frame: {id: 'FRAME'}}})
.mockResponse('Network.loadNetworkResource', {
resource: {success: true, httpStatusCode: 200, stream: '1'},
}, 500)
.mockResponse('Network.disable');
}, 500);

let timeout;
fetcher._readIOStream = jest.fn().mockImplementation((_, options) => {
Expand Down
1 change: 0 additions & 1 deletion lighthouse-core/test/lib/emulation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('emulation', () => {
driver = new Driver(connectionStub);

connectionStub.sendCommand = createMockSendCommandFn()
.mockResponse('Network.enable')
.mockResponse('Network.setUserAgentOverride')
.mockResponse('Emulation.setDeviceMetricsOverride')
.mockResponse('Emulation.setTouchEmulationEnabled');
Expand Down