Commit 49acf1ec authored by Theresa Wellington's avatar Theresa Wellington Committed by Commit Bot

Force empty partner bookmarks for some Android bookmarks tests

On some bots the partner bookmarks folder is unexpectedly showing up,
causing flakiness due to an unexpected number of items in the bookmarks
manager. Force an empty partner bookmarks folder.

Also add a speculative fix for
BookmarkReorderTest.testShowInFolder_OpenOtherFolder that waits for a
stable RecyclerView to try to prevent an NPE that's occassionally
occuring.

BUG=1018170

Change-Id: I1112125c07a13173c4a2afc65d87e066ff432717
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1881367Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Theresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709616}
parent 6a2bf2df
......@@ -36,7 +36,6 @@ import org.chromium.chrome.browser.night_mode.NightModeTestUtils;
import org.chromium.chrome.browser.ui.widget.ListMenuButton;
import org.chromium.chrome.browser.widget.selection.SelectableListToolbar.ViewType;
import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
import org.chromium.chrome.test.util.BookmarkTestUtil;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils;
import org.chromium.components.bookmarks.BookmarkId;
......@@ -720,6 +719,7 @@ public class BookmarkReorderTest extends BookmarkTest {
// Show in folder.
onView(withText("Show in folder")).perform(click());
RecyclerViewTestUtils.waitForStableRecyclerView(mItemsContainer);
// Make sure that we're in the right folder (index 1 because of promo).
View itemA = mItemsContainer.findViewHolderForAdapterPosition(1).itemView;
......@@ -749,6 +749,9 @@ public class BookmarkReorderTest extends BookmarkTest {
public void testAddBookmarkInBackgroundWithSelection() throws Exception {
BookmarkId id = addBookmark(TEST_PAGE_TITLE_FOO, mTestPageFoo);
BookmarkPromoHeader.forcePromoStateForTests(PromoState.PROMO_NONE);
// Force empty partner bookmark folder to keep set of bookmark items consistent across
// devices.
loadEmptyPartnerBookmarksForTesting();
openBookmarkManager();
Assert.assertEquals(1, getAdapter().getItemCount());
BookmarkRow row =
......@@ -786,6 +789,9 @@ public class BookmarkReorderTest extends BookmarkTest {
BookmarkId googleId = addBookmark(TEST_PAGE_TITLE_GOOGLE, mTestPage);
BookmarkId aId = addBookmark(TEST_TITLE_A, TEST_URL_A);
BookmarkPromoHeader.forcePromoStateForTests(PromoState.PROMO_NONE);
// Force empty partner bookmark folder to keep set of bookmark items consistent across
// devices.
loadEmptyPartnerBookmarksForTesting();
openBookmarkManager();
Assert.assertEquals(3, getAdapter().getItemCount());
BookmarkRow row =
......@@ -816,6 +822,9 @@ public class BookmarkReorderTest extends BookmarkTest {
BookmarkId googleId = addBookmark(TEST_PAGE_TITLE_GOOGLE, mTestPage);
BookmarkId aId = addBookmark(TEST_TITLE_A, TEST_URL_A);
BookmarkPromoHeader.forcePromoStateForTests(PromoState.PROMO_NONE);
// Force empty partner bookmark folder to keep set of bookmark items consistent across
// devices.
loadEmptyPartnerBookmarksForTesting();
openBookmarkManager();
Assert.assertEquals(3, getAdapter().getItemCount());
BookmarkRow row =
......@@ -846,6 +855,9 @@ public class BookmarkReorderTest extends BookmarkTest {
public void testUpdateSelectedBookmarkInBackground() throws Exception {
BookmarkId id = addBookmark(TEST_PAGE_TITLE_FOO, mTestPageFoo);
BookmarkPromoHeader.forcePromoStateForTests(PromoState.PROMO_NONE);
// Force empty partner bookmark folder to keep set of bookmark items consistent across
// devices.
loadEmptyPartnerBookmarksForTesting();
openBookmarkManager();
Assert.assertEquals(1, getAdapter().getItemCount());
BookmarkRow row =
......@@ -881,17 +893,6 @@ public class BookmarkReorderTest extends BookmarkTest {
});
}
/**
* Loads an empty partner bookmarks folder for testing. The partner bookmarks folder will appear
* in the mobile bookmarks folder.
*
*/
private void loadEmptyPartnerBookmarksForTesting() {
TestThreadUtils.runOnUiThreadBlocking(
() -> { mBookmarkModel.loadEmptyPartnerBookmarkShimForTesting(); });
BookmarkTestUtil.waitForBookmarkModelLoaded();
}
/**
* Adds a bookmark in the scenario where we have partner bookmarks.
*
......
......@@ -130,6 +130,17 @@ public class BookmarkTest {
BookmarkTestUtil.waitForBookmarkModelLoaded();
}
/**
* Loads an empty partner bookmarks folder for testing. The partner bookmarks folder will appear
* in the mobile bookmarks folder.
*
*/
protected void loadEmptyPartnerBookmarksForTesting() {
TestThreadUtils.runOnUiThreadBlocking(
() -> { mBookmarkModel.loadEmptyPartnerBookmarkShimForTesting(); });
BookmarkTestUtil.waitForBookmarkModelLoaded();
}
@After
public void tearDown() {
mTestServer.stopAndDestroyServer();
......@@ -305,6 +316,9 @@ public class BookmarkTest {
syncDelegate.setMasterSyncAutomatically(true);
AndroidSyncSettings.overrideForTests(syncDelegate, null);
BookmarkPromoHeader.forcePromoStateForTests(BookmarkPromoHeader.PromoState.PROMO_SYNC);
// Force empty partner bookmark folder to keep set of bookmark items consistent across
// devices.
loadEmptyPartnerBookmarksForTesting();
addBookmark(TEST_PAGE_TITLE_GOOGLE, mTestPage);
addBookmark(TEST_PAGE_TITLE_FOO, mTestPageFoo);
openBookmarkManager();
......@@ -354,6 +368,9 @@ public class BookmarkTest {
@MediumTest
public void testSearchBookmarks_Delete() throws Exception {
BookmarkPromoHeader.forcePromoStateForTests(BookmarkPromoHeader.PromoState.PROMO_NONE);
// Force empty partner bookmark folder to keep set of bookmark items consistent across
// devices.
loadEmptyPartnerBookmarksForTesting();
BookmarkId testFolder = addFolder(TEST_FOLDER_TITLE);
BookmarkId testBookmark = addBookmark(TEST_PAGE_TITLE_GOOGLE, mTestPage);
addBookmark(TEST_PAGE_TITLE_FOO, mTestPageFoo);
......
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