Skip to content

Commit

Permalink
Ignoring other extension assets in request compression audit (#2733)
Browse files Browse the repository at this point in the history
* Ignoring other extension assets in request compression audit

* Moved skipping extensions' assets to response compression gatherer

* Reverted schema param
  • Loading branch information
arturmiz authored and patrickhulce committed Jul 25, 2017
1 parent 934aa42 commit 428f637
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const Gatherer = require('../gatherer');
const gzip = require('zlib').gzip;

const compressionTypes = ['gzip', 'br', 'deflate'];
const CHROME_EXTENSION_PROTOCOL = 'chrome-extension:';

class ResponseCompression extends Gatherer {
/**
Expand All @@ -25,7 +26,10 @@ class ResponseCompression extends Gatherer {

networkRecords.forEach(record => {
const isTextBasedResource = record.resourceType() && record.resourceType().isTextType();
if (!isTextBasedResource || !record.resourceSize || !record.finished) {
const isChromeExtensionResource = record.url.startsWith(CHROME_EXTENSION_PROTOCOL);

if (!isTextBasedResource || !record.resourceSize || !record.finished ||
isChromeExtensionResource) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,43 @@ describe('Optimized responses', () => {
});
});

it('ignores responses from installed Chrome extensions', () => {
const traceData = {
networkRecords: [
{
_url: 'chrome-extension://index.css',
_mimeType: 'text/css',
_requestId: 1,
_resourceSize: 10,
_resourceType: {
_isTextType: true,
},
_responseHeaders: [],
content: 'aaaaaaaaaa',
finished: true,
},
{
_url: 'http://google.com/chrome-extension.css',
_mimeType: 'text/css',
_requestId: 1,
_resourceSize: 123,
_resourceType: {
_isTextType: true,
},
_responseHeaders: [],
content: 'aaaaaaaaaa',
finished: true,
}
]
};

return responseCompression.afterPass(options, createNetworkRequests(traceData))
.then(artifact => {
assert.equal(artifact.length, 1);
assert.equal(artifact[0].resourceSize, 123);
});
});

// Change into SDK.networkRequest when examples are ready
function createNetworkRequests(traceData) {
traceData.networkRecords = traceData.networkRecords.map(record => {
Expand Down

0 comments on commit 428f637

Please sign in to comment.