Skip to content

Commit

Permalink
back by popular demand
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed May 21, 2019
1 parent 2a588d1 commit 99f1e15
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
15 changes: 10 additions & 5 deletions lighthouse-core/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1479,12 +1479,17 @@ class Driver {
* Clear the network cache on disk and in memory.
* @return {Promise<void>}
*/
cleanBrowserCaches() {
async cleanBrowserCaches() {
const status = {msg: 'Cleaning browser cache', id: 'lh:driver:cleanBrowserCaches'};
log.time(status);

// Wipe entire disk cache
return this.sendCommand('Network.clearBrowserCache')
// Toggle 'Disable Cache' to evict the memory cache
.then(_ => this.sendCommand('Network.setCacheDisabled', {cacheDisabled: true}))
.then(_ => this.sendCommand('Network.setCacheDisabled', {cacheDisabled: false}));
await this.sendCommand('Network.clearBrowserCache');
// Toggle 'Disable Cache' to evict the memory cache
await this.sendCommand('Network.setCacheDisabled', {cacheDisabled: true});
await this.sendCommand('Network.setCacheDisabled', {cacheDisabled: false});

log.timeEnd(status);
}

/**
Expand Down
14 changes: 12 additions & 2 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ class GatherRunner {
* @return {Promise<void>}
*/
static async setupPassNetwork(passContext) {
const status = {msg: 'Setting up network for the pass trace', id: `lh:gather:setupPassNetwork`};
log.time(status);

const passConfig = passContext.passConfig;
await passContext.driver.setThrottling(passContext.settings, passConfig);

Expand All @@ -189,6 +192,8 @@ class GatherRunner {
// neccessary at the beginning of the next pass.
await passContext.driver.blockUrlPatterns(blockedUrls);
await passContext.driver.setExtraHTTPHeaders(passContext.settings.extraHeaders);

log.timeEnd(status);
}

/**
Expand All @@ -197,6 +202,9 @@ class GatherRunner {
* @return {Promise<void>}
*/
static async beginRecording(passContext) {
const status = {msg: 'Beginning devtoolsLog and trace', id: 'lh:gather:beginRecording'};
log.time(status);

const {driver, passConfig, settings} = passContext;

// Always record devtoolsLog
Expand All @@ -205,6 +213,8 @@ class GatherRunner {
if (passConfig.recordTrace) {
await driver.beginTrace(settings);
}

log.timeEnd(status);
}

/**
Expand Down Expand Up @@ -400,7 +410,7 @@ class GatherRunner {
* @param {{driver: Driver, requestedUrl: string, settings: LH.Config.Settings}} options
* @return {Promise<LH.BaseArtifacts>}
*/
static async getBaseArtifacts(options) {
static async initializeBaseArtifacts(options) {
const hostUserAgent = (await options.driver.getBrowserVersion()).userAgent;

const {emulatedFormFactor} = options.settings;
Expand Down Expand Up @@ -502,7 +512,7 @@ class GatherRunner {
// So we first navigate to about:blank, then apply our emulation & setup
await GatherRunner.loadBlank(driver);

const baseArtifacts = await GatherRunner.getBaseArtifacts(options);
const baseArtifacts = await GatherRunner.initializeBaseArtifacts(options);
baseArtifacts.BenchmarkIndex = await options.driver.getBenchmarkIndex();

await GatherRunner.setupDriver(driver, options);
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/gather/gather-runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ describe('GatherRunner', function() {
driver,
passConfig,
settings,
baseArtifacts: await GatherRunner.getBaseArtifacts({driver, settings, requestedUrl}),
baseArtifacts: await GatherRunner.initializeBaseArtifacts({driver, settings, requestedUrl}),
};

await GatherRunner.runPass(passContext, {TestGatherer: []});
Expand Down

0 comments on commit 99f1e15

Please sign in to comment.