Commit 885cf1f6 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Batch device_dialog tests together

Introduces BlankCTATabInitialState.java, which manages initial state
across test suites. No post-batch cleanup is required as the only state
carried across test suites is the Activity, which is finished by the
test runner.

Also batches all device_dialog instrumentation tests together,
dramatically speeding them up.

Bug: 989569
Change-Id: I66fa56da157491defe1dca9b4ce9464a3d308961
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2307650Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792242}
parent 21e6c4e1
...@@ -38,6 +38,7 @@ import org.junit.After; ...@@ -38,6 +38,7 @@ import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -78,7 +79,6 @@ import org.chromium.chrome.browser.contextualsearch.ContextualSearchInternalStat ...@@ -78,7 +79,6 @@ import org.chromium.chrome.browser.contextualsearch.ContextualSearchInternalStat
import org.chromium.chrome.browser.contextualsearch.ResolvedSearchTerm.CardTag; import org.chromium.chrome.browser.contextualsearch.ResolvedSearchTerm.CardTag;
import org.chromium.chrome.browser.externalnav.ExternalNavigationDelegateImpl; import org.chromium.chrome.browser.externalnav.ExternalNavigationDelegateImpl;
import org.chromium.chrome.browser.findinpage.FindToolbar; import org.chromium.chrome.browser.findinpage.FindToolbar;
import org.chromium.chrome.browser.firstrun.FirstRunStatus;
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;
import org.chromium.chrome.browser.gsa.GSAContextDisplaySelection; import org.chromium.chrome.browser.gsa.GSAContextDisplaySelection;
...@@ -92,6 +92,7 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver; ...@@ -92,6 +92,7 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver;
import org.chromium.chrome.browser.tabmodel.TabModelUtils; import org.chromium.chrome.browser.tabmodel.TabModelUtils;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate; import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
import org.chromium.chrome.test.batch.BlankCTATabInitialStateRule;
import org.chromium.chrome.test.util.ApplicationTestUtils; import org.chromium.chrome.test.util.ApplicationTestUtils;
import org.chromium.chrome.test.util.ChromeTabUtils; import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.FullscreenTestUtils; import org.chromium.chrome.test.util.FullscreenTestUtils;
...@@ -145,38 +146,13 @@ import java.util.concurrent.TimeoutException; ...@@ -145,38 +146,13 @@ import java.util.concurrent.TimeoutException;
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@Batch(Batch.PER_CLASS) @Batch(Batch.PER_CLASS)
public class ContextualSearchManagerTest { public class ContextualSearchManagerTest {
// This class batches with multiple paramaterized versions of itself, and therefore cannot use
// @BeforeClass/@AfterClass as these would be evaluated once for each parameterized class.
// TODO(crbug.com/1090043): Use @BeforeClass once this is fixed.
private static class SharedStaticState {
private static ChromeActivityTestRule<ChromeActivity> sActivityTestRule;
private static boolean sActivityStarted;
public static ChromeActivityTestRule<ChromeActivity> getActivityTestRule() {
if (sActivityTestRule == null) {
sActivityTestRule = new ChromeActivityTestRule<>(ChromeActivity.class);
}
return sActivityTestRule;
}
public static void ensureActivityStarted() {
if (sActivityStarted) return;
sActivityStarted = true;
TestThreadUtils.runOnUiThreadBlocking(() -> {
FirstRunStatus.setFirstRunFlowComplete(true);
LocaleManager.setInstanceForTest(new LocaleManager() {
@Override
public boolean needToCheckForSearchEnginePromo() {
return false;
}
});
});
sActivityTestRule.startMainActivityOnBlankPage();
}
}
@ClassRule @ClassRule
public static ChromeActivityTestRule<ChromeActivity> mActivityTestRule = public static final ChromeActivityTestRule<ChromeActivity> sActivityTestRule =
SharedStaticState.getActivityTestRule(); new ChromeActivityTestRule(ChromeActivity.class);
@Rule
public final BlankCTATabInitialStateRule mInitialStateRule =
new BlankCTATabInitialStateRule(sActivityTestRule, false);
/** Parameter provider for enabling/disabling triggering-related Features. */ /** Parameter provider for enabling/disabling triggering-related Features. */
public static class FeatureParamProvider implements ParameterProvider { public static class FeatureParamProvider implements ParameterProvider {
...@@ -247,18 +223,18 @@ public class ContextualSearchManagerTest { ...@@ -247,18 +223,18 @@ public class ContextualSearchManagerTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
SharedStaticState.ensureActivityStarted(); LocaleManager.setInstanceForTest(new LocaleManager() {
@Override
public boolean needToCheckForSearchEnginePromo() {
return false;
}
});
// TODO(crbug.com/989569): Allow TestServer reuse across tests to avoid waiting on test mTestServer = sActivityTestRule.getTestServer();
// server startup for each test.
mTestServer = mActivityTestRule.getTestServer();
// Since we re-use the tab across tests, if the test page is already loaded, it's difficult sActivityTestRule.loadUrl(mTestServer.getURL(TEST_PAGE));
// to reload it without being racy, so we navigate to about:blank first.
mActivityTestRule.loadUrl("about:blank");
mActivityTestRule.loadUrl(mTestServer.getURL(TEST_PAGE));
mManager = mActivityTestRule.getActivity().getContextualSearchManager(); mManager = sActivityTestRule.getActivity().getContextualSearchManager();
Assert.assertNotNull(mManager); Assert.assertNotNull(mManager);
mPanel = mManager.getContextualSearchPanel(); mPanel = mManager.getContextualSearchPanel();
...@@ -271,7 +247,7 @@ public class ContextualSearchManagerTest { ...@@ -271,7 +247,7 @@ public class ContextualSearchManagerTest {
mFakeServer = new ContextualSearchFakeServer(mPolicy, this, mManager, mFakeServer = new ContextualSearchFakeServer(mPolicy, this, mManager,
mManager.getOverlayContentDelegate(), new OverlayContentProgressObserver(), mManager.getOverlayContentDelegate(), new OverlayContentProgressObserver(),
mActivityTestRule.getActivity()); sActivityTestRule.getActivity());
mPanel.setOverlayPanelContentFactory(mFakeServer); mPanel.setOverlayPanelContentFactory(mFakeServer);
mManager.setNetworkCommunicator(mFakeServer); mManager.setNetworkCommunicator(mFakeServer);
...@@ -284,7 +260,7 @@ public class ContextualSearchManagerTest { ...@@ -284,7 +260,7 @@ public class ContextualSearchManagerTest {
mActivityMonitor = InstrumentationRegistry.getInstrumentation().addMonitor( mActivityMonitor = InstrumentationRegistry.getInstrumentation().addMonitor(
filter, new Instrumentation.ActivityResult(Activity.RESULT_OK, null), true); filter, new Instrumentation.ActivityResult(Activity.RESULT_OK, null), true);
mDpToPx = mActivityTestRule.getActivity().getResources().getDisplayMetrics().density; mDpToPx = sActivityTestRule.getActivity().getResources().getDisplayMetrics().density;
// Set the test Features map for all tests regardless of whether they are parameterized. // Set the test Features map for all tests regardless of whether they are parameterized.
// Non-parameterized tests typically override this setting by calling setTestFeatures // Non-parameterized tests typically override this setting by calling setTestFeatures
...@@ -309,10 +285,6 @@ public class ContextualSearchManagerTest { ...@@ -309,10 +285,6 @@ public class ContextualSearchManagerTest {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
// Close all but the first tab as these tests expect to start with a single tab.
while (TabModelUtils.closeTabByIndex(
mActivityTestRule.getActivity().getCurrentTabModel(), 1)) {
}
mManager.dismissContextualSearchBar(); mManager.dismissContextualSearchBar();
mPanel.closePanel(StateChangeReason.UNKNOWN, false); mPanel.closePanel(StateChangeReason.UNKNOWN, false);
}); });
...@@ -374,7 +346,7 @@ public class ContextualSearchManagerTest { ...@@ -374,7 +346,7 @@ public class ContextualSearchManagerTest {
private void setOnlineStatusAndReload(boolean isOnline) { private void setOnlineStatusAndReload(boolean isOnline) {
mFakeServer.setIsOnline(isOnline); mFakeServer.setIsOnline(isOnline);
final String testUrl = mTestServer.getURL(TEST_PAGE); final String testUrl = mTestServer.getURL(TEST_PAGE);
final Tab tab = mActivityTestRule.getActivity().getActivityTab(); final Tab tab = sActivityTestRule.getActivity().getActivityTab();
TestThreadUtils.runOnUiThreadBlocking(() -> tab.reload()); TestThreadUtils.runOnUiThreadBlocking(() -> tab.reload());
// Make sure the page is fully loaded. // Make sure the page is fully loaded.
ChromeTabUtils.waitForTabPageLoaded(tab, testUrl); ChromeTabUtils.waitForTabPageLoaded(tab, testUrl);
...@@ -413,7 +385,7 @@ public class ContextualSearchManagerTest { ...@@ -413,7 +385,7 @@ public class ContextualSearchManagerTest {
private void clearSelection() { private void clearSelection() {
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
SelectionPopupController.fromWebContents(mActivityTestRule.getWebContents()) SelectionPopupController.fromWebContents(sActivityTestRule.getWebContents())
.clearSelection(); .clearSelection();
}); });
} }
...@@ -427,7 +399,7 @@ public class ContextualSearchManagerTest { ...@@ -427,7 +399,7 @@ public class ContextualSearchManagerTest {
* @param nodeId A string containing the node ID. * @param nodeId A string containing the node ID.
*/ */
public void longPressNodeWithoutWaiting(String nodeId) throws TimeoutException { public void longPressNodeWithoutWaiting(String nodeId) throws TimeoutException {
Tab tab = mActivityTestRule.getActivity().getActivityTab(); Tab tab = sActivityTestRule.getActivity().getActivityTab();
DOMUtils.longPressNode(tab.getWebContents(), nodeId); DOMUtils.longPressNode(tab.getWebContents(), nodeId);
} }
...@@ -474,7 +446,7 @@ public class ContextualSearchManagerTest { ...@@ -474,7 +446,7 @@ public class ContextualSearchManagerTest {
*/ */
public long longPressNodeWithoutUp(String nodeId) throws TimeoutException { public long longPressNodeWithoutUp(String nodeId) throws TimeoutException {
long downTime = SystemClock.uptimeMillis(); long downTime = SystemClock.uptimeMillis();
Tab tab = mActivityTestRule.getActivity().getActivityTab(); Tab tab = sActivityTestRule.getActivity().getActivityTab();
DOMUtils.longPressNodeWithoutUp(tab.getWebContents(), nodeId, downTime); DOMUtils.longPressNodeWithoutUp(tab.getWebContents(), nodeId, downTime);
waitForSelectActionBarVisible(); waitForSelectActionBarVisible();
waitForPanelToPeek(); waitForPanelToPeek();
...@@ -497,7 +469,7 @@ public class ContextualSearchManagerTest { ...@@ -497,7 +469,7 @@ public class ContextualSearchManagerTest {
// Drag to the specified position by a DOM node id. // Drag to the specified position by a DOM node id.
int stepCount = 100; int stepCount = 100;
Tab tab = mActivityTestRule.getActivity().getActivityTab(); Tab tab = sActivityTestRule.getActivity().getActivityTab();
DOMUtils.dragNodeTo(tab.getWebContents(), startNodeId, endNodeId, stepCount, downTime); DOMUtils.dragNodeTo(tab.getWebContents(), startNodeId, endNodeId, stepCount, downTime);
DOMUtils.dragNodeEnd(tab.getWebContents(), endNodeId, downTime); DOMUtils.dragNodeEnd(tab.getWebContents(), endNodeId, downTime);
...@@ -517,7 +489,7 @@ public class ContextualSearchManagerTest { ...@@ -517,7 +489,7 @@ public class ContextualSearchManagerTest {
* @param nodeId A string containing the node ID. * @param nodeId A string containing the node ID.
*/ */
public void clickNode(String nodeId) throws TimeoutException { public void clickNode(String nodeId) throws TimeoutException {
Tab tab = mActivityTestRule.getActivity().getActivityTab(); Tab tab = sActivityTestRule.getActivity().getActivityTab();
DOMUtils.clickNode(tab.getWebContents(), nodeId); DOMUtils.clickNode(tab.getWebContents(), nodeId);
} }
...@@ -810,7 +782,7 @@ public class ContextualSearchManagerTest { ...@@ -810,7 +782,7 @@ public class ContextualSearchManagerTest {
*/ */
private void pressKey(int keycode) { private void pressKey(int keycode) {
KeyUtils.singleKeyEventActivity(InstrumentationRegistry.getInstrumentation(), KeyUtils.singleKeyEventActivity(InstrumentationRegistry.getInstrumentation(),
mActivityTestRule.getActivity(), keycode); sActivityTestRule.getActivity(), keycode);
} }
/** /**
...@@ -1064,16 +1036,16 @@ public class ContextualSearchManagerTest { ...@@ -1064,16 +1036,16 @@ public class ContextualSearchManagerTest {
*/ */
private void fling(float startX, float startY, float endX, float endY, int stepCount) { private void fling(float startX, float startY, float endX, float endY, int stepCount) {
Point size = new Point(); Point size = new Point();
mActivityTestRule.getActivity().getWindowManager().getDefaultDisplay().getSize(size); sActivityTestRule.getActivity().getWindowManager().getDefaultDisplay().getSize(size);
float dragStartX = size.x * startX; float dragStartX = size.x * startX;
float dragEndX = size.x * endX; float dragEndX = size.x * endX;
float dragStartY = size.y * startY; float dragStartY = size.y * startY;
float dragEndY = size.y * endY; float dragEndY = size.y * endY;
long downTime = SystemClock.uptimeMillis(); long downTime = SystemClock.uptimeMillis();
TouchCommon.dragStart(mActivityTestRule.getActivity(), dragStartX, dragStartY, downTime); TouchCommon.dragStart(sActivityTestRule.getActivity(), dragStartX, dragStartY, downTime);
TouchCommon.dragTo(mActivityTestRule.getActivity(), dragStartX, dragEndX, dragStartY, TouchCommon.dragTo(sActivityTestRule.getActivity(), dragStartX, dragEndX, dragStartY,
dragEndY, stepCount, downTime); dragEndY, stepCount, downTime);
TouchCommon.dragEnd(mActivityTestRule.getActivity(), dragEndX, dragEndY, downTime); TouchCommon.dragEnd(sActivityTestRule.getActivity(), dragEndX, dragEndY, downTime);
} }
/** /**
...@@ -1082,21 +1054,21 @@ public class ContextualSearchManagerTest { ...@@ -1082,21 +1054,21 @@ public class ContextualSearchManagerTest {
*/ */
private void swipe(float startX, float startY, float endX, float endY, int stepCount) { private void swipe(float startX, float startY, float endX, float endY, int stepCount) {
Point size = new Point(); Point size = new Point();
mActivityTestRule.getActivity().getWindowManager().getDefaultDisplay().getSize(size); sActivityTestRule.getActivity().getWindowManager().getDefaultDisplay().getSize(size);
float dragStartX = size.x * startX; float dragStartX = size.x * startX;
float dragEndX = size.x * endX; float dragEndX = size.x * endX;
float dragStartY = size.y * startY; float dragStartY = size.y * startY;
float dragEndY = size.y * endY; float dragEndY = size.y * endY;
int halfCount = stepCount / 2; int halfCount = stepCount / 2;
long downTime = SystemClock.uptimeMillis(); long downTime = SystemClock.uptimeMillis();
TouchCommon.dragStart(mActivityTestRule.getActivity(), dragStartX, dragStartY, downTime); TouchCommon.dragStart(sActivityTestRule.getActivity(), dragStartX, dragStartY, downTime);
TouchCommon.dragTo(mActivityTestRule.getActivity(), dragStartX, dragEndX, dragStartY, TouchCommon.dragTo(sActivityTestRule.getActivity(), dragStartX, dragEndX, dragStartY,
dragEndY, halfCount, downTime); dragEndY, halfCount, downTime);
// Generate events in the stationary end position in order to simulate a "pause" in // Generate events in the stationary end position in order to simulate a "pause" in
// the movement, therefore preventing this gesture from being interpreted as a fling. // the movement, therefore preventing this gesture from being interpreted as a fling.
TouchCommon.dragTo(mActivityTestRule.getActivity(), dragEndX, dragEndX, dragEndY, dragEndY, TouchCommon.dragTo(sActivityTestRule.getActivity(), dragEndX, dragEndX, dragEndY, dragEndY,
halfCount, downTime); halfCount, downTime);
TouchCommon.dragEnd(mActivityTestRule.getActivity(), dragEndX, dragEndY, downTime); TouchCommon.dragEnd(sActivityTestRule.getActivity(), dragEndX, dragEndY, downTime);
} }
/** /**
...@@ -1142,7 +1114,7 @@ public class ContextualSearchManagerTest { ...@@ -1142,7 +1114,7 @@ public class ContextualSearchManagerTest {
* Taps the base page at the given x, y position. * Taps the base page at the given x, y position.
*/ */
private void tapBasePage(float x, float y) { private void tapBasePage(float x, float y) {
View root = mActivityTestRule.getActivity().getWindow().getDecorView().getRootView(); View root = sActivityTestRule.getActivity().getWindow().getDecorView().getRootView();
x *= root.getWidth(); x *= root.getWidth();
y *= root.getHeight(); y *= root.getHeight();
TouchCommon.singleClickView(root, (int) x, (int) y); TouchCommon.singleClickView(root, (int) x, (int) y);
...@@ -1170,7 +1142,7 @@ public class ContextualSearchManagerTest { ...@@ -1170,7 +1142,7 @@ public class ContextualSearchManagerTest {
* TODO(donnd): Replace this method with panelBarClick since this appears to be unreliable. * TODO(donnd): Replace this method with panelBarClick since this appears to be unreliable.
*/ */
private void clickPanelBar() { private void clickPanelBar() {
View root = mActivityTestRule.getActivity().getWindow().getDecorView().getRootView(); View root = sActivityTestRule.getActivity().getWindow().getDecorView().getRootView();
float tapX = ((mPanel.getOffsetX() + mPanel.getWidth()) / 2f) * mDpToPx; float tapX = ((mPanel.getOffsetX() + mPanel.getWidth()) / 2f) * mDpToPx;
float tapY = (mPanel.getOffsetY() + (mPanel.getBarContainerHeight() / 2f)) * mDpToPx; float tapY = (mPanel.getOffsetY() + (mPanel.getBarContainerHeight() / 2f)) * mDpToPx;
...@@ -1357,7 +1329,7 @@ public class ContextualSearchManagerTest { ...@@ -1357,7 +1329,7 @@ public class ContextualSearchManagerTest {
waitForPanelToPeek(); waitForPanelToPeek();
OmniboxTestUtils.toggleUrlBarFocus( OmniboxTestUtils.toggleUrlBarFocus(
(UrlBar) mActivityTestRule.getActivity().findViewById(R.id.url_bar), true); (UrlBar) sActivityTestRule.getActivity().findViewById(R.id.url_bar), true);
assertPanelClosedOrUndefined(); assertPanelClosedOrUndefined();
} }
...@@ -1851,7 +1823,7 @@ public class ContextualSearchManagerTest { ...@@ -1851,7 +1823,7 @@ public class ContextualSearchManagerTest {
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> { PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> {
ChromeTabUtils.simulateRendererKilledForTesting( ChromeTabUtils.simulateRendererKilledForTesting(
mActivityTestRule.getActivity().getActivityTab(), true); sActivityTestRule.getActivity().getActivityTab(), true);
}); });
// Give the panelState time to change // Give the panelState time to change
...@@ -1872,12 +1844,12 @@ public class ContextualSearchManagerTest { ...@@ -1872,12 +1844,12 @@ public class ContextualSearchManagerTest {
public void testContextualSearchNotDismissedOnBackgroundTabCrash( public void testContextualSearchNotDismissedOnBackgroundTabCrash(
@EnabledFeature int enabledFeature) throws Exception { @EnabledFeature int enabledFeature) throws Exception {
ChromeTabUtils.newTabFromMenu( ChromeTabUtils.newTabFromMenu(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity()); InstrumentationRegistry.getInstrumentation(), sActivityTestRule.getActivity());
final Tab tab2 = final Tab tab2 =
TabModelUtils.getCurrentTab(mActivityTestRule.getActivity().getCurrentTabModel()); TabModelUtils.getCurrentTab(sActivityTestRule.getActivity().getCurrentTabModel());
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
TabModelUtils.setIndex(mActivityTestRule.getActivity().getCurrentTabModel(), 0); TabModelUtils.setIndex(sActivityTestRule.getActivity().getCurrentTabModel(), 0);
}); });
triggerResolve("states"); triggerResolve("states");
...@@ -1909,7 +1881,7 @@ public class ContextualSearchManagerTest { ...@@ -1909,7 +1881,7 @@ public class ContextualSearchManagerTest {
tabCreatedHelper.notifyCalled(); tabCreatedHelper.notifyCalled();
} }
}; };
mActivityTestRule.getActivity().getTabModelSelector().addObserver(observer); sActivityTestRule.getActivity().getTabModelSelector().addObserver(observer);
// -------- TEST --------- // -------- TEST ---------
// Start a slow-resolve search and maximize the Panel. // Start a slow-resolve search and maximize the Panel.
...@@ -1936,7 +1908,7 @@ public class ContextualSearchManagerTest { ...@@ -1936,7 +1908,7 @@ public class ContextualSearchManagerTest {
tabCreatedHelper.waitForCallback(tabCreatedHelperCallCount); tabCreatedHelper.waitForCallback(tabCreatedHelperCallCount);
// -------- CLEAN UP --------- // -------- CLEAN UP ---------
mActivityTestRule.getActivity().getTabModelSelector().removeObserver(observer); sActivityTestRule.getActivity().getTabModelSelector().removeObserver(observer);
} }
//============================================================================================ //============================================================================================
...@@ -2109,7 +2081,7 @@ public class ContextualSearchManagerTest { ...@@ -2109,7 +2081,7 @@ public class ContextualSearchManagerTest {
private void closeAppMenu() { private void closeAppMenu() {
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(
() -> mActivityTestRule.getAppMenuCoordinator().getAppMenuHandler().hideAppMenu()); () -> sActivityTestRule.getAppMenuCoordinator().getAppMenuHandler().hideAppMenu());
} }
/** /**
...@@ -2117,7 +2089,7 @@ public class ContextualSearchManagerTest { ...@@ -2117,7 +2089,7 @@ public class ContextualSearchManagerTest {
*/ */
private void assertAppMenuVisibility(final boolean isVisible) { private void assertAppMenuVisibility(final boolean isVisible) {
CriteriaHelper.pollInstrumentationThread(() -> { CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(mActivityTestRule.getAppMenuCoordinator() Criteria.checkThat(sActivityTestRule.getAppMenuCoordinator()
.getAppMenuHandler() .getAppMenuHandler()
.isAppMenuShowing(), .isAppMenuShowing(),
Matchers.is(isVisible)); Matchers.is(isVisible));
...@@ -2408,7 +2380,7 @@ public class ContextualSearchManagerTest { ...@@ -2408,7 +2380,7 @@ public class ContextualSearchManagerTest {
} }
private SelectionPopupController getSelectionPopupController() { private SelectionPopupController getSelectionPopupController() {
return SelectionPopupController.fromWebContents(mActivityTestRule.getWebContents()); return SelectionPopupController.fromWebContents(sActivityTestRule.getWebContents());
} }
/** /**
...@@ -2500,7 +2472,7 @@ public class ContextualSearchManagerTest { ...@@ -2500,7 +2472,7 @@ public class ContextualSearchManagerTest {
public void testExternalNavigationWithUserGesture(@EnabledFeature int enabledFeature) { public void testExternalNavigationWithUserGesture(@EnabledFeature int enabledFeature) {
final ExternalNavigationHandler externalNavHandler = final ExternalNavigationHandler externalNavHandler =
new ExternalNavigationHandler(new ExternalNavigationDelegateImpl( new ExternalNavigationHandler(new ExternalNavigationDelegateImpl(
mActivityTestRule.getActivity().getActivityTab())); sActivityTestRule.getActivity().getActivityTab()));
final NavigationParams navigationParams = new NavigationParams( final NavigationParams navigationParams = new NavigationParams(
"intent://test/#Intent;scheme=test;package=com.chrome.test;end", "", "intent://test/#Intent;scheme=test;package=com.chrome.test;end", "",
false /* isPost */, true /* hasUserGesture */, PageTransition.LINK, false /* isPost */, true /* hasUserGesture */, PageTransition.LINK,
...@@ -2510,7 +2482,7 @@ public class ContextualSearchManagerTest { ...@@ -2510,7 +2482,7 @@ public class ContextualSearchManagerTest {
InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() { InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
@Override @Override
public void run() { public void run() {
mActivityTestRule.getActivity().onUserInteraction(); sActivityTestRule.getActivity().onUserInteraction();
Assert.assertFalse(mManager.getOverlayContentDelegate().shouldInterceptNavigation( Assert.assertFalse(mManager.getOverlayContentDelegate().shouldInterceptNavigation(
externalNavHandler, navigationParams)); externalNavHandler, navigationParams));
} }
...@@ -2530,7 +2502,7 @@ public class ContextualSearchManagerTest { ...@@ -2530,7 +2502,7 @@ public class ContextualSearchManagerTest {
@EnabledFeature int enabledFeature) { @EnabledFeature int enabledFeature) {
final ExternalNavigationHandler externalNavHandler = final ExternalNavigationHandler externalNavHandler =
new ExternalNavigationHandler(new ExternalNavigationDelegateImpl( new ExternalNavigationHandler(new ExternalNavigationDelegateImpl(
mActivityTestRule.getActivity().getActivityTab())); sActivityTestRule.getActivity().getActivityTab()));
final NavigationParams initialNavigationParams = new NavigationParams("http://test.com", "", final NavigationParams initialNavigationParams = new NavigationParams("http://test.com", "",
false /* isPost */, true /* hasUserGesture */, PageTransition.LINK, false /* isPost */, true /* hasUserGesture */, PageTransition.LINK,
...@@ -2547,7 +2519,7 @@ public class ContextualSearchManagerTest { ...@@ -2547,7 +2519,7 @@ public class ContextualSearchManagerTest {
InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() { InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
@Override @Override
public void run() { public void run() {
mActivityTestRule.getActivity().onUserInteraction(); sActivityTestRule.getActivity().onUserInteraction();
OverlayContentDelegate delegate = mManager.getOverlayContentDelegate(); OverlayContentDelegate delegate = mManager.getOverlayContentDelegate();
Assert.assertTrue(delegate.shouldInterceptNavigation( Assert.assertTrue(delegate.shouldInterceptNavigation(
externalNavHandler, initialNavigationParams)); externalNavHandler, initialNavigationParams));
...@@ -2569,7 +2541,7 @@ public class ContextualSearchManagerTest { ...@@ -2569,7 +2541,7 @@ public class ContextualSearchManagerTest {
public void testExternalNavigationWithoutUserGesture(@EnabledFeature int enabledFeature) { public void testExternalNavigationWithoutUserGesture(@EnabledFeature int enabledFeature) {
final ExternalNavigationHandler externalNavHandler = final ExternalNavigationHandler externalNavHandler =
new ExternalNavigationHandler(new ExternalNavigationDelegateImpl( new ExternalNavigationHandler(new ExternalNavigationDelegateImpl(
mActivityTestRule.getActivity().getActivityTab())); sActivityTestRule.getActivity().getActivityTab()));
final NavigationParams navigationParams = new NavigationParams( final NavigationParams navigationParams = new NavigationParams(
"intent://test/#Intent;scheme=test;package=com.chrome.test;end", "", "intent://test/#Intent;scheme=test;package=com.chrome.test;end", "",
false /* isPost */, false /* hasUserGesture */, PageTransition.LINK, false /* isPost */, false /* hasUserGesture */, PageTransition.LINK,
...@@ -2579,7 +2551,7 @@ public class ContextualSearchManagerTest { ...@@ -2579,7 +2551,7 @@ public class ContextualSearchManagerTest {
InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() { InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
@Override @Override
public void run() { public void run() {
mActivityTestRule.getActivity().onUserInteraction(); sActivityTestRule.getActivity().onUserInteraction();
Assert.assertFalse(mManager.getOverlayContentDelegate().shouldInterceptNavigation( Assert.assertFalse(mManager.getOverlayContentDelegate().shouldInterceptNavigation(
externalNavHandler, navigationParams)); externalNavHandler, navigationParams));
} }
...@@ -3059,8 +3031,8 @@ public class ContextualSearchManagerTest { ...@@ -3059,8 +3031,8 @@ public class ContextualSearchManagerTest {
throws Exception { throws Exception {
// Toggle tab to fulllscreen. // Toggle tab to fulllscreen.
FullscreenTestUtils.togglePersistentFullscreenAndAssert( FullscreenTestUtils.togglePersistentFullscreenAndAssert(
mActivityTestRule.getActivity().getActivityTab(), true, sActivityTestRule.getActivity().getActivityTab(), true,
mActivityTestRule.getActivity()); sActivityTestRule.getActivity());
// Simulate a resolving search and assert that the panel peeks. // Simulate a resolving search and assert that the panel peeks.
simulateResolveSearch("search"); simulateResolveSearch("search");
...@@ -3089,9 +3061,9 @@ public class ContextualSearchManagerTest { ...@@ -3089,9 +3061,9 @@ public class ContextualSearchManagerTest {
simulateResolveSearch("search"); simulateResolveSearch("search");
// Toggle tab to fullscreen. // Toggle tab to fullscreen.
Tab tab = mActivityTestRule.getActivity().getActivityTab(); Tab tab = sActivityTestRule.getActivity().getActivityTab();
FullscreenTestUtils.togglePersistentFullscreenAndAssert( FullscreenTestUtils.togglePersistentFullscreenAndAssert(
tab, true, mActivityTestRule.getActivity()); tab, true, sActivityTestRule.getActivity());
// Assert that the panel is closed. // Assert that the panel is closed.
waitForPanelToClose(); waitForPanelToClose();
...@@ -3101,7 +3073,7 @@ public class ContextualSearchManagerTest { ...@@ -3101,7 +3073,7 @@ public class ContextualSearchManagerTest {
// Toggle tab to non-fullscreen. // Toggle tab to non-fullscreen.
FullscreenTestUtils.togglePersistentFullscreenAndAssert( FullscreenTestUtils.togglePersistentFullscreenAndAssert(
tab, false, mActivityTestRule.getActivity()); tab, false, sActivityTestRule.getActivity());
// Assert that the panel is closed. // Assert that the panel is closed.
waitForPanelToClose(); waitForPanelToClose();
...@@ -3193,7 +3165,7 @@ public class ContextualSearchManagerTest { ...@@ -3193,7 +3165,7 @@ public class ContextualSearchManagerTest {
// Check that the peeking bar is showing the quick action data. // Check that the peeking bar is showing the quick action data.
Assert.assertTrue(quickActionControl.hasQuickAction()); Assert.assertTrue(quickActionControl.hasQuickAction());
Assert.assertTrue(barControl.getCaptionVisible()); Assert.assertTrue(barControl.getCaptionVisible());
Assert.assertEquals(mActivityTestRule.getActivity().getResources().getString( Assert.assertEquals(sActivityTestRule.getActivity().getResources().getString(
R.string.contextual_search_quick_action_caption_phone), R.string.contextual_search_quick_action_caption_phone),
barControl.getCaptionText()); barControl.getCaptionText());
Assert.assertEquals(1.f, imageControl.getCustomImageVisibilityPercentage(), 0); Assert.assertEquals(1.f, imageControl.getCustomImageVisibilityPercentage(), 0);
...@@ -3211,7 +3183,7 @@ public class ContextualSearchManagerTest { ...@@ -3211,7 +3183,7 @@ public class ContextualSearchManagerTest {
// Assert that the quick action data is showing. // Assert that the quick action data is showing.
Assert.assertTrue(barControl.getCaptionVisible()); Assert.assertTrue(barControl.getCaptionVisible());
Assert.assertEquals(mActivityTestRule.getActivity().getResources().getString( Assert.assertEquals(sActivityTestRule.getActivity().getResources().getString(
R.string.contextual_search_quick_action_caption_phone), R.string.contextual_search_quick_action_caption_phone),
barControl.getCaptionText()); barControl.getCaptionText());
// TODO(donnd): figure out why we get ~0.65 on Oreo rather than 1. https://crbug.com/818515. // TODO(donnd): figure out why we get ~0.65 on Oreo rather than 1. https://crbug.com/818515.
...@@ -3250,7 +3222,7 @@ public class ContextualSearchManagerTest { ...@@ -3250,7 +3222,7 @@ public class ContextualSearchManagerTest {
-> mPanel.onSearchTermResolved("search", null, "tel:555-555-5555", -> mPanel.onSearchTermResolved("search", null, "tel:555-555-5555",
QuickActionCategory.PHONE, CardTag.CT_CONTACT)); QuickActionCategory.PHONE, CardTag.CT_CONTACT));
mActivityTestRule.getActivity().onUserInteraction(); sActivityTestRule.getActivity().onUserInteraction();
retryPanelBarInteractions(() -> { retryPanelBarInteractions(() -> {
// Tap on the portion of the bar that should trigger the quick action intent to be // Tap on the portion of the bar that should trigger the quick action intent to be
// fired. // fired.
...@@ -3286,7 +3258,7 @@ public class ContextualSearchManagerTest { ...@@ -3286,7 +3258,7 @@ public class ContextualSearchManagerTest {
// Assert that the URL was loaded. // Assert that the URL was loaded.
ChromeTabUtils.waitForTabPageLoaded( ChromeTabUtils.waitForTabPageLoaded(
mActivityTestRule.getActivity().getActivityTab(), testUrl); sActivityTestRule.getActivity().getActivityTab(), testUrl);
}, false); }, false);
} }
...@@ -3458,11 +3430,11 @@ public class ContextualSearchManagerTest { ...@@ -3458,11 +3430,11 @@ public class ContextualSearchManagerTest {
public void testTriggeringContextualSearchHidesFindInPageOverlay( public void testTriggeringContextualSearchHidesFindInPageOverlay(
@EnabledFeature int enabledFeature) throws Exception { @EnabledFeature int enabledFeature) throws Exception {
MenuUtils.invokeCustomMenuActionSync(InstrumentationRegistry.getInstrumentation(), MenuUtils.invokeCustomMenuActionSync(InstrumentationRegistry.getInstrumentation(),
mActivityTestRule.getActivity(), R.id.find_in_page_id); sActivityTestRule.getActivity(), R.id.find_in_page_id);
CriteriaHelper.pollUiThread(() -> { CriteriaHelper.pollUiThread(() -> {
FindToolbar findToolbar = FindToolbar findToolbar =
(FindToolbar) mActivityTestRule.getActivity().findViewById(R.id.find_toolbar); (FindToolbar) sActivityTestRule.getActivity().findViewById(R.id.find_toolbar);
Criteria.checkThat(findToolbar, Matchers.notNullValue()); Criteria.checkThat(findToolbar, Matchers.notNullValue());
Criteria.checkThat(findToolbar.isShown(), Matchers.is(true)); Criteria.checkThat(findToolbar.isShown(), Matchers.is(true));
Criteria.checkThat(findToolbar.isAnimating(), Matchers.is(false)); Criteria.checkThat(findToolbar.isAnimating(), Matchers.is(false));
...@@ -3471,7 +3443,7 @@ public class ContextualSearchManagerTest { ...@@ -3471,7 +3443,7 @@ public class ContextualSearchManagerTest {
// Don't type anything to Find because that may cause scrolling which makes clicking in the // Don't type anything to Find because that may cause scrolling which makes clicking in the
// page flaky. // page flaky.
View findToolbar = mActivityTestRule.getActivity().findViewById(R.id.find_toolbar); View findToolbar = sActivityTestRule.getActivity().findViewById(R.id.find_toolbar);
Assert.assertTrue(findToolbar.isShown()); Assert.assertTrue(findToolbar.isShown());
simulateResolveSearch("search"); simulateResolveSearch("search");
...@@ -3554,7 +3526,7 @@ public class ContextualSearchManagerTest { ...@@ -3554,7 +3526,7 @@ public class ContextualSearchManagerTest {
@ParameterAnnotations.UseMethodParameter(FeatureParamProvider.class) @ParameterAnnotations.UseMethodParameter(FeatureParamProvider.class)
public void testTabReparenting(@EnabledFeature int enabledFeature) throws Exception { public void testTabReparenting(@EnabledFeature int enabledFeature) throws Exception {
// Move our "tap_test" tab to another activity. // Move our "tap_test" tab to another activity.
final ChromeActivity ca = mActivityTestRule.getActivity(); final ChromeActivity ca = sActivityTestRule.getActivity();
// Create a new tab so |ca| isn't destroyed. // Create a new tab so |ca| isn't destroyed.
ChromeTabUtils.newTabFromMenu(InstrumentationRegistry.getInstrumentation(), ca); ChromeTabUtils.newTabFromMenu(InstrumentationRegistry.getInstrumentation(), ca);
......
...@@ -13,16 +13,18 @@ import android.view.View; ...@@ -13,16 +13,18 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ListView; import android.widget.ListView;
import androidx.test.filters.LargeTest; import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.JniMocker; import org.chromium.base.test.util.JniMocker;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -30,6 +32,7 @@ import org.chromium.chrome.browser.ChromeActivity; ...@@ -30,6 +32,7 @@ import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.batch.BlankCTATabInitialStateRule;
import org.chromium.components.location.LocationUtils; import org.chromium.components.location.LocationUtils;
import org.chromium.components.security_state.ConnectionSecurityLevel; import org.chromium.components.security_state.ConnectionSecurityLevel;
import org.chromium.content_public.browser.test.util.Criteria; import org.chromium.content_public.browser.test.util.Criteria;
...@@ -48,11 +51,18 @@ import java.util.concurrent.Callable; ...@@ -48,11 +51,18 @@ import java.util.concurrent.Callable;
*/ */
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Batch(BluetoothChooserDialogTest.DEVICE_DIALOG_BATCH_NAME)
public class BluetoothChooserDialogTest { public class BluetoothChooserDialogTest {
@Rule public static final String DEVICE_DIALOG_BATCH_NAME = "device_dialog";
public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
@ClassRule
public static final ChromeActivityTestRule<ChromeActivity> sActivityTestRule =
new ChromeActivityTestRule<>(ChromeActivity.class); new ChromeActivityTestRule<>(ChromeActivity.class);
@Rule
public final BlankCTATabInitialStateRule mInitialStateRule =
new BlankCTATabInitialStateRule(sActivityTestRule, false);
@Rule @Rule
public JniMocker mocker = new JniMocker(); public JniMocker mocker = new JniMocker();
...@@ -110,7 +120,6 @@ public class BluetoothChooserDialogTest { ...@@ -110,7 +120,6 @@ public class BluetoothChooserDialogTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mActivityTestRule.startMainActivityOnBlankPage();
mLocationUtils = new FakeLocationUtils(); mLocationUtils = new FakeLocationUtils();
LocationUtils.setFactory(() -> mLocationUtils); LocationUtils.setFactory(() -> mLocationUtils);
mChooserDialog = createDialog(); mChooserDialog = createDialog();
...@@ -126,7 +135,7 @@ public class BluetoothChooserDialogTest { ...@@ -126,7 +135,7 @@ public class BluetoothChooserDialogTest {
private BluetoothChooserDialog createDialog() { private BluetoothChooserDialog createDialog() {
return TestThreadUtils.runOnUiThreadBlockingNoException( return TestThreadUtils.runOnUiThreadBlockingNoException(
() -> { () -> {
mWindowAndroid = mActivityTestRule.getActivity().getWindowAndroid(); mWindowAndroid = sActivityTestRule.getActivity().getWindowAndroid();
BluetoothChooserDialog dialog = new BluetoothChooserDialog(mWindowAndroid, BluetoothChooserDialog dialog = new BluetoothChooserDialog(mWindowAndroid,
"https://origin.example.com/", ConnectionSecurityLevel.SECURE, "https://origin.example.com/", ConnectionSecurityLevel.SECURE,
/*nativeBluetoothChooserDialogPtr=*/42); /*nativeBluetoothChooserDialogPtr=*/42);
...@@ -178,7 +187,7 @@ public class BluetoothChooserDialogTest { ...@@ -178,7 +187,7 @@ public class BluetoothChooserDialogTest {
} }
@Test @Test
@LargeTest @SmallTest
public void testCancel() { public void testCancel() {
ItemChooserDialog itemChooser = mChooserDialog.mItemChooserDialog; ItemChooserDialog itemChooser = mChooserDialog.mItemChooserDialog;
Dialog dialog = itemChooser.getDialogForTesting(); Dialog dialog = itemChooser.getDialogForTesting();
...@@ -191,7 +200,7 @@ public class BluetoothChooserDialogTest { ...@@ -191,7 +200,7 @@ public class BluetoothChooserDialogTest {
// Before we add items to the dialog, the 'searching' message should be // Before we add items to the dialog, the 'searching' message should be
// showing, the Commit button should be disabled and the list view hidden. // showing, the Commit button should be disabled and the list view hidden.
Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString( Assert.assertEquals(removeLinkTags(sActivityTestRule.getActivity().getString(
R.string.bluetooth_searching)), R.string.bluetooth_searching)),
statusView.getText().toString()); statusView.getText().toString());
Assert.assertFalse(button.isEnabled()); Assert.assertFalse(button.isEnabled());
...@@ -206,7 +215,7 @@ public class BluetoothChooserDialogTest { ...@@ -206,7 +215,7 @@ public class BluetoothChooserDialogTest {
} }
@Test @Test
@LargeTest @SmallTest
public void testSelectItem() { public void testSelectItem() {
Dialog dialog = mChooserDialog.mItemChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.mItemChooserDialog.getDialogForTesting();
...@@ -235,7 +244,7 @@ public class BluetoothChooserDialogTest { ...@@ -235,7 +244,7 @@ public class BluetoothChooserDialogTest {
// the progress spinner should disappear, the Commit button should still // the progress spinner should disappear, the Commit button should still
// be disabled (since nothing's selected), and the list view should // be disabled (since nothing's selected), and the list view should
// show. // show.
Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString( Assert.assertEquals(removeLinkTags(sActivityTestRule.getActivity().getString(
R.string.bluetooth_searching)), R.string.bluetooth_searching)),
statusView.getText().toString()); statusView.getText().toString());
Assert.assertFalse(button.isEnabled()); Assert.assertFalse(button.isEnabled());
...@@ -250,7 +259,7 @@ public class BluetoothChooserDialogTest { ...@@ -250,7 +259,7 @@ public class BluetoothChooserDialogTest {
mChooserDialog.mConnectedIcon, mChooserDialog.mConnectedIconDescription)); mChooserDialog.mConnectedIcon, mChooserDialog.mConnectedIconDescription));
Assert.assertTrue(itemAdapter.getItem(2).hasSameContents("id-3", "Name 3", Assert.assertTrue(itemAdapter.getItem(2).hasSameContents("id-3", "Name 3",
mChooserDialog.mSignalStrengthLevelIcon[1], mChooserDialog.mSignalStrengthLevelIcon[1],
mActivityTestRule.getActivity().getResources().getQuantityString( sActivityTestRule.getActivity().getResources().getQuantityString(
R.plurals.signal_strength_level_n_bars, 1, 1))); R.plurals.signal_strength_level_n_bars, 1, 1)));
// We show the connected icon even if the device has a signal strength. // We show the connected icon even if the device has a signal strength.
Assert.assertTrue(itemAdapter.getItem(3).hasSameContents("id-4", "Name 4", Assert.assertTrue(itemAdapter.getItem(3).hasSameContents("id-4", "Name 4",
...@@ -263,7 +272,7 @@ public class BluetoothChooserDialogTest { ...@@ -263,7 +272,7 @@ public class BluetoothChooserDialogTest {
} }
@Test @Test
@LargeTest @SmallTest
public void testNoLocationPermission() { public void testNoLocationPermission() {
ItemChooserDialog itemChooser = mChooserDialog.mItemChooserDialog; ItemChooserDialog itemChooser = mChooserDialog.mItemChooserDialog;
Dialog dialog = itemChooser.getDialogForTesting(); Dialog dialog = itemChooser.getDialogForTesting();
...@@ -285,10 +294,10 @@ public class BluetoothChooserDialogTest { ...@@ -285,10 +294,10 @@ public class BluetoothChooserDialogTest {
() -> mChooserDialog.notifyDiscoveryState( () -> mChooserDialog.notifyDiscoveryState(
BluetoothChooserDialog.DiscoveryMode.DISCOVERY_FAILED_TO_START)); BluetoothChooserDialog.DiscoveryMode.DISCOVERY_FAILED_TO_START));
Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString( Assert.assertEquals(removeLinkTags(sActivityTestRule.getActivity().getString(
R.string.bluetooth_need_location_permission)), R.string.bluetooth_need_location_permission)),
errorView.getText().toString()); errorView.getText().toString());
Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString( Assert.assertEquals(removeLinkTags(sActivityTestRule.getActivity().getString(
R.string.bluetooth_adapter_off_help)), R.string.bluetooth_adapter_off_help)),
statusView.getText().toString()); statusView.getText().toString());
Assert.assertFalse(button.isEnabled()); Assert.assertFalse(button.isEnabled());
...@@ -312,14 +321,14 @@ public class BluetoothChooserDialogTest { ...@@ -312,14 +321,14 @@ public class BluetoothChooserDialogTest {
new int[] {PackageManager.PERMISSION_GRANTED})); new int[] {PackageManager.PERMISSION_GRANTED}));
Assert.assertEquals(1, mRestartSearchCount); Assert.assertEquals(1, mRestartSearchCount);
Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString( Assert.assertEquals(removeLinkTags(sActivityTestRule.getActivity().getString(
R.string.bluetooth_searching)), R.string.bluetooth_searching)),
statusView.getText().toString()); statusView.getText().toString());
mChooserDialog.closeDialog(); mChooserDialog.closeDialog();
} }
@Test @Test
@LargeTest @SmallTest
public void testNoLocationServices() { public void testNoLocationServices() {
ItemChooserDialog itemChooser = mChooserDialog.mItemChooserDialog; ItemChooserDialog itemChooser = mChooserDialog.mItemChooserDialog;
Dialog dialog = itemChooser.getDialogForTesting(); Dialog dialog = itemChooser.getDialogForTesting();
...@@ -345,10 +354,10 @@ public class BluetoothChooserDialogTest { ...@@ -345,10 +354,10 @@ public class BluetoothChooserDialogTest {
() -> mChooserDialog.notifyDiscoveryState( () -> mChooserDialog.notifyDiscoveryState(
BluetoothChooserDialog.DiscoveryMode.DISCOVERY_FAILED_TO_START)); BluetoothChooserDialog.DiscoveryMode.DISCOVERY_FAILED_TO_START));
Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString( Assert.assertEquals(removeLinkTags(sActivityTestRule.getActivity().getString(
R.string.bluetooth_need_location_services_on)), R.string.bluetooth_need_location_services_on)),
errorView.getText().toString()); errorView.getText().toString());
Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString( Assert.assertEquals(removeLinkTags(sActivityTestRule.getActivity().getString(
R.string.bluetooth_need_location_permission_help)), R.string.bluetooth_need_location_permission_help)),
statusView.getText().toString()); statusView.getText().toString());
Assert.assertFalse(button.isEnabled()); Assert.assertFalse(button.isEnabled());
...@@ -359,12 +368,13 @@ public class BluetoothChooserDialogTest { ...@@ -359,12 +368,13 @@ public class BluetoothChooserDialogTest {
// Turn on Location Services. // Turn on Location Services.
mLocationUtils.mSystemLocationSettingsEnabled = true; mLocationUtils.mSystemLocationSettingsEnabled = true;
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(
() -> mChooserDialog.mLocationModeBroadcastReceiver.onReceive( ()
mActivityTestRule.getActivity(), -> mChooserDialog.mLocationModeBroadcastReceiver.onReceive(
sActivityTestRule.getActivity(),
new Intent(LocationManager.MODE_CHANGED_ACTION))); new Intent(LocationManager.MODE_CHANGED_ACTION)));
Assert.assertEquals(1, mRestartSearchCount); Assert.assertEquals(1, mRestartSearchCount);
Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString( Assert.assertEquals(removeLinkTags(sActivityTestRule.getActivity().getString(
R.string.bluetooth_searching)), R.string.bluetooth_searching)),
statusView.getText().toString()); statusView.getText().toString());
...@@ -374,7 +384,7 @@ public class BluetoothChooserDialogTest { ...@@ -374,7 +384,7 @@ public class BluetoothChooserDialogTest {
// TODO(jyasskin): Test when the user denies Chrome the ability to ask for permission. // TODO(jyasskin): Test when the user denies Chrome the ability to ask for permission.
@Test @Test
@LargeTest @SmallTest
public void testTurnOnAdapter() { public void testTurnOnAdapter() {
final ItemChooserDialog itemChooser = mChooserDialog.mItemChooserDialog; final ItemChooserDialog itemChooser = mChooserDialog.mItemChooserDialog;
Dialog dialog = itemChooser.getDialogForTesting(); Dialog dialog = itemChooser.getDialogForTesting();
...@@ -391,10 +401,10 @@ public class BluetoothChooserDialogTest { ...@@ -391,10 +401,10 @@ public class BluetoothChooserDialogTest {
// Turn off adapter. // Turn off adapter.
TestThreadUtils.runOnUiThreadBlocking(() -> mChooserDialog.notifyAdapterTurnedOff()); TestThreadUtils.runOnUiThreadBlocking(() -> mChooserDialog.notifyAdapterTurnedOff());
Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString( Assert.assertEquals(removeLinkTags(sActivityTestRule.getActivity().getString(
R.string.bluetooth_adapter_off)), R.string.bluetooth_adapter_off)),
errorView.getText().toString()); errorView.getText().toString());
Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString( Assert.assertEquals(removeLinkTags(sActivityTestRule.getActivity().getString(
R.string.bluetooth_adapter_off_help)), R.string.bluetooth_adapter_off_help)),
statusView.getText().toString()); statusView.getText().toString());
Assert.assertFalse(button.isEnabled()); Assert.assertFalse(button.isEnabled());
......
...@@ -9,15 +9,17 @@ import android.view.View; ...@@ -9,15 +9,17 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ListView; import android.widget.ListView;
import androidx.test.filters.LargeTest; import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.JniMocker; import org.chromium.base.test.util.JniMocker;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -25,6 +27,7 @@ import org.chromium.chrome.browser.ChromeActivity; ...@@ -25,6 +27,7 @@ import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.batch.BlankCTATabInitialStateRule;
import org.chromium.components.security_state.ConnectionSecurityLevel; import org.chromium.components.security_state.ConnectionSecurityLevel;
import org.chromium.content_public.browser.bluetooth_scanning.Event; import org.chromium.content_public.browser.bluetooth_scanning.Event;
import org.chromium.content_public.browser.test.util.Criteria; import org.chromium.content_public.browser.test.util.Criteria;
...@@ -37,11 +40,16 @@ import org.chromium.ui.base.ActivityWindowAndroid; ...@@ -37,11 +40,16 @@ import org.chromium.ui.base.ActivityWindowAndroid;
*/ */
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Batch(BluetoothChooserDialogTest.DEVICE_DIALOG_BATCH_NAME)
public class BluetoothScanningPermissionDialogTest { public class BluetoothScanningPermissionDialogTest {
@Rule @ClassRule
public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = public static final ChromeActivityTestRule<ChromeActivity> sActivityTestRule =
new ChromeActivityTestRule<>(ChromeActivity.class); new ChromeActivityTestRule<>(ChromeActivity.class);
@Rule
public final BlankCTATabInitialStateRule mInitialStateRule =
new BlankCTATabInitialStateRule(sActivityTestRule, false);
@Rule @Rule
public JniMocker mocker = new JniMocker(); public JniMocker mocker = new JniMocker();
...@@ -62,13 +70,12 @@ public class BluetoothScanningPermissionDialogTest { ...@@ -62,13 +70,12 @@ public class BluetoothScanningPermissionDialogTest {
public void setUp() throws Exception { public void setUp() throws Exception {
mocker.mock(BluetoothScanningPermissionDialogJni.TEST_HOOKS, mocker.mock(BluetoothScanningPermissionDialogJni.TEST_HOOKS,
new TestBluetoothScanningPermissionDialogJni()); new TestBluetoothScanningPermissionDialogJni());
mActivityTestRule.startMainActivityOnBlankPage();
mPermissionDialog = createDialog(); mPermissionDialog = createDialog();
} }
private BluetoothScanningPermissionDialog createDialog() { private BluetoothScanningPermissionDialog createDialog() {
return TestThreadUtils.runOnUiThreadBlockingNoException(() -> { return TestThreadUtils.runOnUiThreadBlockingNoException(() -> {
mWindowAndroid = mActivityTestRule.getActivity().getWindowAndroid(); mWindowAndroid = sActivityTestRule.getActivity().getWindowAndroid();
BluetoothScanningPermissionDialog dialog = new BluetoothScanningPermissionDialog( BluetoothScanningPermissionDialog dialog = new BluetoothScanningPermissionDialog(
mWindowAndroid, "https://origin.example.com/", ConnectionSecurityLevel.SECURE, mWindowAndroid, "https://origin.example.com/", ConnectionSecurityLevel.SECURE,
/*nativeBluetoothScanningPermissionDialogPtr=*/42); /*nativeBluetoothScanningPermissionDialogPtr=*/42);
...@@ -77,7 +84,7 @@ public class BluetoothScanningPermissionDialogTest { ...@@ -77,7 +84,7 @@ public class BluetoothScanningPermissionDialogTest {
} }
@Test @Test
@LargeTest @SmallTest
public void testAddDevice() { public void testAddDevice() {
Dialog dialog = mPermissionDialog.getDialogForTesting(); Dialog dialog = mPermissionDialog.getDialogForTesting();
...@@ -117,7 +124,7 @@ public class BluetoothScanningPermissionDialogTest { ...@@ -117,7 +124,7 @@ public class BluetoothScanningPermissionDialogTest {
} }
@Test @Test
@LargeTest @SmallTest
public void testCancelPermissionDialogWithoutClickingAnyButton() { public void testCancelPermissionDialogWithoutClickingAnyButton() {
Dialog dialog = mPermissionDialog.getDialogForTesting(); Dialog dialog = mPermissionDialog.getDialogForTesting();
......
...@@ -14,16 +14,19 @@ import android.widget.ListView; ...@@ -14,16 +14,19 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import androidx.core.util.ObjectsCompat; import androidx.core.util.ObjectsCompat;
import androidx.test.filters.LargeTest; import androidx.test.filters.SmallTest;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat; import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest; import org.chromium.base.test.util.DisabledTest;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -31,6 +34,7 @@ import org.chromium.chrome.browser.ChromeActivity; ...@@ -31,6 +34,7 @@ import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.batch.BlankCTATabInitialStateRule;
import org.chromium.content_public.browser.test.util.Criteria; 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;
...@@ -42,11 +46,16 @@ import org.chromium.ui.widget.TextViewWithClickableSpans; ...@@ -42,11 +46,16 @@ import org.chromium.ui.widget.TextViewWithClickableSpans;
*/ */
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Batch(BluetoothChooserDialogTest.DEVICE_DIALOG_BATCH_NAME)
public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCallback { public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCallback {
@Rule @ClassRule
public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = public static final ChromeActivityTestRule<ChromeActivity> sActivityTestRule =
new ChromeActivityTestRule<>(ChromeActivity.class); new ChromeActivityTestRule<>(ChromeActivity.class);
@Rule
public final BlankCTATabInitialStateRule mInitialStateRule =
new BlankCTATabInitialStateRule(sActivityTestRule, false);
ItemChooserDialog mChooserDialog; ItemChooserDialog mChooserDialog;
String mLastSelectedId = "None"; String mLastSelectedId = "None";
...@@ -59,7 +68,6 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -59,7 +68,6 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mActivityTestRule.startMainActivityOnBlankPage();
mChooserDialog = createDialog(); mChooserDialog = createDialog();
mTestDrawable1 = getNewTestDrawable(); mTestDrawable1 = getNewTestDrawable();
...@@ -71,6 +79,14 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -71,6 +79,14 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
Assert.assertFalse(ObjectsCompat.equals(mTestDrawable1, mTestDrawable2)); Assert.assertFalse(ObjectsCompat.equals(mTestDrawable1, mTestDrawable2));
} }
@After
public void tearDown() {
TestThreadUtils.runOnUiThreadBlocking(() -> {
mChooserDialog.setIdleState();
mChooserDialog.dismiss();
});
}
// ItemChooserDialog.ItemSelectedCallback: // ItemChooserDialog.ItemSelectedCallback:
@Override @Override
...@@ -80,7 +96,7 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -80,7 +96,7 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
private Drawable getNewTestDrawable() { private Drawable getNewTestDrawable() {
Drawable drawable = Drawable drawable =
VectorDrawableCompat.create(mActivityTestRule.getActivity().getResources(), VectorDrawableCompat.create(sActivityTestRule.getActivity().getResources(),
R.drawable.ic_bluetooth_connected, null); R.drawable.ic_bluetooth_connected, null);
// Calling mutate() on a Drawable should typically create a new ConstantState // Calling mutate() on a Drawable should typically create a new ConstantState
// for that Drawable. Ensure the new drawable doesn't share a state with other // for that Drawable. Ensure the new drawable doesn't share a state with other
...@@ -101,7 +117,7 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -101,7 +117,7 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
statusIdleNoneFound, statusIdleSomeFound, positiveButton); statusIdleNoneFound, statusIdleSomeFound, positiveButton);
ItemChooserDialog dialog = TestThreadUtils.runOnUiThreadBlockingNoException(() -> { ItemChooserDialog dialog = TestThreadUtils.runOnUiThreadBlockingNoException(() -> {
ItemChooserDialog dialog1 = new ItemChooserDialog( ItemChooserDialog dialog1 = new ItemChooserDialog(
mActivityTestRule.getActivity(), ItemChooserDialogTest.this, labels); sActivityTestRule.getActivity(), ItemChooserDialogTest.this, labels);
return dialog1; return dialog1;
}); });
return dialog; return dialog;
...@@ -152,7 +168,7 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -152,7 +168,7 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
} }
@Test @Test
@LargeTest @SmallTest
public void testAddItemsWithNoIcons() { public void testAddItemsWithNoIcons() {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog = mChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.getDialogForTesting();
...@@ -173,14 +189,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -173,14 +189,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
Assert.assertEquals(View.GONE, icon2.getVisibility()); Assert.assertEquals(View.GONE, icon2.getVisibility());
Assert.assertEquals(null, icon2.getDrawable()); Assert.assertEquals(null, icon2.getDrawable());
} }
mChooserDialog.setIdleState();
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
public void testAddItemsWithIcons() { public void testAddItemsWithIcons() {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog = mChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.getDialogForTesting();
...@@ -209,14 +222,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -209,14 +222,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
Assert.assertEquals(mTestDrawable2, icon2.getDrawable()); Assert.assertEquals(mTestDrawable2, icon2.getDrawable());
Assert.assertEquals(mTestDrawableDescription2, icon2.getContentDescription()); Assert.assertEquals(mTestDrawableDescription2, icon2.getContentDescription());
} }
mChooserDialog.setIdleState();
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
public void testAddItemWithIconAfterItemWithNoIcon() { public void testAddItemWithIconAfterItemWithNoIcon() {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog = mChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.getDialogForTesting();
...@@ -240,14 +250,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -240,14 +250,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
Assert.assertEquals(View.VISIBLE, icon2.getVisibility()); Assert.assertEquals(View.VISIBLE, icon2.getVisibility());
Assert.assertEquals(mTestDrawable2, icon2.getDrawable()); Assert.assertEquals(mTestDrawable2, icon2.getDrawable());
} }
mChooserDialog.setIdleState();
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
public void testAddItemWithNoIconAfterItemWithIcon() { public void testAddItemWithNoIconAfterItemWithIcon() {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog = mChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.getDialogForTesting();
...@@ -271,14 +278,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -271,14 +278,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
Assert.assertEquals(mTestDrawable1, icon1.getDrawable()); Assert.assertEquals(mTestDrawable1, icon1.getDrawable());
Assert.assertEquals(View.INVISIBLE, icon2.getVisibility()); Assert.assertEquals(View.INVISIBLE, icon2.getVisibility());
} }
mChooserDialog.setIdleState();
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
public void testRemoveItemWithIconNoItemsWithIconsLeft() { public void testRemoveItemWithIconNoItemsWithIconsLeft() {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog = mChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.getDialogForTesting();
...@@ -308,14 +312,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -308,14 +312,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
ImageView icon2 = getIconImageView(dialog, 1); ImageView icon2 = getIconImageView(dialog, 1);
Assert.assertEquals(View.GONE, icon2.getVisibility()); Assert.assertEquals(View.GONE, icon2.getVisibility());
} }
mChooserDialog.setIdleState();
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
public void testRemoveItemWithIconOneItemWithIconLeft() { public void testRemoveItemWithIconOneItemWithIconLeft() {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog = mChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.getDialogForTesting();
...@@ -358,14 +359,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -358,14 +359,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
Assert.assertEquals(mTestDrawable2, icon2.getDrawable()); Assert.assertEquals(mTestDrawable2, icon2.getDrawable());
Assert.assertEquals(View.INVISIBLE, icon3.getVisibility()); Assert.assertEquals(View.INVISIBLE, icon3.getVisibility());
} }
mChooserDialog.setIdleState();
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
public void testUpdateItemWithIconToNoIcon() { public void testUpdateItemWithIconToNoIcon() {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog = mChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.getDialogForTesting();
...@@ -392,14 +390,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -392,14 +390,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
Assert.assertTrue(itemAdapter.getItem(0).hasSameContents( Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
"key1", "desc1", null /* icon */, null /* iconDescription */)); "key1", "desc1", null /* icon */, null /* iconDescription */));
} }
mChooserDialog.setIdleState();
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
public void testUpdateItemWithNoIconToIcon() { public void testUpdateItemWithNoIconToIcon() {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog = mChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.getDialogForTesting();
...@@ -426,14 +421,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -426,14 +421,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
Assert.assertTrue(itemAdapter.getItem(0).hasSameContents( Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
"key1", "desc1", mTestDrawable1, mTestDrawableDescription1)); "key1", "desc1", mTestDrawable1, mTestDrawableDescription1));
} }
mChooserDialog.setIdleState();
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
public void testUpdateItemIcon() { public void testUpdateItemIcon() {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog = mChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.getDialogForTesting();
...@@ -463,14 +455,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -463,14 +455,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
Assert.assertTrue(itemAdapter.getItem(0).hasSameContents( Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
"key1", "desc1", mTestDrawable2, mTestDrawableDescription2)); "key1", "desc1", mTestDrawable2, mTestDrawableDescription2));
} }
mChooserDialog.setIdleState();
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
@DisabledTest(message = "crbug.com/958558") @DisabledTest(message = "crbug.com/958558")
public void testSimpleItemSelection() { public void testSimpleItemSelection() {
Dialog dialog = mChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.getDialogForTesting();
...@@ -512,12 +501,10 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -512,12 +501,10 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
// Select the first item and verify it got selected. // Select the first item and verify it got selected.
selectItem(dialog, 1, "key1", true); selectItem(dialog, 1, "key1", true);
Assert.assertTrue(getDescriptionTextView(dialog, 1).isSelected()); Assert.assertTrue(getDescriptionTextView(dialog, 1).isSelected());
mChooserDialog.dismiss();
} }
@Test @Test
@LargeTest @SmallTest
public void testNoItemsAddedDiscoveryIdle() { public void testNoItemsAddedDiscoveryIdle() {
Dialog dialog = mChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.getDialogForTesting();
Assert.assertTrue(dialog.isShowing()); Assert.assertTrue(dialog.isShowing());
...@@ -541,12 +528,10 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -541,12 +528,10 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
Assert.assertEquals(View.VISIBLE, items.getEmptyView().getVisibility()); Assert.assertEquals(View.VISIBLE, items.getEmptyView().getVisibility());
Assert.assertEquals("statusIdleNoneFound", statusView.getText().toString()); Assert.assertEquals("statusIdleNoneFound", statusView.getText().toString());
Assert.assertFalse(button.isEnabled()); Assert.assertFalse(button.isEnabled());
mChooserDialog.dismiss();
} }
@Test @Test
@LargeTest @SmallTest
public void testPairButtonDisabledAfterSelectedItemRemoved() throws Throwable { public void testPairButtonDisabledAfterSelectedItemRemoved() throws Throwable {
final Dialog dialog = TestThreadUtils.runOnUiThreadBlocking(() -> { final Dialog dialog = TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog1 = mChooserDialog.getDialogForTesting(); Dialog dialog1 = mChooserDialog.getDialogForTesting();
...@@ -566,13 +551,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -566,13 +551,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
mChooserDialog.removeItemFromList("key1"); mChooserDialog.removeItemFromList("key1");
Assert.assertFalse(button.isEnabled()); Assert.assertFalse(button.isEnabled());
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
public void testSelectAnItemAndRemoveAnotherItem() throws Throwable { public void testSelectAnItemAndRemoveAnotherItem() throws Throwable {
final Dialog dialog = TestThreadUtils.runOnUiThreadBlocking(() -> { final Dialog dialog = TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog1 = mChooserDialog.getDialogForTesting(); Dialog dialog1 = mChooserDialog.getDialogForTesting();
...@@ -599,13 +582,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -599,13 +582,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
mChooserDialog.removeItemFromList("key3"); mChooserDialog.removeItemFromList("key3");
Assert.assertTrue(button.isEnabled()); Assert.assertTrue(button.isEnabled());
Assert.assertEquals("key2", itemAdapter.getSelectedItemKey()); Assert.assertEquals("key2", itemAdapter.getSelectedItemKey());
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
public void testSelectAnItemAndRemoveTheSelectedItem() throws Throwable { public void testSelectAnItemAndRemoveTheSelectedItem() throws Throwable {
final Dialog dialog = TestThreadUtils.runOnUiThreadBlocking(() -> { final Dialog dialog = TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog1 = mChooserDialog.getDialogForTesting(); Dialog dialog1 = mChooserDialog.getDialogForTesting();
...@@ -627,13 +608,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -627,13 +608,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
mChooserDialog.removeItemFromList("key2"); mChooserDialog.removeItemFromList("key2");
Assert.assertFalse(button.isEnabled()); Assert.assertFalse(button.isEnabled());
Assert.assertEquals("", itemAdapter.getSelectedItemKey()); Assert.assertEquals("", itemAdapter.getSelectedItemKey());
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
public void testUpdateItemAndRemoveItemFromList() { public void testUpdateItemAndRemoveItemFromList() {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog = mChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.getDialogForTesting();
...@@ -679,13 +658,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -679,13 +658,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
Assert.assertEquals(View.VISIBLE, items.getEmptyView().getVisibility()); Assert.assertEquals(View.VISIBLE, items.getEmptyView().getVisibility());
Assert.assertEquals("statusIdleNoneFound", statusView.getText().toString()); Assert.assertEquals("statusIdleNoneFound", statusView.getText().toString());
Assert.assertFalse(button.isEnabled()); Assert.assertFalse(button.isEnabled());
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
public void testAddItemAndRemoveItemFromList() { public void testAddItemAndRemoveItemFromList() {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog = mChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.getDialogForTesting();
...@@ -751,13 +728,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -751,13 +728,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
Assert.assertEquals(View.VISIBLE, items.getEmptyView().getVisibility()); Assert.assertEquals(View.VISIBLE, items.getEmptyView().getVisibility());
Assert.assertEquals("statusIdleNoneFound", statusView.getText().toString()); Assert.assertEquals("statusIdleNoneFound", statusView.getText().toString());
Assert.assertFalse(button.isEnabled()); Assert.assertFalse(button.isEnabled());
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
public void testAddItemWithSameNameToListAndRemoveItemFromList() { public void testAddItemWithSameNameToListAndRemoveItemFromList() {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
Dialog dialog = mChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.getDialogForTesting();
...@@ -807,13 +782,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall ...@@ -807,13 +782,11 @@ public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCall
// After removing item 1, item 3 is the only remaining item, so its display text // After removing item 1, item 3 is the only remaining item, so its display text
// also changed to its original description. // also changed to its original description.
Assert.assertEquals("desc1", itemAdapter.getDisplayText(0)); Assert.assertEquals("desc1", itemAdapter.getDisplayText(0));
mChooserDialog.dismiss();
}); });
} }
@Test @Test
@LargeTest @SmallTest
public void testListHeight() { public void testListHeight() {
// 500 * .3 is 150, which is 48 * 3.125. 48 * 3.5 is 168. // 500 * .3 is 150, which is 48 * 3.125. 48 * 3.5 is 168.
Assert.assertEquals(168, ItemChooserDialog.getListHeight(500, 1.0f)); Assert.assertEquals(168, ItemChooserDialog.getListHeight(500, 1.0f));
......
...@@ -9,15 +9,17 @@ import android.view.View; ...@@ -9,15 +9,17 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ListView; import android.widget.ListView;
import androidx.test.filters.LargeTest; import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.JniMocker; import org.chromium.base.test.util.JniMocker;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -25,6 +27,7 @@ import org.chromium.chrome.browser.ChromeActivity; ...@@ -25,6 +27,7 @@ import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.batch.BlankCTATabInitialStateRule;
import org.chromium.components.security_state.ConnectionSecurityLevel; import org.chromium.components.security_state.ConnectionSecurityLevel;
import org.chromium.content_public.browser.test.util.Criteria; 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;
...@@ -37,11 +40,16 @@ import org.chromium.ui.widget.TextViewWithClickableSpans; ...@@ -37,11 +40,16 @@ import org.chromium.ui.widget.TextViewWithClickableSpans;
*/ */
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Batch(BluetoothChooserDialogTest.DEVICE_DIALOG_BATCH_NAME)
public class UsbChooserDialogTest { public class UsbChooserDialogTest {
@Rule @ClassRule
public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = public static final ChromeActivityTestRule<ChromeActivity> sActivityTestRule =
new ChromeActivityTestRule<>(ChromeActivity.class); new ChromeActivityTestRule<>(ChromeActivity.class);
@Rule
public final BlankCTATabInitialStateRule mInitialStateRule =
new BlankCTATabInitialStateRule(sActivityTestRule, false);
@Rule @Rule
public JniMocker mocker = new JniMocker(); public JniMocker mocker = new JniMocker();
...@@ -65,14 +73,13 @@ public class UsbChooserDialogTest { ...@@ -65,14 +73,13 @@ public class UsbChooserDialogTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mocker.mock(UsbChooserDialogJni.TEST_HOOKS, new TestUsbChooserDialogJni()); mocker.mock(UsbChooserDialogJni.TEST_HOOKS, new TestUsbChooserDialogJni());
mActivityTestRule.startMainActivityOnBlankPage();
mChooserDialog = createDialog(); mChooserDialog = createDialog();
} }
private UsbChooserDialog createDialog() { private UsbChooserDialog createDialog() {
return TestThreadUtils.runOnUiThreadBlockingNoException(() -> { return TestThreadUtils.runOnUiThreadBlockingNoException(() -> {
UsbChooserDialog dialog = new UsbChooserDialog(/*nativeUsbChooserDialogPtr=*/42); UsbChooserDialog dialog = new UsbChooserDialog(/*nativeUsbChooserDialogPtr=*/42);
dialog.show(mActivityTestRule.getActivity(), "https://origin.example.com/", dialog.show(sActivityTestRule.getActivity(), "https://origin.example.com/",
ConnectionSecurityLevel.SECURE); ConnectionSecurityLevel.SECURE);
return dialog; return dialog;
}); });
...@@ -110,7 +117,7 @@ public class UsbChooserDialogTest { ...@@ -110,7 +117,7 @@ public class UsbChooserDialogTest {
} }
@Test @Test
@LargeTest @SmallTest
public void testCancel() { public void testCancel() {
Dialog dialog = mChooserDialog.mItemChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.mItemChooserDialog.getDialogForTesting();
Assert.assertTrue(dialog.isShowing()); Assert.assertTrue(dialog.isShowing());
...@@ -129,7 +136,7 @@ public class UsbChooserDialogTest { ...@@ -129,7 +136,7 @@ public class UsbChooserDialogTest {
} }
@Test @Test
@LargeTest @SmallTest
public void testSelectItem() { public void testSelectItem() {
Dialog dialog = mChooserDialog.mItemChooserDialog.getDialogForTesting(); Dialog dialog = mChooserDialog.mItemChooserDialog.getDialogForTesting();
...@@ -151,7 +158,7 @@ public class UsbChooserDialogTest { ...@@ -151,7 +158,7 @@ public class UsbChooserDialogTest {
// After adding items to the dialog, the help message should be showing, // After adding items to the dialog, the help message should be showing,
// the 'Connect' button should still be disabled (since nothing's selected), // the 'Connect' button should still be disabled (since nothing's selected),
// and the list view should show. // and the list view should show.
Assert.assertEquals(removeLinkTags(mActivityTestRule.getActivity().getString( Assert.assertEquals(removeLinkTags(sActivityTestRule.getActivity().getString(
R.string.usb_chooser_dialog_footnote_text)), R.string.usb_chooser_dialog_footnote_text)),
statusView.getText().toString()); statusView.getText().toString());
Assert.assertFalse(button.isEnabled()); Assert.assertFalse(button.isEnabled());
......
...@@ -193,6 +193,7 @@ android_library("chrome_java_test_support") { ...@@ -193,6 +193,7 @@ android_library("chrome_java_test_support") {
"javatests/src/org/chromium/chrome/test/MultiActivityTestRule.java", "javatests/src/org/chromium/chrome/test/MultiActivityTestRule.java",
"javatests/src/org/chromium/chrome/test/ReducedModeNativeTestRule.java", "javatests/src/org/chromium/chrome/test/ReducedModeNativeTestRule.java",
"javatests/src/org/chromium/chrome/test/TestContentProvider.java", "javatests/src/org/chromium/chrome/test/TestContentProvider.java",
"javatests/src/org/chromium/chrome/test/batch/BlankCTATabInitialStateRule.java",
"javatests/src/org/chromium/chrome/test/gcore/MockChromeGoogleApiClient.java", "javatests/src/org/chromium/chrome/test/gcore/MockChromeGoogleApiClient.java",
"javatests/src/org/chromium/chrome/test/invalidation/IntentSavingContext.java", "javatests/src/org/chromium/chrome/test/invalidation/IntentSavingContext.java",
"javatests/src/org/chromium/chrome/test/omaha/AttributeFinder.java", "javatests/src/org/chromium/chrome/test/omaha/AttributeFinder.java",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.test.batch;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.chromium.base.test.util.Batch;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.firstrun.FirstRunStatus;
import org.chromium.chrome.browser.tab.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabModelUtils;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
/**
* To be used by batched tests that would like to reset to a single blank tab open in
* ChromeTabbedActivity between each test, without restarting the Activity.
*
* State is stored statically, and so the Activity may be reused across multiple test suites within
* the same {@link Batch}.
*/
public class BlankCTATabInitialStateRule implements TestRule {
private static ChromeActivity sActivity;
private final ChromeActivityTestRule<ChromeActivity> mActivityTestRule;
private final boolean mClearAllTabState;
/**
* @param activityTestRule The ActivityTestRule to be reset to initial state between each test.
* @param clearAllTabState More thoroughly clears all tab state, at the cost of restarting the
* renderer process between each test.
*/
public BlankCTATabInitialStateRule(
ChromeActivityTestRule<ChromeActivity> activityTestRule, boolean clearAllTabState) {
super();
mActivityTestRule = activityTestRule;
mClearAllTabState = clearAllTabState;
}
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
if (sActivity == null) {
TestThreadUtils.runOnUiThreadBlocking(
() -> { FirstRunStatus.setFirstRunFlowComplete(true); });
mActivityTestRule.startMainActivityOnBlankPage();
sActivity = mActivityTestRule.getActivity();
} else {
mActivityTestRule.setActivity(sActivity);
if (mClearAllTabState) {
resetTabStateThorough();
} else {
resetTabStateFast();
}
}
base.evaluate();
}
};
}
// Avoids closing the primary tab (and killing the renderer) in order to reset tab state
// quickly, at the cost of thoroughness. This should be adequate for most tests.
private void resetTabStateFast() {
TestThreadUtils.runOnUiThreadBlocking(() -> {
// Close all but the first tab as these tests expect to start with a single
// tab.
while (TabModelUtils.closeTabByIndex(sActivity.getCurrentTabModel(), 1)) {
}
});
mActivityTestRule.loadUrl("about:blank");
TestThreadUtils.runOnUiThreadBlocking(() -> {
sActivity.getCurrentWebContents().getNavigationController().clearHistory();
});
}
// Thoroughly resets tab state by closing all tabs before restoring the primary tab to
// about:blank state.
private void resetTabStateThorough() {
TestThreadUtils.runOnUiThreadBlocking(() -> {
sActivity.getTabModelSelector().closeAllTabs();
sActivity.getTabCreator(false).launchUrl("about:blank", TabLaunchType.FROM_CHROME_UI);
});
}
}
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