|
| 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