Commit c6eb001a authored by John Budorick's avatar John Budorick Committed by Commit Bot

android: wait for tab counts in TabSwitcherControllerTest.

Should mitigate races between the tests & tabs closing, which
emulators seem to lose much more frequently than devices.

Bug: 1054849
Change-Id: Ifc2bb578ee9a9315b09b32c02b7eba7037fc4941
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2073148Reviewed-by: default avatarSky Malice <skym@chromium.org>
Commit-Queue: John Budorick <jbudorick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744664}
parent 5be79981
...@@ -20,6 +20,8 @@ import org.chromium.chrome.test.pagecontroller.controllers.tabswitcher.TabSwitch ...@@ -20,6 +20,8 @@ import org.chromium.chrome.test.pagecontroller.controllers.tabswitcher.TabSwitch
import org.chromium.chrome.test.pagecontroller.controllers.tabswitcher.TabSwitcherMenuController; import org.chromium.chrome.test.pagecontroller.controllers.tabswitcher.TabSwitcherMenuController;
import org.chromium.chrome.test.pagecontroller.rules.ChromeUiApplicationTestRule; import org.chromium.chrome.test.pagecontroller.rules.ChromeUiApplicationTestRule;
import org.chromium.chrome.test.pagecontroller.rules.ChromeUiAutomatorTestRule; import org.chromium.chrome.test.pagecontroller.rules.ChromeUiAutomatorTestRule;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
/** /**
* Tests for the TabSwitcherController. * Tests for the TabSwitcherController.
...@@ -47,18 +49,27 @@ public class TabSwitcherControllerTest { ...@@ -47,18 +49,27 @@ public class TabSwitcherControllerTest {
Assert.assertTrue(NewTabPageController.getInstance().isCurrentPageThis()); Assert.assertTrue(NewTabPageController.getInstance().isCurrentPageThis());
} }
private void waitForTabCount(final int count) {
CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override
public boolean isSatisfied() {
return mController.getNumberOfOpenTabs() == count;
}
});
}
@Test @Test
public void testCloseAllTabs() { public void testCloseAllTabs() {
mController.clickNewTab().openTabSwitcher().clickNewTab().openTabSwitcher(); mController.clickNewTab().openTabSwitcher().clickNewTab().openTabSwitcher();
mController.clickCloseAllTabs(); mController.clickCloseAllTabs();
Assert.assertEquals(0, mController.getNumberOfOpenTabs()); waitForTabCount(0);
} }
@Test @Test
public void testNumberOfOpenTabs() { public void testNumberOfOpenTabs() {
int startTabs = mController.getNumberOfOpenTabs(); int startTabs = mController.getNumberOfOpenTabs();
mController.clickNewTab().openTabSwitcher(); mController.clickNewTab().openTabSwitcher();
Assert.assertEquals(startTabs + 1, mController.getNumberOfOpenTabs()); waitForTabCount(startTabs + 1);
} }
@Test @Test
......
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