mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-13 20:14:57 -10:00
Automatic update from web-platform-tests [iframe] Reset the size when navigating cross-origin This patch resets the intrinsic size info from `<iframe>` content when the content navigates cross-origin, to prevent leaking the size information. To do this, when `DocumentLoader` for an `<iframe>` child content checks if it's a cross-origin navigation in `CommitNavigation()`, and clears the natural dimension if so. `FrameLoader` is changed to keep the old document origin. `RenderWidgetHostViewChildFrame` needs a new queue for the intrinsic size events, as its `frame_connector_` isn't set yet at the `CommitNavigation()` timing. `content_switch_dependent_feature_overrides.cc` is needed to change to enable the flag in the browser when testing. In the non-testing environments, the flag in Blink and Browser are automatically synchronized. The existing test `responsive-iframe-navigation.html` is extended to test cross-origin as a new variant. In addition, it tests the initial viewport size of the child frame. All changes are under a runtime flag. Bug: 418397278 Change-Id: If8977a4fab2f9bf0c7bdb7bd2dc7c939b2b03f64 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7893591 Commit-Queue: Koji Ishii <[email protected]> Reviewed-by: Rakina Zata Amni <[email protected]> Reviewed-by: Kent Tamura <[email protected]> Reviewed-by: Ian Kilpatrick <[email protected]> Cr-Commit-Position: refs/heads/main@{#1644590} -- wpt-commits: baafee6d47fb8e90bdcd186d9cf2378042081b96 wpt-pr: 60522
116 lines
3.8 KiB
HTML
116 lines
3.8 KiB
HTML
<!doctype HTML>
|
|
<title>Responsive iframe should keep size during navigation</title>
|
|
<link rel="author" href="mailto:[email protected]">
|
|
<link rel="help" href="https://drafts.csswg.org/css-sizing/">
|
|
<meta name="variant" content="?origin=same">
|
|
<meta name="variant" content="?origin=cross">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="/common/get-host-info.sub.js"></script>
|
|
<style>
|
|
iframe {
|
|
frame-sizing: content-height;
|
|
}
|
|
</style>
|
|
<script>
|
|
const params = new URLSearchParams(window.location.search);
|
|
const origin = params.get('origin');
|
|
|
|
const iframe = document.createElement('iframe');
|
|
iframe.id = 'iframe';
|
|
iframe.frameBorder = '0';
|
|
iframe.src = 'resources/iframe-contents-navigation.html';
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
document.body.appendChild(iframe);
|
|
});
|
|
|
|
async_test(t => {
|
|
let numIframeLoadEvents = 0;
|
|
const heights = [];
|
|
|
|
// Use `ResizeObserver` to catch all resizes.
|
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
for (const entry of entries) {
|
|
assert_equals(entry.target, iframe);
|
|
heights.push(entry.contentRect.height);
|
|
switch (numIframeLoadEvents) {
|
|
case 0:
|
|
break;
|
|
case 1:
|
|
if (origin === 'cross') {
|
|
// At this point, it could be either 2 or 3 heights.
|
|
if (heights.length === 3) {
|
|
assert_array_equals(heights, [150, 200, 150]);
|
|
} else {
|
|
assert_array_equals(heights, [150, 200]);
|
|
}
|
|
} else {
|
|
assert_array_equals(heights, [150, 200]);
|
|
}
|
|
break;
|
|
case 2:
|
|
if (origin === 'cross') {
|
|
// We expect heights to have transitioned: 150 -> 200 -> 150 -> 400.
|
|
assert_array_equals(heights, [150, 200, 150, 400]);
|
|
} else {
|
|
assert_array_equals(heights, [150, 200, 400]);
|
|
}
|
|
t.done();
|
|
break;
|
|
default:
|
|
assert_less_than(numIframeLoadEvents, 3, "Unexpected iframe load events");
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
resizeObserver.observe(iframe);
|
|
|
|
window.addEventListener('message', t.step_func((e) => {
|
|
const data = e.data;
|
|
if (data && data.action === 'slow-will-block') {
|
|
// Check the initial viewport size of the child content.
|
|
const viewportHeight = data.viewportHeight;
|
|
if (origin === 'cross') {
|
|
assert_equals(viewportHeight, 150, "Cross-origin should see reset viewport height");
|
|
} else {
|
|
assert_equals(viewportHeight, 200, "Same-origin should see retained viewport height");
|
|
}
|
|
|
|
// Check re-layouts don't reset the height while loading new content.
|
|
triggerLayouts();
|
|
}
|
|
}));
|
|
|
|
iframe.addEventListener('load', t.step_func(() => {
|
|
++numIframeLoadEvents;
|
|
switch (numIframeLoadEvents) {
|
|
case 1:
|
|
assert_equals(iframe.offsetHeight, 200, "Initial height should be 200px");
|
|
let src = 'iframe-contents-slow.html';
|
|
if (origin === 'cross') {
|
|
const url = new URL(`resources/${src}`, window.location.href);
|
|
src = get_host_info().HTTP_REMOTE_ORIGIN + url.pathname;
|
|
}
|
|
iframe.contentWindow.postMessage({action: 'navigate', url: src}, '*');
|
|
break;
|
|
case 2:
|
|
break;
|
|
}
|
|
}));
|
|
|
|
function triggerLayouts() {
|
|
// Trigger layout by appending a `div`.
|
|
const div = document.createElement('div');
|
|
div.textContent = 'Trigger Layout';
|
|
document.body.appendChild(div);
|
|
document.body.offsetTop; // Force layout.
|
|
|
|
// Trigger layout by toggling `display: none`.
|
|
iframe.style.display = 'none';
|
|
document.body.offsetTop; // Force layout.
|
|
iframe.style.display = '';
|
|
document.body.offsetTop; // Force layout.
|
|
}
|
|
}, "Responsive iframe preserves size during navigation");
|
|
</script>
|