Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tests for viewport units with dynamic toolbar</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script>
const TOOLBAR_HEIGHT = 100;
add_task(async () => {
await SpecialPowers.pushPrefEnv({
set: [
["layout.dynamic-toolbar-max-height", TOOLBAR_HEIGHT],
["dom.meta-viewport.enabled",true],
],
});
// Load initial-scale=1.0 document in a new tab.
let newWindow = window.open("file_viewport_units_with_dynamic_toolbar.html");
await new Promise(resolve => {
newWindow.addEventListener("load", () => {
resolve()
})
});
const metrics = await SpecialPowers.spawn(newWindow, [], () => {
return {
scale: content.visualViewport.scale,
vh: content.document.querySelector("div").getBoundingClientRect().height,
};
});
is(metrics.scale, 1.0, "The document is scaled by 1.0");
// (Pinch-)Zoom in the document.
SpecialPowers.getDOMWindowUtils(newWindow).setResolutionAndScaleTo(2.0);
// Change the full-zoom value and restore it to invalidate viewport units.
SpecialPowers.setFullZoom(newWindow, 2.0);
SpecialPowers.setFullZoom(newWindow, 1.0);
const metricsOnZoomed = await SpecialPowers.spawn(newWindow, [], () => {
return {
scale: content.visualViewport.scale,
vh: content.document.querySelector("div").getBoundingClientRect().height,
};
});
is(metricsOnZoomed.scale, 2.0, "The document is now scaled by 2.0");
is(metricsOnZoomed.vh, metrics.vh, "The vh units value should be same");
newWindow.close();
});
</script>
</body>
</html>