From 0aa1ece06d422cad225ce61c4d191be51ed46703 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Mon, 25 Jun 2018 16:32:10 -0700 Subject: [PATCH 1/4] core: remove WebInspector.resourceTypes references --- .../byte-efficiency/byte-efficiency-audit.js | 4 +- .../efficient-animated-content.js | 4 +- .../render-blocking-resources.js | 4 +- .../audits/byte-efficiency/unminified-css.js | 2 +- .../byte-efficiency/unminified-javascript.js | 2 +- .../byte-efficiency/unused-css-rules.js | 2 +- .../byte-efficiency/unused-javascript.js | 2 +- .../byte-efficiency/uses-long-cache-ttl.js | 14 +++---- lighthouse-core/audits/font-display.js | 4 +- lighthouse-core/audits/network-requests.js | 2 +- .../computed/critical-request-chains.js | 16 +++---- .../computed/metrics/lantern-interactive.js | 6 +-- .../gather/computed/metrics/lantern-metric.js | 4 +- .../gather/computed/page-dependency-graph.js | 4 +- .../gather/computed/trace-of-tab.js | 2 +- .../gatherers/dobetterweb/optimized-images.js | 2 +- .../dobetterweb/response-compression.js | 17 ++++++-- lighthouse-core/gather/gatherers/scripts.js | 4 +- .../lib/dependency-graph/network-node.js | 6 +-- .../simulator/network-analyzer.js | 4 +- lighthouse-core/lib/network-request.js | 30 ++++++++++--- lighthouse-core/lib/web-inspector.js | 2 - .../byte-efficiency-audit-test.js | 8 ++-- .../efficient-animated-content-test.js | 12 +++--- .../render-blocking-resources-test.js | 4 +- .../uses-long-cache-ttl-test.js | 6 +-- .../test/audits/font-display-test.js | 10 ++--- .../computed/critical-request-chains-test.js | 8 ++-- .../computed/page-dependency-graph-test.js | 12 +++--- .../dobetterweb/optimized-images-test.js | 18 ++++---- .../dobetterweb/response-compression-test.js | 42 ++++--------------- .../test/lib/network-recorder-test.js | 2 +- typings/web-inspector.d.ts | 2 +- 33 files changed, 132 insertions(+), 129 deletions(-) diff --git a/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js b/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js index 490a94f311b7..14eb83e4d730 100644 --- a/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js +++ b/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js @@ -70,7 +70,7 @@ class UnusedBytes extends Audit { * * @param {LH.WebInspector.NetworkRequest=} networkRecord * @param {number} totalBytes Uncompressed size of the resource - * @param {string=} resourceType + * @param {LH.Crdp.Page.ResourceType=} resourceType * @param {number=} compressionRatio * @return {number} */ @@ -80,7 +80,7 @@ class UnusedBytes extends Audit { // roughly the size of the content gzipped. // See https://discuss.httparchive.org/t/file-size-and-compression-savings/145 for multipliers return Math.round(totalBytes * compressionRatio); - } else if (networkRecord._resourceType && networkRecord._resourceType._name === resourceType) { + } else if (networkRecord._resourceType === resourceType) { // This was a regular standalone asset, just use the transfer size. return networkRecord.transferSize || 0; } else { diff --git a/lighthouse-core/audits/byte-efficiency/efficient-animated-content.js b/lighthouse-core/audits/byte-efficiency/efficient-animated-content.js index b55077ee2ec9..d349ed9fee00 100644 --- a/lighthouse-core/audits/byte-efficiency/efficient-animated-content.js +++ b/lighthouse-core/audits/byte-efficiency/efficient-animated-content.js @@ -8,7 +8,7 @@ */ 'use strict'; -const WebInspector = require('../../lib/web-inspector'); +const NetworkRequest = require('../../lib/network-request'); const ByteEfficiencyAudit = require('./byte-efficiency-audit'); // If GIFs are above this size, we'll flag them @@ -49,7 +49,7 @@ class EfficientAnimatedContent extends ByteEfficiencyAudit { static audit_(artifacts, networkRecords) { const unoptimizedContent = networkRecords.filter( record => record._mimeType === 'image/gif' && - record._resourceType === WebInspector.resourceTypes.Image && + record._resourceType === NetworkRequest.TYPES.Image && (record._resourceSize || 0) > GIF_BYTE_THRESHOLD ); diff --git a/lighthouse-core/audits/byte-efficiency/render-blocking-resources.js b/lighthouse-core/audits/byte-efficiency/render-blocking-resources.js index 0d3d651be588..9a8688b5e2d7 100644 --- a/lighthouse-core/audits/byte-efficiency/render-blocking-resources.js +++ b/lighthouse-core/audits/byte-efficiency/render-blocking-resources.js @@ -13,7 +13,7 @@ const Audit = require('../audit'); const Node = require('../../lib/dependency-graph/node'); const ByteEfficiencyAudit = require('./byte-efficiency-audit'); const UnusedCSS = require('./unused-css-rules'); -const WebInspector = require('../../lib/web-inspector'); +const NetworkRequest = require('../../lib/network-request'); const Simulator = require('../../lib/dependency-graph/simulator/simulator'); // eslint-disable-line no-unused-vars const NetworkNode = require('../../lib/dependency-graph/network-node.js'); // eslint-disable-line no-unused-vars @@ -154,7 +154,7 @@ class RenderBlockingResources extends Audit { const networkNode = /** @type {NetworkNode} */ (node); const isStylesheet = - networkNode.record._resourceType === WebInspector.resourceTypes.Stylesheet; + networkNode.record._resourceType === NetworkRequest.TYPES.Stylesheet; if (canDeferRequest && isStylesheet) { // We'll inline the used bytes of the stylesheet and assume the rest can be deferred const wastedBytes = wastedCssBytesByUrl.get(networkNode.record.url) || 0; diff --git a/lighthouse-core/audits/byte-efficiency/unminified-css.js b/lighthouse-core/audits/byte-efficiency/unminified-css.js index f8a3b8bb6d77..05903d904fcf 100644 --- a/lighthouse-core/audits/byte-efficiency/unminified-css.js +++ b/lighthouse-core/audits/byte-efficiency/unminified-css.js @@ -107,7 +107,7 @@ class UnminifiedCSS extends ByteEfficiencyAudit { } const totalBytes = ByteEfficiencyAudit.estimateTransferSize(networkRecord, content.length, - 'stylesheet'); + 'Stylesheet'); const wastedRatio = 1 - totalTokenLength / content.length; const wastedBytes = Math.round(totalBytes * wastedRatio); diff --git a/lighthouse-core/audits/byte-efficiency/unminified-javascript.js b/lighthouse-core/audits/byte-efficiency/unminified-javascript.js index 45b7a7e04ac5..27544965e019 100644 --- a/lighthouse-core/audits/byte-efficiency/unminified-javascript.js +++ b/lighthouse-core/audits/byte-efficiency/unminified-javascript.js @@ -57,7 +57,7 @@ class UnminifiedJavaScript extends ByteEfficiencyAudit { } const totalBytes = ByteEfficiencyAudit.estimateTransferSize(networkRecord, contentLength, - 'script'); + 'Script'); const wastedRatio = 1 - totalTokenLength / contentLength; const wastedBytes = Math.round(totalBytes * wastedRatio); diff --git a/lighthouse-core/audits/byte-efficiency/unused-css-rules.js b/lighthouse-core/audits/byte-efficiency/unused-css-rules.js index 3e7520da32f1..00ff4d6008e7 100644 --- a/lighthouse-core/audits/byte-efficiency/unused-css-rules.js +++ b/lighthouse-core/audits/byte-efficiency/unused-css-rules.js @@ -81,7 +81,7 @@ class UnusedCSSRules extends ByteEfficiencyAudit { } const totalTransferredBytes = ByteEfficiencyAudit.estimateTransferSize( - stylesheetInfo.networkRecord, totalUncompressedBytes, 'stylesheet'); + stylesheetInfo.networkRecord, totalUncompressedBytes, 'Stylesheet'); const percentUnused = (totalUncompressedBytes - usedUncompressedBytes) / totalUncompressedBytes; const wastedBytes = Math.round(percentUnused * totalTransferredBytes); diff --git a/lighthouse-core/audits/byte-efficiency/unused-javascript.js b/lighthouse-core/audits/byte-efficiency/unused-javascript.js index 78d1115f3500..39d7159f841b 100644 --- a/lighthouse-core/audits/byte-efficiency/unused-javascript.js +++ b/lighthouse-core/audits/byte-efficiency/unused-javascript.js @@ -73,7 +73,7 @@ class UnusedJavaScript extends ByteEfficiencyAudit { } const totalBytes = ByteEfficiencyAudit.estimateTransferSize(networkRecord, contentLength, - 'script'); + 'Script'); const wastedRatio = (unusedLength / contentLength) || 0; const wastedBytes = Math.round(totalBytes * wastedRatio); diff --git a/lighthouse-core/audits/byte-efficiency/uses-long-cache-ttl.js b/lighthouse-core/audits/byte-efficiency/uses-long-cache-ttl.js index ca3e9c60cfca..9a7085145f3f 100644 --- a/lighthouse-core/audits/byte-efficiency/uses-long-cache-ttl.js +++ b/lighthouse-core/audits/byte-efficiency/uses-long-cache-ttl.js @@ -9,7 +9,7 @@ const assert = require('assert'); // @ts-ignore - typed where used. const parseCacheControl = require('parse-cache-control'); const Audit = require('../audit'); -const WebInspector = require('../../lib/web-inspector'); +const NetworkRequest = require('../../lib/network-request'); const URL = require('../../lib/url-shim'); const linearInterpolation = require('../../lib/statistics').linearInterpolation; @@ -135,17 +135,17 @@ class CacheHeaders extends Audit { const CACHEABLE_STATUS_CODES = new Set([200, 203, 206]); const STATIC_RESOURCE_TYPES = new Set([ - WebInspector.resourceTypes.Font, - WebInspector.resourceTypes.Image, - WebInspector.resourceTypes.Media, - WebInspector.resourceTypes.Script, - WebInspector.resourceTypes.Stylesheet, + NetworkRequest.TYPES.Font, + NetworkRequest.TYPES.Image, + NetworkRequest.TYPES.Media, + NetworkRequest.TYPES.Script, + NetworkRequest.TYPES.Stylesheet, ]); const resourceUrl = record._url; return ( CACHEABLE_STATUS_CODES.has(record.statusCode) && - STATIC_RESOURCE_TYPES.has(record._resourceType) && + STATIC_RESOURCE_TYPES.has(record._resourceType || 'Other') && !resourceUrl.includes('data:') ); } diff --git a/lighthouse-core/audits/font-display.js b/lighthouse-core/audits/font-display.js index 7fababa112aa..f649f1298874 100644 --- a/lighthouse-core/audits/font-display.js +++ b/lighthouse-core/audits/font-display.js @@ -6,7 +6,7 @@ 'use strict'; const Audit = require('./audit'); -const WebInspector = require('../lib/web-inspector'); +const NetworkRequest = require('../lib/network-request'); const allowedFontFaceDisplays = ['block', 'fallback', 'optional', 'swap']; class FontDisplay extends Audit { @@ -40,7 +40,7 @@ class FontDisplay extends Audit { return artifacts.requestNetworkRecords(devtoolsLogs).then((networkRecords) => { const results = networkRecords.filter(record => { - const isFont = record._resourceType === WebInspector.resourceTypes.Font; + const isFont = record._resourceType === NetworkRequest.TYPES.Font; return isFont; }) diff --git a/lighthouse-core/audits/network-requests.js b/lighthouse-core/audits/network-requests.js index 194f37d5b8ed..d1ea28578c4c 100644 --- a/lighthouse-core/audits/network-requests.js +++ b/lighthouse-core/audits/network-requests.js @@ -46,7 +46,7 @@ class NetworkRequests extends Audit { transferSize: record.transferSize, statusCode: record.statusCode, mimeType: record._mimeType, - resourceType: record._resourceType && record._resourceType._name, + resourceType: record._resourceType, }; }); diff --git a/lighthouse-core/gather/computed/critical-request-chains.js b/lighthouse-core/gather/computed/critical-request-chains.js index addf6658a123..893f334ec35e 100644 --- a/lighthouse-core/gather/computed/critical-request-chains.js +++ b/lighthouse-core/gather/computed/critical-request-chains.js @@ -6,7 +6,7 @@ 'use strict'; const ComputedArtifact = require('./computed-artifact'); -const WebInspector = require('../../lib/web-inspector'); +const NetworkRequest = require('../../lib/network-request'); const assert = require('assert'); class CriticalRequestChains extends ComputedArtifact { @@ -30,19 +30,19 @@ class CriticalRequestChains extends ComputedArtifact { return false; } - const resourceTypeCategory = request._resourceType && request._resourceType._category; - // Iframes are considered High Priority but they are not render blocking - const isIframe = request._resourceType === WebInspector.resourceTypes.Document + const isIframe = request._resourceType === NetworkRequest.TYPES.Document && request._frameId !== mainResource._frameId; // XHRs are fetched at High priority, but we exclude them, as they are unlikely to be critical // Images are also non-critical. - // Treat any images missed by category, primarily favicons, as non-critical resources + // Treat any missed images, primarily favicons, as non-critical resources const nonCriticalResourceTypes = [ - WebInspector.resourceTypes.Image._category, - WebInspector.resourceTypes.XHR._category, + NetworkRequest.TYPES.Image, + NetworkRequest.TYPES.XHR, + NetworkRequest.TYPES.Fetch, + NetworkRequest.TYPES.EventSource, ]; - if (nonCriticalResourceTypes.includes(resourceTypeCategory) || + if (nonCriticalResourceTypes.includes(request._resourceType || 'Other') || isIframe || request._mimeType && request._mimeType.startsWith('image/')) { return false; diff --git a/lighthouse-core/gather/computed/metrics/lantern-interactive.js b/lighthouse-core/gather/computed/metrics/lantern-interactive.js index 47c99f3316c1..6b7d43e79928 100644 --- a/lighthouse-core/gather/computed/metrics/lantern-interactive.js +++ b/lighthouse-core/gather/computed/metrics/lantern-interactive.js @@ -9,7 +9,7 @@ const MetricArtifact = require('./lantern-metric'); const Node = require('../../../lib/dependency-graph/node'); const CPUNode = require('../../../lib/dependency-graph/cpu-node'); // eslint-disable-line no-unused-vars const NetworkNode = require('../../../lib/dependency-graph/network-node'); // eslint-disable-line no-unused-vars -const WebInspector = require('../../../lib/web-inspector'); +const NetworkRequest = require('../../../lib/network-request'); // Any CPU task of 20 ms or more will end up being a critical long task on mobile const CRITICAL_LONG_TASK_THRESHOLD = 20; @@ -46,8 +46,8 @@ class Interactive extends MetricArtifact { const asNetworkNode = /** @type {NetworkNode} */ (node); // Include all scripts and high priority requests, exclude all images - const isImage = asNetworkNode.record._resourceType === WebInspector.resourceTypes.Image; - const isScript = asNetworkNode.record._resourceType === WebInspector.resourceTypes.Script; + const isImage = asNetworkNode.record._resourceType === NetworkRequest.TYPES.Image; + const isScript = asNetworkNode.record._resourceType === NetworkRequest.TYPES.Script; return ( !isImage && (isScript || diff --git a/lighthouse-core/gather/computed/metrics/lantern-metric.js b/lighthouse-core/gather/computed/metrics/lantern-metric.js index 19f49611febc..0476e354cb45 100644 --- a/lighthouse-core/gather/computed/metrics/lantern-metric.js +++ b/lighthouse-core/gather/computed/metrics/lantern-metric.js @@ -9,7 +9,7 @@ const ComputedArtifact = require('../computed-artifact'); const Node = require('../../../lib/dependency-graph/node'); const NetworkNode = require('../../../lib/dependency-graph/network-node'); // eslint-disable-line no-unused-vars const Simulator = require('../../../lib/dependency-graph/simulator/simulator'); // eslint-disable-line no-unused-vars -const WebInspector = require('../../../lib/web-inspector'); +const NetworkRequest = require('../../../lib/network-request'); class LanternMetricArtifact extends ComputedArtifact { /** @@ -23,7 +23,7 @@ class LanternMetricArtifact extends ComputedArtifact { dependencyGraph.traverse(node => { if (node.type === Node.TYPES.CPU) return; const asNetworkNode = /** @type {NetworkNode} */ (node); - if (asNetworkNode.record._resourceType !== WebInspector.resourceTypes.Script) return; + if (asNetworkNode.record._resourceType !== NetworkRequest.TYPES.Script) return; if (condition && !condition(asNetworkNode)) return; scriptUrls.add(asNetworkNode.record.url); }); diff --git a/lighthouse-core/gather/computed/page-dependency-graph.js b/lighthouse-core/gather/computed/page-dependency-graph.js index 90ed45b113e0..2a733f6e8c8e 100644 --- a/lighthouse-core/gather/computed/page-dependency-graph.js +++ b/lighthouse-core/gather/computed/page-dependency-graph.js @@ -10,7 +10,7 @@ const NetworkNode = require('../../lib/dependency-graph/network-node'); const CPUNode = require('../../lib/dependency-graph/cpu-node'); const NetworkAnalyzer = require('../../lib/dependency-graph/simulator/network-analyzer'); const TracingProcessor = require('../../lib/traces/tracing-processor'); -const WebInspector = require('../../lib/web-inspector'); +const NetworkRequest = require('../../lib/network-request'); const Node = require('../../lib/dependency-graph/node.js'); // eslint-disable-line no-unused-vars @@ -155,7 +155,7 @@ class PageDependencyGraphArtifact extends ComputedArtifact { const networkNode = networkNodeOutput.idToNodeMap.get(reqId); if (!networkNode || // Ignore all non-XHRs - networkNode.record._resourceType !== WebInspector.resourceTypes.XHR || + networkNode.record._resourceType !== NetworkRequest.TYPES.XHR || // Ignore all network nodes that started before this CPU task started // A network request that started earlier could not possibly have been started by this task networkNode.startTime <= cpuNode.startTime) return; diff --git a/lighthouse-core/gather/computed/trace-of-tab.js b/lighthouse-core/gather/computed/trace-of-tab.js index ec9da3425738..696c6fbe470a 100644 --- a/lighthouse-core/gather/computed/trace-of-tab.js +++ b/lighthouse-core/gather/computed/trace-of-tab.js @@ -25,7 +25,7 @@ const Sentry = require('../../lib/sentry'); // Bring in web-inspector for side effect of adding [].stableSort // See https://github.com/GoogleChrome/lighthouse/pull/2415 // eslint-disable-next-line no-unused-vars -const WebInspector = require('../../lib/web-inspector'); +const NetworkRequest = require('../../lib/network-request'); class TraceOfTab extends ComputedArtifact { get name() { diff --git a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js index e245ca9c415d..d93138339c62 100644 --- a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js +++ b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js @@ -86,7 +86,7 @@ class OptimizedImages extends Gatherer { seenUrls.add(record._url); const isOptimizableImage = record._resourceType && - record._resourceType._name === 'image' && + record._resourceType === 'Image' && /image\/(png|bmp|jpeg)/.test(record._mimeType); const isSameOrigin = URL.originsMatch(pageUrl, record._url); const isBase64DataUri = /^data:.{2,40}base64\s*,/.test(record._url); diff --git a/lighthouse-core/gather/gatherers/dobetterweb/response-compression.js b/lighthouse-core/gather/gatherers/dobetterweb/response-compression.js index 49a6930e033f..ad13c32b2307 100644 --- a/lighthouse-core/gather/gatherers/dobetterweb/response-compression.js +++ b/lighthouse-core/gather/gatherers/dobetterweb/response-compression.js @@ -11,12 +11,21 @@ 'use strict'; const Gatherer = require('../gatherer'); +const NetworkRequest = require('../../../lib/network-request'); const gzip = require('zlib').gzip; +const CHROME_EXTENSION_PROTOCOL = 'chrome-extension:'; const compressionHeaders = ['content-encoding', 'x-original-content-encoding']; const compressionTypes = ['gzip', 'br', 'deflate']; const binaryMimeTypes = ['image', 'audio', 'video']; -const CHROME_EXTENSION_PROTOCOL = 'chrome-extension:'; +const textResourceTypes = [ + NetworkRequest.TYPES.Document, + NetworkRequest.TYPES.Script, + NetworkRequest.TYPES.Stylesheet, + NetworkRequest.TYPES.XHR, + NetworkRequest.TYPES.Fetch, + NetworkRequest.TYPES.EventSource, +]; class ResponseCompression extends Gatherer { /** @@ -29,14 +38,14 @@ class ResponseCompression extends Gatherer { networkRecords.forEach(record => { const mimeType = record._mimeType; - const resourceType = record._resourceType; + const resourceType = record._resourceType || NetworkRequest.TYPES.Other; const resourceSize = record._resourceSize; const isBinaryResource = mimeType && binaryMimeTypes.some(type => mimeType.startsWith(type)); - const isTextBasedResource = !isBinaryResource && resourceType && resourceType.isTextType(); + const isTextResource = !isBinaryResource && textResourceTypes.includes(resourceType); const isChromeExtensionResource = record.url.startsWith(CHROME_EXTENSION_PROTOCOL); - if (!isTextBasedResource || !resourceSize || !record.finished || + if (!isTextResource || !resourceSize || !record.finished || isChromeExtensionResource || !record.transferSize || record.statusCode === 304) { return; } diff --git a/lighthouse-core/gather/gatherers/scripts.js b/lighthouse-core/gather/gatherers/scripts.js index d38b10fbe2a6..3cf119c9e9fe 100644 --- a/lighthouse-core/gather/gatherers/scripts.js +++ b/lighthouse-core/gather/gatherers/scripts.js @@ -6,7 +6,7 @@ 'use strict'; const Gatherer = require('./gatherer'); -const WebInspector = require('../../lib/web-inspector'); +const NetworkRequest = require('../../lib/network-request'); /** * @fileoverview Gets JavaScript file contents. @@ -23,7 +23,7 @@ class Scripts extends Gatherer { /** @type {Object} */ const scriptContentMap = {}; const scriptRecords = loadData.networkRecords - .filter(record => record._resourceType === WebInspector.resourceTypes.Script); + .filter(record => record._resourceType === NetworkRequest.TYPES.Script); for (const record of scriptRecords) { try { diff --git a/lighthouse-core/lib/dependency-graph/network-node.js b/lighthouse-core/lib/dependency-graph/network-node.js index 1a21f2e6d57a..8396ebf9d3be 100644 --- a/lighthouse-core/lib/dependency-graph/network-node.js +++ b/lighthouse-core/lib/dependency-graph/network-node.js @@ -6,7 +6,7 @@ 'use strict'; const Node = require('./node'); -const WebInspector = require('../web-inspector'); +const NetworkRequest = require('../network-request'); class NetworkNode extends Node { /** @@ -64,8 +64,8 @@ class NetworkNode extends Node { */ hasRenderBlockingPriority() { const priority = this._record.priority(); - const isScript = this._record._resourceType === WebInspector.resourceTypes.Script; - const isDocument = this._record._resourceType === WebInspector.resourceTypes.Document; + const isScript = this._record._resourceType === NetworkRequest.TYPES.Script; + const isDocument = this._record._resourceType === NetworkRequest.TYPES.Document; const isBlockingScript = priority === 'High' && isScript; const isBlockingHtmlImport = priority === 'High' && isDocument; return priority === 'VeryHigh' || isBlockingScript || isBlockingHtmlImport; diff --git a/lighthouse-core/lib/dependency-graph/simulator/network-analyzer.js b/lighthouse-core/lib/dependency-graph/simulator/network-analyzer.js index c271347959bd..5b400c4e331f 100644 --- a/lighthouse-core/lib/dependency-graph/simulator/network-analyzer.js +++ b/lighthouse-core/lib/dependency-graph/simulator/network-analyzer.js @@ -6,7 +6,7 @@ 'use strict'; const INITIAL_CWD = 14 * 1024; -const WebInspector = require('../../web-inspector'); +const NetworkRequest = require('../../network-request'); class NetworkAnalyzer { /** @@ -328,7 +328,7 @@ class NetworkAnalyzer { static findMainDocument(records) { // TODO(phulce): handle more edge cases like client redirects, or plumb through finalUrl const documentRequests = records.filter(record => record._resourceType === - WebInspector.resourceTypes.Document); + NetworkRequest.TYPES.Document); return documentRequests.sort((a, b) => a.startTime - b.startTime)[0]; } } diff --git a/lighthouse-core/lib/network-request.js b/lighthouse-core/lib/network-request.js index 2116101902c6..42926ad31d0d 100644 --- a/lighthouse-core/lib/network-request.js +++ b/lighthouse-core/lib/network-request.js @@ -12,10 +12,26 @@ */ const URL = require('./url-shim'); -const ResourceType = require('../../third-party/devtools/ResourceType'); const SECURE_SCHEMES = ['data', 'https', 'wss', 'blob', 'chrome', 'chrome-extension', 'about']; +/** @type {Record} */ +const RESOURCE_TYPES = { + XHR: 'XHR', + Fetch: 'Fetch', + EventSource: 'EventSource', + Script: 'Script', + Stylesheet: 'Stylesheet', + Image: 'Image', + Media: 'Media', + Font: 'Font', + Document: 'Document', + TextTrack: 'TextTrack', + WebSocket: 'WebSocket', + Other: 'Other', + Manifest: 'Manifest', +}; + module.exports = class NetworkRequest { constructor() { this.requestId = ''; @@ -57,7 +73,7 @@ module.exports = class NetworkRequest { this._initiator = /** @type {LH.Crdp.Network.Initiator} */ ({type: 'other'}); /** @type {LH.Crdp.Network.ResourceTiming|undefined} */ this._timing = undefined; - /** @type {ResourceType|undefined} */ + /** @type {LH.Crdp.Page.ResourceType|undefined} */ this._resourceType = undefined; this._mimeType = ''; this.priority = () => /** @type {LH.Crdp.Network.ResourcePriority} */ ('Low'); @@ -107,7 +123,7 @@ module.exports = class NetworkRequest { this.requestMethod = data.request.method; this._initiator = data.initiator; - this._resourceType = data.type && ResourceType.TYPES[data.type]; + this._resourceType = data.type && RESOURCE_TYPES[data.type]; this.priority = () => data.request.initialPriority; this._frameId = data.frameId; @@ -163,7 +179,7 @@ module.exports = class NetworkRequest { this.endTime = data.timestamp; this.failed = true; - this._resourceType = data.type && ResourceType.TYPES[data.type]; + this._resourceType = data.type && RESOURCE_TYPES[data.type]; this.localizedFailDescription = data.errorText; this._updateResponseReceivedTimeIfNecessary(); @@ -211,7 +227,7 @@ module.exports = class NetworkRequest { this.statusCode = response.status; this._timing = response.timing; - if (resourceType) this._resourceType = ResourceType.TYPES[resourceType]; + if (resourceType) this._resourceType = RESOURCE_TYPES[resourceType]; this._mimeType = response.mimeType; this._responseHeaders = NetworkRequest._headersDictToHeadersArray(response.headers); @@ -264,4 +280,8 @@ module.exports = class NetworkRequest { } return result; } + + static get TYPES() { + return RESOURCE_TYPES; + } }; diff --git a/lighthouse-core/lib/web-inspector.js b/lighthouse-core/lib/web-inspector.js index 8375a4647206..d38ef458421a 100644 --- a/lighthouse-core/lib/web-inspector.js +++ b/lighthouse-core/lib/web-inspector.js @@ -194,7 +194,5 @@ module.exports = (function() { // Restore setImmediate, see comment at top. global.setImmediate = _setImmediate; - // TODO(phulce): replace client requires to not need this - WebInspector.resourceTypes = require('../../third-party/devtools/ResourceType').TYPES; return WebInspector; })(); diff --git a/lighthouse-core/test/audits/byte-efficiency/byte-efficiency-audit-test.js b/lighthouse-core/test/audits/byte-efficiency/byte-efficiency-audit-test.js index b1db444c1a0d..0d48d413acb2 100644 --- a/lighthouse-core/test/audits/byte-efficiency/byte-efficiency-audit-test.js +++ b/lighthouse-core/test/audits/byte-efficiency/byte-efficiency-audit-test.js @@ -57,19 +57,19 @@ describe('Byte efficiency base audit', () => { }); it('should return transferSize when asset matches', () => { - const _resourceType = {_name: 'stylesheet'}; - const result = estimate({transferSize: 1234, _resourceType}, 10000, 'stylesheet'); + const _resourceType = 'Stylesheet'; + const result = estimate({transferSize: 1234, _resourceType}, 10000, 'Stylesheet'); assert.equal(result, 1234); }); it('should estimate by network compression ratio when asset does not match', () => { - const _resourceType = {_name: 'other'}; + const _resourceType = 'Other'; const result = estimate({_resourceSize: 2000, transferSize: 1000, _resourceType}, 100); assert.equal(result, 50); }); it('should not error when missing resource size', () => { - const _resourceType = {_name: 'other'}; + const _resourceType = 'Other'; const result = estimate({transferSize: 1000, _resourceType}, 100); assert.equal(result, 100); }); diff --git a/lighthouse-core/test/audits/byte-efficiency/efficient-animated-content-test.js b/lighthouse-core/test/audits/byte-efficiency/efficient-animated-content-test.js index f2b727c0e6fd..3d7e2bfa67bd 100644 --- a/lighthouse-core/test/audits/byte-efficiency/efficient-animated-content-test.js +++ b/lighthouse-core/test/audits/byte-efficiency/efficient-animated-content-test.js @@ -8,20 +8,20 @@ /* eslint-env mocha */ const EfficientAnimatedContent = require('../../../audits/byte-efficiency/efficient-animated-content'); -const WebInspector = require('../../../lib/web-inspector'); +const NetworkRequest = require('../../../lib/network-request'); const assert = require('assert'); describe('Page uses videos for animated GIFs', () => { it('should flag gifs above 100kb as unoptimized', async () => { const networkRecords = [ { - _resourceType: WebInspector.resourceTypes.Image, + _resourceType: NetworkRequest.TYPES.Image, _mimeType: 'image/gif', _resourceSize: 100240, url: 'https://example.com/example.gif', }, { - _resourceType: WebInspector.resourceTypes.Image, + _resourceType: NetworkRequest.TYPES.Image, _mimeType: 'image/gif', _resourceSize: 110000, url: 'https://example.com/example2.gif', @@ -42,7 +42,7 @@ describe('Page uses videos for animated GIFs', () => { const networkRecords = [ { mimeType: 'image/gif', - _resourceType: WebInspector.resourceTypes.Media, + _resourceType: NetworkRequest.TYPES.Media, resourceSize: 150000, }, ]; @@ -57,12 +57,12 @@ describe('Page uses videos for animated GIFs', () => { it(`shouldn't flag non gif content`, async () => { const networkRecords = [ { - _resourceType: WebInspector.resourceTypes.Document, + _resourceType: NetworkRequest.TYPES.Document, mimeType: 'text/html', resourceSize: 150000, }, { - _resourceType: WebInspector.resourceTypes.Stylesheet, + _resourceType: NetworkRequest.TYPES.Stylesheet, mimeType: 'text/css', resourceSize: 150000, }, diff --git a/lighthouse-core/test/audits/byte-efficiency/render-blocking-resources-test.js b/lighthouse-core/test/audits/byte-efficiency/render-blocking-resources-test.js index c3b529947f15..abced68c49b7 100644 --- a/lighthouse-core/test/audits/byte-efficiency/render-blocking-resources-test.js +++ b/lighthouse-core/test/audits/byte-efficiency/render-blocking-resources-test.js @@ -12,7 +12,7 @@ const Runner = require('../../../runner'); const NetworkNode = require('../../../lib/dependency-graph/network-node'); const CPUNode = require('../../../lib/dependency-graph/cpu-node'); const Simulator = require('../../../lib/dependency-graph/simulator/simulator'); -const WebInspector = require('../../../lib/web-inspector'); +const NetworkRequest = require('../../../lib/network-request'); const assert = require('assert'); const trace = require('../../fixtures/traces/progressive-app-m60.json'); @@ -80,7 +80,7 @@ describe('Render blocking resources audit', () => { const simulator = new Simulator({rtt: 1000, serverResponseTimeByOrigin}); const documentNode = new NetworkNode(record({transferSize: 10 * 1000})); const styleNode = new NetworkNode( - record({transferSize: 23 * 1000, _resourceType: WebInspector.resourceTypes.Stylesheet}) + record({transferSize: 23 * 1000, _resourceType: NetworkRequest.TYPES.Stylesheet}) ); // pushes document over 14KB const deferredIds = new Set([2]); const wastedBytesMap = new Map([[undefined, 18 * 1000]]); diff --git a/lighthouse-core/test/audits/byte-efficiency/uses-long-cache-ttl-test.js b/lighthouse-core/test/audits/byte-efficiency/uses-long-cache-ttl-test.js index 431341858a31..046f36dc681b 100644 --- a/lighthouse-core/test/audits/byte-efficiency/uses-long-cache-ttl-test.js +++ b/lighthouse-core/test/audits/byte-efficiency/uses-long-cache-ttl-test.js @@ -7,7 +7,7 @@ const CacheHeadersAudit = require('../../../audits/byte-efficiency/uses-long-cache-ttl.js'); const assert = require('assert'); -const WebInspector = require('../../../lib/web-inspector'); +const NetworkRequest = require('../../../lib/network-request'); const options = CacheHeadersAudit.defaultOptions; /* eslint-env mocha */ @@ -21,7 +21,7 @@ function networkRecord(options = {}) { return { _url: options.url || 'https://example.com/asset', statusCode: options.statusCode || 200, - _resourceType: options.resourceType || WebInspector.resourceTypes.Script, + _resourceType: options.resourceType || NetworkRequest.TYPES.Script, transferSize: options.transferSize || 10000, _responseHeaders: headers, }; @@ -152,7 +152,7 @@ describe('Cache headers audit', () => { networkRecord({statusCode: 500}), networkRecord({url: 'https://example.com/dynamic.js?userId=crazy', transferSize: 10}), networkRecord({url: 'data:image/jpeg;base64,what'}), - networkRecord({resourceType: WebInspector.resourceTypes.XHR}), + networkRecord({resourceType: NetworkRequest.TYPES.XHR}), ]; return CacheHeadersAudit.audit(artifacts, {options}).then(result => { diff --git a/lighthouse-core/test/audits/font-display-test.js b/lighthouse-core/test/audits/font-display-test.js index 4c4f97cb3fc5..667b5927612a 100644 --- a/lighthouse-core/test/audits/font-display-test.js +++ b/lighthouse-core/test/audits/font-display-test.js @@ -5,7 +5,7 @@ */ 'use strict'; -const WebInspector = require('../../lib/web-inspector'); +const NetworkRequest = require('../../lib/network-request'); const Audit = require('../../audits/font-display.js'); const assert = require('assert'); @@ -51,12 +51,12 @@ describe('Performance: Font Display audit', () => { { url: openSansFont.src[0], endTime: 3, startTime: 1, - _resourceType: WebInspector.resourceTypes.Font, + _resourceType: NetworkRequest.TYPES.Font, }, { url: openSansFontBold.src[0], endTime: 3, startTime: 1, - _resourceType: WebInspector.resourceTypes.Font, + _resourceType: NetworkRequest.TYPES.Font, }, ], webFonts)).then(result => { const items = [{ @@ -78,12 +78,12 @@ describe('Performance: Font Display audit', () => { { url: openSansFont.src[0], endTime: 3, startTime: 1, - _resourceType: WebInspector.resourceTypes.Font, + _resourceType: NetworkRequest.TYPES.Font, }, { url: openSansFontBold.src[0], endTime: 3, startTime: 1, - _resourceType: WebInspector.resourceTypes.Font, + _resourceType: NetworkRequest.TYPES.Font, }, ], webFonts)).then(result => { assert.strictEqual(result.rawValue, true); diff --git a/lighthouse-core/test/gather/computed/critical-request-chains-test.js b/lighthouse-core/test/gather/computed/critical-request-chains-test.js index 3da32f1d4c63..c7dd095dc88a 100644 --- a/lighthouse-core/test/gather/computed/critical-request-chains-test.js +++ b/lighthouse-core/test/gather/computed/critical-request-chains-test.js @@ -9,7 +9,7 @@ const assert = require('assert'); const CriticalRequestChains = require('../../../gather/computed/critical-request-chains'); -const WebInspector = require('../../../lib/web-inspector'); +const NetworkRequest = require('../../../lib/network-request'); const Runner = require('../../../runner.js'); const HIGH = 'High'; @@ -316,16 +316,16 @@ describe('CriticalRequestChain gatherer: extractChain function', () => { // 1th record is the root document networkRecords[0]._url = 'https://example.com'; networkRecords[0]._mimeType = 'text/html'; - networkRecords[0]._resourceType = WebInspector.resourceTypes.Document; + networkRecords[0]._resourceType = NetworkRequest.TYPES.Document; // 2nd record is an iframe in the page networkRecords[1]._url = 'https://example.com/iframe.html'; networkRecords[1]._mimeType = 'text/html'; - networkRecords[1]._resourceType = WebInspector.resourceTypes.Document; + networkRecords[1]._resourceType = NetworkRequest.TYPES.Document; networkRecords[1]._frameId = '2'; // 3rd record is an iframe loaded by a script networkRecords[2]._url = 'https://youtube.com/'; networkRecords[2]._mimeType = 'text/html'; - networkRecords[2]._resourceType = WebInspector.resourceTypes.Document; + networkRecords[2]._resourceType = NetworkRequest.TYPES.Document; networkRecords[2]._frameId = '3'; const criticalChains = CriticalRequestChains.extractChain(networkRecords, mainResource); diff --git a/lighthouse-core/test/gather/computed/page-dependency-graph-test.js b/lighthouse-core/test/gather/computed/page-dependency-graph-test.js index 24c51555b6ea..8e850eff074d 100644 --- a/lighthouse-core/test/gather/computed/page-dependency-graph-test.js +++ b/lighthouse-core/test/gather/computed/page-dependency-graph-test.js @@ -8,7 +8,7 @@ const PageDependencyGraph = require('../../../gather/computed/page-dependency-graph'); const Node = require('../../../lib/dependency-graph/node'); const Runner = require('../../../runner.js'); -const WebInspector = require('../../../lib/web-inspector'); +const NetworkRequest = require('../../../lib/network-request'); const sampleTrace = require('../../fixtures/traces/progressive-app-m60.json'); const sampleDevtoolsLog = require('../../fixtures/traces/progressive-app-m60.devtools.log.json'); @@ -20,7 +20,7 @@ function createRequest( url, startTime = 0, _initiator = null, - _resourceType = WebInspector.resourceTypes.Document + _resourceType = NetworkRequest.TYPES.Document ) { startTime = startTime / 1000; const endTime = startTime + 0.05; @@ -165,7 +165,7 @@ describe('PageDependencyGraph computed artifact:', () => { const request1 = createRequest(1, '1', 0); const request2 = createRequest(2, '2', 50); const request3 = createRequest(3, '3', 50); - const request4 = createRequest(4, '4', 300, null, WebInspector.resourceTypes.XHR); + const request4 = createRequest(4, '4', 300, null, NetworkRequest.TYPES.XHR); const networkRecords = [request1, request2, request3, request4]; addTaskEvents(200, 200, [ @@ -216,10 +216,10 @@ describe('PageDependencyGraph computed artifact:', () => { it('should be forgiving without cyclic dependencies', () => { const request1 = createRequest(1, '1', 0); - const request2 = createRequest(2, '2', 250, null, WebInspector.resourceTypes.XHR); + const request2 = createRequest(2, '2', 250, null, NetworkRequest.TYPES.XHR); const request3 = createRequest(3, '3', 210); const request4 = createRequest(4, '4', 590); - const request5 = createRequest(5, '5', 595, null, WebInspector.resourceTypes.XHR); + const request5 = createRequest(5, '5', 595, null, NetworkRequest.TYPES.XHR); const networkRecords = [request1, request2, request3, request4, request5]; addTaskEvents(200, 200, [ @@ -257,7 +257,7 @@ describe('PageDependencyGraph computed artifact:', () => { }); it('should set isMainDocument on first document request', () => { - const request1 = createRequest(1, '1', 0, null, WebInspector.resourceTypes.Image); + const request1 = createRequest(1, '1', 0, null, NetworkRequest.TYPES.Image); const request2 = createRequest(2, '2', 5); const networkRecords = [request1, request2]; diff --git a/lighthouse-core/test/gather/gatherers/dobetterweb/optimized-images-test.js b/lighthouse-core/test/gather/gatherers/dobetterweb/optimized-images-test.js index c71e2f81bfba..546c409e1808 100644 --- a/lighthouse-core/test/gather/gatherers/dobetterweb/optimized-images-test.js +++ b/lighthouse-core/test/gather/gatherers/dobetterweb/optimized-images-test.js @@ -24,7 +24,7 @@ const traceData = { _mimeType: 'image/jpeg', _resourceSize: 10000, transferSize: 20000, - _resourceType: {_name: 'image'}, + _resourceType: 'Image', finished: true, }, { @@ -32,7 +32,7 @@ const traceData = { _mimeType: 'image/png', _resourceSize: 11000, transferSize: 20000, - _resourceType: {_name: 'image'}, + _resourceType: 'Image', finished: true, }, { @@ -40,7 +40,7 @@ const traceData = { _mimeType: 'image/bmp', _resourceSize: 12000, transferSize: 9000, // bitmap was compressed another way - _resourceType: {_name: 'image'}, + _resourceType: 'Image', finished: true, }, { @@ -48,7 +48,7 @@ const traceData = { _mimeType: 'image/bmp', _resourceSize: 12000, transferSize: 20000, - _resourceType: {_name: 'image'}, + _resourceType: 'Image', finished: true, }, { @@ -56,7 +56,7 @@ const traceData = { _mimeType: 'image/svg+xml', _resourceSize: 13000, transferSize: 20000, - _resourceType: {_name: 'image'}, + _resourceType: 'Image', finished: true, }, { @@ -64,13 +64,13 @@ const traceData = { _mimeType: 'image/jpeg', _resourceSize: 15000, transferSize: 20000, - _resourceType: {_name: 'image'}, + _resourceType: 'Image', finished: true, }, { _url: 'data: image/jpeg ; base64 ,SgVcAT32587935321...', _mimeType: 'image/jpeg', - _resourceType: {_name: 'image'}, + _resourceType: 'Image', _resourceSize: 14000, transferSize: 20000, finished: true, @@ -78,7 +78,7 @@ const traceData = { { _url: 'http://google.com/big-image.bmp', _mimeType: 'image/bmp', - _resourceType: {_name: 'image'}, + _resourceType: 'Image', _resourceSize: 12000, transferSize: 20000, finished: false, // ignore for not finishing @@ -86,7 +86,7 @@ const traceData = { { _url: 'http://google.com/not-an-image.bmp', _mimeType: 'image/bmp', - _resourceType: {_name: 'document'}, // ignore for not really being an image + _resourceType: 'Document', // ignore for not really being an image _resourceSize: 12000, transferSize: 20000, finished: true, diff --git a/lighthouse-core/test/gather/gatherers/dobetterweb/response-compression-test.js b/lighthouse-core/test/gather/gatherers/dobetterweb/response-compression-test.js index 06473b13ddc0..7e31800416c0 100644 --- a/lighthouse-core/test/gather/gatherers/dobetterweb/response-compression-test.js +++ b/lighthouse-core/test/gather/gatherers/dobetterweb/response-compression-test.js @@ -23,9 +23,7 @@ const traceData = { _requestId: 0, _resourceSize: 9, transferSize: 10, - _resourceType: { - _isTextType: true, - }, + _resourceType: 'Script', _responseHeaders: [{ name: 'Content-Encoding', value: 'gzip', @@ -40,9 +38,7 @@ const traceData = { _requestId: 1, _resourceSize: 6, transferSize: 7, - _resourceType: { - _isTextType: true, - }, + _resourceType: 'Stylesheet', _responseHeaders: [], content: 'abcabc', finished: true, @@ -54,9 +50,7 @@ const traceData = { _requestId: 2, _resourceSize: 7, transferSize: 8, - _resourceType: { - _isTextType: true, - }, + _resourceType: 'XHR', _responseHeaders: [], content: '1234567', finished: true, @@ -68,9 +62,7 @@ const traceData = { _requestId: 22, _resourceSize: 7, transferSize: 7, - _resourceType: { - _isTextType: true, - }, + _resourceType: 'XHR', _responseHeaders: [], content: '1234567', finished: true, @@ -82,9 +74,7 @@ const traceData = { _requestId: 23, _resourceSize: 7, transferSize: 8, - _resourceType: { - _isTextType: true, - }, + _resourceType: 'XHR', _responseHeaders: [], content: '1234567', finished: false, // ignore for not finishing @@ -96,9 +86,7 @@ const traceData = { _requestId: 3, _resourceSize: 10, transferSize: 10, - _resourceType: { - _isTextType: false, - }, + _resourceType: 'Image', _responseHeaders: [], content: 'aaaaaaaaaa', finished: true, @@ -110,9 +98,7 @@ const traceData = { _requestId: 4, _resourceSize: 100, transferSize: 100, - _resourceType: { - _isTextType: false, - }, + _resourceType: 'Media', _responseHeaders: [], content: 'bbbbbbbb', finished: true, @@ -163,9 +149,7 @@ describe('Optimized responses', () => { _requestId: 1, _resourceSize: 10, transferSize: 10, - _resourceType: { - _isTextType: true, - }, + _resourceType: 'Stylesheet', _responseHeaders: [], content: 'aaaaaaaaaa', finished: true, @@ -176,9 +160,7 @@ describe('Optimized responses', () => { _requestId: 1, _resourceSize: 123, transferSize: 123, - _resourceType: { - _isTextType: true, - }, + _resourceType: 'Stylesheet', _responseHeaders: [], content: 'aaaaaaaaaa', finished: true, @@ -203,12 +185,6 @@ describe('Optimized responses', () => { record.transferSize = record.transferSize; record.responseHeaders = record._responseHeaders; record.requestId = record._requestId; - record._resourceType = Object.assign( - { - isTextType: () => record._resourceType._isTextType, - }, - record._resourceType - ); return record; }); diff --git a/lighthouse-core/test/lib/network-recorder-test.js b/lighthouse-core/test/lib/network-recorder-test.js index 7119b3a1d036..2b3ef88aade8 100644 --- a/lighthouse-core/test/lib/network-recorder-test.js +++ b/lighthouse-core/test/lib/network-recorder-test.js @@ -42,7 +42,7 @@ describe('network recorder', function() { assert.equal(redirectA._resourceType, undefined); assert.equal(redirectB._resourceType, undefined); assert.equal(redirectC._resourceType, undefined); - assert.equal(mainDocument._resourceType._name, 'document'); + assert.equal(mainDocument._resourceType, 'Document'); }); describe('#findNetworkQuietPeriods', () => { diff --git a/typings/web-inspector.d.ts b/typings/web-inspector.d.ts index 9f194b6c4bd4..e348dd991915 100644 --- a/typings/web-inspector.d.ts +++ b/typings/web-inspector.d.ts @@ -44,7 +44,7 @@ declare global { _initiator: Crdp.Network.Initiator; _timing?: Crdp.Network.ResourceTiming; - _resourceType?: ResourceType; + _resourceType?: Crdp.Page.ResourceType; _mimeType: string; priority(): Crdp.Network.ResourcePriority; initiatorRequest(): NetworkRequest | undefined; From 95004b16c69891234dd2584a90a6c4b358c4a5d6 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Tue, 26 Jun 2018 09:38:37 -0700 Subject: [PATCH 2/4] fixup --- lighthouse-core/audits/network-requests.js | 2 +- .../test/audits/byte-efficiency/unminified-css-test.js | 2 +- .../audits/byte-efficiency/unminified-javascript-test.js | 2 +- .../test/audits/byte-efficiency/unused-css-rules-test.js | 2 +- .../test/audits/byte-efficiency/unused-javascript-test.js | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lighthouse-core/audits/network-requests.js b/lighthouse-core/audits/network-requests.js index d1ea28578c4c..5f711b71304d 100644 --- a/lighthouse-core/audits/network-requests.js +++ b/lighthouse-core/audits/network-requests.js @@ -46,7 +46,7 @@ class NetworkRequests extends Audit { transferSize: record.transferSize, statusCode: record.statusCode, mimeType: record._mimeType, - resourceType: record._resourceType, + resourceType: (record._resourceType || 'other').toLowerCase(), }; }); diff --git a/lighthouse-core/test/audits/byte-efficiency/unminified-css-test.js b/lighthouse-core/test/audits/byte-efficiency/unminified-css-test.js index 8c5ec38ddff6..392a091b5781 100644 --- a/lighthouse-core/test/audits/byte-efficiency/unminified-css-test.js +++ b/lighthouse-core/test/audits/byte-efficiency/unminified-css-test.js @@ -11,7 +11,7 @@ const assert = require('assert'); /* eslint-env mocha */ -const _resourceType = {_name: 'stylesheet'}; +const _resourceType = 'Stylesheet'; describe('Page uses optimized css', () => { describe('#computeTokenLength', () => { it('should compute length of meaningful content', () => { diff --git a/lighthouse-core/test/audits/byte-efficiency/unminified-javascript-test.js b/lighthouse-core/test/audits/byte-efficiency/unminified-javascript-test.js index a27db629b6e5..c2fb670c05cd 100644 --- a/lighthouse-core/test/audits/byte-efficiency/unminified-javascript-test.js +++ b/lighthouse-core/test/audits/byte-efficiency/unminified-javascript-test.js @@ -12,7 +12,7 @@ const assert = require('assert'); /* eslint-env mocha */ -const _resourceType = {_name: 'script'}; +const _resourceType = 'Script'; describe('Page uses optimized responses', () => { it('fails when given unminified scripts', () => { const auditResult = UnminifiedJavascriptAudit.audit_({ diff --git a/lighthouse-core/test/audits/byte-efficiency/unused-css-rules-test.js b/lighthouse-core/test/audits/byte-efficiency/unused-css-rules-test.js index 7633576c7b9a..8a47e608f4f1 100644 --- a/lighthouse-core/test/audits/byte-efficiency/unused-css-rules-test.js +++ b/lighthouse-core/test/audits/byte-efficiency/unused-css-rules-test.js @@ -123,7 +123,7 @@ describe('Best Practices: unused css rules audit', () => { { url: 'file://a.css', transferSize: 10 * 1024, - _resourceType: {_name: 'stylesheet'}, + _resourceType: 'Stylesheet', }, ]); }; diff --git a/lighthouse-core/test/audits/byte-efficiency/unused-javascript-test.js b/lighthouse-core/test/audits/byte-efficiency/unused-javascript-test.js index 5f20dc47fde7..ced78458e66d 100644 --- a/lighthouse-core/test/audits/byte-efficiency/unused-javascript-test.js +++ b/lighthouse-core/test/audits/byte-efficiency/unused-javascript-test.js @@ -76,9 +76,9 @@ describe('UnusedJavaScript audit', () => { const scriptB = generateScript('scriptB.js', [[0, 200, true], [0, 50, false]]); const inlineA = generateScript('inline.html', [[0, 5000, true], [5000, 6000, false]]); const inlineB = generateScript('inline.html', [[0, 15000, true], [0, 5000, false]]); - const recordA = generateRecord('scriptA.js', 35000, {_name: 'script'}); - const recordB = generateRecord('scriptB.js', 50000, {_name: 'script'}); - const recordInline = generateRecord('inline.html', 1000000, {_name: 'document'}); + const recordA = generateRecord('scriptA.js', 35000, 'Script'); + const recordB = generateRecord('scriptB.js', 50000, 'Script'); + const recordInline = generateRecord('inline.html', 1000000, 'Document'); const result = UnusedJavaScript.audit_( {JsUsage: [scriptA, scriptB, scriptUnknown, inlineA, inlineB]}, From 7c613a33ffb99fa58532992cf56b71a686d21774 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Tue, 26 Jun 2018 13:17:34 -0700 Subject: [PATCH 3/4] feedback --- third-party/devtools/LICENSE | 27 ---------- third-party/devtools/ResourceType.js | 73 ---------------------------- typings/web-inspector.d.ts | 2 - 3 files changed, 102 deletions(-) delete mode 100644 third-party/devtools/LICENSE delete mode 100644 third-party/devtools/ResourceType.js diff --git a/third-party/devtools/LICENSE b/third-party/devtools/LICENSE deleted file mode 100644 index 972bb2edb099..000000000000 --- a/third-party/devtools/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/third-party/devtools/ResourceType.js b/third-party/devtools/ResourceType.js deleted file mode 100644 index 4952fae31955..000000000000 --- a/third-party/devtools/ResourceType.js +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2012 Google Inc. All rights reserved. - * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -// ADAPTED FROM https://cs.chromium.org/chromium/src/third_party/blink/renderer/devtools/front_end/common/ResourceType.js - -/* eslint-disable */ - -class ResourceType { - /** - * @param {string} name - * @param {string} title - * @param {string} category - * @param {boolean} isTextType - */ - constructor(name, title, category, isTextType) { - this._name = name; - this._title = title; - this._category = category; - this._isTextType = isTextType; - } - - /** - * @return {boolean} - */ - isTextType() { - return this._isTextType; - } -}; - -/** @type {Record} */ -ResourceType.TYPES = { - XHR: new ResourceType('xhr', 'XHR', 'XHR', true), - Fetch: new ResourceType('fetch', 'Fetch', 'XHR', true), - EventSource: new ResourceType('eventsource', 'EventSource', 'XHR', true), - Script: new ResourceType('script', 'Script', 'Script', true), - Stylesheet: new ResourceType('stylesheet', 'Stylesheet', 'Stylesheet', true), - Image: new ResourceType('image', 'Image', 'Image', false), - Media: new ResourceType('media', 'Media', 'Media', false), - Font: new ResourceType('font', 'Font', 'Font', false), - Document: new ResourceType('document', 'Document', 'Document', true), - TextTrack: new ResourceType('texttrack', 'TextTrack', 'Other', true), - WebSocket: new ResourceType('websocket', 'WebSocket', 'WebSocket', false), - Other: new ResourceType('other', 'Other', 'Other', false), - Manifest: new ResourceType('manifest', 'Manifest', 'Manifest', true), -}; - -module.exports = ResourceType; diff --git a/typings/web-inspector.d.ts b/typings/web-inspector.d.ts index e348dd991915..2af9cc07a5a7 100644 --- a/typings/web-inspector.d.ts +++ b/typings/web-inspector.d.ts @@ -4,8 +4,6 @@ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -import ResourceType = require("../third-party/devtools/ResourceType"); - declare global { module LH.WebInspector { // TODO(phulce): migrate to use network-request.js From fd088d307d46104dd7183cfbd25728297b74ce5c Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Tue, 26 Jun 2018 18:13:35 -0700 Subject: [PATCH 4/4] no more toLowerCase --- lighthouse-core/audits/network-requests.js | 2 +- lighthouse-core/test/results/sample_v2.json | 36 ++++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lighthouse-core/audits/network-requests.js b/lighthouse-core/audits/network-requests.js index 5f711b71304d..d1ea28578c4c 100644 --- a/lighthouse-core/audits/network-requests.js +++ b/lighthouse-core/audits/network-requests.js @@ -46,7 +46,7 @@ class NetworkRequests extends Audit { transferSize: record.transferSize, statusCode: record.statusCode, mimeType: record._mimeType, - resourceType: (record._resourceType || 'other').toLowerCase(), + resourceType: record._resourceType, }; }); diff --git a/lighthouse-core/test/results/sample_v2.json b/lighthouse-core/test/results/sample_v2.json index 806d986d9e69..126a12b19d3f 100644 --- a/lighthouse-core/test/results/sample_v2.json +++ b/lighthouse-core/test/results/sample_v2.json @@ -917,7 +917,7 @@ "transferSize": 12640, "statusCode": 200, "mimeType": "text/html", - "resourceType": "document" + "resourceType": "Document" }, { "url": "http://localhost:10200/dobetterweb/dbw_tester.css?delay=2000&async=true", @@ -926,7 +926,7 @@ "transferSize": 821, "statusCode": 200, "mimeType": "text/css", - "resourceType": "stylesheet" + "resourceType": "Stylesheet" }, { "url": "http://localhost:10200/dobetterweb/dbw_tester.css?delay=100", @@ -935,7 +935,7 @@ "transferSize": 821, "statusCode": 200, "mimeType": "text/css", - "resourceType": "stylesheet" + "resourceType": "Stylesheet" }, { "url": "http://localhost:10200/dobetterweb/unknown404.css?delay=200", @@ -944,7 +944,7 @@ "transferSize": 139, "statusCode": 404, "mimeType": "text/css", - "resourceType": "stylesheet" + "resourceType": "Stylesheet" }, { "url": "http://localhost:10200/dobetterweb/dbw_tester.css?delay=2200", @@ -953,7 +953,7 @@ "transferSize": 821, "statusCode": 200, "mimeType": "text/css", - "resourceType": "stylesheet" + "resourceType": "Stylesheet" }, { "url": "http://localhost:10200/dobetterweb/dbw_disabled.css?delay=200&isdisabled", @@ -962,7 +962,7 @@ "transferSize": 1108, "statusCode": 200, "mimeType": "text/css", - "resourceType": "stylesheet" + "resourceType": "Stylesheet" }, { "url": "http://localhost:10200/dobetterweb/dbw_partial_a.html?delay=200", @@ -971,7 +971,7 @@ "transferSize": 736, "statusCode": 200, "mimeType": "text/html", - "resourceType": "document" + "resourceType": "Document" }, { "url": "http://localhost:10200/dobetterweb/dbw_partial_b.html?delay=200&isasync", @@ -980,7 +980,7 @@ "transferSize": 733, "statusCode": 200, "mimeType": "text/html", - "resourceType": "document" + "resourceType": "Document" }, { "url": "http://localhost:10200/dobetterweb/dbw_tester.css?delay=3000&async=true", @@ -989,7 +989,7 @@ "transferSize": 821, "statusCode": 200, "mimeType": "text/css", - "resourceType": "stylesheet" + "resourceType": "Stylesheet" }, { "url": "http://localhost:10200/dobetterweb/dbw_tester.js", @@ -998,7 +998,7 @@ "transferSize": 1703, "statusCode": 200, "mimeType": "text/javascript", - "resourceType": "script" + "resourceType": "Script" }, { "url": "http://localhost:10200/dobetterweb/empty_module.js?delay=500", @@ -1007,7 +1007,7 @@ "transferSize": 144, "statusCode": 200, "mimeType": "text/javascript", - "resourceType": "script" + "resourceType": "Script" }, { "url": "http://localhost:10200/dobetterweb/lighthouse-480x318.jpg", @@ -1016,7 +1016,7 @@ "transferSize": 24741, "statusCode": 200, "mimeType": "image/jpeg", - "resourceType": "image" + "resourceType": "Image" }, { "url": "http://localhost:10200/zone.js", @@ -1025,7 +1025,7 @@ "transferSize": 71654, "statusCode": 200, "mimeType": "text/javascript", - "resourceType": "script" + "resourceType": "Script" }, { "url": "http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js", @@ -1034,7 +1034,7 @@ "transferSize": 30174, "statusCode": 200, "mimeType": "text/javascript", - "resourceType": "script" + "resourceType": "Script" }, { "url": "http://localhost:10200/dobetterweb/dbw_tester.css?scriptActivated&delay=200", @@ -1043,7 +1043,7 @@ "transferSize": 821, "statusCode": 200, "mimeType": "text/css", - "resourceType": "stylesheet" + "resourceType": "Stylesheet" }, { "url": "http://localhost:10200/dobetterweb/dbw_tester.html", @@ -1052,7 +1052,7 @@ "transferSize": 12640, "statusCode": 200, "mimeType": "text/html", - "resourceType": "xhr" + "resourceType": "XHR" }, { "url": "blob:http://localhost:10200/ae0eac03-ab9b-4a6a-b299-f5212153e277", @@ -1061,7 +1061,7 @@ "transferSize": 0, "statusCode": 200, "mimeType": "text/plain", - "resourceType": "image" + "resourceType": "Image" }, { "url": "http://localhost:10200/favicon.ico", @@ -1070,7 +1070,7 @@ "transferSize": 221, "statusCode": 404, "mimeType": "text/plain", - "resourceType": "other" + "resourceType": "Other" } ] }