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: remove some trivial uses of WebInspector #6090

Merged
merged 1 commit into from
Sep 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 4 additions & 7 deletions lighthouse-core/audits/seo/font-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
'use strict';

/** @typedef {LH.Artifacts.FontSize['analyzedFailingNodesData'][0]} FailingNodeData */
/** @typedef {{Type: {Regular: 'Regular', Inline: 'Inline', Attributes: 'Attributes'}}} WebInspectorCSSStyle */
Copy link
Member Author

Choose a reason for hiding this comment

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

The values that are compared against these are typed to only be one of these values, so really no point in bringing it in just for these three constants.


const URL = require('../../lib/url-shim');
const Audit = require('../audit');
const ViewportAudit = require('../viewport');
const WebInspector = require('../../lib/web-inspector');
const CSSStyleDeclaration = /** @type {WebInspectorCSSStyle} */ (WebInspector.CSSStyleDeclaration);
const MINIMAL_PERCENTAGE_OF_LEGIBLE_TEXT = 60;

/**
Expand Down Expand Up @@ -107,8 +104,8 @@ function nodeToTableNode(node) {
function findStyleRuleSource(baseURL, styleDeclaration, node) {
if (
!styleDeclaration ||
styleDeclaration.type === CSSStyleDeclaration.Type.Attributes ||
styleDeclaration.type === CSSStyleDeclaration.Type.Inline
styleDeclaration.type === 'Attributes' ||
styleDeclaration.type === 'Inline'
) {
return {
selector: nodeToTableNode(node),
Expand All @@ -124,7 +121,7 @@ function findStyleRuleSource(baseURL, styleDeclaration, node) {
};
}

if (styleDeclaration.type === CSSStyleDeclaration.Type.Regular && styleDeclaration.parentRule) {
if (styleDeclaration.type === 'Regular' && styleDeclaration.parentRule) {
const rule = styleDeclaration.parentRule;
const stylesheet = styleDeclaration.stylesheet;

Expand Down Expand Up @@ -169,7 +166,7 @@ function findStyleRuleSource(baseURL, styleDeclaration, node) {
* @return {string}
*/
function getFontArtifactId(styleDeclaration, node) {
if (styleDeclaration && styleDeclaration.type === CSSStyleDeclaration.Type.Regular) {
if (styleDeclaration && styleDeclaration.type === 'Regular') {
const startLine = styleDeclaration.range ? styleDeclaration.range.startLine : 0;
const startColumn = styleDeclaration.range ? styleDeclaration.range.startColumn : 0;
return `${styleDeclaration.styleSheetId}@${startLine}:${startColumn}`;
Expand Down
5 changes: 0 additions & 5 deletions lighthouse-core/lib/network-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
'use strict';

const NetworkManager = require('./web-inspector').NetworkManager;
const NetworkRequest = require('./network-request');
const EventEmitter = require('events').EventEmitter;
const log = require('lighthouse-logger');
Expand Down Expand Up @@ -47,10 +46,6 @@ class NetworkRecorder extends EventEmitter {
return super.once(event, listener);
}

get EventTypes() {
Copy link
Member Author

Choose a reason for hiding this comment

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

was only introduced for easier testing in #582 and that usage was removed in #2133, so this isn't doing anything :)

return NetworkManager.Events;
}

isIdle() {
return !!this._getActiveIdlePeriod(0);
}
Expand Down
89 changes: 4 additions & 85 deletions lighthouse-core/lib/web-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ module.exports = (function() {

global.CSSAgent = {};
global.CSSAgent.StyleSheetOrigin = {
INJECTED: 'injected',
USER_AGENT: 'user-agent',
INSPECTOR: 'inspector',
REGULAR: 'regular',
Injected: 'injected',
UserAgent: 'user-agent',
Inspector: 'inspector',
Regular: 'regular',
Copy link
Member Author

Choose a reason for hiding this comment

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

these shouldn't have been all caps (see e.g. https://github.com/ChromeDevTools/devtools-frontend/blob/51d3d758c57dc51d1864b3003de1fdda82963623/front_end/sdk/CSSRule.js#L70). We only touch the code that checks if a style was injected or came from the user-agent, but unsure if that was affecting the output of our font-size code...

};

global.CSS = {};
Expand All @@ -45,110 +45,29 @@ module.exports = (function() {
// See https://github.com/GoogleChrome/lighthouse/issues/73
const _setImmediate = global.setImmediate;

global.Runtime = global.Runtime || {};
global.Runtime.experiments = global.Runtime.experiments || {};
// DevTools runtime doesn't know about some experiments that DTM looks for
// To avoid exceptions, we assume all experiments are disabled
global.Runtime.experiments.isEnabled = (_ => false);

const _queryParam = global.Runtime.queryParam;
global.Runtime.queryParam = function(arg) {
switch (arg) {
case 'remoteFrontend':
return false;
case 'ws':
return false;
default: {
if (_queryParam) {
return _queryParam.call(global.Runtime, arg);
}
throw new Error('Mock queryParam case not implemented.');
}
}
};

global.TreeElement = {};
global.WorkerRuntime = {};

global.Protocol = {
Agents() {},
};

global.WebInspector = {};
const WebInspector = global.WebInspector;
WebInspector._moduleSettings = {
cacheDisabled: {
addChangeListener() {},
get() {
return false;
},
},
monitoringXHREnabled: {
addChangeListener() {},
get() {
return false;
},
},
showNativeFunctionsInJSProfile: {
addChangeListener() {},
get() {
return true;
},
},
};
WebInspector.moduleSetting = function(settingName) {
return this._moduleSettings[settingName];
};

// Shared Dependencies
require('chrome-devtools-frontend/front_end/common/Object.js');
require('chrome-devtools-frontend/front_end/common/ParsedURL.js');
require('chrome-devtools-frontend/front_end/common/UIString.js');
require('chrome-devtools-frontend/front_end/common/SegmentedRange.js');
require('chrome-devtools-frontend/front_end/platform/utilities.js');
require('chrome-devtools-frontend/front_end/sdk/Target.js');
require('chrome-devtools-frontend/front_end/sdk/TargetManager.js');

// Dependencies for timeline-model
WebInspector.targetManager = {
observeTargets() { },
addEventListener() { },
};
WebInspector.settings = {
createSetting() {
return {
get() {
return false;
},
addChangeListener() {},
};
},
};
WebInspector.console = {
error() {},
};
WebInspector.VBox = function() {};
WebInspector.HBox = function() {};
WebInspector.ViewportDataGrid = function() {};
WebInspector.ViewportDataGridNode = function() {};
global.WorkerRuntime.Worker = function() {};

// used for streaming json parsing
require('chrome-devtools-frontend/front_end/common/TextUtils.js');
require('chrome-devtools-frontend/front_end/timeline/TimelineLoader.js');

// Mock for WebInspector code that writes to console.
WebInspector.ConsoleMessage = function() {};
WebInspector.ConsoleMessage.MessageSource = {
Network: 'network',
};
WebInspector.ConsoleMessage.MessageLevel = {
Log: 'log',
};
WebInspector.ConsoleMessage.MessageType = {
Log: 'log',
};

// Dependencies for effective CSS rule calculation.
require('chrome-devtools-frontend/front_end/common/TextRange.js');
require('chrome-devtools-frontend/front_end/sdk/CSSMatchedStyles.js');
Expand Down
5 changes: 2 additions & 3 deletions lighthouse-core/test/audits/seo/font-size-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

const FontSizeAudit = require('../../../audits/seo/font-size.js');
const assert = require('assert');
const CSSStyleDeclaration = require('../../../lib/web-inspector').CSSStyleDeclaration;

const URL = 'https://example.com';
const validViewport = 'width=device-width';
Expand Down Expand Up @@ -89,15 +88,15 @@ describe('SEO: Font size audit', () => {
it('groups entries with same source, sorts them by coverage', () => {
const style1 = {
styleSheetId: 1,
type: CSSStyleDeclaration.Type.Regular,
type: 'Regular',
range: {
startLine: 123,
startColumn: 10,
},
};
const style2 = {
styleSheetId: 1,
type: CSSStyleDeclaration.Type.Regular,
type: 'Regular',
range: {
startLine: 0,
startColumn: 10,
Expand Down