Commit 40c880a8 authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[Display Cutout] Add a kCoverForcedByUserAgent

Add a kCoverForcedByUserAgent ViewportFit value which is used
when the media controls are forcing kCover. The value will
behave exactly the same as kCover but being seperate will
allow us to track it seperately in metrics.

BUG=855739

Change-Id: I7cf8418f190b47cf1e04d5dc461448a4df5234ed
Reviewed-on: https://chromium-review.googlesource.com/1117766Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#573503}
parent 4242093f
......@@ -173,6 +173,7 @@ public class DisplayCutoutController implements InsetObserverView.WindowInsetObs
switch (mViewportFit) {
case ViewportFit.CONTAIN:
return VIEWPORT_FIT_CONTAIN;
case ViewportFit.COVER_FORCED_BY_USER_AGENT:
case ViewportFit.COVER:
return VIEWPORT_FIT_COVER;
case ViewportFit.AUTO:
......
......@@ -11,6 +11,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.blink.mojom.ViewportFit;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
......@@ -74,6 +75,28 @@ public class DisplayCutoutTest {
DisplayCutoutTestRule.LayoutParamsApi28.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT);
}
/**
* Test that the safe area is applied when we have viewport fit cover forced by the user agent.
*/
@Test
@LargeTest
public void testViewportFitCoverForced() throws InterruptedException, TimeoutException {
mTestRule.enterFullscreen();
// Set the viewport fit internally as this value is internal only.
mTestRule.setViewportFitInternal(ViewportFit.COVER_FORCED_BY_USER_AGENT);
mTestRule.waitForSafeArea(DisplayCutoutTestRule.TEST_SAFE_AREA_WITH_CUTOUT);
mTestRule.waitForLayoutInDisplayCutoutMode(
DisplayCutoutTestRule.LayoutParamsApi28.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES);
mTestRule.exitFullscreen();
mTestRule.waitForSafeArea(DisplayCutoutTestRule.TEST_SAFE_AREA_WITHOUT_CUTOUT);
mTestRule.waitForLayoutInDisplayCutoutMode(
DisplayCutoutTestRule.LayoutParamsApi28.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT);
}
/**
* Test that no safe area is applied when we have no viewport fit.
*/
......
......@@ -13,6 +13,7 @@ import org.junit.Assert;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.UsedByReflection;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.fullscreen.FullscreenOptions;
......@@ -23,6 +24,7 @@ import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.DOMUtils;
import org.chromium.content.browser.test.util.JavaScriptUtils;
import org.chromium.content_public.browser.WebContentsObserver;
import org.chromium.net.test.EmbeddedTestServer;
import java.util.concurrent.TimeoutException;
......@@ -244,6 +246,11 @@ public class DisplayCutoutTestRule extends ChromeActivityTestRule<ChromeActivity
mTab.getWebContents(), "setViewportFit('" + value + "')");
}
/** Set the viewport-fit value using internal APIs. */
public void setViewportFitInternal(@WebContentsObserver.ViewportFitType int value) {
ThreadUtils.runOnUiThreadBlocking(() -> mTestController.setViewportFit(value));
}
/** Get the safe area using JS and parse the JSON result to a Rect. */
private Rect getSafeAreaUsingJavaScript(String code)
throws InterruptedException, TimeoutException {
......
......@@ -98,6 +98,16 @@ public class DisplayCutoutControllerTest {
mDisplayCutoutController.getDisplayCutoutMode());
}
@Test
@SmallTest
public void testCutoutModeWhenCoverForcedAndInteractable() throws Throwable {
when(mTab.isUserInteractable()).thenReturn(true);
mDisplayCutoutController.setViewportFit(ViewportFit.COVER_FORCED_BY_USER_AGENT);
Assert.assertEquals("LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES",
mDisplayCutoutController.getDisplayCutoutMode());
}
@Test
@SmallTest
public void testCutoutModeWhenContainAndInteractable() throws Throwable {
......@@ -124,6 +134,14 @@ public class DisplayCutoutControllerTest {
mDisplayCutoutController.getDisplayCutoutMode());
}
@Test
@SmallTest
public void testCutoutModeWhenCoverForcedAndNotInteractable() throws Throwable {
mDisplayCutoutController.setViewportFit(ViewportFit.COVER_FORCED_BY_USER_AGENT);
Assert.assertEquals("LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT",
mDisplayCutoutController.getDisplayCutoutMode());
}
@Test
@SmallTest
public void testCutoutModeWhenContainAndNotInteractable() throws Throwable {
......
......@@ -17,6 +17,10 @@ enum ViewportFit {
// The initial layout viewport and the visual viewport are set to the
// circumscribed rectangle of the physical screen of the device.
kCover,
// This has the same behaviour as |kCover| but it identifies that the
// ViewportFit value was forced by the user agent by the media controls.
kCoverForcedByUserAgent,
};
// Used for renderer -> browser calls about display cutout.
......
......@@ -1101,11 +1101,11 @@ TEST_F(ViewportFitDocumentTest, ForceExpandIntoCutout) {
// Now override the viewport fit value and expect it to be kCover.
GetDocument().GetViewportData().SetExpandIntoDisplayCutout(true);
EXPECT_EQ(mojom::ViewportFit::kCover, GetViewportFit());
EXPECT_EQ(mojom::ViewportFit::kCoverForcedByUserAgent, GetViewportFit());
// Test that even if we change the value we ignore it.
SetHtmlInnerHTML("<meta name='viewport' content='viewport-fit=auto'>");
EXPECT_EQ(mojom::ViewportFit::kCover, GetViewportFit());
EXPECT_EQ(mojom::ViewportFit::kCoverForcedByUserAgent, GetViewportFit());
// Now remove the override and check that it went back to the previous value.
GetDocument().GetViewportData().SetExpandIntoDisplayCutout(false);
......
......@@ -82,7 +82,7 @@ void ViewportData::UpdateViewportDescription() {
// If we are forcing to expand into the display cutout then we should override
// the viewport fit value.
if (force_expand_display_cutout_)
current_viewport_fit = mojom::ViewportFit::kCover;
current_viewport_fit = mojom::ViewportFit::kCoverForcedByUserAgent;
if (viewport_fit_ != current_viewport_fit) {
if (AssociatedInterfaceProvider* provider =
......
......@@ -177,7 +177,7 @@ TEST_F(MediaControlsDisplayCutoutDelegateTest, CombinedGesture) {
SimulateEvent(CreateTouchEventWithList(EventTypeNames::touchmove, list));
// Check the viewport fit value has been correctly set.
EXPECT_EQ(mojom::ViewportFit::kCover, CurrentViewportFit());
EXPECT_EQ(mojom::ViewportFit::kCoverForcedByUserAgent, CurrentViewportFit());
// Finish the gesture by contracting.
list = CreateTouchListWithTwoPoints(0, 0, 0, 0);
......@@ -197,7 +197,7 @@ TEST_F(MediaControlsDisplayCutoutDelegateTest, ContractingGesture) {
SimulateExpandingGesture();
// Check the viewport fit value has been correctly set.
EXPECT_EQ(mojom::ViewportFit::kCover, CurrentViewportFit());
EXPECT_EQ(mojom::ViewportFit::kCoverForcedByUserAgent, CurrentViewportFit());
// Simulate a contracting gesture and check the value has been restored.
SimulateContractingGesture();
......@@ -223,7 +223,7 @@ TEST_F(MediaControlsDisplayCutoutDelegateTest, ExpandingGesture) {
SimulateExpandingGesture();
// Check the viewport fit value has been correctly set.
EXPECT_EQ(mojom::ViewportFit::kCover, CurrentViewportFit());
EXPECT_EQ(mojom::ViewportFit::kCoverForcedByUserAgent, CurrentViewportFit());
// Exit fullscreen and check the value has been restored.
SimulateExitFullscreen();
......@@ -240,11 +240,11 @@ TEST_F(MediaControlsDisplayCutoutDelegateTest, ExpandingGesture_DoubleNoop) {
SimulateExpandingGesture();
// Check the viewport fit value has been correctly set.
EXPECT_EQ(mojom::ViewportFit::kCover, CurrentViewportFit());
EXPECT_EQ(mojom::ViewportFit::kCoverForcedByUserAgent, CurrentViewportFit());
// Simulate another expanding gesture and make sure nothing changed.
SimulateExpandingGesture();
EXPECT_EQ(mojom::ViewportFit::kCover, CurrentViewportFit());
EXPECT_EQ(mojom::ViewportFit::kCoverForcedByUserAgent, CurrentViewportFit());
}
TEST_F(MediaControlsDisplayCutoutDelegateTest, IncompleteGestureClearsState) {
......
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