[Android] Fix for misaligned MVT area (#32806)

* [Android] Fix for misaligned MVT area

Regression was introduced between
`Nightly v1.85.63 (Chromium 141.0.7390.108)` and
`Nightly v1.85.70 (Chromium 142.0.7444.23)`.

Resolves https://github.com/brave/brave-browser/issues/51406

Chromium change:
https://source.chromium.org/chromium/chromium/src/+/90a9724173475c0c3913a7cb9ca619d2458b1d08

	[SurfacePolish][CleanUp] Clean up surface polish code for MVT (Part 3)

	This CL represents part 3 of the cleanup for the surface polish code in
	the MVT, focusing on refining the code associated New tab page.

	Low-Coverage-Reason: TRIVIAL_CHANGE This CL cleans up the NewTabPageLayout code by deleting unused code and updating variable names.
	Bug: 331667743
	Change-Id: Idaaab489aa72714d4cd294ac86cc86b1dbe20065
	Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5591789
This commit is contained in:
AlexeyBarabash
2025-12-12 21:56:46 +00:00
committed by GitHub
parent 922c34a669
commit 855a518957
7 changed files with 75 additions and 0 deletions
+1
View File
@@ -54,6 +54,7 @@
*** getLogoMargin(...);
*** calculateTabletMvtWidth(...);
*** updateMvtOnTablet(...);
*** isInNarrowWindowOnTablet(...);
}
-keep class org.chromium.chrome.browser.suggestions.tile.MostVisitedTilesMediator {
@@ -1231,6 +1231,13 @@ public class BraveNewTabPageLayout extends NewTabPageLayout
}
}
// Replace this static method to avoid leftMargin override to 0 at
// NewTabPageLayout.updateMvtOnTablet on tablets and avoid
// misalign of MVT area.
public static boolean isInNarrowWindowOnTablet(boolean isTablet, UiConfig uiConfig) {
return isTablet;
}
protected boolean useFixedMVTLayout() {
return !UserPrefs.get(ProfileManager.getLastUsedRegularProfile())
.getBoolean(BravePref.NEW_TAB_PAGE_SHOW_BACKGROUND_IMAGE);
@@ -481,6 +481,14 @@ public class BytecodeTest {
"updateMvtOnTablet",
MethodModifier.REGULAR,
void.class));
Assert.assertTrue(
methodExists(
"org/chromium/chrome/browser/ntp/NewTabPageLayout",
"isInNarrowWindowOnTablet",
MethodModifier.STATIC,
boolean.class,
boolean.class,
UiConfig.class));
Assert.assertTrue(
methodExists(
+9
View File
@@ -109,4 +109,13 @@ if (is_android) {
"//chrome/android/junit:chrome_junit_tests_helper",
]
}
robolectric_library("brave_junit_tests_org.chromium.chrome.browser.ntp") {
resources_package = "org.chromium.chrome.browser.ntp"
sources = [
"src/org/chromium/chrome/browser/ntp/BraveNewTabPageUtilUnitTest.java",
]
deps = [ "//chrome/android/junit:chrome_junit_tests_helper" ]
}
}
@@ -0,0 +1,44 @@
/* Copyright (c) 2025 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
package org.chromium.chrome.browser.ntp;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.annotation.Config;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.components.browser_ui.widget.displaystyle.HorizontalDisplayStyle;
import org.chromium.components.browser_ui.widget.displaystyle.UiConfig;
import org.chromium.components.browser_ui.widget.displaystyle.UiConfig.DisplayStyle;
import org.chromium.components.browser_ui.widget.displaystyle.VerticalDisplayStyle;
/** Unit tests for helper function in {@link BraveNewTabPage} class. */
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class BraveNewTabPageUtilUnitTest {
@Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@Test
public void testIsInNarrowWindowOnTablet() {
UiConfig uiConfig = Mockito.mock(UiConfig.class);
UiConfig.DisplayStyle displayStyleWide =
new DisplayStyle(HorizontalDisplayStyle.WIDE, VerticalDisplayStyle.REGULAR);
when(uiConfig.getCurrentDisplayStyle()).thenReturn(displayStyleWide);
assertTrue(
"Brave overridden isInNarrowWindowOnTablet on tablet when displayStyleWide =="
+ " HorizontalDisplayStyle.WIDE.",
BraveNewTabPageLayout.isInNarrowWindowOnTablet(true, uiConfig));
}
}
@@ -54,5 +54,10 @@ public class BraveNewTabPageLayoutClassAdapter extends BraveClassVisitor {
makePublicMethod(sNewTabPageLayoutClassName, "updateMvtOnTablet");
changeSuperName(sNewTabPageLayoutClassName, sNewTabPageLayoutSuperClassName);
changeMethodOwner(
sNewTabPageLayoutClassName,
"isInNarrowWindowOnTablet",
sBraveNewTabPageLayoutClassName);
}
}
+1
View File
@@ -1471,6 +1471,7 @@ if (is_android) {
deps = [
"//brave/android/junit:brave_junit_tests_org.chromium.chrome.browser.app",
"//brave/android/junit:brave_junit_tests_org.chromium.chrome.browser.homepage",
"//brave/android/junit:brave_junit_tests_org.chromium.chrome.browser.ntp",
"//brave/android/junit:brave_junit_tests_org.chromium.chrome.browser.rate",
"//brave/android/junit:brave_junit_tests_org.chromium.chrome.browser.referrer",
"//brave/android/junit:brave_junit_tests_org.chromium.chrome.browser.settings",