Commit 32f8cff1 authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[Mfill Android] Add TextView for PSL origins in sheets

With this CL, we will now show the origins as user info titles iff the
the credential origin differs from the current site origin.

Mock about how this will look like are in the linked bug. The changes
only affect the not yet launched accessory V2.

Bug: 981928
Change-Id: Id3c26c8d224222f2160965ca43f95cfafcd64767
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695294
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarIoana Pandele <ioanap@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676345}
parent e22752cf
...@@ -15,6 +15,15 @@ ...@@ -15,6 +15,15 @@
android:layout_marginBottom="@dimen/keyboard_accessory_sheet_bottom_margin" android:layout_marginBottom="@dimen/keyboard_accessory_sheet_bottom_margin"
android:orientation="vertical"> android:orientation="vertical">
<TextView
android:id="@+id/password_info_title"
android:paddingTop="@dimen/keyboard_accessory_sheet_bottom_margin"
android:paddingBottom="@dimen/keyboard_accessory_sheet_bottom_margin"
android:gravity="center_vertical|start"
android:textAppearance="@style/TextAppearance.BlackHint1"
android:minHeight="@dimen/keyboard_accessory_height"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<LinearLayout <LinearLayout
android:gravity="center_vertical|start" android:gravity="center_vertical|start"
......
...@@ -16,6 +16,7 @@ import android.util.AttributeSet; ...@@ -16,6 +16,7 @@ import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView;
import org.chromium.chrome.browser.keyboard_accessory.R; import org.chromium.chrome.browser.keyboard_accessory.R;
import org.chromium.ui.widget.ChipView; import org.chromium.ui.widget.ChipView;
...@@ -24,6 +25,7 @@ import org.chromium.ui.widget.ChipView; ...@@ -24,6 +25,7 @@ import org.chromium.ui.widget.ChipView;
* This view represents a section of user credentials in the password tab of the keyboard accessory. * This view represents a section of user credentials in the password tab of the keyboard accessory.
*/ */
class PasswordAccessoryInfoView extends LinearLayout { class PasswordAccessoryInfoView extends LinearLayout {
private TextView mTitle;
private ImageView mIcon; private ImageView mIcon;
private ChipView mUsername; private ChipView mUsername;
private ChipView mPassword; private ChipView mPassword;
...@@ -59,6 +61,7 @@ class PasswordAccessoryInfoView extends LinearLayout { ...@@ -59,6 +61,7 @@ class PasswordAccessoryInfoView extends LinearLayout {
protected void onFinishInflate() { protected void onFinishInflate() {
super.onFinishInflate(); super.onFinishInflate();
mTitle = findViewById(R.id.password_info_title);
mIcon = findViewById(R.id.favicon); mIcon = findViewById(R.id.favicon);
mUsername = findViewById(R.id.suggestion_text); mUsername = findViewById(R.id.suggestion_text);
mPassword = findViewById(R.id.password_text); mPassword = findViewById(R.id.password_text);
...@@ -77,6 +80,10 @@ class PasswordAccessoryInfoView extends LinearLayout { ...@@ -77,6 +80,10 @@ class PasswordAccessoryInfoView extends LinearLayout {
mIcon.setImageDrawable(icon); mIcon.setImageDrawable(icon);
} }
TextView getTitle() {
return mTitle;
}
ChipView getUsername() { ChipView getUsername() {
return mUsername; return mUsername;
} }
......
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.keyboard_accessory.sheet_tabs; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.keyboard_accessory.sheet_tabs;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.method.PasswordTransformationMethod; import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import org.chromium.chrome.browser.keyboard_accessory.R; import org.chromium.chrome.browser.keyboard_accessory.R;
...@@ -49,6 +50,9 @@ class PasswordAccessorySheetModernViewBinder { ...@@ -49,6 +50,9 @@ class PasswordAccessorySheetModernViewBinder {
bindChipView(view.getUsername(), info.getFields().get(0)); bindChipView(view.getUsername(), info.getFields().get(0));
bindChipView(view.getPassword(), info.getFields().get(1)); bindChipView(view.getPassword(), info.getFields().get(1));
view.getTitle().setVisibility(info.getTitle().isEmpty() ? View.GONE : View.VISIBLE);
view.getTitle().setText(info.getTitle());
view.setIconForBitmap(null); // Set the default icon, then try to get a better one. view.setIconForBitmap(null); // Set the default icon, then try to get a better one.
if (info.getFaviconProvider() != null) { if (info.getFaviconProvider() != null) {
info.getFaviconProvider().fetchFavicon( info.getFaviconProvider().fetchFavicon(
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.keyboard_accessory.sheet_tabs; package org.chromium.chrome.browser.keyboard_accessory.sheet_tabs;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
...@@ -15,7 +16,6 @@ import android.support.v7.widget.RecyclerView; ...@@ -15,7 +16,6 @@ import android.support.v7.widget.RecyclerView;
import android.text.method.PasswordTransformationMethod; import android.text.method.PasswordTransformationMethod;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import org.junit.After; import org.junit.After;
...@@ -137,19 +137,49 @@ public class PasswordAccessorySheetModernViewTest { ...@@ -137,19 +137,49 @@ public class PasswordAccessorySheetModernViewTest {
assertThat(clicked.get(), is(true)); assertThat(clicked.get(), is(true));
} }
@Test
@MediumTest
public void testAddingUserInfoTitlesAreRenderedIfNotEmpty() {
assertThat(mView.get().getChildCount(), is(0));
final UserInfoField kUnusedInfoField =
new UserInfoField("Unused Name", "Unused Password", "", false, cb -> {});
TestThreadUtils.runOnUiThreadBlocking(() -> {
UserInfo sameOriginInfo = new UserInfo("", null);
sameOriginInfo.addField(kUnusedInfoField);
sameOriginInfo.addField(kUnusedInfoField);
mModel.add(new AccessorySheetDataPiece(
sameOriginInfo, AccessorySheetDataPiece.Type.PASSWORD_INFO));
UserInfo pslOriginInfo = new UserInfo("other.origin.eg", null);
pslOriginInfo.addField(kUnusedInfoField);
pslOriginInfo.addField(kUnusedInfoField);
mModel.add(new AccessorySheetDataPiece(
pslOriginInfo, AccessorySheetDataPiece.Type.PASSWORD_INFO));
});
CriteriaHelper.pollUiThread(Criteria.equals(2, () -> mView.get().getChildCount()));
assertThat(getUserInfoAt(0).getTitle().isShown(), is(false));
assertThat(getUserInfoAt(1).getTitle().isShown(), is(true));
assertThat(getUserInfoAt(1).getTitle().getText(), is("other.origin.eg"));
}
private PasswordAccessoryInfoView getUserInfoAt(int index) {
assertThat(mView.get().getChildCount(), is(greaterThan(index)));
assertThat(mView.get().getChildAt(index), instanceOf(PasswordAccessoryInfoView.class));
return (PasswordAccessoryInfoView) mView.get().getChildAt(index);
}
private ChipView getNameSuggestion() { private ChipView getNameSuggestion() {
assertThat(mView.get().getChildAt(0), instanceOf(LinearLayout.class)); View view = getUserInfoAt(0).findViewById(R.id.suggestion_text);
LinearLayout layout = (LinearLayout) mView.get().getChildAt(0);
View view = layout.findViewById(R.id.suggestion_text);
assertThat(view, is(not(nullValue()))); assertThat(view, is(not(nullValue())));
assertThat(view, instanceOf(ChipView.class)); assertThat(view, instanceOf(ChipView.class));
return (ChipView) view; return (ChipView) view;
} }
private ChipView getPasswordSuggestion() { private ChipView getPasswordSuggestion() {
assertThat(mView.get().getChildAt(0), instanceOf(LinearLayout.class)); View view = getUserInfoAt(0).findViewById(R.id.password_text);
LinearLayout layout = (LinearLayout) mView.get().getChildAt(0);
View view = layout.findViewById(R.id.password_text);
assertThat(view, is(not(nullValue()))); assertThat(view, is(not(nullValue())));
assertThat(view, instanceOf(ChipView.class)); assertThat(view, instanceOf(ChipView.class));
return (ChipView) view; return (ChipView) view;
......
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