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 @@
android:layout_marginBottom="@dimen/keyboard_accessory_sheet_bottom_margin"
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
android:gravity="center_vertical|start"
......
......@@ -16,6 +16,7 @@ import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.chromium.chrome.browser.keyboard_accessory.R;
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.
*/
class PasswordAccessoryInfoView extends LinearLayout {
private TextView mTitle;
private ImageView mIcon;
private ChipView mUsername;
private ChipView mPassword;
......@@ -59,6 +61,7 @@ class PasswordAccessoryInfoView extends LinearLayout {
protected void onFinishInflate() {
super.onFinishInflate();
mTitle = findViewById(R.id.password_info_title);
mIcon = findViewById(R.id.favicon);
mUsername = findViewById(R.id.suggestion_text);
mPassword = findViewById(R.id.password_text);
......@@ -77,6 +80,10 @@ class PasswordAccessoryInfoView extends LinearLayout {
mIcon.setImageDrawable(icon);
}
TextView getTitle() {
return mTitle;
}
ChipView getUsername() {
return mUsername;
}
......
......@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.keyboard_accessory.sheet_tabs;
import android.support.v7.widget.RecyclerView;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.view.ViewGroup;
import org.chromium.chrome.browser.keyboard_accessory.R;
......@@ -49,6 +50,9 @@ class PasswordAccessorySheetModernViewBinder {
bindChipView(view.getUsername(), info.getFields().get(0));
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.
if (info.getFaviconProvider() != null) {
info.getFaviconProvider().fetchFavicon(
......
......@@ -4,6 +4,7 @@
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.is;
import static org.hamcrest.Matchers.not;
......@@ -15,7 +16,6 @@ import android.support.v7.widget.RecyclerView;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.junit.After;
......@@ -137,19 +137,49 @@ public class PasswordAccessorySheetModernViewTest {
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() {
assertThat(mView.get().getChildAt(0), instanceOf(LinearLayout.class));
LinearLayout layout = (LinearLayout) mView.get().getChildAt(0);
View view = layout.findViewById(R.id.suggestion_text);
View view = getUserInfoAt(0).findViewById(R.id.suggestion_text);
assertThat(view, is(not(nullValue())));
assertThat(view, instanceOf(ChipView.class));
return (ChipView) view;
}
private ChipView getPasswordSuggestion() {
assertThat(mView.get().getChildAt(0), instanceOf(LinearLayout.class));
LinearLayout layout = (LinearLayout) mView.get().getChildAt(0);
View view = layout.findViewById(R.id.password_text);
View view = getUserInfoAt(0).findViewById(R.id.password_text);
assertThat(view, is(not(nullValue())));
assertThat(view, instanceOf(ChipView.class));
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