Commit 9f6e77ff authored by Eleonora Rocchi's avatar Eleonora Rocchi Committed by Commit Bot

[PwdCheckAndroid] Add copy button to the view dialog

This CL adds a copy button in the dialog used by the user to view a
compromised password. It also adds a test to verify the button is
working correctly.

Screenshot in the linked bug.

Bug: 1119825, 1092444
Change-Id: I36cd31f1172be23e035360f89d75320ca62a0397
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2380286Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Commit-Queue: Eleonora Rocchi <erocchi@google.com>
Cr-Commit-Position: refs/heads/master@{#803458}
parent 4dd021ff
...@@ -6,14 +6,26 @@ ...@@ -6,14 +6,26 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:orientation="vertical"> android:orientation="horizontal">
<TextView <TextView
android:id="@+id/view_dialog_compromised_password" android:id="@+id/view_dialog_compromised_password"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_gravity="center" android:layout_weight="1"
android:layout_margin="@dimen/view_dialog_compromised_password_margin" android:layout_marginStart="@dimen/view_dialog_compromised_password_margin"
android:textAppearance="@style/TextAppearance.TextLarge.Secondary"/> android:textAppearance="@style/TextAppearance.TextLarge.Secondary"/>
<ImageButton
android:id="@+id/view_dialog_copy_button"
android:background="?android:attr/selectableItemBackground"
android:contentDescription="@string/password_entry_viewer_copy_stored_password"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="@dimen/view_dialog_copy_button_margin_end"
android:layout_height="@dimen/view_dialog_copy_button_clickable_surface_size"
android:layout_width="@dimen/view_dialog_copy_button_clickable_surface_size"
android:src="@drawable/ic_content_copy_black"
app:tint="@color/default_icon_color"/>
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -32,5 +32,7 @@ ...@@ -32,5 +32,7 @@
<dimen name="compromised_credential_row_padding_top">12dp</dimen> <dimen name="compromised_credential_row_padding_top">12dp</dimen>
<dimen name="compromised_credential_row_reason_margin_top">2dp</dimen> <dimen name="compromised_credential_row_reason_margin_top">2dp</dimen>
<dimen name="view_dialog_copy_button_clickable_surface_size">48dp</dimen>
<dimen name="view_dialog_copy_button_margin_end">4dp</dimen>
<dimen name="view_dialog_compromised_password_margin">24dp</dimen> <dimen name="view_dialog_compromised_password_margin">24dp</dimen>
</resources> </resources>
...@@ -5,9 +5,13 @@ ...@@ -5,9 +5,13 @@
package org.chromium.chrome.browser.password_check; package org.chromium.chrome.browser.password_check;
import android.app.Dialog; import android.app.Dialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputType; import android.text.InputType;
import android.view.View; import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView; import android.widget.TextView;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
...@@ -39,6 +43,17 @@ public class PasswordCheckViewDialogFragment extends PasswordCheckDialogFragment ...@@ -39,6 +43,17 @@ public class PasswordCheckViewDialogFragment extends PasswordCheckDialogFragment
passwordView.setInputType(InputType.TYPE_CLASS_TEXT passwordView.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
| InputType.TYPE_TEXT_FLAG_MULTI_LINE); | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
ClipboardManager clipboard =
(ClipboardManager) getActivity().getApplicationContext().getSystemService(
Context.CLIPBOARD_SERVICE);
ImageButton copyButton = dialogContent.findViewById(R.id.view_dialog_copy_button);
copyButton.setClickable(true);
copyButton.setOnClickListener(unusedView -> {
ClipData clip = ClipData.newPlainText("password", mCredential.getPassword());
clipboard.setPrimaryClip(clip);
});
AlertDialog viewDialog = new AlertDialog.Builder(getActivity()) AlertDialog viewDialog = new AlertDialog.Builder(getActivity())
.setTitle(mCredential.getDisplayOrigin()) .setTitle(mCredential.getDisplayOrigin())
.setNegativeButton(R.string.close, mHandler) .setNegativeButton(R.string.close, mHandler)
......
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.password_check; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.password_check;
import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.matcher.RootMatchers.withDecorView; import static androidx.test.espresso.matcher.RootMatchers.withDecorView;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText; import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.not;
...@@ -46,6 +47,8 @@ import static org.chromium.chrome.browser.password_manager.settings.Reauthentica ...@@ -46,6 +47,8 @@ import static org.chromium.chrome.browser.password_manager.settings.Reauthentica
import static org.chromium.content_public.browser.test.util.CriteriaHelper.pollUiThread; import static org.chromium.content_public.browser.test.util.CriteriaHelper.pollUiThread;
import static org.chromium.content_public.browser.test.util.TestThreadUtils.runOnUiThreadBlocking; import static org.chromium.content_public.browser.test.util.TestThreadUtils.runOnUiThreadBlocking;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
...@@ -608,6 +611,30 @@ public class PasswordCheckViewTest { ...@@ -608,6 +611,30 @@ public class PasswordCheckViewTest {
assertThat(recordedConfirmation.get(), is(1)); assertThat(recordedConfirmation.get(), is(1));
} }
@Test
@MediumTest
public void testCopyPasswordViewDialog() {
PasswordCheckDeletionDialogFragment.Handler fakeHandler =
new PasswordCheckDeletionDialogFragment.Handler() {
@Override
public void onDismiss() {}
@Override
public void onClick(DialogInterface dialogInterface, int i) {}
};
ReauthenticationManager.recordLastReauth(
System.currentTimeMillis(), ReauthScope.ONE_AT_A_TIME);
mModel.set(VIEW_CREDENTIAL, ANA);
runOnUiThreadBlocking(() -> mModel.set(VIEW_DIALOG_HANDLER, fakeHandler));
onView(withId(R.id.view_dialog_copy_button)).perform(click());
ClipboardManager clipboard = (ClipboardManager) mPasswordCheckView.getActivity()
.getApplicationContext()
.getSystemService(Context.CLIPBOARD_SERVICE);
assertThat(clipboard.getPrimaryClip().getItemAt(0).getText().toString(),
is(ANA.getPassword()));
}
@Test @Test
@MediumTest @MediumTest
public void testCloseViewDialogTriggersHandler() { public void testCloseViewDialogTriggersHandler() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment