Skip to content

Commit

Permalink
Privacy Guide: Dynamic PS link visibility
Browse files Browse the repository at this point in the history
- Dynamically remove the PS link in the completion step.

(cherry picked from commit 1120cf1)

Bug: 1448806
Change-Id: Ib1359e2b90158bbc78ef2b6a6b183e62c5b0c1fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4567527
Reviewed-by: Nicola Tommasi <tommasin@chromium.org>
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Rubin Deliallisi <rubindl@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1149626}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4571028
Auto-Submit: Nicola Tommasi <tommasin@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Nicola Tommasi <tommasin@chromium.org>
Reviewed-by: Rubin Deliallisi <rubindl@chromium.org>
Cr-Commit-Position: refs/branch-heads/5790@{#126}
Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
  • Loading branch information
Rubin Deliallisi authored and Chromium LUCI CQ committed May 30, 2023
1 parent c231db4 commit 3fe845b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 9 deletions.
1 change: 1 addition & 0 deletions chrome/browser/privacy_guide/android/BUILD.gn
Expand Up @@ -73,6 +73,7 @@ robolectric_library("junit") {
"//base:base_java",
"//base:base_java_test_support",
"//base:base_junit_test_support",
"//chrome/browser/privacy_sandbox/android:java",
"//chrome/browser/profiles/android:java",
"//chrome/browser/safe_browsing/android:java",
"//chrome/browser/signin/services/android:java",
Expand Down
Expand Up @@ -41,11 +41,13 @@ found in the LICENSE file.
style="@style/TextAppearance.TextLarge.Secondary" />

<org.chromium.chrome.browser.privacy_guide.PrivacyGuideExplanationHeading
android:id="@+id/ps_heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleText="@string/privacy_guide_privacy_sandbox_heading" />

<LinearLayout
android:id="@+id/ps_explanation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/done_step_explanation_marginBottom"
Expand Down
Expand Up @@ -21,6 +21,7 @@

import org.chromium.base.IntentUtils;
import org.chromium.chrome.browser.privacy_guide.PrivacyGuideUtils.CustomTabIntentHelper;
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxBridge;
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxReferrer;
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxSettingsBaseFragment;
import org.chromium.components.browser_ui.settings.SettingsLauncher;
Expand All @@ -45,8 +46,14 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

ChromeImageButton psButton = view.findViewById(R.id.ps_button);
psButton.setOnClickListener(this::onPsButtonClick);
if (!PrivacySandboxBridge.isPrivacySandboxRestricted()
|| PrivacySandboxBridge.isRestrictedNoticeEnabled()) {
ChromeImageButton psButton = view.findViewById(R.id.ps_button);
psButton.setOnClickListener(this::onPsButtonClick);
} else {
view.findViewById(R.id.ps_heading).setVisibility(View.GONE);
view.findViewById(R.id.ps_explanation).setVisibility(View.GONE);
}

if (isUserSignedIn()) {
ChromeImageButton waaButton = view.findViewById(R.id.waa_button);
Expand Down
Expand Up @@ -23,6 +23,9 @@
import org.mockito.junit.MockitoRule;

import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.base.test.util.JniMocker;
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxBridge;
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxBridgeJni;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.services.IdentityServicesProvider;
import org.chromium.components.signin.identitymanager.ConsentLevel;
Expand All @@ -35,21 +38,24 @@
public class DoneFragmentTest {
@Rule
public MockitoRule mMockitoRule = MockitoJUnit.rule();
@Rule
public JniMocker mMocker = new JniMocker();

@Mock
private Profile mProfile;
@Mock
private IdentityServicesProvider mIdentityServicesProvider;
@Mock
private IdentityManager mIdentityManager;
@Mock
private PrivacySandboxBridge.Natives mPrivacySandboxBridge;

private FragmentScenario mScenario;
private DoneFragment mFragment;
private View mPsButton;
private View mWaaButton;

private void initFragmentWithSignInState(boolean isSignedIn) {
when(mIdentityManager.hasPrimaryAccount(ConsentLevel.SIGNIN)).thenReturn(isSignedIn);
private void initFragment() {
mScenario = FragmentScenario.launchInContainer(
DoneFragment.class, Bundle.EMPTY, R.style.Theme_MaterialComponents);
mScenario.onFragment(fragment -> {
Expand All @@ -59,11 +65,22 @@ private void initFragmentWithSignInState(boolean isSignedIn) {
});
}

private void setSignedInState(boolean isSignedIn) {
when(mIdentityManager.hasPrimaryAccount(ConsentLevel.SIGNIN)).thenReturn(isSignedIn);
}

private void setPrivacySandboxState(boolean isRestricted, boolean isRestrictedNoticeEnabled) {
when(mPrivacySandboxBridge.isPrivacySandboxRestricted()).thenReturn(isRestricted);
when(mPrivacySandboxBridge.isRestrictedNoticeEnabled())
.thenReturn(isRestrictedNoticeEnabled);
}

@Before
public void setUp() {
Profile.setLastUsedProfileForTesting(mProfile);
IdentityServicesProvider.setInstanceForTests(mIdentityServicesProvider);
when(mIdentityServicesProvider.getIdentityManager(mProfile)).thenReturn(mIdentityManager);
mMocker.mock(PrivacySandboxBridgeJni.TEST_HOOKS, mPrivacySandboxBridge);
}

@After
Expand All @@ -76,16 +93,50 @@ public void tearDown() {
}

@Test
public void testOneLinkVisibleWhenSignedOut() {
initFragmentWithSignInState(false);
public void testPSButtonNotVisible() {
setPrivacySandboxState(true, false);
initFragment();

assertFalse(mPsButton.isShown());
}

@Test
public void testPSButtonVisibleWhenNotRestricted() {
setPrivacySandboxState(false, false);
initFragment();

assertTrue(mPsButton.isShown());
assertFalse(mWaaButton.isShown());
}

@Test
public void testTwoLinksVisibleWhenSignedIn() {
initFragmentWithSignInState(true);
public void testPSButtonVisibleWhenRestrictedNoticeEnabled() {
setPrivacySandboxState(true, true);
initFragment();

assertTrue(mPsButton.isShown());
}

@Test
public void testPSButtonVisibleWhenNotRestrictedAndRestrictedNoticeEnabled() {
setPrivacySandboxState(false, true);
initFragment();

assertTrue(mPsButton.isShown());
}

@Test
public void testWaaButtonVisibleWhenSignedIn() {
setSignedInState(true);
initFragment();

assertTrue(mWaaButton.isShown());
}

@Test
public void testWaaButtonNotVisibleWhenNotSignedIn() {
setSignedInState(false);
initFragment();

assertFalse(mWaaButton.isShown());
}
}

0 comments on commit 3fe845b

Please sign in to comment.