Skip to content

Commit 1b91382

Browse files
Liviu RauDevtools-frontend LUCI CQ
authored andcommitted
Migrate test/e2e/emulation/foldable-device_test.ts
Fixed: 416404363 Change-Id: I14b69dd0ab4379cc097f312ce5be814d89e36441 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6787529 Auto-Submit: Liviu Rau <[email protected]> Reviewed-by: Simon Zünd <[email protected]> Commit-Queue: Simon Zünd <[email protected]>
1 parent e4e051d commit 1b91382

File tree

5 files changed

+60
-49
lines changed

5 files changed

+60
-49
lines changed

test/e2e/emulation/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ node_ts_library("emulation") {
88
sources = [
99
"custom-devices_test.ts",
1010
"dual-screen_test.ts",
11-
"foldable-device_test.ts",
1211
]
1312

1413
deps = [

test/e2e/emulation/foldable-device_test.ts

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

test/e2e/helpers/emulation-helpers.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,11 @@ export const clickDevicePosture =
165165
await waitForNotExpanded(DEVICE_POSTURE_DROPDOWN_SELECTOR, devToolsPage);
166166
};
167167

168-
export const getDevicePostureDropDown = async () => {
168+
export const getDevicePostureDropDown =
169+
async (devToolsPage: DevToolsPage = getBrowserAndPagesWrappers().devToolsPage) => {
169170
// dropdown menu for the posture selection.
170-
const dropdown = await $(DEVICE_POSTURE_DROPDOWN_SELECTOR) as puppeteer.ElementHandle<HTMLButtonElement>;
171-
return dropdown;
171+
const dropdown = await devToolsPage.$(DEVICE_POSTURE_DROPDOWN_SELECTOR);
172+
return dropdown as puppeteer.ElementHandle<HTMLButtonElement>| null;
172173
};
173174

174175
export const clickToggleButton = async () => {

test/e2e_non_hosted/emulation/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import("../../../scripts/build/typescript/typescript.gni")
66

77
ts_e2e_library("emulation") {
88
sources = [
9+
"foldable-device_test.ts",
910
"media-query-inspector_test.ts",
1011
"responsive_test.ts",
1112
]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
import {assert} from 'chai';
5+
6+
import {
7+
clickDevicePosture,
8+
getDevicePostureDropDown,
9+
getWidthOfDevice,
10+
openDeviceToolbar,
11+
selectFoldableDevice,
12+
selectNonDualScreenDevice,
13+
} from '../../e2e/helpers/emulation-helpers.js';
14+
import type {DevToolsPage} from '../shared/frontend-helper.js';
15+
import type {InspectedPage} from '../shared/target-helper.js';
16+
17+
const ZENBOOK_VERTICAL_SPANNED_WIDTH = '1706';
18+
const ZENBOOK_VERTICAL_WIDTH = '853';
19+
20+
// The test needs to be adapted from a browser test to an e2e test.
21+
// The main difference is that we need to pass the devToolsPage and inspectedPage
22+
// instances to the helper functions.
23+
// The browser test used a beforeEach hook to setup the page, this is now
24+
// a helper function that is called at the beginning of each test.
25+
async function setup(devToolsPage: DevToolsPage, inspectedPage: InspectedPage) {
26+
await inspectedPage.goToResource('emulation/dual-screen-inspector.html');
27+
await devToolsPage.waitFor('.tabbed-pane-left-toolbar');
28+
await openDeviceToolbar(devToolsPage, inspectedPage);
29+
}
30+
31+
describe('Test the Device Posture API support', () => {
32+
it('User can change the posture of a foldable device', async ({devToolsPage, inspectedPage}) => {
33+
await setup(devToolsPage, inspectedPage);
34+
await selectFoldableDevice(devToolsPage);
35+
let widthSingle = await getWidthOfDevice(devToolsPage);
36+
assert.strictEqual(widthSingle, ZENBOOK_VERTICAL_WIDTH);
37+
38+
await clickDevicePosture('Folded', devToolsPage);
39+
const widthDual = await getWidthOfDevice(devToolsPage);
40+
assert.strictEqual(widthDual, ZENBOOK_VERTICAL_SPANNED_WIDTH);
41+
42+
await clickDevicePosture('Continuous', devToolsPage);
43+
widthSingle = await getWidthOfDevice(devToolsPage);
44+
assert.strictEqual(widthSingle, ZENBOOK_VERTICAL_WIDTH);
45+
});
46+
47+
it('User may not change the posture for a non-foldable screen device', async ({devToolsPage, inspectedPage}) => {
48+
await setup(devToolsPage, inspectedPage);
49+
await selectNonDualScreenDevice(devToolsPage);
50+
// posture dropdown should not be found
51+
const dropdown = await getDevicePostureDropDown(devToolsPage);
52+
const hidden = dropdown ? await dropdown.evaluate(x => (x as Element).classList.contains('hidden')) : true;
53+
assert.isTrue(hidden);
54+
});
55+
});

0 commit comments

Comments
 (0)