Commit 7d2e46d5 authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[TouchToFill][Android] Add origin labels for PSL matches

This CL adds the TextView showing the origin for PSL matched credentials
if there is one. Colors, height and margins are adjusted accordingly.

Screenshots (one for eliding, one for a simple label are in the bugs).

Bug: 1011833,1012184
Change-Id: Ie6968579557aafc70e9ed0ce1d2cba90e4e3d193
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1848389
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704248}
parent 6a2e9d07
...@@ -12,6 +12,7 @@ android_library("java") { ...@@ -12,6 +12,7 @@ android_library("java") {
"//base:jni_java", "//base:jni_java",
"//chrome/android:chrome_java", "//chrome/android:chrome_java",
"//chrome/browser/touch_to_fill/android:public_java", "//chrome/browser/touch_to_fill/android:public_java",
"//chrome/browser/util/android:java",
"//ui/android:ui_java", "//ui/android:ui_java",
] ]
......
...@@ -8,37 +8,48 @@ ...@@ -8,37 +8,48 @@
android:descendantFocusability="blocksDescendants" android:descendantFocusability="blocksDescendants"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minHeight="70dp" android:minHeight="72dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal" android:orientation="horizontal"
android:background="@drawable/touch_to_fill_credential_background"> android:background="@drawable/touch_to_fill_credential_background">
<ImageView <ImageView
android:id="@+id/favicon" android:id="@+id/favicon"
android:layout_width="20dp" android:layout_width="24dp"
android:layout_height="20dp" android:layout_height="24dp"
android:layout_marginStart="12dp"
android:importantForAccessibility="no" android:importantForAccessibility="no"
android:layout_gravity="center"/> android:layout_gravity="center"/>
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="8dp" android:layout_margin="6dp"
android:layout_marginStart="16dp" android:layout_marginStart="12dp"
android:layout_weight="1" android:layout_weight="1"
android:orientation="vertical"> android:orientation="vertical">
<TextView
android:id="@+id/credential_origin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="20dp"
android:ellipsize="start"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.BlackBody" />
<TextView <TextView
android:id="@+id/username" android:id="@+id/username"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minHeight="20dp"
android:ellipsize="end" android:ellipsize="end"
android:singleLine="true" android:singleLine="true"
android:textAppearance="@style/TextAppearance.BlackTitle1" /> android:textAppearance="@style/TextAppearance.BlackBodyDefault" />
<TextView <TextView
android:id="@+id/password" android:id="@+id/password"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minHeight="20dp"
android:ellipsize="end" android:ellipsize="end"
android:singleLine="true" android:singleLine="true"
android:textAppearance="@style/TextAppearance.BlackBody" /> android:textAppearance="@style/TextAppearance.BlackBodyDefault" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
...@@ -8,6 +8,7 @@ import static org.chromium.chrome.browser.touch_to_fill.TouchToFillProperties.CR ...@@ -8,6 +8,7 @@ import static org.chromium.chrome.browser.touch_to_fill.TouchToFillProperties.CR
import static org.chromium.chrome.browser.touch_to_fill.TouchToFillProperties.FORMATTED_URL; import static org.chromium.chrome.browser.touch_to_fill.TouchToFillProperties.FORMATTED_URL;
import static org.chromium.chrome.browser.touch_to_fill.TouchToFillProperties.VIEW_EVENT_LISTENER; import static org.chromium.chrome.browser.touch_to_fill.TouchToFillProperties.VIEW_EVENT_LISTENER;
import static org.chromium.chrome.browser.touch_to_fill.TouchToFillProperties.VISIBLE; import static org.chromium.chrome.browser.touch_to_fill.TouchToFillProperties.VISIBLE;
import static org.chromium.chrome.browser.util.UrlUtilities.stripScheme;
import android.text.method.PasswordTransformationMethod; import android.text.method.PasswordTransformationMethod;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -41,6 +42,12 @@ class TouchToFillViewBinder { ...@@ -41,6 +42,12 @@ class TouchToFillViewBinder {
* @param credential The {@link Credential} whose data needs to be displayed. * @param credential The {@link Credential} whose data needs to be displayed.
*/ */
static void bindCredentialView(View view, Credential credential) { static void bindCredentialView(View view, Credential credential) {
TextView pslOriginText = view.findViewById(R.id.credential_origin);
String formattedOrigin = stripScheme(credential.getOriginUrl());
formattedOrigin = formattedOrigin.replaceFirst("/$", ""); // Strip possibly trailing slash.
pslOriginText.setText(formattedOrigin);
pslOriginText.setVisibility(credential.isPublicSuffixMatch() ? View.VISIBLE : View.GONE);
TextView usernameText = view.findViewById(R.id.username); TextView usernameText = view.findViewById(R.id.username);
usernameText.setText(credential.getFormattedUsername()); usernameText.setText(credential.getFormattedUsername());
......
...@@ -24,6 +24,7 @@ public class Credential { ...@@ -24,6 +24,7 @@ public class Credential {
*/ */
public Credential(String username, String password, String formattedUsername, String originUrl, public Credential(String username, String password, String formattedUsername, String originUrl,
boolean isPublicSuffixMatch) { boolean isPublicSuffixMatch) {
assert originUrl != null : "Credential origin is null! Pass an empty one instead.";
mUsername = username; mUsername = username;
mPassword = password; mPassword = password;
mFormattedUsername = formattedUsername; mFormattedUsername = formattedUsername;
......
...@@ -18,6 +18,7 @@ import static org.chromium.content_public.browser.test.util.CriteriaHelper.pollU ...@@ -18,6 +18,7 @@ import static org.chromium.content_public.browser.test.util.CriteriaHelper.pollU
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.text.method.PasswordTransformationMethod; import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
...@@ -111,20 +112,31 @@ public class TouchToFillViewTest { ...@@ -111,20 +112,31 @@ public class TouchToFillViewTest {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
mTouchToFillView.setVisible(true); mTouchToFillView.setVisible(true);
mModel.get(CREDENTIAL_LIST) mModel.get(CREDENTIAL_LIST)
.addAll(Arrays.asList(new Credential("Ana", "S3cr3t", "Ana", null, false), .addAll(Arrays.asList(new Credential("Ana", "S3cr3t", "Ana", "", false),
new Credential("", "***", "No Username", "m.example.xyz", true))); new Credential("", "***", "No Username", "http://m.example.xyz/", true),
new Credential(
"Bob", "***", "Bob", "http://mobile.example.xyz", true)));
}); });
pollUiThread(() -> getBottomSheetState() == SheetState.FULL); pollUiThread(() -> getBottomSheetState() == SheetState.FULL);
assertThat(getCredentials().getChildCount(), is(2)); assertThat(getCredentials().getChildCount(), is(3));
assertThat(getCredentialOriginAt(0).getVisibility(), is(View.GONE));
assertThat(getCredentialNameAt(0).getText(), is("Ana")); assertThat(getCredentialNameAt(0).getText(), is("Ana"));
assertThat(getCredentialPasswordAt(0).getText(), is("S3cr3t")); assertThat(getCredentialPasswordAt(0).getText(), is("S3cr3t"));
assertThat(getCredentialPasswordAt(0).getTransformationMethod(), assertThat(getCredentialPasswordAt(0).getTransformationMethod(),
instanceOf(PasswordTransformationMethod.class)); instanceOf(PasswordTransformationMethod.class));
assertThat(getCredentialOriginAt(1).getVisibility(), is(View.VISIBLE));
assertThat(getCredentialOriginAt(1).getText(), is("m.example.xyz"));
assertThat(getCredentialNameAt(1).getText(), is("No Username")); assertThat(getCredentialNameAt(1).getText(), is("No Username"));
assertThat(getCredentialPasswordAt(1).getText(), is("***")); assertThat(getCredentialPasswordAt(1).getText(), is("***"));
assertThat(getCredentialPasswordAt(1).getTransformationMethod(), assertThat(getCredentialPasswordAt(1).getTransformationMethod(),
instanceOf(PasswordTransformationMethod.class)); instanceOf(PasswordTransformationMethod.class));
assertThat(getCredentialOriginAt(2).getVisibility(), is(View.VISIBLE));
assertThat(getCredentialOriginAt(2).getText(), is("mobile.example.xyz"));
assertThat(getCredentialNameAt(2).getText(), is("Bob"));
assertThat(getCredentialPasswordAt(2).getText(), is("***"));
assertThat(getCredentialPasswordAt(2).getTransformationMethod(),
instanceOf(PasswordTransformationMethod.class));
} }
@Test @Test
...@@ -180,6 +192,10 @@ public class TouchToFillViewTest { ...@@ -180,6 +192,10 @@ public class TouchToFillViewTest {
return getCredentials().getChildAt(index).findViewById(R.id.password); return getCredentials().getChildAt(index).findViewById(R.id.password);
} }
private TextView getCredentialOriginAt(int index) {
return getCredentials().getChildAt(index).findViewById(R.id.credential_origin);
}
TouchToFillProperties.ViewEventListener waitForEvent() { TouchToFillProperties.ViewEventListener waitForEvent() {
return verify(mMockListener, return verify(mMockListener,
timeout(ScalableTimeout.scaleTimeout(CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL))); timeout(ScalableTimeout.scaleTimeout(CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL)));
......
...@@ -36,7 +36,7 @@ import java.util.Collections; ...@@ -36,7 +36,7 @@ import java.util.Collections;
public class TouchToFillControllerTest { public class TouchToFillControllerTest {
private static final String TEST_URL = "www.example.xyz"; private static final String TEST_URL = "www.example.xyz";
private static final String TEST_MOBILE_URL = "www.example.xyz"; private static final String TEST_MOBILE_URL = "www.example.xyz";
private static final Credential ANA = new Credential("Ana", "S3cr3t", "Ana", null, false); private static final Credential ANA = new Credential("Ana", "S3cr3t", "Ana", "", false);
private static final Credential BOB = private static final Credential BOB =
new Credential("Bob", "*****", "Bob", TEST_MOBILE_URL, true); new Credential("Bob", "*****", "Bob", TEST_MOBILE_URL, true);
private static final Credential CARL = new Credential("Carl", "G3h3!m", "Carl", "", false); private static final Credential CARL = new Credential("Carl", "G3h3!m", "Carl", "", false);
......
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