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): extract storage and service worker driver methods #12400

Merged
merged 2 commits into from
Apr 26, 2021

Conversation

patrickhulce
Copy link
Collaborator

Summary
Splits out the storage and service worker bits from #12366 along with a couple of the super low value driver abstractions. Again the goal here is that FR-shared logic is refactored to accept a session instead of a driver. Ultimately everything left in driver.js and gather-runner.js should be specific to legacy flow with everything shared living elsewhere.

Related Issues/PRs
ref #11313 #12366

@patrickhulce patrickhulce requested a review from a team as a code owner April 23, 2021 21:46
@patrickhulce patrickhulce requested review from adamraine and removed request for a team April 23, 2021 21:46
@google-cla google-cla bot added the cla: yes label Apr 23, 2021
@@ -51,6 +52,9 @@ class ExecutionContext {
async _getOrCreateIsolatedContextId() {
if (typeof this._executionContextId === 'number') return this._executionContextId;

await this._session.sendCommand('Page.enable');
await this._session.sendCommand('Runtime.enable');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

before this dependency was an implicit global relationship, felt better to make it explicit.

});
}

module.exports = {getServiceWorkerVersions, getServiceWorkerRegistrations};
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nothing should be changed here

cleanBrowserCaches,
getImportantStorageWarning,
UIStrings,
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nothing should be different here either

* @param {string} pageUrl
* @return {Promise<void>}
*/
static assertNoSameOriginServiceWorkerClients(session, pageUrl) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I moved this here instead of service-workers because it's going to be specific to legacy flow and not shared. We can't assert this in FR where we'll be on the page without any about:blank in between.

Given our neutering of the PWA checks I'm not sure it really has much value for us today anyway.

const session = driver.defaultSession;

// Assert no service workers are still installed, so we test that they would actually be installed for a new user.
// TODO(FR-COMPAT): re-evaluate the necessity of this check
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

see above comment


// Enable `Debugger` domain to receive async stacktrace information on network request initiators.
// This is critical for tracing certain performance simulation situations.
session.on('Debugger.paused', () => session.sendCommand('Debugger.resume'));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this will be extracted along with the other shared driver setup in a future PR that focuses on gather-runner

jest.useRealTimers();
});

describe('.getServiceWorkerVersions', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

these weren't tested before 🎉

@@ -495,41 +596,6 @@ describe('GatherRunner', function() {
expect(artifacts.devtoolsLogs).toHaveProperty('pageLoadError-nextPass');
});

it('does not clear origin storage with flag --disable-storage-reset', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this test was moved next to the "clears origin storage" test

Copy link
Collaborator

@connorjclark connorjclark left a comment

Choose a reason for hiding this comment

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

LGTM

wdyt of async/await'ing the FR/shared code? The Promise chains are harder to read. followup/no is fine.

@patrickhulce
Copy link
Collaborator Author

patrickhulce commented Apr 26, 2021

wdyt of async/await'ing the FR/shared code?

Which methods did you have in mind? I agree the promise logic in service workers is hard to follow, but they're mostly event based which demand that structure (could remove a .catch(reject) or two in exchange for a try/catch if that's what you mean?)

Storage methods I believe are all async'd up already.

@connorjclark
Copy link
Collaborator

oh, the only offender was assertNoSameOriginServiceWorkerClients which is in gather-runner. nvm.

Copy link
Member

@adamraine adamraine left a comment

Choose a reason for hiding this comment

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

Overall LGTM

lighthouse-core/gather/gather-runner.js Outdated Show resolved Hide resolved
@@ -202,30 +202,6 @@ describe('.beginTrace', () => {
});
});

describe('.setExtraHTTPHeaders', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Are these tests moved to gather-runner-test.js?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no the methods have been eliminated, not moved, and so have the tests.

gather runner already had tests that the protocol methods were called correctly so we're good on that front 👍

Co-authored-by: Adam Raine <6752989+adamraine@users.noreply.github.com>
@patrickhulce patrickhulce merged commit d19b646 into master Apr 26, 2021
@patrickhulce patrickhulce deleted the fr_driver_namespacing branch April 26, 2021 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants