Skip to content

[mediaqueries] add tests for custom media queries#48480

Open
romainmenke wants to merge 2 commits intoweb-platform-tests:masterfrom
romainmenke:css-media-queries-add-tests-for-custom-media-queries--amiable-butterfly-fish-35955c5e66
Open

[mediaqueries] add tests for custom media queries#48480
romainmenke wants to merge 2 commits intoweb-platform-tests:masterfrom
romainmenke:css-media-queries-add-tests-for-custom-media-queries--amiable-butterfly-fish-35955c5e66

Conversation

@romainmenke
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Member

@dbaron dbaron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these largely look good. I made a few suggestions to add additional tests that seem like they'd be useful. It's fine to add those now -- but if you'd prefer to just get these tests landed and maybe add those later, that's also ok too.

<head>
<title>Test: custom media queries that are undefined behave different from queries that evaluate to false</title>
<link rel="author" title="Romain Menke" href="https://github.com/romainmenke">
<link rel="help" href="https://www.w3.org/TR/mediaqueries-5/#at-ruledef-custom-media">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion!
I've added these links.

<!doctype html>
<html>
<head>
<title>Test: support for custom media queries</title>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to pair this test with a set of 5 similar things that all don't match. (For example, a custom query that isn't defined, a false one, the not of a true one, etc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this in a separate file (and shifted all the file numbers).

<head>
<title>Test: custom media queries with cycles are invalid</title>
<link rel="author" title="Romain Menke" href="https://github.com/romainmenke">
<link rel="help" href="https://www.w3.org/TR/mediaqueries-5/#at-ruledef-custom-media">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this test it might be good to also test that cyclic custom media queries become undefined even when they have or values that also make them clearly true. For example, these are undefined per spec:

@custom-media --test1-a screen or (--test1-b);
@custom-media --test1-b screen or (--test1-a);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

screen or (--test1-b) isn't valid, but screen, (--test4-b) is and I think it also covers what you want to test.

@romainmenke
Copy link
Copy Markdown
Contributor Author

Thank you for reviewing these @dbaron

I also realized that some tests were missing:

  • valid chains of custom media references
  • naming collisions (taking @layer into account)

So I've also added some tests for these aspects.


/* by source order */
@custom-media --test1 false;
@media (--test1) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this evaluate to false? We resolved source order for @Custom-Media: w3c/csswg-drafts#12536 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct!
Thank you for catching this.

I'll update this to match that resolution

Comment on lines +22 to +24
@media not ((color) or (monochrome)) {
.test1 { background: green; }
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't understand, what is it needed for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't remember and also don't understand why it is needed.
I'll remove it

@nt1m nt1m closed this Dec 11, 2025
@nt1m nt1m reopened this Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants