Commit 01dddec5 authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

De-flake PopupTest#testPopupWindowsAppearWhenAllowed

In my local testing, the translate infobar was showing up
on the webpage because it uses latin placeholder text.

This reworks the infobar check to not check for an exact
count, but to look for infobars of a particular type.

BUG=771103

Change-Id: Ia6544c386e9e8288f7980a2c14e0b0fba0b14e98
Reviewed-on: https://chromium-review.googlesource.com/1087684Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564925}
parent 9023a87c
...@@ -18,11 +18,11 @@ import org.junit.runner.RunWith; ...@@ -18,11 +18,11 @@ import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.FlakyTest;
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.infobar.InfoBar; import org.chromium.chrome.browser.infobar.InfoBar;
import org.chromium.chrome.browser.infobar.InfoBarContainer; import org.chromium.chrome.browser.infobar.InfoBarContainer;
import org.chromium.chrome.browser.infobar.InfoBarIdentifier;
import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
...@@ -34,6 +34,8 @@ import org.chromium.content.browser.test.util.TouchCommon; ...@@ -34,6 +34,8 @@ import org.chromium.content.browser.test.util.TouchCommon;
import org.chromium.net.test.EmbeddedTestServer; import org.chromium.net.test.EmbeddedTestServer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/** /**
* Tests whether popup windows appear. * Tests whether popup windows appear.
...@@ -118,28 +120,57 @@ public class PopupTest { ...@@ -118,28 +120,57 @@ public class PopupTest {
Assert.assertEquals(1, selector.getTotalTabCount()); Assert.assertEquals(1, selector.getTotalTabCount());
} }
private void waitForForegroundInfoBar(@InfoBarIdentifier int id) {
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
if (getNumInfobarsShowing() == 0) {
updateFailureReason("No infobars present");
return false;
}
InfoBar frontInfoBar = mActivityTestRule.getInfoBars().get(0);
if (frontInfoBar.getInfoBarIdentifier() != id) {
updateFailureReason(String.format(Locale.ENGLISH,
"Invalid infobar type shown: %d", frontInfoBar.getInfoBarIdentifier()));
frontInfoBar.onCloseButtonClicked();
return false;
}
return true;
}
});
}
private void waitForNoInfoBarOfType(@InfoBarIdentifier int id) {
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
List<InfoBar> infoBars = mActivityTestRule.getInfoBars();
if (infoBars.isEmpty()) return true;
for (InfoBar infoBar : infoBars) {
if (infoBar.getInfoBarIdentifier() == id) return false;
}
return true;
}
});
}
@Test @Test
@MediumTest @MediumTest
@Feature({"Popup"}) @Feature({"Popup"})
@FlakyTest(message = "crbug.com/771103")
public void testPopupWindowsAppearWhenAllowed() throws Exception { public void testPopupWindowsAppearWhenAllowed() throws Exception {
final TabModelSelector selector = mActivityTestRule.getActivity().getTabModelSelector(); final TabModelSelector selector = mActivityTestRule.getActivity().getTabModelSelector();
mActivityTestRule.loadUrl(mPopupHtmlUrl); mActivityTestRule.loadUrl(mPopupHtmlUrl);
CriteriaHelper.pollUiThread(Criteria.equals(1, () -> getNumInfobarsShowing())); waitForForegroundInfoBar(InfoBarIdentifier.POPUP_BLOCKED_INFOBAR_DELEGATE_MOBILE);
Assert.assertEquals(1, selector.getTotalTabCount()); Assert.assertEquals(1, selector.getTotalTabCount());
final InfoBarContainer container = selector.getCurrentTab().getInfoBarContainer(); final InfoBarContainer container = selector.getCurrentTab().getInfoBarContainer();
ArrayList<InfoBar> infobars = container.getInfoBarsForTesting(); ArrayList<InfoBar> infobars = container.getInfoBarsForTesting();
Assert.assertEquals(1, infobars.size());
// Wait until the animations are done, then click the "open popups" button. // Wait until the animations are done, then click the "open popups" button.
final InfoBar infobar = infobars.get(0); final InfoBar infobar = infobars.get(0);
CriteriaHelper.pollUiThread(new Criteria() { Assert.assertEquals(InfoBarIdentifier.POPUP_BLOCKED_INFOBAR_DELEGATE_MOBILE,
@Override infobar.getInfoBarIdentifier());
public boolean isSatisfied() { CriteriaHelper.pollUiThread(Criteria.equals(false, () -> container.isAnimating()));
return !container.isAnimating();
}
});
TouchCommon.singleClickView(infobar.getView().findViewById(R.id.button_primary)); TouchCommon.singleClickView(infobar.getView().findViewById(R.id.button_primary));
// Document mode popups appear slowly and sequentially to prevent Android from throwing them // Document mode popups appear slowly and sequentially to prevent Android from throwing them
...@@ -160,11 +191,21 @@ public class PopupTest { ...@@ -160,11 +191,21 @@ public class PopupTest {
CriteriaHelper.pollUiThread(new Criteria() { CriteriaHelper.pollUiThread(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
if (getNumInfobarsShowing() != 0) return false; int tabCount = selector.getTotalTabCount();
if (selector.getTotalTabCount() != 5) return false; if (tabCount != 5) {
return TextUtils.equals("Two", selector.getCurrentTab().getTitle()); updateFailureReason(String.format(
Locale.ENGLISH, "Expected 5 tabs, but found: %d", tabCount));
return false;
}
String tabTitle = selector.getCurrentTab().getTitle();
updateFailureReason(String.format(
Locale.ENGLISH, "Exepcted title 'Two', but found: %s", tabTitle));
return TextUtils.equals("Two", tabTitle);
} }
}, 7500, CriteriaHelper.DEFAULT_POLLING_INTERVAL); }, 7500, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
waitForNoInfoBarOfType(InfoBarIdentifier.POPUP_BLOCKED_INFOBAR_DELEGATE_MOBILE);
Assert.assertNotSame(currentTabId, selector.getCurrentTab().getId()); Assert.assertNotSame(currentTabId, selector.getCurrentTab().getId());
} }
} }
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