Bug 1523541 - window.innerHeight returns the size for vh units when the dynamic toolbar is completely hidden. r=botond

Differential Revision: https://phabricator.services.mozilla.com/D55071

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Hiroyuki Ikezoe 2019-12-04 04:41:08 +00:00
Родитель 831ca102d1
Коммит 63e3dd4144
3 изменённых файлов: 50 добавлений и 4 удалений

Просмотреть файл

@ -3325,7 +3325,15 @@ nsresult nsGlobalWindowOuter::GetInnerSize(CSSIntSize& aSize) {
viewManager->FlushDelayedResize(false);
}
aSize = CSSIntRect::FromAppUnitsRounded(presContext->GetVisibleArea().Size());
// FIXME: Bug 1598487 - Return the layout viewport instead of the ICB.
nsSize viewportSize = presContext->GetVisibleArea().Size();
if (presContext->GetDynamicToolbarState() == DynamicToolbarState::Collapsed) {
viewportSize =
nsLayoutUtils::ExpandHeightForViewportUnits(presContext, viewportSize);
}
aSize = CSSIntRect::FromAppUnitsRounded(viewportSize);
return NS_OK;
}

Просмотреть файл

@ -48,9 +48,6 @@ is(parseInt(percentHeight) + 50, parseInt(vhHeight),
"vh units should be 50px greater than %-units");
is(document.documentElement.clientHeight, parseInt(percentHeight),
"documentElement.clientHeight should equal to %-units");
is(window.innerHeight, parseInt(percentHeight),
"window.innerHeight should equal to %-units when the dynamic toolbar is " +
"visible");
ok(matchMedia(`(height: ${percentHeight})`).matches,
"Media Queries' height is not including the dynamic toolbar max height");

Просмотреть файл

@ -243,4 +243,45 @@ class DynamicToolbarTest : BaseSessionTest() {
assertThat("'resize' event on window should be fired when the dynamc toolbar is completely hidden",
promise.value as Boolean, equalTo(true))
}
@WithDisplay(height = SCREEN_HEIGHT, width = SCREEN_WIDTH)
@Test
fun windowInnerHeight() {
val dynamicToolbarMaxHeight = SCREEN_HEIGHT / 2
sessionRule.display?.run { setDynamicToolbarMaxHeight(dynamicToolbarMaxHeight) }
// Set active since setVerticalClipping call affects only for forground tab.
mainSession.setActive(true)
// We intentionally use FIXED_BOTTOM instead of FIXED_VH in this test since
// FIXED_VH has `minimum-scale=0.5` thus we can't properly test window.innerHeight
// with FXIED_VH for now due to bug 1598487.
mainSession.loadTestPath(BaseSessionTest.FIXED_BOTTOM)
mainSession.waitForPageStop()
val pixelRatio = sessionRule.session.evaluateJS("window.devicePixelRatio") as Double
for (i in 1..dynamicToolbarMaxHeight - 1) {
val promise = sessionRule.session.evaluatePromiseJS("""
new Promise(resolve => {
window.visualViewport.addEventListener('resize', resolve(window.innerHeight));
});
""".trimIndent())
// Simulate the dynamic toolbar is going to be hidden.
sessionRule.display?.run { setVerticalClipping(-i) }
assertThat("window.innerHeight should not be changed in response to the dynamc toolbar transition",
promise.value as Double, closeTo(SCREEN_HEIGHT / 2 / pixelRatio, .01))
}
val promise = sessionRule.session.evaluatePromiseJS("""
new Promise(resolve => {
window.addEventListener('resize', () => { resolve(window.innerHeight); }, { once: true });
});
""".trimIndent())
sessionRule.display?.run { setVerticalClipping(-dynamicToolbarMaxHeight) }
assertThat("window.innerHeight should be changed when the dynamc toolbar is completely hidden",
promise.value as Double, closeTo(SCREEN_HEIGHT / pixelRatio, .01))
}
}