Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug: 1439583 Change-Id: Ic2656541e4bc2f3cf05462bffd534b460c256c2d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4521629 Reviewed-by: Brandon Wylie <wylieb@chromium.org> Commit-Queue: Sky Malice <skym@chromium.org> Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com> Cr-Commit-Position: refs/heads/main@{#1147556}
- Loading branch information
Sky Malice
authored and
Chromium LUCI CQ
committed
May 23, 2023
1 parent
5618193
commit af41a98
Showing
16 changed files
with
337 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
chrome/android/java/res/layout/bookmark_search_box_row.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2023 The Chromium Authors | ||
Use of this source code is governed by a BSD-style license that can be | ||
found in the LICENSE file. | ||
--> | ||
|
||
<org.chromium.chrome.browser.bookmarks.BookmarkSearchBoxRow | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:background="@drawable/search_row_modern_bg" | ||
android:id="@+id/bookmark_toolbar" | ||
android:layout_height="40dp" | ||
android:layout_width="match_parent" | ||
android:layout_marginBottom="18dp"> | ||
|
||
<EditText | ||
tools:ignore="Autofill,LabelFor" | ||
android:background="@null" | ||
android:hint="@string/bookmark_toolbar_search" | ||
android:id="@+id/search_text" | ||
android:imeOptions="flagNoExtractUi|actionSearch" | ||
android:inputType="text" | ||
android:layout_height="match_parent" | ||
android:layout_width="match_parent" | ||
android:paddingHorizontal="@dimen/bookmark_search_hint_horizontal_padding" | ||
android:singleLine="true" | ||
android:textColorHint="@macro/search_box_hint" | ||
android:textAppearance="@style/TextAppearance.TextLarge.Primary" /> | ||
|
||
</org.chromium.chrome.browser.bookmarks.BookmarkSearchBoxRow> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkSearchBoxRow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.chrome.browser.bookmarks; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.view.KeyEvent; | ||
import android.view.inputmethod.EditorInfo; | ||
import android.widget.EditText; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import org.chromium.chrome.R; | ||
import org.chromium.ui.KeyboardVisibilityDelegate; | ||
import org.chromium.ui.text.EmptyTextWatcher; | ||
|
||
/** | ||
* Row in a {@link androidx.recyclerview.widget.RecyclerView} for querying and filtering shown | ||
* bookmarks. | ||
*/ | ||
public class BookmarkSearchBoxRow extends LinearLayout { | ||
public BookmarkSearchBoxRow(Context context, @Nullable AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
@Override | ||
protected void onFinishInflate() { | ||
super.onFinishInflate(); | ||
|
||
EditText searchText = findViewById(R.id.search_text); | ||
searchText.addTextChangedListener(new EmptyTextWatcher() { | ||
@Override | ||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { | ||
// TODO(https://crbug.com/1439583): Propagate query string upward. | ||
} | ||
}); | ||
searchText.setOnEditorActionListener(this::onEditorAction); | ||
} | ||
|
||
private boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { | ||
if (actionId == EditorInfo.IME_ACTION_SEARCH | ||
|| keyEvent != null && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) { | ||
KeyboardVisibilityDelegate.getInstance().hideKeyboard(textView); | ||
clearFocus(); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...d/javatests/src/org/chromium/chrome/browser/bookmarks/BookmarkSearchBoxRowRenderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.chrome.browser.bookmarks; | ||
|
||
import android.graphics.Color; | ||
import android.view.LayoutInflater; | ||
import android.view.ViewGroup; | ||
import android.widget.FrameLayout; | ||
import android.widget.LinearLayout; | ||
|
||
import androidx.test.filters.MediumTest; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.chromium.base.test.BaseActivityTestRule; | ||
import org.chromium.base.test.params.ParameterAnnotations; | ||
import org.chromium.base.test.params.ParameterAnnotations.ClassParameter; | ||
import org.chromium.base.test.params.ParameterSet; | ||
import org.chromium.base.test.params.ParameterizedRunner; | ||
import org.chromium.base.test.util.Batch; | ||
import org.chromium.base.test.util.Feature; | ||
import org.chromium.chrome.R; | ||
import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate; | ||
import org.chromium.chrome.test.util.ChromeRenderTestRule; | ||
import org.chromium.chrome.test.util.browser.Features; | ||
import org.chromium.content_public.browser.test.util.TestThreadUtils; | ||
import org.chromium.ui.test.util.BlankUiTestActivity; | ||
import org.chromium.ui.test.util.DisableAnimationsTestRule; | ||
import org.chromium.ui.test.util.NightModeTestUtils; | ||
import org.chromium.ui.test.util.NightModeTestUtils.NightModeParams; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** Render tests for {@link BookmarkSearchBoxRow}. */ | ||
@RunWith(ParameterizedRunner.class) | ||
@ParameterAnnotations.UseRunnerDelegate(ChromeJUnit4RunnerDelegate.class) | ||
@Batch(Batch.PER_CLASS) | ||
public class BookmarkSearchBoxRowRenderTest { | ||
@ClassParameter | ||
private static List<ParameterSet> sClassParams = new NightModeParams().getParameters(); | ||
|
||
@Rule | ||
public final DisableAnimationsTestRule mDisableAnimationsRule = new DisableAnimationsTestRule(); | ||
@Rule | ||
public BaseActivityTestRule<BlankUiTestActivity> mActivityTestRule = | ||
new BaseActivityTestRule<>(BlankUiTestActivity.class); | ||
@Rule | ||
public ChromeRenderTestRule mRenderTestRule = | ||
ChromeRenderTestRule.Builder.withPublicCorpus() | ||
.setBugComponent(ChromeRenderTestRule.Component.UI_BROWSER_BOOKMARKS) | ||
.build(); | ||
@Rule | ||
public TestRule mProcessor = new Features.JUnitProcessor(); | ||
|
||
private LinearLayout mContentView; | ||
|
||
public BookmarkSearchBoxRowRenderTest(boolean nightModeEnabled) { | ||
NightModeTestUtils.setUpNightModeForBlankUiTestActivity(nightModeEnabled); | ||
mRenderTestRule.setNightModeEnabled(nightModeEnabled); | ||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
mActivityTestRule.launchActivity(null); | ||
mActivityTestRule.getActivity().setTheme(R.style.Theme_BrowserUI_DayNight); | ||
|
||
TestThreadUtils.runOnUiThreadBlocking(() -> { | ||
mContentView = new LinearLayout(mActivityTestRule.getActivity()); | ||
mContentView.setBackgroundColor(Color.WHITE); | ||
|
||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( | ||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); | ||
mActivityTestRule.getActivity().setContentView(mContentView, params); | ||
|
||
LayoutInflater.from(mActivityTestRule.getActivity()) | ||
.inflate(org.chromium.chrome.R.layout.bookmark_search_box_row, mContentView); | ||
}); | ||
} | ||
|
||
@Test | ||
@MediumTest | ||
@Feature({"RenderTest"}) | ||
public void testNormal() throws IOException { | ||
mRenderTestRule.render(mContentView, "normal"); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...android/javatests/src/org/chromium/chrome/browser/bookmarks/BookmarkSearchBoxRowTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.chrome.browser.bookmarks; | ||
|
||
import android.app.Activity; | ||
import android.view.KeyEvent; | ||
import android.view.LayoutInflater; | ||
import android.view.ViewGroup; | ||
import android.widget.EditText; | ||
import android.widget.FrameLayout; | ||
import android.widget.LinearLayout; | ||
|
||
import androidx.test.filters.MediumTest; | ||
import androidx.test.platform.app.InstrumentationRegistry; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.chromium.base.test.BaseActivityTestRule; | ||
import org.chromium.base.test.util.Batch; | ||
import org.chromium.base.test.util.Criteria; | ||
import org.chromium.base.test.util.CriteriaHelper; | ||
import org.chromium.base.test.util.Matchers; | ||
import org.chromium.chrome.R; | ||
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; | ||
import org.chromium.chrome.test.util.browser.Features; | ||
import org.chromium.content_public.browser.test.util.KeyUtils; | ||
import org.chromium.content_public.browser.test.util.TestThreadUtils; | ||
import org.chromium.content_public.browser.test.util.TouchCommon; | ||
import org.chromium.ui.test.util.BlankUiTestActivity; | ||
import org.chromium.ui.test.util.DisableAnimationsTestRule; | ||
|
||
/** Non-render tests for {@link BookmarkSearchBoxRow}. */ | ||
@RunWith(ChromeJUnit4ClassRunner.class) | ||
@Batch(Batch.PER_CLASS) | ||
public class BookmarkSearchBoxRowTest { | ||
@Rule | ||
public final DisableAnimationsTestRule mDisableAnimationsRule = new DisableAnimationsTestRule(); | ||
@Rule | ||
public BaseActivityTestRule<BlankUiTestActivity> mActivityTestRule = | ||
new BaseActivityTestRule<>(BlankUiTestActivity.class); | ||
@Rule | ||
public TestRule mProcessor = new Features.JUnitProcessor(); | ||
|
||
private BookmarkSearchBoxRow mBookmarkSearchBoxRow; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
mActivityTestRule.launchActivity(null); | ||
|
||
TestThreadUtils.runOnUiThreadBlocking(() -> { | ||
Activity activity = mActivityTestRule.getActivity(); | ||
LinearLayout contentView = new LinearLayout(activity); | ||
|
||
// Older Android versions need this otherwise {@link View#clearFocus()} will be ignored. | ||
// This also mirrors what {@link SelectableListLayout} does. | ||
contentView.setFocusableInTouchMode(true); | ||
|
||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( | ||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); | ||
activity.setContentView(contentView, params); | ||
|
||
LayoutInflater layoutInflater = LayoutInflater.from(activity); | ||
mBookmarkSearchBoxRow = | ||
layoutInflater.inflate(R.layout.bookmark_search_box_row, contentView) | ||
.findViewById(R.id.bookmark_toolbar); | ||
}); | ||
} | ||
|
||
@Test | ||
@MediumTest | ||
public void testFocusAndEnter() { | ||
EditText editText = mBookmarkSearchBoxRow.findViewById(R.id.search_text); | ||
|
||
TestThreadUtils.runOnUiThreadBlocking(() -> TouchCommon.singleClickView(editText)); | ||
CriteriaHelper.pollUiThread( | ||
() -> Criteria.checkThat(editText.hasFocus(), Matchers.is(true))); | ||
|
||
TestThreadUtils.runOnUiThreadBlocking( | ||
() | ||
-> KeyUtils.singleKeyEventView(InstrumentationRegistry.getInstrumentation(), | ||
editText, KeyEvent.KEYCODE_ENTER)); | ||
CriteriaHelper.pollUiThread( | ||
() -> Criteria.checkThat(editText.hasFocus(), Matchers.is(false))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.