Skip to content

Commit

Permalink
Read later: Delete reading list in search state should not crash.
Browse files Browse the repository at this point in the history
Fix a crash when deleting a reading list from overflow menu in search
state with empty query key word.

Reading list and partner bookmark backend only call into
bookmarkModelChanged instead of bookmarkNodeRemoved. closeSearchUI()
will set bookmark recycler view list properly.

Bug: 1163831
Change-Id: I622026c4f76b0dc560cda72439aff01fd415f7c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2666375
Reviewed-by: David Trainor <dtrainor@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#849664}
  • Loading branch information
Xing Liu authored and Chromium LUCI CQ committed Feb 2, 2021
1 parent 345eb59 commit e1eae8f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ public void bookmarkModelChanged() {
clearHighlight();
mDelegate.notifyStateChange(BookmarkItemsAdapter.this);

if (mDelegate.getCurrentState() == BookmarkUIState.STATE_SEARCHING
&& !TextUtils.equals(mSearchText, EMPTY_QUERY)) {
search(mSearchText);
if (mDelegate.getCurrentState() == BookmarkUIState.STATE_SEARCHING) {
if (!TextUtils.equals(mSearchText, EMPTY_QUERY)) {
search(mSearchText);
} else {
mDelegate.closeSearchUI();
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,36 @@ public void testReadingListDeletion() throws Exception {
CriteriaHelper.pollUiThread(() -> mBookmarkModel.getReadingListItem(mTestUrlA) == null);
}

@Test
@SmallTest
@Features.EnableFeatures({ChromeFeatureList.READ_LATER})
public void testSearchReadingList_Deletion() throws Exception {
addReadingListBookmark(TEST_PAGE_TITLE_GOOGLE, mTestUrlA);
BookmarkPromoHeader.forcePromoStateForTests(PromoState.PROMO_NONE);
openBookmarkManager();
CriteriaHelper.pollUiThread(() -> mBookmarkModel.getReadingListItem(mTestUrlA) != null);

// Open the "Reading list" folder.
TestThreadUtils.runOnUiThreadBlocking(
() -> mManager.openFolder(mBookmarkModel.getRootFolderId()));
onView(withText("Reading list")).perform(click());
RecyclerViewTestUtils.waitForStableRecyclerView(mItemsContainer);

// Enter search UI, but don't enter any search key word.
BookmarkManager manager = getBookmarkManager();
TestThreadUtils.runOnUiThreadBlocking(manager::openSearchUI);
Assert.assertEquals("Wrong state, should be searching", BookmarkUIState.STATE_SEARCHING,
manager.getCurrentState());
RecyclerViewTestUtils.waitForStableRecyclerView(mItemsContainer);

// Delete the reading list page in search state.
View readingListItem = mItemsContainer.findViewHolderForAdapterPosition(0).itemView;
View more = readingListItem.findViewById(R.id.more);
TestThreadUtils.runOnUiThreadBlocking(more::callOnClick);
onView(withText("Delete")).check(matches(isDisplayed())).perform(click());
CriteriaHelper.pollUiThread(() -> mBookmarkModel.getReadingListItem(mTestUrlA) == null);
}

@Test
@SmallTest
@Features.EnableFeatures({ChromeFeatureList.READ_LATER})
Expand Down

0 comments on commit e1eae8f

Please sign in to comment.