Skip to content

Commit

Permalink
Fixed resize event to be fired on the appearance of scroll bar in iframe
Browse files Browse the repository at this point in the history
Added check for change of scrollable area size in iframe
to make resize event fired on the appearance of scroll bar in iframe.
And added a test case to wpt.

Bug: 1487465
Change-Id: Ida82a010461ac6d856d879842d413bbbe19c67a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5096173
Commit-Queue: Nate Chapin <[email protected]>
Reviewed-by: David Bokan <[email protected]>
Reviewed-by: Nate Chapin <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1238373}
  • Loading branch information
canalun authored and chromium-wpt-export-bot committed Dec 16, 2023
1 parent 3fe62bd commit a85f0df
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions visual-viewport/viewport-scrollbars-cause-resize-in-iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!doctype html>
<title>Viewport: Scrollbars Cause Resize</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
<h1>Viewport: Scrollbars Cause Resize In IFrame</h1>
<h4>
Test Description: This test checks that the appearance of classic
scrollbars will cause a resize event to be fired at window.visualViewport in iframe.
</h4>
<iframe srcdoc="<p>Hello, world!</p>"></iframe>
<script>
async_test(t => {
window.onload = () => {
const iframe = document.querySelector("iframe");

let resize_event_count = 0;
iframe.contentWindow.visualViewport.addEventListener("resize", () => {
resize_event_count++;
});

const originalVisualViewportWidth = iframe.contentWindow.visualViewport.width;

iframe.contentDocument.body.style.height = "10000px";
// Force layout to queue a resize event at this moment.
iframe.contentDocument.body.clientWidth;

requestAnimationFrame(t.step_func_done(() => {
// it's uncontrollable whether the test will run
// with classic or overlay scrollbars in the case of Mac,
// so the check has to be conditional.
const width_changed = iframe.contentWindow.visualViewport.width !== originalVisualViewportWidth;
assert_equals(resize_event_count, width_changed ? 1 : 0);
}));
}
}, "the appearance of classic scrollbars will fire a resize event" +
"at window.visualViewport in iframe");
</script>
<div id="log"></div>

0 comments on commit a85f0df

Please sign in to comment.