Commit 5c98faff authored by Theresa Wellington's avatar Theresa Wellington Committed by Commit Bot

Another attempt to deflake BookmarkTest#testOpenBookmark

A previous CL attempted to deflake this test by waiting for page load
start instead of page load finished. This appears to have helped a bit
but there was a failed run after the "fix". The failures were due to
either the pageLoadStarted check comparison failing to get the right Tab
(claimed activity tab URL was about:blank while post test screenshot
showed correcct URL) or an NPE when attempting to get the activity tab.

This CL waits for the last focused activity to be ChromeTabbedActivity
then polls for ChromeTabbedActivity#getActivityTab()'s URL to match the
expected test page.

BUG=1068608

Change-Id: I13dd6e3ad59963ebfa21d99d011e8b8a600496d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2145764
Commit-Queue: Theresa  <twellington@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758267}
parent 26c9c3aa
...@@ -15,6 +15,7 @@ import android.widget.TextView; ...@@ -15,6 +15,7 @@ import android.widget.TextView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import org.hamcrest.core.IsInstanceOf;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert; import org.junit.Assert;
...@@ -36,6 +37,7 @@ import org.chromium.base.test.util.Restriction; ...@@ -36,6 +37,7 @@ import org.chromium.base.test.util.Restriction;
import org.chromium.base.test.util.RetryOnFailure; import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem; import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
...@@ -44,6 +46,7 @@ import org.chromium.chrome.browser.partnerbookmarks.PartnerBookmarksShim; ...@@ -44,6 +46,7 @@ import org.chromium.chrome.browser.partnerbookmarks.PartnerBookmarksShim;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys; import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager; import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.ui.messages.snackbar.Snackbar; import org.chromium.chrome.browser.ui.messages.snackbar.Snackbar;
import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager; import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
...@@ -52,7 +55,6 @@ import org.chromium.chrome.test.util.ActivityUtils; ...@@ -52,7 +55,6 @@ import org.chromium.chrome.test.util.ActivityUtils;
import org.chromium.chrome.test.util.ApplicationTestUtils; import org.chromium.chrome.test.util.ApplicationTestUtils;
import org.chromium.chrome.test.util.BookmarkTestUtil; import org.chromium.chrome.test.util.BookmarkTestUtil;
import org.chromium.chrome.test.util.ChromeRenderTestRule; import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.MenuUtils; import org.chromium.chrome.test.util.MenuUtils;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils; import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils;
...@@ -62,6 +64,7 @@ import org.chromium.components.browser_ui.widget.selectable_list.SelectableListT ...@@ -62,6 +64,7 @@ import org.chromium.components.browser_ui.widget.selectable_list.SelectableListT
import org.chromium.components.embedder_support.util.UrlConstants; import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.sync.AndroidSyncSettings; import org.chromium.components.sync.AndroidSyncSettings;
import org.chromium.components.sync.test.util.MockSyncContentResolverDelegate; import org.chromium.components.sync.test.util.MockSyncContentResolverDelegate;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.browser.test.util.TouchCommon; import org.chromium.content_public.browser.test.util.TouchCommon;
...@@ -309,8 +312,20 @@ public class BookmarkTest { ...@@ -309,8 +312,20 @@ public class BookmarkTest {
Assert.assertTrue("Grid view does not contain added bookmark: ", Assert.assertTrue("Grid view does not contain added bookmark: ",
isItemPresentInBookmarkList(TEST_PAGE_TITLE_GOOGLE)); isItemPresentInBookmarkList(TEST_PAGE_TITLE_GOOGLE));
final View title = getViewWithText(mItemsContainer, TEST_PAGE_TITLE_GOOGLE); final View title = getViewWithText(mItemsContainer, TEST_PAGE_TITLE_GOOGLE);
ChromeTabUtils.waitForTabPageLoadStart(mActivityTestRule.getActivity().getActivityTab(), TestThreadUtils.runOnUiThreadBlocking(() -> TouchCommon.singleClickView(title));
mTestPage, () -> TouchCommon.singleClickView(title)); ChromeTabbedActivity activity = waitForTabbedActivity();
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
Tab activityTab = activity.getActivityTab();
String tabUrl = activityTab == null || activityTab.getUrl() == null
? ""
: activityTab.getUrl().getSpec();
updateFailureReason(activityTab == null ? "Activity tab is null."
: "Tab URL incorrect: " + tabUrl);
return mTestPage.equals(tabUrl);
}
});
} }
@Test @Test
...@@ -670,10 +685,16 @@ public class BookmarkTest { ...@@ -670,10 +685,16 @@ public class BookmarkTest {
} }
private void waitForEditActivity() { private void waitForEditActivity() {
CriteriaHelper.pollUiThread(() CriteriaHelper.pollUiThread(
-> ApplicationStatus.getLastTrackedFocusedActivity() Criteria.checkThat(ApplicationStatus::getLastTrackedFocusedActivity,
instanceof BookmarkEditActivity, IsInstanceOf.instanceOf(BookmarkEditActivity.class)));
"Timed out waiting for BookmarkEditActivity");
InstrumentationRegistry.getInstrumentation().waitForIdleSync(); InstrumentationRegistry.getInstrumentation().waitForIdleSync();
} }
private ChromeTabbedActivity waitForTabbedActivity() {
CriteriaHelper.pollUiThread(
Criteria.checkThat(ApplicationStatus::getLastTrackedFocusedActivity,
IsInstanceOf.instanceOf(ChromeTabbedActivity.class)));
return (ChromeTabbedActivity) ApplicationStatus.getLastTrackedFocusedActivity();
}
} }
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