Commit 88b825e1 authored by Scott Violet's avatar Scott Violet Committed by Chromium LUCI CQ

weblayer: fix bug where controls would show on rotation

onOffsetsChanged() does nothing if fullscreen. This changes the
code to call to setControlsOffset() so that the offsets are
correctly updated.

BUG=1149335
TEST=testTopViewRemainsHiddenOnFullscreenRotation

Change-Id: I419f629292caf5f4454a04920c6a9778c8f16731
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2575898Reviewed-by: default avatarRobbie McElrath <rmcelrath@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834026}
parent 80fe85e9
......@@ -7,13 +7,15 @@ package org.chromium.weblayer.test;
import androidx.test.filters.SmallTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.weblayer.Browser;
import org.chromium.weblayer.BrowserControlsOffsetCallback;
import org.chromium.weblayer.shell.InstrumentationActivity;
/**
......@@ -28,8 +30,8 @@ public class FullscreenCallbackTest {
private InstrumentationActivity mActivity;
private TestFullscreenCallback mDelegate;
@Before
public void setUp() {
// Launch WL and triggers html fullscreen.
private void enterFullscren() {
String url = mActivityTestRule.getTestDataURL("fullscreen.html");
mActivity = mActivityTestRule.launchShellWithUrl(url);
Assert.assertNotNull(mActivity);
......@@ -47,6 +49,7 @@ public class FullscreenCallbackTest {
@SmallTest
@DisabledTest(message = "crbug.com/1133893")
public void testFullscreen() {
enterFullscren();
// Second touch exits.
EventUtils.simulateTouchCenterOfView(mActivity.getWindow().getDecorView());
mDelegate.waitForExitFullscreen();
......@@ -56,6 +59,7 @@ public class FullscreenCallbackTest {
@Test
@SmallTest
public void testExitFullscreenWhenDelegateCleared() {
enterFullscren();
// Clearing the FullscreenCallback should exit fullscreen.
TestThreadUtils.runOnUiThreadBlocking(
() -> { mActivity.getTab().setFullscreenCallback(null); });
......@@ -66,6 +70,7 @@ public class FullscreenCallbackTest {
@Test
@SmallTest
public void testExitFullscreenUsingRunnable() {
enterFullscren();
// Running the runnable supplied to the delegate should exit fullscreen.
TestThreadUtils.runOnUiThreadBlocking(mDelegate.mExitFullscreenRunnable);
mDelegate.waitForExitFullscreen();
......@@ -75,6 +80,7 @@ public class FullscreenCallbackTest {
@Test
@SmallTest
public void testExitFullscreenWhenTabDestroyed() {
enterFullscren();
// Destroying the tab should exit fullscreen.
TestThreadUtils.runOnUiThreadBlocking(
() -> { mActivity.getTab().getBrowser().destroyTab(mActivity.getTab()); });
......@@ -88,6 +94,57 @@ public class FullscreenCallbackTest {
@Test
@SmallTest
public void testDestroyFragmentWhileFullscreen() {
enterFullscren();
TestThreadUtils.runOnUiThreadBlocking(() -> { mActivity.destroyFragment(); });
}
// Waits for the top offset to go to -height. This means the view is completely hidden.
private final class BrowserControlsOffsetCallbackImpl extends BrowserControlsOffsetCallback {
private final CallbackHelper mCallbackHelper;
BrowserControlsOffsetCallbackImpl(CallbackHelper callbackHelper) {
mCallbackHelper = callbackHelper;
}
@Override
public void onTopViewOffsetChanged(int offset) {
int height = mActivity.getTopContentsContainer().getHeight();
if (height != 0 && offset == -height) {
mCallbackHelper.notifyCalled();
}
}
}
@Test
@SmallTest
public void testTopViewRemainsHiddenOnFullscreenRotation() throws Exception {
String url = mActivityTestRule.getTestDataURL("rotation2.html");
mActivity = mActivityTestRule.launchShellWithUrl(url);
// Ensure the fragment is not recreated as otherwise things bounce around more.
mActivityTestRule.setRetainInstance(true);
Assert.assertNotNull(mActivity);
mDelegate = new TestFullscreenCallback();
CallbackHelper callbackHelper = new CallbackHelper();
// The offsets may move around during rotation. Wait for reattachment before installing
// the BrowserControlsOffsetCallback.
InstrumentationActivity.registerOnCreatedCallback(
new InstrumentationActivity.OnCreatedCallback() {
@Override
public void onCreated(Browser browser) {
browser.registerBrowserControlsOffsetCallback(
new BrowserControlsOffsetCallbackImpl(callbackHelper));
}
});
TestThreadUtils.runOnUiThreadBlocking(
() -> { mActivity.getTab().setFullscreenCallback(mDelegate); });
EventUtils.simulateTouchCenterOfView(mActivity.getWindow().getDecorView());
mDelegate.waitForFullscreen();
Assert.assertEquals(1, mDelegate.mEnterFullscreenCount);
// There should be a fullscreen element.
Assert.assertTrue(mActivityTestRule.executeScriptAndExtractBoolean(
"document.fullscreenElement != null"));
// Rotation should trigger the view being totally hidden.
callbackHelper.waitForFirst();
}
}
......@@ -376,7 +376,12 @@ class BrowserControlsContainerView extends FrameLayout {
mLastHeight = height;
if (mLastWidth > 0 && mLastHeight > 0 && mViewResourceAdapter == null) {
createAdapterAndLayer();
if (mLastShownAmountWithView == DEFAULT_LAST_SHOWN_AMOUNT && mSavedState != null) {
if (mIsFullscreen) {
// This calls setControlsOffset() as onOffsetsChanged() does (mostly) nothing when
// fullscreen.
setControlsOffset(mIsTop ? -mLastHeight : mLastHeight, 0);
} else if (mLastShownAmountWithView == DEFAULT_LAST_SHOWN_AMOUNT
&& mSavedState != null) {
// If there wasn't a View before and we have non-empty saved state from a previous
// BrowserControlsContainerView instance, apply those saved offsets now. We can't
// rely on BrowserControlsOffsetManager to notify us of the correct location as we
......
<html>
<body style="height:5000px">
<p>A page that will rotate on touch.</p>
</body>
<script>
async function toggleFullscreen() {
if (!document.fullscreenElement) {
await document.documentElement.requestFullscreen();
await screen.orientation.lock("landscape-primary");
} else {
document.exitFullscreen();
}
}
document.addEventListener('touchend', function(e) { toggleFullscreen(); }, false);
</script>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment