blob: b19176c9fd6697091f00d0df805ed37009c0ca11 [file] [edit]
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {assert} from 'chai';
import {describe, it} from '../conductor/mocha-interface.js';
import {
getStyleRule,
goToResourceAndWaitForStyleSection,
SECTION_SUBTITLE_SELECTOR,
STYLE_PROPERTIES_SELECTOR,
waitForAndClickTreeElementWithPartialText,
waitForStyleRule,
} from '../helpers/elements-helpers.js';
import type {DevToolsPage} from '../shared/DevToolsPage.js';
async function getStyleRuleProperties(selector: string, count: number, devToolsPage: DevToolsPage) {
const rule = await getStyleRule(devToolsPage, selector);
const propertyElements =
await devToolsPage.waitForMany(STYLE_PROPERTIES_SELECTOR + ' .webkit-css-property', count, rule);
const properties = await Promise.all(propertyElements.map(e => e.evaluate(e => e.textContent)));
properties.sort();
const subtitle =
await devToolsPage.waitFor(SECTION_SUBTITLE_SELECTOR, rule).then(e => e.evaluate(e => e.textContent));
return {properties, subtitle};
}
describe('The styles pane', () => {
it('shows css functions', async ({devToolsPage, inspectedPage}) => {
await goToResourceAndWaitForStyleSection(devToolsPage, inspectedPage, 'elements/at-function.html');
await waitForStyleRule(devToolsPage, 'body');
await waitForAndClickTreeElementWithPartialText(devToolsPage, 'id=\u200B"test1"');
await waitForStyleRule(devToolsPage, '#test1');
assert.deepEqual(await getStyleRuleProperties('--f(--x)', 4, devToolsPage), {
properties: ['--myVar', '--y', '--y', 'result'],
subtitle: '<style>',
});
});
it('shows a foldable @function section when there are 5 or less functions', async ({devToolsPage, inspectedPage}) => {
await goToResourceAndWaitForStyleSection(devToolsPage, inspectedPage, 'elements/at-function.html');
await waitForStyleRule(devToolsPage, 'body');
await waitForAndClickTreeElementWithPartialText(devToolsPage, 'id=\u200B"test1"');
await waitForStyleRule(devToolsPage, '#test1');
const stylesPane = await devToolsPage.waitFor('div.styles-pane');
{
const section = await devToolsPage.waitForElementWithTextContent('@function', stylesPane);
assert.deepEqual(await section.evaluate(e => e.ariaExpanded), 'true');
const rule = await getStyleRule(devToolsPage, '--f(--x)');
assert.isTrue(await rule.evaluate(e => !e.classList.contains('hidden')));
}
{
const section = await devToolsPage.click('pierceShadowText/@function', {root: stylesPane});
await devToolsPage.waitForFunction(async () => 'false' === await section.evaluate(e => e.ariaExpanded));
const rule = await getStyleRule(devToolsPage, '--f(--x)');
await devToolsPage.waitForFunction(() => rule.evaluate(e => e.classList.contains('hidden')));
}
});
it('shows a collapsed @function section when there are more than 5 functions',
async ({devToolsPage, inspectedPage}) => {
await goToResourceAndWaitForStyleSection(devToolsPage, inspectedPage, 'elements/at-function.html');
await waitForStyleRule(devToolsPage, 'body');
await waitForAndClickTreeElementWithPartialText(devToolsPage, 'id=\u200B"test3"');
await waitForStyleRule(devToolsPage, '#test3');
const stylesPane = await devToolsPage.waitFor('div.styles-pane');
{
const section = await devToolsPage.waitForElementWithTextContent('@function', stylesPane);
assert.deepEqual(await section.evaluate(e => e.ariaExpanded), 'false');
// Pick the style rule added last to ensure the sections are fully drawn
const rule = await getStyleRule(devToolsPage, '--inner1(--x)');
assert.isTrue(await rule.evaluate(e => e.classList.contains('hidden')));
}
await devToolsPage.waitForFunction(async () => {
const section = await devToolsPage.click('pierceShadowText/@function', {root: stylesPane});
await devToolsPage.waitForFunction(async () => 'true' === await section.evaluate(e => e.ariaExpanded));
const rule = await getStyleRule(devToolsPage, '--inner1(--x)');
return await rule.evaluate(e => !e.classList.contains('hidden'));
});
});
it('expands @function section when a function link is clicked', async ({devToolsPage, inspectedPage}) => {
await goToResourceAndWaitForStyleSection(devToolsPage, inspectedPage, 'elements/at-function.html');
await waitForStyleRule(devToolsPage, 'body');
await waitForAndClickTreeElementWithPartialText(devToolsPage, 'id=\u200B"test3"');
await waitForStyleRule(devToolsPage, '#test3');
const stylesPane = await devToolsPage.waitFor('div.styles-pane');
const section = await devToolsPage.waitForElementWithTextContent('@function', stylesPane);
{
assert.deepEqual(await section.evaluate(e => e.ariaExpanded), 'false');
// Pick the style rule added last to ensure the sections are fully drawn
const rule = await getStyleRule(devToolsPage, '--inner1(--x)');
assert.isTrue(await rule.evaluate(e => e.classList.contains('hidden')));
}
await devToolsPage.waitForFunction(async () => {
await devToolsPage.click('[aria-label="CSS property value: --outer(yellow)"] button[role="link"]');
await devToolsPage.waitForFunction(async () => 'true' === await section.evaluate(e => e.ariaExpanded));
const rule = await getStyleRule(devToolsPage, '--inner1(--x)');
return await rule.evaluate(e => !e.classList.contains('hidden'));
});
});
});