Commit 44cfe871 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

weblayer: fullscreen related tests

This is a good basic set. I would like more, but they require
js injection.

BUG=none
TEST=test*Fullscreen*

Change-Id: I0a605e4aefe3b0be6b9a754e437aa496f1e059bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1866271Reviewed-by: default avatarClark DuVall <cduvall@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706942}
parent 49e25a72
......@@ -237,7 +237,7 @@ void BrowserControllerImpl::OnExitFullscreen() {
// If |processing_enter_fullscreen_| is true, it means the callback is being
// called while processing EnterFullscreenModeForTab(). WebContents doesn't
// deal well with this. FATAL as Android generally doesn't run with DCHECKs.
LOG_IF(FATAL, !processing_enter_fullscreen_)
LOG_IF(FATAL, processing_enter_fullscreen_)
<< "exiting fullscreen while entering fullscreen is not supported";
web_contents_->ExitFullscreen(/* will_cause_resize */ false);
}
......
......@@ -40,6 +40,7 @@ public final class BrowserController {
mImpl.setFullscreenDelegateClient(mFullscreenDelegateClient);
} else {
mImpl.setFullscreenDelegateClient(null);
mFullscreenDelegateClient = null;
}
} catch (RemoteException e) {
throw new APICallException(e);
......
......@@ -265,10 +265,13 @@ instrumentation_test_apk("weblayer_instrumentation_test_apk") {
deps = [
"//base:base_java_test_support",
"//content/public/test/android:content_java_test_support",
"//net/android:net_java_test_support",
"//third_party/android_support_test_runner:runner_java",
]
java_files = [
"javatests/src/org/chromium/weblayer/test/BrowserObserverTest.java",
"javatests/src/org/chromium/weblayer/test/EventUtils.java",
"javatests/src/org/chromium/weblayer/test/FullscreenDelegateTest.java",
"javatests/src/org/chromium/weblayer/test/NavigationTest.java",
"javatests/src/org/chromium/weblayer/test/SmokeTest.java",
"javatests/src/org/chromium/weblayer/test/RenderingTest.java",
......@@ -276,5 +279,11 @@ instrumentation_test_apk("weblayer_instrumentation_test_apk") {
"javatests/src/org/chromium/weblayer/test/FragmentRestoreTest.java",
"shell_apk/src/org/chromium/weblayer/shell/WebLayerShellActivity.java",
]
additional_apks = [ "//weblayer/shell/android:weblayer_support_apk" ]
additional_apks = [
"//weblayer/shell/android:weblayer_support_apk",
"//net/android:net_test_support_apk",
]
data = [
"//weblayer/test/data/",
]
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.weblayer.test;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
/**
* Utilities related to event generation.
*/
public final class EventUtils {
private EventUtils() {}
/**
* Asynchronously posts a touch-down and touch-up event at the center of the supplied View.
*/
public static void simulateTouchCenterOfView(final View view) {
view.post(() -> {
long eventTime = SystemClock.uptimeMillis();
float x = (float) (view.getRight() - view.getLeft()) / 2;
float y = (float) (view.getBottom() - view.getTop()) / 2;
view.dispatchTouchEvent(
MotionEvent.obtain(eventTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0));
view.dispatchTouchEvent(
MotionEvent.obtain(eventTime, eventTime, MotionEvent.ACTION_UP, x, y, 0));
});
}
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.weblayer.test;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import org.junit.After;
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.BaseJUnit4ClassRunner;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.weblayer.FullscreenDelegate;
import org.chromium.weblayer.shell.WebLayerShellActivity;
/**
* Tests that FullscreenDelegate methods are invoked as expected.
*/
@RunWith(BaseJUnit4ClassRunner.class)
public class FullscreenDelegateTest {
@Rule
public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule();
private EmbeddedTestServer mTestServer;
private WebLayerShellActivity mActivity;
private Delegate mDelegate;
private static class Delegate extends FullscreenDelegate {
public int mEnterFullscreenCount;
public int mExitFullscreenCount;
public Runnable mExitFullscreenRunnable;
@Override
public void enterFullscreen(Runnable exitFullscreenRunner) {
mEnterFullscreenCount++;
mExitFullscreenRunnable = exitFullscreenRunner;
}
@Override
public void exitFullscreen() {
mExitFullscreenCount++;
}
public void waitForFullscreen() {
CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override
public boolean isSatisfied() {
return mEnterFullscreenCount == 1;
}
}, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
}
public void waitForExitFullscreen() {
CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override
public boolean isSatisfied() {
return mExitFullscreenCount == 1;
}
}, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
}
}
@Before
public void setUp() {
mTestServer = new EmbeddedTestServer();
mTestServer.initializeNative(InstrumentationRegistry.getInstrumentation().getContext(),
EmbeddedTestServer.ServerHTTPSSetting.USE_HTTP);
mTestServer.addDefaultHandlers("weblayer/test/data");
Assert.assertTrue(mTestServer.start(0));
String url = mTestServer.getURL("/fullscreen.html");
mActivity = mActivityTestRule.launchShellWithUrl(url);
Assert.assertNotNull(mActivity);
mActivityTestRule.waitForNavigation(url);
mDelegate = new Delegate();
TestThreadUtils.runOnUiThreadBlocking(
() -> { mActivity.getBrowserController().setFullscreenDelegate(mDelegate); });
// First touch enters fullscreen.
EventUtils.simulateTouchCenterOfView(mActivity.getWindow().getDecorView());
mDelegate.waitForFullscreen();
Assert.assertEquals(1, mDelegate.mEnterFullscreenCount);
}
@After
public void tearDown() {
mTestServer.stopAndDestroyServer();
}
@Test
@SmallTest
public void testFullscreen() {
// Second touch exits.
EventUtils.simulateTouchCenterOfView(mActivity.getWindow().getDecorView());
mDelegate.waitForExitFullscreen();
Assert.assertEquals(1, mDelegate.mExitFullscreenCount);
}
@Test
@SmallTest
public void testExitFullscreenWhenDelegateCleared() {
// Clearing the FullscreenDelegate should exit fullscreen.
TestThreadUtils.runOnUiThreadBlocking(
() -> { mActivity.getBrowserController().setFullscreenDelegate(null); });
mDelegate.waitForExitFullscreen();
Assert.assertEquals(1, mDelegate.mExitFullscreenCount);
}
@Test
@SmallTest
public void testExitFullscreenUsingRunnable() {
// Running the runnable supplied to the delegate should exit fullscreen.
TestThreadUtils.runOnUiThreadBlocking(mDelegate.mExitFullscreenRunnable);
mDelegate.waitForExitFullscreen();
Assert.assertEquals(1, mDelegate.mExitFullscreenCount);
}
}
<html>
<body>
<p id='x'></p>
</body>
<script>
function toggleFullscreen() {
if (!document.fullscreenElement) {
document.getElementById('x').requestFullscreen();
} else {
document.exitFullscreen();
}
}
document.addEventListener('touchstart', 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