// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.access_loss;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Activity;
import android.content.Context;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.quality.Strictness;
import org.robolectric.annotation.Config;
import org.chromium.base.ContextUtils;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetController;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetObserver;
/** Tests for {@link PasswordAccessLossWarningBridge} */
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@Batch(Batch.PER_CLASS)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class PasswordAccessLossWarningBridgeTest {
private PasswordAccessLossWarningBridge mBridge;
private final ArgumentCaptor<BottomSheetObserver> mBottomSheetObserverCaptor =
ArgumentCaptor.forClass(BottomSheetObserver.class);
private Context mContext;
@Rule public MockitoRule mMockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS);
@Mock private BottomSheetController mBottomSheetController;
@Mock private Profile mProfile;
@Mock private Activity mActivity;
@Before
public void setUp() {
MockitoAnnotations.openMocks(this);
mContext = ContextUtils.getApplicationContext();
mBridge =
new PasswordAccessLossWarningBridge(
mContext, mBottomSheetController, mProfile, mActivity);
}
private void setUpBottomSheetController() {
when(mBottomSheetController.requestShowContent(any(), anyBoolean())).thenReturn(true);
doNothing().when(mBottomSheetController).addObserver(mBottomSheetObserverCaptor.capture());
}
@Test
public void showsSheet() {
setUpBottomSheetController();
mBridge.show(PasswordAccessLossWarningType.NEW_GMS_CORE_MIGRATION_FAILED);
verify(mBottomSheetController).requestShowContent(any(), anyBoolean());
verify(mBottomSheetController).addObserver(any());
}
}