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

report: screen emulation and dpr in meta tooltip #14515

Merged
merged 5 commits into from
Nov 18, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -6079,6 +6079,7 @@
"runtimeSettingsCPUThrottling": "CPU throttling",
"runtimeSettingsDevice": "Device",
"runtimeSettingsNetworkThrottling": "Network throttling",
"runtimeSettingsScreenEmulation": "Screen emulation",
"runtimeSettingsUANetwork": "User agent (network)",
"runtimeSingleLoad": "Single page load",
"runtimeSingleLoadTooltip": "This data is taken from a single page load, as opposed to field data summarizing many sessions.",
Expand Down Expand Up @@ -10011,6 +10012,7 @@
"runtimeSettingsCPUThrottling": "CPU throttling",
"runtimeSettingsDevice": "Device",
"runtimeSettingsNetworkThrottling": "Network throttling",
"runtimeSettingsScreenEmulation": "Screen emulation",
"runtimeSettingsUANetwork": "User agent (network)",
"runtimeSingleLoad": "Single page load",
"runtimeSingleLoadTooltip": "This data is taken from a single page load, as opposed to field data summarizing many sessions.",
Expand Down Expand Up @@ -13487,6 +13489,7 @@
"runtimeSettingsCPUThrottling": "CPU throttling",
"runtimeSettingsDevice": "Device",
"runtimeSettingsNetworkThrottling": "Network throttling",
"runtimeSettingsScreenEmulation": "Screen emulation",
"runtimeSettingsUANetwork": "User agent (network)",
"runtimeSingleLoad": "Single page load",
"runtimeSingleLoadTooltip": "This data is taken from a single page load, as opposed to field data summarizing many sessions.",
Expand Down Expand Up @@ -20217,6 +20220,7 @@
"runtimeSettingsCPUThrottling": "CPU throttling",
"runtimeSettingsDevice": "Device",
"runtimeSettingsNetworkThrottling": "Network throttling",
"runtimeSettingsScreenEmulation": "Screen emulation",
"runtimeSettingsUANetwork": "User agent (network)",
"runtimeSingleLoad": "Single page load",
"runtimeSingleLoadTooltip": "This data is taken from a single page load, as opposed to field data summarizing many sessions.",
Expand Down
1 change: 1 addition & 0 deletions core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -8337,6 +8337,7 @@
"runtimeSettingsCPUThrottling": "CPU throttling",
"runtimeSettingsDevice": "Device",
"runtimeSettingsNetworkThrottling": "Network throttling",
"runtimeSettingsScreenEmulation": "Screen emulation",
"runtimeSettingsUANetwork": "User agent (network)",
"runtimeSingleLoad": "Single page load",
"runtimeSingleLoadTooltip": "This data is taken from a single page load, as opposed to field data summarizing many sessions.",
Expand Down
11 changes: 9 additions & 2 deletions core/util.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ class Util {

/**
* @param {LH.Result['configSettings']} settings
* @return {!{deviceEmulation: string, networkThrottling: string, cpuThrottling: string, summary: string}}
* @return {!{deviceEmulation: string, screenEmulation?: string, networkThrottling: string, cpuThrottling: string, summary: string}}
*/
static getEmulationDescriptions(settings) {
let cpuThrottling;
Expand Down Expand Up @@ -516,14 +516,19 @@ class Util {
summary = cpuThrottling = networkThrottling = Util.i18n.strings.runtimeUnknown;
}

// TODO(paulirish): revise Runtime Settings strings: https://github.com/GoogleChrome/lighthouse/pull/11796
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

dead task

const deviceEmulation = {
mobile: Util.i18n.strings.runtimeMobileEmulation,
desktop: Util.i18n.strings.runtimeDesktopEmulation,
}[settings.formFactor] || Util.i18n.strings.runtimeNoEmulation;

const screenEmulation = settings.screenEmulation.disabled ?
undefined :
// eslint-disable-next-line max-len
`${settings.screenEmulation.width}x${settings.screenEmulation.height}, DPR ${settings.screenEmulation.deviceScaleFactor}`;

return {
deviceEmulation,
screenEmulation,
cpuThrottling,
networkThrottling,
summary,
Expand Down Expand Up @@ -721,6 +726,8 @@ const UIStrings = {
runtimeSettingsBenchmark: 'CPU/Memory Power',
/** Label for a row in a table that shows the version of the Axe library used. Example row values: 2.1.0, 3.2.3 */
runtimeSettingsAxeVersion: 'Axe version',
/** Label for a row in a table that shows the screen resolution and DPR that was emulated for the Lighthouse run. Example values: '800x600, DPR: 3' */
runtimeSettingsScreenEmulation: 'Screen emulation',

/** Label for button to create an issue against the Lighthouse GitHub project. */
footerIssue: 'File an issue',
Expand Down
5 changes: 4 additions & 1 deletion flow-report/src/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const SidebarRuntimeSettings: FunctionComponent<{settings: LH.ConfigSettings}> =
({settings}) => {
const strings = useLocalizedStrings();
const env = Util.getEmulationDescriptions(settings);
const deviceEmulationString = env.screenEmulation ?
`${env.deviceEmulation} - ${env.screenEmulation}` :
env.deviceEmulation;

return (
<div className="SidebarRuntimeSettings">
Expand All @@ -43,7 +46,7 @@ const SidebarRuntimeSettings: FunctionComponent<{settings: LH.ConfigSettings}> =
<EnvIcon/>
</div>
{
env.deviceEmulation
deviceEmulationString
}
</div>
<div
Expand Down
9 changes: 8 additions & 1 deletion flow-report/test/sidebar/sidebar-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ describe('SidebarRuntimeSettings', () => {
throughputKbps: 1.6 * 1024,
rttMs: 150,
},
screenEmulation: {disabled: true},
} as any;
const root = render(<SidebarRuntimeSettings settings={settings}/>, {wrapper});

expect(root.getByText('Emulated Moto G4')).toBeTruthy();
expect(root.queryByText('Emulated Moto G4 -')).toBeFalsy();
expect(root.getByText('Slow 4G throttling')).toBeTruthy();
expect(root.getByText('4x slowdown'));
});
Expand All @@ -78,10 +80,15 @@ describe('SidebarRuntimeSettings', () => {
throughputKbps: 1,
rttMs: 1,
},
screenEmulation: {
width: 100,
height: 100,
deviceScaleFactor: 2,
},
} as any;
const root = render(<SidebarRuntimeSettings settings={settings}/>, {wrapper});

expect(root.getByText('Emulated Desktop')).toBeTruthy();
expect(root.getByText('Emulated Desktop - 100x100, DPR 2')).toBeTruthy();
expect(root.getByText('Custom throttling')).toBeTruthy();
expect(root.getByText('1x slowdown'));
});
Expand Down
3 changes: 3 additions & 0 deletions proto/lighthouse-result.proto
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,9 @@ message I18n {

// This label is for a button that will show the user a trace of the page.
string view_original_trace_label = 59;

// Label for a row in a table that shows the screen emulation used
string runtime_settings_screen_emulation = 60;
}

// The message holding all formatted strings used in the renderer.
Expand Down
18 changes: 13 additions & 5 deletions report/renderer/report-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ export class ReportRenderer {
*/
_renderMetaBlock(report, footer) {
const envValues = Util.getEmulationDescriptions(report.configSettings || {});


const match = report.userAgent.match(/(\w*Chrome\/[\d.]+)/); // \w* to include 'HeadlessChrome'
const chromeVer = Array.isArray(match)
? match[1].replace('/', ' ').replace('Chrome', 'Chromium')
Expand All @@ -129,15 +127,25 @@ export class ReportRenderer {
const benchmarkIndex = report.environment.benchmarkIndex.toFixed(0);
const axeVersion = report.environment.credits?.['axe-core'];

const devicesTooltipTextLines = [
`${Util.i18n.strings.runtimeSettingsBenchmark}: ${benchmarkIndex}`,
`${Util.i18n.strings.runtimeSettingsCPUThrottling}: ${envValues.cpuThrottling}`,
];
if (envValues.screenEmulation) {
devicesTooltipTextLines.push(
`${Util.i18n.strings.runtimeSettingsScreenEmulation}: ${envValues.screenEmulation}`);
}
if (axeVersion) {
devicesTooltipTextLines.push(`${Util.i18n.strings.runtimeSettingsAxeVersion}: ${axeVersion}`);
}

// [CSS icon class, textContent, tooltipText]
const metaItems = [
['date',
`Captured at ${Util.i18n.formatDateTime(report.fetchTime)}`],
['devices',
`${envValues.deviceEmulation} with Lighthouse ${report.lighthouseVersion}`,
`${Util.i18n.strings.runtimeSettingsBenchmark}: ${benchmarkIndex}` +
`\n${Util.i18n.strings.runtimeSettingsCPUThrottling}: ${envValues.cpuThrottling}` +
(axeVersion ? `\n${Util.i18n.strings.runtimeSettingsAxeVersion}: ${axeVersion}` : '')],
devicesTooltipTextLines.join('\n')],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

minor refactor for readability.

['samples-one',
Util.i18n.strings.runtimeSingleLoad,
Util.i18n.strings.runtimeSingleLoadTooltip],
Expand Down
11 changes: 9 additions & 2 deletions report/renderer/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ class Util {

/**
* @param {LH.Result['configSettings']} settings
* @return {!{deviceEmulation: string, networkThrottling: string, cpuThrottling: string, summary: string}}
* @return {!{deviceEmulation: string, screenEmulation?: string, networkThrottling: string, cpuThrottling: string, summary: string}}
*/
static getEmulationDescriptions(settings) {
let cpuThrottling;
Expand Down Expand Up @@ -512,14 +512,19 @@ class Util {
summary = cpuThrottling = networkThrottling = Util.i18n.strings.runtimeUnknown;
}

// TODO(paulirish): revise Runtime Settings strings: https://github.com/GoogleChrome/lighthouse/pull/11796
const deviceEmulation = {
mobile: Util.i18n.strings.runtimeMobileEmulation,
desktop: Util.i18n.strings.runtimeDesktopEmulation,
}[settings.formFactor] || Util.i18n.strings.runtimeNoEmulation;

const screenEmulation = settings.screenEmulation.disabled ?
undefined :
// eslint-disable-next-line max-len
`${settings.screenEmulation.width}x${settings.screenEmulation.height}, DPR ${settings.screenEmulation.deviceScaleFactor}`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Continuing our tradition of not properly localizing these strings.


return {
deviceEmulation,
screenEmulation,
cpuThrottling,
networkThrottling,
summary,
Expand Down Expand Up @@ -717,6 +722,8 @@ const UIStrings = {
runtimeSettingsBenchmark: 'CPU/Memory Power',
/** Label for a row in a table that shows the version of the Axe library used. Example row values: 2.1.0, 3.2.3 */
runtimeSettingsAxeVersion: 'Axe version',
/** Label for a row in a table that shows the screen resolution and DPR that was emulated for the Lighthouse run. Example values: '800x600, DPR: 3' */
runtimeSettingsScreenEmulation: 'Screen emulation',

/** Label for button to create an issue against the Lighthouse GitHub project. */
footerIssue: 'File an issue',
Expand Down
1 change: 1 addition & 0 deletions report/test/renderer/report-renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ describe('ReportRenderer', () => {
expect(itemsTxt).toContain('RTT');
expect(itemsTxt).toMatch(/\dx/);
expect(itemsTxt).toContain(sampleResults.environment.networkUserAgent);
expect(itemsTxt).toMatch('360x640, DPR 2.625');
});
});

Expand Down
14 changes: 12 additions & 2 deletions report/test/renderer/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,22 @@ describe('util helpers', () => {
});

it('builds device emulation string', () => {
const get = opts => Util.getEmulationDescriptions(opts).deviceEmulation;
const get = opts => Util.getEmulationDescriptions({
...opts,
screenEmulation: {disabled: true},
}).deviceEmulation;
assert.equal(get({formFactor: 'mobile'}), 'Emulated Moto G4');
assert.equal(get({formFactor: 'desktop'}), 'Emulated Desktop');
});

it('builds throttling strings when provided', () => {
const descriptions = Util.getEmulationDescriptions({throttlingMethod: 'provided'});
const descriptions = Util.getEmulationDescriptions({
throttlingMethod: 'provided',
screenEmulation: {disabled: true},
});
assert.equal(descriptions.cpuThrottling, 'Provided by environment');
assert.equal(descriptions.networkThrottling, 'Provided by environment');
assert.equal(descriptions.screenEmulation, undefined);
});

it('builds throttling strings when devtools', () => {
Expand All @@ -53,6 +60,7 @@ describe('util helpers', () => {
downloadThroughputKbps: 1400.00000000001,
uploadThroughputKbps: 600,
},
screenEmulation: {disabled: true},
});

// eslint-disable-next-line max-len
Expand All @@ -68,11 +76,13 @@ describe('util helpers', () => {
rttMs: 150,
throughputKbps: 1600,
},
screenEmulation: {width: 100, height: 100, deviceScaleFactor: 2},
});

// eslint-disable-next-line max-len
assert.equal(descriptions.networkThrottling, '150\xa0ms TCP RTT, 1,600\xa0kb/s throughput (Simulated)');
assert.equal(descriptions.cpuThrottling, '2x slowdown (Simulated)');
assert.equal(descriptions.screenEmulation, '100x100, DPR 2');
});

describe('#prepareReportResult', () => {
Expand Down
3 changes: 3 additions & 0 deletions shared/localization/locales/en-US.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions shared/localization/locales/en-XL.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.