Skip to content

Commit

Permalink
Add @DoNotMock to GURL.java
Browse files Browse the repository at this point in the history
This will cause Error Prone to fail builds if someone tries to
create a mock of a GURL object.

Bug: None
Change-Id: I7077342095adecef43ab6a1dc808e425e5ec74c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3733528
Owners-Override: Andrew Grieve <agrieve@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1019874}
  • Loading branch information
agrieve authored and Chromium LUCI CQ committed Jun 30, 2022
1 parent ea26a20 commit 127b44d
Show file tree
Hide file tree
Showing 30 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

/** Test NetworkFetcherTask. */
@RunWith(BaseRobolectricTestRunner.class)
@SuppressWarnings("DoNotMock") // Mocks GURL.
public class NetworkFetcherTaskTest {
private HttpURLConnection mConnection;
private Context mContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@EnableFeatures(ChromeFeatureList.AUTOFILL_KEYBOARD_ACCESSORY)
@SuppressWarnings("DoNotMock") // Mocks GURL
public class KeyboardAccessoryModernViewTest {
private static final String CUSTOM_ICON_URL = "https://www.example.com/image.png";
private static final Bitmap TEST_CARD_ART_IMAGE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@SuppressWarnings("DoNotMock") // Mocks GURL
public class CreditCardAccessorySheetViewTest {
private static final String CUSTOM_ICON_URL = "https://www.example.com/image.png";
private static final Bitmap TEST_CARD_ART_IMAGE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* This is a util class for TabUi unit tests.
*/
// TODO(crbug.com/1023701): Generalize all prepareTab method from tab_ui/junit directory.
@SuppressWarnings("ResultOfMethodCallIgnored")
@SuppressWarnings({"DoNotMock", "ResultOfMethodCallIgnored"}) // Mocks GURL
public class TabUiUnitTestUtils {
public static TabImpl prepareTab() {
TabImpl tab = mock(TabImpl.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
ShadowProfile.class, ShadowGURL.class})
@EnableFeatures(ChromeFeatureList.DARKEN_WEBSITES_CHECKBOX_IN_THEMES_SETTING)
@DisableFeatures(ChromeFeatureList.FORCE_WEB_CONTENTS_DARK_MODE)
@SuppressWarnings("DoNotMock") // Mocking GURL
public class ActivityTabWebContentsDelegateAndroidUnitTest {
@Implements(WebContentsDarkModeController.class)
static class ShadowWebContentsDarkModeController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/** Unit tests for {@link AutofillSuggestion} */
@RunWith(BaseRobolectricTestRunner.class)
@SuppressWarnings("DoNotMock") // Mocks GURL.
public class AutofillSuggestionTest {
@Test
@SmallTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@SuppressWarnings("DoNotMock") // Mocking GURL
public class DigitalGoodsUnitTest {
private final DigitalGoodsImpl.Delegate mDelegate = () -> {
GURL url = Mockito.mock(GURL.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* Tests for {@link CurrentPageVerifier}.
*/
@RunWith(BaseRobolectricTestRunner.class)
@SuppressWarnings("DoNotMock") // Mocking GURL
public class CurrentPageVerifierTest {
private static final Origin TRUSTED_ORIGIN = Origin.create("https://www.origin1.com/");
private static final Origin OTHER_TRUSTED_ORIGIN = Origin.create("https://www.origin2.com/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
@Config(manifest = Config.NONE)
@CommandLineFlags.
Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, ChromeSwitches.DISABLE_NATIVE_INITIALIZATION})
@SuppressWarnings("DoNotMock") // Mocks GURL.
public class HistoryClustersCoordinatorTest {
private static final String INCOGNITO_EXTRA = "IN_INCOGNITO";
private static final String NEW_TAB_EXTRA = "IN_NEW_TAB";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
/** Unit tests for HistoryClustersMediator. */
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE, shadows = {ShadowAppCompatResources.class, ShadowGURL.class})
@SuppressWarnings("DoNotMock") // Mocks GURL
public class HistoryClustersMediatorTest {
private static final String ITEM_URL_SPEC = "https://www.wombats.com/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
/**
* Utility class for holding a Tab and relevant objects for media notification tests.
*/
@SuppressWarnings("DoNotMock") // Mocks GURL
public class MediaNotificationTestTabHolder {
@Mock
UrlFormatter.Natives mUrlFormatterJniMock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
/** Unit tests for {@link ShareButtonController}. */
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@SuppressWarnings("DoNotMock") // Mocks GURL
public final class ShareButtonControllerUnitTest {
private static final int WIDTH_DELTA = 50;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

/** Unit test for {@link SurveyHttpClientBridge}. */
@RunWith(BaseRobolectricTestRunner.class)
@SuppressWarnings("DoNotMock") // Mocks GURL
public class SurveyHttpClientBridgeUnitTest {
private static final long FAKE_NATIVE_POINTER = 123456789L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@SuppressWarnings("DoNotMock") // Mocking GURL
public class RequestDesktopUtilsUnitTest {
@Rule
public JniMocker mJniMocker = new JniMocker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE, shadows = {ShadowGURL.class, ShadowTrustedCdn.class})
@DisableFeatures({ChromeFeatureList.LOCATION_BAR_MODEL_OPTIMIZATIONS})
@SuppressWarnings("DoNotMock") // Mocks GURL
public class LocationBarModelUnitTest {
@Implements(TrustedCdn.class)
static class ShadowTrustedCdn {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
@RunWith(ChromeJUnit4ClassRunner.class)
@Batch(Batch.PER_CLASS)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@SuppressWarnings("DoNotMock") // Mocks GURL
public class MerchantTrustBottomSheetCoordinatorTest extends BlankUiTestActivityTestCase {
@Rule
public final ChromeBrowserTestRule mBrowserTestRule = new ChromeBrowserTestRule();
Expand Down Expand Up @@ -177,4 +178,4 @@ public void testBottomSheetObserverOnSheetStateChanged() {
SheetState.FULL, StateChangeReason.NONE);
verify(mMockMetrics, times(1)).recordMetricsForBottomSheetFullyOpened();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@SuppressWarnings("DoNotMock") // Mocking GURL
public class MerchantTrustBottomSheetMediatorTest {
@Rule
public TestRule mProcessor = new Features.JUnitProcessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@SuppressWarnings("DoNotMock") // Mocking GURL
public class MerchantTrustMessageContextTest {
@Rule
public TestRule mProcessor = new Features.JUnitProcessor();
Expand Down Expand Up @@ -112,4 +113,4 @@ public void testGetWebContents() {
(new MerchantTrustMessageContext(mMockNavigationHandle, mMockWebContents))
.getWebContents());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@SuppressWarnings("DoNotMock") // Mocking GURL
public class MerchantTrustSignalsCoordinatorTest {
@Rule
public TestRule mProcessor = new Features.JUnitProcessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
import org.chromium.url.GURL;

import java.util.concurrent.TimeoutException;

/**
* Tests for {@link MerchantTrustSignalsDataProvider}.
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@SuppressWarnings("DoNotMock") // Mocking GURL
public class MerchantTrustSignalsDataProviderTest {
@Rule
public TestRule mProcessor = new Features.JUnitProcessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@SuppressWarnings("DoNotMock") // Mocking GURL
public class MerchantTrustSignalsMediatorTest {
@Rule
public TestRule mProcessor = new Features.JUnitProcessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE, shadows = {ShadowRecordHistogram.class})
@SuppressWarnings("DoNotMock") // Mocks GURL
public class ImplicitPriceDropSubscriptionsManagerUnitTest {
@Rule
public TestRule mProcessor = new Features.JUnitProcessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE, shadows = {ShadowRecordHistogram.class})
@SuppressWarnings("DoNotMock") // Mocks GURL.
public class PasswordCheckControllerTest {
private static final CompromisedCredential ANA =
new CompromisedCredential("https://m.a.xyz/signin", mock(GURL.class), "Ana", "m.a.xyz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@SuppressWarnings("DoNotMock") // Mocking GURL
public class SearchResumptionModuleMediatorUnitTest {
// The search suggestions are meant to be shown on any website.
private static final String URL_TO_TRACK = "/foo.com";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@SuppressWarnings("DoNotMock") // Mocks GURL.
public class LongScreenshotsCompositorTest {
private TestPlayerCompositorDelegate mCompositorDelegate;
private Bitmap mTestBitmap = Bitmap.createBitmap(512, 1024, Bitmap.Config.ARGB_8888);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
/** Unit tests for {@link WebContentsDarkModeController}. */
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE, shadows = {ShadowRecordHistogram.class, ShadowColorUtils.class})
@SuppressWarnings("DoNotMock") // Mocking GURL
public class WebContentsDarkModeControllerUnitTest {
@Rule
public JniMocker mJniMocker = new JniMocker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
@RunWith(LocalRobolectricTestRunner.class)
@Config(manifest = Config.NONE,
shadows = {VoiceToolbarButtonControllerUnitTest.ShadowChromeFeatureList.class})
@SuppressWarnings("DoNotMock") // Mocks GURL
public final class VoiceToolbarButtonControllerUnitTest {
// TODO(crbug.com/1199025): Remove this shadow.
@Implements(ChromeFeatureList.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* Tests for {@link MimeTypeUtils}, verifying behavior across OS versions.
*/
@RunWith(BaseRobolectricTestRunner.class)
@SuppressWarnings("DoNotMock") // Mocking GURL
public class MimeTypeUtilsTest {
@Mock
private GURL mMockedUrl;
Expand Down
1 change: 1 addition & 0 deletions url/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ if (is_android) {
"//base:base_java",
"//base:jni_java",
"//build/android:build_java",
"//third_party/android_deps:com_google_errorprone_error_prone_annotations_java",
"//third_party/androidx:androidx_annotation_annotation_java",
]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
Expand Down
3 changes: 3 additions & 0 deletions url/android/java/src/org/chromium/url/GURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.google.errorprone.annotations.DoNotMock;

import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative;
Expand All @@ -36,6 +38,7 @@
*/
@JNINamespace("url")
@MainDex
@DoNotMock("Create a real instance instead. For Robolectric, see JUnitTestGURLs.java")
public class GURL {
private static final String TAG = "GURL";
/* package */ static final int SERIALIZER_VERSION = 1;
Expand Down

0 comments on commit 127b44d

Please sign in to comment.