Commit edaef9cb authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Allow use of fullscreen API from fullscreen PWAs

Whatever issues caused us to initially disable the fullscreen API from
fullscreen PWAs, they no longer seem to be present. In testing the
sample in issue 720304 I couldn't find any issues.

Bug: 963929
Change-Id: I6fab2f4a558c2b7fdbd61b8ed92714f671bce7db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1627563Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664570}
parent 9b9402cd
......@@ -42,8 +42,6 @@ import org.chromium.chrome.browser.customtabs.CustomTabAppMenuPropertiesDelegate
import org.chromium.chrome.browser.customtabs.CustomTabIntentDataProvider;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import org.chromium.chrome.browser.document.DocumentUtils;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.fullscreen.FullscreenOptions;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabBrowserControlsState;
......@@ -589,30 +587,6 @@ public class WebappActivity extends SingleTabActivity {
protected void onUpdatedLastUsedTime(
WebappDataStorage storage, boolean previouslyLaunched, long previousUsageTimestamp) {}
@Override
protected ChromeFullscreenManager createFullscreenManager() {
// Disable HTML5 fullscreen in PWA fullscreen mode.
return new ChromeFullscreenManager(this, ChromeFullscreenManager.ControlsPosition.TOP) {
@Override
public void enterPersistentFullscreenMode(FullscreenOptions options) {
if (mWebappInfo.displayMode() == WebDisplayMode.FULLSCREEN) return;
super.enterPersistentFullscreenMode(options);
}
@Override
public void exitPersistentFullscreenMode() {
if (mWebappInfo.displayMode() == WebDisplayMode.FULLSCREEN) return;
super.exitPersistentFullscreenMode();
}
@Override
public boolean getPersistentFullscreenMode() {
if (mWebappInfo.displayMode() == WebDisplayMode.FULLSCREEN) return false;
return super.getPersistentFullscreenMode();
}
};
}
protected TabObserver createTabObserver() {
return new EmptyTabObserver() {
@Override
......
......@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.webapps;
import android.graphics.Color;
import android.net.Uri;
import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest;
import android.view.View;
import android.widget.TextView;
......@@ -23,6 +24,13 @@ import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.omnibox.UrlBar;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.WebappTestPage;
import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.JavaScriptUtils;
import org.chromium.content_public.browser.test.util.TouchCommon;
import java.util.concurrent.TimeoutException;
/**
* Test for various Display Modes of Web Apps.
......@@ -41,7 +49,7 @@ public class WebappDisplayModeTest {
@SmallTest
@Feature({"Webapps"})
public void testStandalone() throws Exception {
WebappActivity activity = startActivity(WebDisplayMode.STANDALONE);
WebappActivity activity = startActivity(WebDisplayMode.STANDALONE, "");
Assert.assertFalse(activity.getToolbarManager().getToolbarLayoutForTesting().isShown());
Assert.assertFalse(isFullscreen(activity));
......@@ -51,17 +59,40 @@ public class WebappDisplayModeTest {
@SmallTest
@Feature({"Webapps"})
public void testFullScreen() throws Exception {
WebappActivity activity = startActivity(WebDisplayMode.FULLSCREEN);
WebappActivity activity = startActivity(WebDisplayMode.FULLSCREEN, "");
Assert.assertFalse(activity.getToolbarManager().getToolbarLayoutForTesting().isShown());
Assert.assertTrue(isFullscreen(activity));
}
@Test
@MediumTest
@Feature({"Webapps"})
public void testFullScreenInFullscreen() throws Exception {
WebappActivity activity = startActivity(WebDisplayMode.FULLSCREEN, "fullscreen_on_click");
Assert.assertFalse(activity.getToolbarManager().getToolbarLayoutForTesting().isShown());
Assert.assertTrue(isFullscreen(activity));
WebContents contents = activity.getActivityTab().getWebContents();
TouchCommon.singleClickView(activity.getActivityTab().getContentView());
// Poll because clicking races with evaluating js evaluation.
CriteriaHelper.pollInstrumentationThread(
() -> getJavascriptResult(contents, "isBodyFullscreen()").equals("true"));
Assert.assertTrue(isFullscreen(activity));
TouchCommon.singleClickView(activity.getActivityTab().getContentView());
CriteriaHelper.pollInstrumentationThread(
() -> getJavascriptResult(contents, "isBodyFullscreen()").equals("false"));
Assert.assertTrue(isFullscreen(activity));
}
@Test
@SmallTest
@Feature({"Webapps"})
public void testMinimalUi() throws Exception {
WebappActivity activity = startActivity(WebDisplayMode.MINIMAL_UI);
WebappActivity activity = startActivity(WebDisplayMode.MINIMAL_UI, "");
Assert.assertFalse(isFullscreen(activity));
Assert.assertTrue(activity.getToolbarManager().getToolbarLayoutForTesting().isShown());
......@@ -76,11 +107,23 @@ public class WebappDisplayModeTest {
activity.findViewById(R.id.close_button).getVisibility());
}
private WebappActivity startActivity(@WebDisplayMode int displayMode) throws Exception {
private String getJavascriptResult(WebContents webContents, String js) {
try {
return JavaScriptUtils.executeJavaScriptAndWaitForResult(webContents, js);
} catch (InterruptedException | TimeoutException e) {
Assert.fail("Fatal interruption or timeout running JavaScript '" + js
+ "': " + e.toString());
return "";
}
}
private WebappActivity startActivity(@WebDisplayMode int displayMode, String action)
throws Exception {
String url = WebappTestPage.getServiceWorkerUrlWithAction(
mActivityTestRule.getTestServer(), action);
mActivityTestRule.startWebappActivity(
mActivityTestRule.createIntent()
.putExtra(ShortcutHelper.EXTRA_URL,
mActivityTestRule.getTestServer().getURL(WEB_APP_PATH))
.putExtra(ShortcutHelper.EXTRA_URL, url)
.putExtra(ShortcutHelper.EXTRA_DISPLAY_MODE, displayMode)
.putExtra(ShortcutHelper.EXTRA_THEME_COLOR, (long) Color.CYAN));
......
......@@ -17,6 +17,7 @@ const Action = {
CANCEL_PROMPT: 'cancel_prompt',
STASH_EVENT: 'stash_event',
STASH_EVENT_AND_PREVENT_DEFAULT: 'stash_event_and_prevent_default',
FULLSCREEN_ON_CLICK: 'fullscreen_on_click',
};
const LISTENER = "listener";
......@@ -61,6 +62,18 @@ function callStashedPrompt() {
callPrompt(stashedEvent);
}
function isBodyFullscreen() {
return document.fullscreenElement == document.body;
}
function toggleFullscreen() {
if (isBodyFullscreen()) {
document.exitFullscreen();
} else {
document.body.requestFullscreen();
}
}
function addClickListener(action) {
switch (action) {
case Action.CALL_STASHED_PROMPT_ON_CLICK:
......@@ -70,6 +83,9 @@ function addClickListener(action) {
window.addEventListener('click', callStashedPrompt);
verifyEvents("appinstalled");
break;
case Action.FULLSCREEN_ON_CLICK:
window.addEventListener('click', toggleFullscreen);
break;
}
}
......@@ -157,6 +173,9 @@ function initialize() {
case Action.STASH_EVENT:
addPromptListener(action);
break;
case Action.FULLSCREEN_ON_CLICK:
addClickListener(action);
break;
default:
throw new Error("Unrecognised action: " + action);
}
......
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