Skip to content

Commit dcb3d0d

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[e2e] Move Sensor test to non hosted mode
Fixed: 416405290, 416404639, 416404525, 416404799 Change-Id: I5b5777ec435d3b52419090a95de6b78a30a37803 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6607467 Auto-Submit: Nikolay Vitkov <[email protected]> Commit-Queue: Wolfgang Beyer <[email protected]> Reviewed-by: Wolfgang Beyer <[email protected]>
1 parent d10b1ca commit dcb3d0d

14 files changed

+208
-234
lines changed

test/e2e/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ node_ts_library("tests") {
3636
"recorder",
3737
"search",
3838
"security",
39-
"sensors",
4039
"settings",
4140
"snippets",
4241
"sources",

test/e2e/helpers/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ node_ts_library("helpers") {
2828
"quick_open-helpers.ts",
2929
"search-helpers.ts",
3030
"security-helpers.ts",
31-
"sensors-helpers.ts",
3231
"settings-helpers.ts",
3332
"settings-shortcuts-helpers.ts",
3433
"sources-helpers.ts",

test/e2e/helpers/sensors-helpers.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/e2e/sensors/emulate-hardware-concurrency_test.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

test/e2e/sensors/orientation_test.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

test/e2e_non_hosted/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ node_ts_library("tests") {
2828
"performance",
2929
"recorder",
3030
"rendering",
31+
"sensors",
3132
"sources",
3233
"targets",
3334
"webaudio",

test/e2e/sensors/BUILD.gn renamed to test/e2e_non_hosted/sensors/BUILD.gn

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44

55
import("../../../scripts/build/typescript/typescript.gni")
66

7-
node_ts_library("sensors") {
7+
ts_e2e_library("sensors") {
88
sources = [
99
"emulate-hardware-concurrency_test.ts",
10+
"helpers.ts",
1011
"idle_test.ts",
1112
"location_test.ts",
1213
"orientation_test.ts",
1314
"touch_test.ts",
1415
]
1516

1617
deps = [
18+
"../../e2e/helpers",
1719
"../../shared",
18-
"../helpers",
1920
]
2021
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2022 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+
import type * as puppeteer from 'puppeteer-core';
7+
8+
import {openPanelViaMoreTools} from '../../e2e/helpers/settings-helpers.js';
9+
import type {DevToolsPage} from '../shared/frontend-helper.js';
10+
import type {InspectedPage} from '../shared/target-helper.js';
11+
12+
async function waitForChangedConcurrency(
13+
lastConcurrency: number|undefined, devToolsPage: DevToolsPage, inspectedPage: InspectedPage) {
14+
return await devToolsPage.waitForFunction(async () => {
15+
const newConcurrency = await inspectedPage.evaluate('navigator.hardwareConcurrency') as number;
16+
if (newConcurrency !== lastConcurrency) {
17+
return newConcurrency;
18+
}
19+
return undefined;
20+
});
21+
}
22+
23+
describe('hardwareConcurrency emulation on Sensors panel', () => {
24+
it('can emulate navigator.hardwareConcurrency', async ({devToolsPage, inspectedPage}) => {
25+
await openPanelViaMoreTools('Sensors', devToolsPage);
26+
let concurrency = await waitForChangedConcurrency(undefined, devToolsPage, inspectedPage);
27+
28+
// Wait for the checkbox to load
29+
const toggle =
30+
await devToolsPage.waitFor('input[title="Hardware concurrency"]') as puppeteer.ElementHandle<HTMLInputElement>;
31+
await devToolsPage.waitForFunction(() => toggle.evaluate((e: HTMLInputElement) => {
32+
if (e.disabled) {
33+
return false;
34+
}
35+
e.click();
36+
return true;
37+
}));
38+
39+
// Check that the concurrency input shows the correct value:
40+
const input =
41+
await devToolsPage.waitFor('input[aria-label="Override the value reported by navigator.hardwareConcurrency"]');
42+
const initialValue = Number(await input.evaluate(input => {
43+
return input.value;
44+
}));
45+
46+
assert.deepEqual(initialValue, concurrency);
47+
48+
// Check setting a different value works:
49+
await input.click({clickCount: 3});
50+
await input.type(`${initialValue + 1}`);
51+
concurrency = await waitForChangedConcurrency(concurrency, devToolsPage, inspectedPage);
52+
assert.deepEqual(concurrency, initialValue + 1);
53+
54+
// Check that the warning is shown when exceeding the default value:
55+
const warning = await devToolsPage.waitForAria('Exceeding the default value may degrade system performance.') as
56+
puppeteer.ElementHandle<HTMLElement>;
57+
await devToolsPage.waitForFunction(
58+
async () => await warning.evaluate(e => getComputedStyle(e).visibility) === 'visible');
59+
60+
// Check that resetting the value works:
61+
const button = await devToolsPage.waitForAria('Reset to the default value');
62+
await button.click();
63+
64+
concurrency = await waitForChangedConcurrency(concurrency, devToolsPage, inspectedPage);
65+
assert.deepEqual(concurrency, initialValue);
66+
});
67+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2020 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 type {ElementHandle} from 'puppeteer-core';
6+
7+
import {
8+
selectOption,
9+
} from '../../shared/helper.js';
10+
import type {DevToolsPage} from '../shared/frontend-helper.js';
11+
12+
export async function setCustomOrientation(devtoolsPage: DevToolsPage) {
13+
const dropDown = await devtoolsPage.waitFor('.orientation-fields select');
14+
void selectOption(await dropDown.toElement('select'), 'custom');
15+
}
16+
17+
export async function getInputFieldValue(field: ElementHandle<Element>): Promise<string> {
18+
return await field.evaluate(input => (input as HTMLInputElement).value);
19+
}
20+
21+
export async function getOrientationInputs(devtoolsPage: DevToolsPage) {
22+
return await devtoolsPage.waitForMany('.orientation-axis-input-container input', 3);
23+
}
24+
25+
export async function getOrientationValues(devtoolsPage: DevToolsPage) {
26+
return await Promise.all((await getOrientationInputs(devtoolsPage))
27+
.map(i => i.evaluate(i => parseInt((i as HTMLInputElement).value, 10))));
28+
}

0 commit comments

Comments
 (0)