mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 21:45:20 +00:00
Tests: Import a WPT test for dynamic changes to media queries in iframes
This commit is contained in:
parent
327dc8e82a
commit
afff44be86
Notes:
github-actions[bot]
2025-02-13 19:53:41 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/afff44be86c Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3558 Reviewed-by: https://github.com/AtkinsSJ ✅
2 changed files with 131 additions and 0 deletions
|
@ -0,0 +1,27 @@
|
|||
Harness status: OK
|
||||
|
||||
Found 22 tests
|
||||
|
||||
22 Fail
|
||||
Fail matchMedia('(max-width: 150px)').matches should update immediately
|
||||
Fail matchMedia('(width: 100px)').matches should update immediately
|
||||
Fail matchMedia('(orientation: portrait)').matches should update immediately
|
||||
Fail matchMedia('(aspect-ratio: 1/1)').matches should update immediately
|
||||
Fail matchMedia('(max-aspect-ratio: 4/3)').matches should update immediately
|
||||
Fail matchMedia('(height: 100px)').matches should update immediately
|
||||
Fail matchMedia('(max-height: 150px)').matches should update immediately
|
||||
Fail matchMedia('(min-aspect-ratio: 3/4)').matches should update immediately
|
||||
Fail matchMedia('(min-height: 150px)').matches should update immediately
|
||||
Fail matchMedia('(aspect-ratio: 1/2)').matches should update immediately
|
||||
Fail matchMedia('(min-width: 150px)').matches should update immediately
|
||||
Fail matchMedia('(min-aspect-ratio: 4/3)').matches should update immediately
|
||||
Fail matchMedia('(max-width: 150px)') should not receive a change event until update the rendering step of HTML5 event loop
|
||||
Fail matchMedia('(width: 100px)') should not receive a change event until update the rendering step of HTML5 event loop
|
||||
Fail matchMedia('(orientation: portrait)') should not receive a change event until update the rendering step of HTML5 event loop
|
||||
Fail matchMedia('(aspect-ratio: 1/1)') should not receive a change event until update the rendering step of HTML5 event loop
|
||||
Fail matchMedia('(max-aspect-ratio: 4/3)') should not receive a change event until update the rendering step of HTML5 event loop
|
||||
Fail matchMedia('(max-width: 150px)') should receive a change event after resize event on the window but before a requestAnimationFrame callback is called
|
||||
Fail matchMedia('(width: 100px)') should receive a change event after resize event on the window but before a requestAnimationFrame callback is called
|
||||
Fail matchMedia('(orientation: portrait)') should receive a change event after resize event on the window but before a requestAnimationFrame callback is called
|
||||
Fail matchMedia('(aspect-ratio: 1/1)') should receive a change event after resize event on the window but before a requestAnimationFrame callback is called
|
||||
Fail matchMedia('(max-aspect-ratio: 4/3)') should receive a change event after resize event on the window but before a requestAnimationFrame callback is called
|
|
@ -0,0 +1,104 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<link rel="help" href="https://drafts.csswg.org/mediaqueries-4/#mf-dimensions">
|
||||
<script src="../../resources/testharness.js"></script>
|
||||
<script src="../../resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
|
||||
async function createFrameAndUpdateLayout(test) {
|
||||
const iframe = await new Promise((resolve) => {
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.style.width = '100px';
|
||||
iframe.style.height = '100px';
|
||||
iframe.onload = () => resolve(iframe);
|
||||
document.body.appendChild(iframe);
|
||||
test.add_cleanup(() => iframe.remove());
|
||||
});
|
||||
iframe.contentDocument.body.innerHTML = '<span>some content</span>';
|
||||
window.preventOptimization1 = iframe.getBoundingClientRect();
|
||||
window.preventOptimization2 = iframe.contentDocument.querySelector('span').getBoundingClientRect();
|
||||
return iframe;
|
||||
}
|
||||
|
||||
for (const query of ['(max-width: 150px)', '(width: 100px)', '(orientation: portrait)', '(aspect-ratio: 1/1)', '(max-aspect-ratio: 4/3)']) {
|
||||
promise_test(async function () {
|
||||
const iframe = await createFrameAndUpdateLayout(this);
|
||||
const mediaQuery = iframe.contentWindow.matchMedia(query);
|
||||
assert_true(mediaQuery.matches);
|
||||
iframe.style.width = '200px';
|
||||
assert_false(mediaQuery.matches);
|
||||
}, `matchMedia('${query}').matches should update immediately`);
|
||||
}
|
||||
|
||||
for (const query of ['(height: 100px)', '(max-height: 150px)', '(min-aspect-ratio: 3/4)']) {
|
||||
promise_test(async function () {
|
||||
const iframe = await createFrameAndUpdateLayout(this);
|
||||
const mediaQuery = iframe.contentWindow.matchMedia(query);
|
||||
assert_true(mediaQuery.matches);
|
||||
iframe.style.height = '200px';
|
||||
assert_false(mediaQuery.matches);
|
||||
}, `matchMedia('${query}').matches should update immediately`);
|
||||
}
|
||||
|
||||
for (const query of ['(min-height: 150px)', '(aspect-ratio: 1/2)']) {
|
||||
promise_test(async function () {
|
||||
const iframe = await createFrameAndUpdateLayout(this);
|
||||
const mediaQuery = iframe.contentWindow.matchMedia(query);
|
||||
assert_false(mediaQuery.matches);
|
||||
iframe.style.height = '200px';
|
||||
assert_true(mediaQuery.matches);
|
||||
}, `matchMedia('${query}').matches should update immediately`);
|
||||
}
|
||||
|
||||
for (const query of ['(min-width: 150px)', '(min-aspect-ratio: 4/3)']) {
|
||||
promise_test(async function () {
|
||||
const iframe = await createFrameAndUpdateLayout(this);
|
||||
const mediaQuery = iframe.contentWindow.matchMedia(query);
|
||||
assert_false(mediaQuery.matches);
|
||||
iframe.style.width = '200px';
|
||||
assert_true(mediaQuery.matches);
|
||||
}, `matchMedia('${query}').matches should update immediately`);
|
||||
}
|
||||
|
||||
for (const query of ['(max-width: 150px)', '(width: 100px)', '(orientation: portrait)', '(aspect-ratio: 1/1)', '(max-aspect-ratio: 4/3)']) {
|
||||
promise_test(async function () {
|
||||
const iframe = await createFrameAndUpdateLayout(this);
|
||||
const mediaQuery = iframe.contentWindow.matchMedia(query);
|
||||
let changes = 0;
|
||||
mediaQuery.addEventListener('change', () => ++changes);
|
||||
assert_true(mediaQuery.matches);
|
||||
assert_equals(changes, 0);
|
||||
iframe.style.width = '200px';
|
||||
assert_false(mediaQuery.matches);
|
||||
assert_equals(changes, 0);
|
||||
await new Promise(requestAnimationFrame);
|
||||
assert_false(mediaQuery.matches);
|
||||
assert_equals(changes, 1);
|
||||
}, `matchMedia('${query}') should not receive a change event until update the rendering step of HTML5 event loop`);
|
||||
}
|
||||
|
||||
for (const query of ['(max-width: 150px)', '(width: 100px)', '(orientation: portrait)', '(aspect-ratio: 1/1)', '(max-aspect-ratio: 4/3)']) {
|
||||
promise_test(async function () {
|
||||
const iframe = await createFrameAndUpdateLayout(this);
|
||||
const mediaQuery = iframe.contentWindow.matchMedia(query);
|
||||
const events = [];
|
||||
iframe.contentWindow.addEventListener('resize', () => {
|
||||
assert_array_equals(events, []);
|
||||
events.push('resize');
|
||||
});
|
||||
mediaQuery.addEventListener('change', () => events.push('change'));
|
||||
assert_true(mediaQuery.matches);
|
||||
assert_array_equals(events, []);
|
||||
iframe.style.width = '200px';
|
||||
assert_false(mediaQuery.matches);
|
||||
assert_array_equals(events, []);
|
||||
await new Promise(requestAnimationFrame);
|
||||
assert_false(mediaQuery.matches);
|
||||
assert_array_equals(events, ['resize', 'change']);
|
||||
}, `matchMedia('${query}') should receive a change event after resize event on the window but before a requestAnimationFrame callback is called`);
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Reference in a new issue