Skip to content

Commit 3f47984

Browse files
Connor ClarkDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Fix calibration process broken due to minification
Also adds an e2e test. Bug: 311438112 Change-Id: If2fe107ac83ba631e3f642ae7a08ae2c38575227 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6191409 Reviewed-by: Adam Raine <[email protected]> Commit-Queue: Connor Clark <[email protected]> Auto-Submit: Connor Clark <[email protected]>
1 parent 4578e06 commit 3f47984

File tree

5 files changed

+60
-11
lines changed

5 files changed

+60
-11
lines changed

front_end/panels/mobile_throttling/CalibrationController.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,17 @@ export class CalibrationController {
103103
moonEl.textContent = '🌑';
104104
moonEl.style.cssText = 'font-size: 5em';
105105
}
106-
await runtimeModel.agent.invoke_evaluate({
107-
expression: 'window.location.href = "about:blank"',
108-
});
109-
await runtimeModel.agent.invoke_evaluate({
110-
expression: `(${setupTestPage})(${JSON.stringify(i18nString(UIStrings.runningCalibration))})`,
111-
});
106+
107+
await primaryPageTarget.pageAgent().invoke_navigate({url: 'about:blank'});
108+
112109
await runtimeModel.agent.invoke_evaluate({
113110
expression: `
114-
${computeBenchmarkIndex}
111+
(${setupTestPage})(${JSON.stringify(i18nString(UIStrings.runningCalibration))});
112+
115113
window.runBenchmark = () => {
116114
window.runs = window.runs ?? 0;
117-
moon.textContent = ['🌑', '🌒','🌓', '🌔', '🌕', '🌖', '🌗', '🌘'][window.runs++ % 8];
118-
return computeBenchmarkIndex(${benchmarkDurationMs});
115+
moon.textContent = ['🌑', '🌒', '🌓', '🌔', '🌕', '🌖', '🌗', '🌘'][window.runs++ % 8];
116+
return (${computeBenchmarkIndex})(${benchmarkDurationMs});
119117
}`,
120118
});
121119

@@ -144,7 +142,11 @@ export class CalibrationController {
144142
expression: 'runBenchmark()',
145143
});
146144
if (!Number.isFinite(result.value)) {
147-
throw new Error(`unexpected score from benchmark: ${result.value}`);
145+
let err = `unexpected score from benchmark: ${result.value}`;
146+
if (result.description) {
147+
err += `\n${result.description}`;
148+
}
149+
throw new Error(err);
148150
}
149151
return result.value;
150152
}

front_end/panels/mobile_throttling/ThrottlingSettingsTab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ const UIStrings = {
157157
*@description Text to explain how the CPU calibration process will work.
158158
*/
159159
calibrationConfirmationPrompt:
160-
'Calibration will take ~10 seconds, and temporarily navigate away from your current page. Do you wish to continue?',
160+
'Calibration will take ~5 seconds, and temporarily navigate away from your current page. Do you wish to continue?',
161161
/**
162162
*@description Text to explain an issue that may impact the CPU calibration process.
163163
*/

test/e2e/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ node_ts_library("tests") {
4848
"snippets",
4949
"sources",
5050
"targets",
51+
"throttling",
5152
"webaudio",
5253
]
5354
sources = [ "mocharc.ts" ]

test/e2e/throttling/BUILD.gn

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2025 The Chromium Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import("../../../scripts/build/typescript/typescript.gni")
6+
7+
node_ts_library("throttling") {
8+
sources = [ "cpu_calibration_test.ts" ]
9+
10+
deps = [
11+
"../../shared",
12+
"../helpers",
13+
]
14+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2025 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import {assert} from 'chai';
6+
7+
import {
8+
click,
9+
getAllTextContents,
10+
waitForElementWithTextContent,
11+
} from '../../shared/helper.js';
12+
import {openSettingsTab} from '../helpers/settings-helpers.js';
13+
14+
describe('CPU Calibration', () => {
15+
it('works', async () => {
16+
await openSettingsTab('Throttling');
17+
18+
assert.deepEqual(await getAllTextContents('.cpu-preset-result'), ['Needs calibration', 'Needs calibration']);
19+
20+
await waitForElementWithTextContent(
21+
'To use the CPU throttling presets, run the calibration process to determine the ideal throttling rate for your device.');
22+
await click('.calibrate-button');
23+
await waitForElementWithTextContent(
24+
'Calibration will take ~5 seconds, and temporarily navigate away from your current page. Do you wish to continue?');
25+
await click('.calibrate-button');
26+
await waitForElementWithTextContent('Recalibrate');
27+
28+
const results = await getAllTextContents('.cpu-preset-result');
29+
assert.include(results[0], 'slowdown');
30+
assert.include(results[1], 'slowdown');
31+
});
32+
});

0 commit comments

Comments
 (0)