Skip to content

Commit

Permalink
[PCCT-SideSheet] Calculate PCCT type no 3P check
Browse files Browse the repository at this point in the history
(cherry picked from commit 113ba60)

Bug: 1427246
Change-Id: I5e14448748f73bd0c8c5a38d1df5eb8c8d66b6fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4370863
Commit-Queue: Zach Katz <[email protected]>
Reviewed-by: Kevin Grosu <[email protected]>
Code-Coverage: Findit <[email protected]>
Cr-Original-Commit-Position: refs/heads/main@{#1121903}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4374070
Bot-Commit: Rubber Stamper <[email protected]>
Cr-Commit-Position: refs/branch-heads/5672@{#54}
Cr-Branched-From: 5f2a724-refs/heads/main@{#1121455}
  • Loading branch information
Zach Katz authored and Chromium LUCI CQ committed Mar 27, 2023
1 parent beb074d commit 43be564
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.chromium.chrome.browser.browserservices.intents.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.customtabs.features.partialcustomtab.PartialCustomTabBaseStrategy.PartialCustomTabType;
import org.chromium.chrome.browser.customtabs.features.toolbar.CustomTabToolbar;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.fullscreen.FullscreenManager;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.lifecycle.ConfigurationChangedObserver;
Expand Down Expand Up @@ -210,14 +209,13 @@ public void destroy() {

private @PartialCustomTabType int calculatePartialCustomTabType() {
return calculatePartialCustomTabType(mActivity, mUnclampedInitialWidth,
mUnclampedInitialHeight, mVersionCompat::getDisplayWidthDp, mBreakPointDp,
ChromeFeatureList.sCctResizableSideSheetForThirdParties.isEnabled());
mUnclampedInitialHeight, mVersionCompat::getDisplayWidthDp, mBreakPointDp);
}

@VisibleForTesting
static @PartialCustomTabType int calculatePartialCustomTabType(Activity activity,
int initialWidth, int initialHeight, Supplier<Integer> displayWidthDpSupplier,
int breakPointDp, boolean ssEnabled) {
int breakPointDp) {
// TODO(crbug.com/1407227) Until we are able to handle multi-window case for both
// bottom-sheet and side-sheet we will display a full-size PCCT.
if (MultiWindowUtils.getInstance().isInMultiWindowMode(activity)) {
Expand All @@ -229,13 +227,13 @@ public void destroy() {
int displayWidthDp = -1;
if (initialWidth > 0 && initialHeight > 0) {
if (displayWidthDp < 0) displayWidthDp = displayWidthDpSupplier.get();
return displayWidthDp < breakPointDp || !ssEnabled ? PartialCustomTabType.BOTTOM_SHEET
: PartialCustomTabType.SIDE_SHEET;
return displayWidthDp < breakPointDp ? PartialCustomTabType.BOTTOM_SHEET
: PartialCustomTabType.SIDE_SHEET;
}
if (initialWidth > 0) {
if (displayWidthDp < 0) displayWidthDp = displayWidthDpSupplier.get();
return displayWidthDp < breakPointDp || !ssEnabled ? PartialCustomTabType.FULL_SIZE
: PartialCustomTabType.SIDE_SHEET;
return displayWidthDp < breakPointDp ? PartialCustomTabType.FULL_SIZE
: PartialCustomTabType.SIDE_SHEET;
}
if (initialHeight > 0) {
return PartialCustomTabType.BOTTOM_SHEET;
Expand All @@ -262,8 +260,7 @@ public void destroy() {
@PartialCustomTabType
int type = calculatePartialCustomTabType(activity, provider.getInitialActivityWidth(),
provider.getInitialActivityHeight(), displayWidthDpSupplier,
provider.getActivityBreakPoint(),
ChromeFeatureList.sCctResizableSideSheetForThirdParties.isEnabled());
provider.getActivityBreakPoint());

@AnimRes
int start_anim_id = defaultResId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,35 +182,6 @@ public void transitionFromBottomSheetToSideSheetWhenOrientationChangedToLandscap
clearInvocations(mPCCTTestRule.mOnActivityLayoutCallback);
}

@Test
@Features.DisableFeatures({ChromeFeatureList.CCT_RESIZABLE_SIDE_SHEET_FOR_THIRD_PARTIES})
public void
transitionFromBottomSheetTo900dpBottomSheetWhenOrientationChangedToLandscape_andDisable3P() {
mPCCTTestRule.configPortraitMode();
PartialCustomTabDisplayManager displayManager = createPcctDisplayManager();

assertEquals("Bottom-Sheet should be the active strategy",
PartialCustomTabType.BOTTOM_SHEET, displayManager.getActiveStrategyType());
verify(mPCCTTestRule.mOnActivityLayoutCallback)
.onActivityLayout(anyInt(), anyInt(), anyInt(), anyInt(),
eq(ACTIVITY_LAYOUT_STATE_BOTTOM_SHEET));
clearInvocations(mPCCTTestRule.mOnActivityLayoutCallback);
mPCCTTestRule.configLandscapeMode();
displayManager.onConfigurationChanged(mPCCTTestRule.mConfiguration);

PartialCustomTabTestRule.waitForAnimationToFinish();

// the density in this case is 1.0
assertEquals("Should be 900dp width bottom sheet", BOTTOM_SHEET_MAX_WIDTH_DP,
(int) (mPCCTTestRule.getWindowAttributes().width));
assertEquals("Bottom-Sheet should be the active strategy",
PartialCustomTabType.BOTTOM_SHEET, displayManager.getActiveStrategyType());
verify(mPCCTTestRule.mOnActivityLayoutCallback)
.onActivityLayout(anyInt(), anyInt(), anyInt(), anyInt(),
eq(ACTIVITY_LAYOUT_STATE_BOTTOM_SHEET));
clearInvocations(mPCCTTestRule.mOnActivityLayoutCallback);
}

@Test
public void
transitionFromBottomSheetTo900dpBottomSheetWhenOrientationChangedToLandscape_andHeightSetWidthNot() {
Expand Down Expand Up @@ -403,26 +374,25 @@ public void calculatePartialCustomTabTypePermutations() {
int initHeight = 0;
Supplier<Integer> displayWidthDp = null;
int breakPointDp = 0;
boolean ssEnabled = true; // side sheet feature flag

// Multi-window mode -> FULL
MultiWindowUtils.getInstance().setIsInMultiWindowModeForTesting(true);
assertEquals("Type should be FULL_SIZE", PartialCustomTabType.FULL_SIZE,
PartialCustomTabDisplayManager.calculatePartialCustomTabType(
null, initWidth, initHeight, displayWidthDp, breakPointDp, ssEnabled));
null, initWidth, initHeight, displayWidthDp, breakPointDp));

// Zero initial width/height -> FULL
MultiWindowUtils.getInstance().setIsInMultiWindowModeForTesting(false);
assertEquals("Type should be FULL_SIZE", PartialCustomTabType.FULL_SIZE,
PartialCustomTabDisplayManager.calculatePartialCustomTabType(
null, initWidth, initHeight, displayWidthDp, breakPointDp, ssEnabled));
null, initWidth, initHeight, displayWidthDp, breakPointDp));

// Non-zero height -> BOTTOM_SHEET
initWidth = 0;
initHeight = 500;
assertEquals("Type should be BOTTOM_SHEET", PartialCustomTabType.BOTTOM_SHEET,
PartialCustomTabDisplayManager.calculatePartialCustomTabType(
null, initWidth, initHeight, displayWidthDp, breakPointDp, ssEnabled));
null, initWidth, initHeight, displayWidthDp, breakPointDp));

// Non-zero width -> either FULL_SIZE or SIDE_SHEET
initWidth = 500;
Expand All @@ -431,18 +401,12 @@ public void calculatePartialCustomTabTypePermutations() {
breakPointDp = 1200;
assertEquals("Type should be FULL_SIZE", PartialCustomTabType.FULL_SIZE,
PartialCustomTabDisplayManager.calculatePartialCustomTabType(
null, initWidth, initHeight, displayWidthDp, breakPointDp, ssEnabled));
null, initWidth, initHeight, displayWidthDp, breakPointDp));

breakPointDp = 800;
assertEquals("Type should be SIDE_SHEET", PartialCustomTabType.SIDE_SHEET,
PartialCustomTabDisplayManager.calculatePartialCustomTabType(
null, initWidth, initHeight, displayWidthDp, breakPointDp, ssEnabled));

ssEnabled = false;
assertEquals("Type should be FULL_SIZE", PartialCustomTabType.FULL_SIZE,
PartialCustomTabDisplayManager.calculatePartialCustomTabType(
null, initWidth, initHeight, displayWidthDp, breakPointDp, ssEnabled));
ssEnabled = true;
null, initWidth, initHeight, displayWidthDp, breakPointDp));

// Non-zero width/height -> either SIDE_SHEET or BOTTOM_SHEET
initWidth = 300;
Expand All @@ -451,21 +415,15 @@ public void calculatePartialCustomTabTypePermutations() {
breakPointDp = 400;
assertEquals("Type should be SIDE_SHEET", PartialCustomTabType.SIDE_SHEET,
PartialCustomTabDisplayManager.calculatePartialCustomTabType(
null, initWidth, initHeight, displayWidthDp, breakPointDp, ssEnabled));

ssEnabled = false;
assertEquals("Type should be BOTTOM SHEET", PartialCustomTabType.BOTTOM_SHEET,
PartialCustomTabDisplayManager.calculatePartialCustomTabType(
null, initWidth, initHeight, displayWidthDp, breakPointDp, ssEnabled));
ssEnabled = true;
null, initWidth, initHeight, displayWidthDp, breakPointDp));

initWidth = 300;
initHeight = 500;
displayWidthDp = () -> 1000;
breakPointDp = 1200;
assertEquals("Type should be BOTTOM_SHEET", PartialCustomTabType.BOTTOM_SHEET,
PartialCustomTabDisplayManager.calculatePartialCustomTabType(
null, initWidth, initHeight, displayWidthDp, breakPointDp, ssEnabled));
null, initWidth, initHeight, displayWidthDp, breakPointDp));
}

@Test
Expand Down

0 comments on commit 43be564

Please sign in to comment.