Android: ExecutionException -> RuntimeException for runOnUiThreadBlocking
This makes the Callable and Runnable overloads behave in the same way. Bug: 353256113 Change-Id: I63a8a84edee0016840add4d13d6136e010a8068d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5707371 Commit-Queue: Andrew Grieve <agrieve@chromium.org> Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Owners-Override: Andrew Grieve <agrieve@chromium.org> Reviewed-by: Michael Thiessen <mthiesse@chromium.org> Cr-Commit-Position: refs/heads/main@{#1328354}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
199ae24a95
commit
031d159e55
android_webview/javatests/src/org/chromium/android_webview/test
base/android
chrome
android
features
start_surface
javatests
src
org
chromium
chrome
features
start_surface
javatests
src
org
chromium
chrome
browser
browser
selection
android
java
src
org
chromium
chrome
browser
selection
ui
android
hats
test
java
src
org
chromium
chrome
browser
signin
java
src
org
chromium
chrome
browser
test
android
javatests
src
org
chromium
chrome
content
public
android
javatests
src
org
chromium
content
browser
test
android
javatests
src
org
chromium
content_public
browser
shell
android
javatests
src
org
chromium
@ -243,8 +243,7 @@ public class AwActivityTestRule extends BaseActivityTestRule<AwTestRunnerActivit
|
||||
() -> awContents.getSettings().setJavaScriptEnabled(true));
|
||||
}
|
||||
|
||||
public static boolean getJavaScriptEnabledOnUiThread(final AwContents awContents)
|
||||
throws ExecutionException {
|
||||
private static boolean getJavaScriptEnabledOnUiThread(final AwContents awContents) {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> awContents.getSettings().getJavaScriptEnabled());
|
||||
}
|
||||
|
@ -37,7 +37,6 @@ import org.chromium.net.test.util.TestWebServer;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/** Test suite for JavaScript Java interaction. */
|
||||
@ -528,9 +527,9 @@ public class JsJavaInteractionTest extends AwParameterizedTest {
|
||||
|
||||
// Pass an URI instead of origin shouldn't work.
|
||||
final String jsObjectName5 = JS_OBJECT_NAME + "5";
|
||||
ExecutionException exception =
|
||||
RuntimeException exception =
|
||||
Assert.assertThrows(
|
||||
ExecutionException.class,
|
||||
RuntimeException.class,
|
||||
() ->
|
||||
addWebMessageListenerOnUiThread(
|
||||
mAwContents,
|
||||
@ -548,9 +547,9 @@ public class JsJavaInteractionTest extends AwParameterizedTest {
|
||||
@Feature({"AndroidWebView", "JsJavaInteraction"})
|
||||
public void testDontAllowAddWebMessageLitenerWithTheSameJsObjectName() throws Throwable {
|
||||
addWebMessageListenerOnUiThread(mAwContents, JS_OBJECT_NAME, new String[] {"*"}, mListener);
|
||||
ExecutionException exception =
|
||||
RuntimeException exception =
|
||||
Assert.assertThrows(
|
||||
ExecutionException.class,
|
||||
RuntimeException.class,
|
||||
() ->
|
||||
addWebMessageListenerOnUiThread(
|
||||
mAwContents,
|
||||
@ -1311,9 +1310,9 @@ public class JsJavaInteractionTest extends AwParameterizedTest {
|
||||
|
||||
// Wrong origin rule.
|
||||
final String testObjectName5 = testObjectName + "5";
|
||||
ExecutionException exception =
|
||||
RuntimeException exception =
|
||||
Assert.assertThrows(
|
||||
ExecutionException.class,
|
||||
RuntimeException.class,
|
||||
() ->
|
||||
addDocumentStartJavaScriptOnUiThread(
|
||||
mAwContents,
|
||||
|
@ -15,7 +15,6 @@ import org.chromium.base.task.TaskTraits;
|
||||
import org.chromium.build.BuildConfig;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
/** Helper methods to deal with threading related tasks. */
|
||||
@ -182,32 +181,27 @@ public class ThreadUtils {
|
||||
* Run the supplied Callable on the main thread, wrapping any exceptions in a RuntimeException.
|
||||
* The method will block until the Callable completes.
|
||||
*
|
||||
* Note that non-test usage of this function is heavily discouraged. For non-tests, use
|
||||
* <p>Note that non-test usage of this function is heavily discouraged. For non-tests, use
|
||||
* callbacks rather than blocking threads.
|
||||
*
|
||||
* @param c The Callable to run
|
||||
* @return The result of the callable
|
||||
*/
|
||||
public static <T> T runOnUiThreadBlockingNoException(Callable<T> c) {
|
||||
try {
|
||||
return runOnUiThreadBlocking(c);
|
||||
} catch (ExecutionException e) {
|
||||
throw JavaUtils.throwUnchecked(e);
|
||||
}
|
||||
return runOnUiThreadBlocking(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the supplied Callable on the main thread, The method will block until the Callable
|
||||
* completes.
|
||||
*
|
||||
* Note that non-test usage of this function is heavily discouraged. For non-tests, use
|
||||
* <p>Note that non-test usage of this function is heavily discouraged. For non-tests, use
|
||||
* callbacks rather than blocking threads.
|
||||
*
|
||||
* @param c The Callable to run
|
||||
* @return The result of the callable
|
||||
* @throws ExecutionException c's exception
|
||||
*/
|
||||
public static <T> T runOnUiThreadBlocking(Callable<T> c) throws ExecutionException {
|
||||
public static <T> T runOnUiThreadBlocking(Callable<T> c) {
|
||||
return PostTask.runSynchronously(TaskTraits.UI_DEFAULT, c);
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@ import android.os.Handler;
|
||||
import org.jni_zero.CalledByNative;
|
||||
import org.jni_zero.JNINamespace;
|
||||
|
||||
import org.chromium.base.JavaUtils;
|
||||
import org.chromium.base.Log;
|
||||
import org.chromium.base.ResettersForTesting;
|
||||
import org.chromium.base.ThreadUtils;
|
||||
@ -127,15 +126,15 @@ public class PostTask {
|
||||
}
|
||||
|
||||
/**
|
||||
* This function executes the task immediately if the current thread is the
|
||||
* same as the one corresponding to the SingleThreadTaskRunner, otherwise it
|
||||
* posts it and blocks until the task finishes.
|
||||
* This function executes the task immediately if the current thread is the same as the one
|
||||
* corresponding to the SingleThreadTaskRunner, otherwise it posts it and blocks until the task
|
||||
* finishes.
|
||||
*
|
||||
* Usage outside of testing contexts is discouraged. Prefer callbacks in order
|
||||
* to avoid blocking.
|
||||
* <p>Usage outside of testing contexts is discouraged. Prefer callbacks in order to avoid
|
||||
* blocking.
|
||||
*
|
||||
* @param taskTraits The TaskTraits that describe the desired TaskRunner.
|
||||
* @param task The task to be run with the specified traits.
|
||||
* @param c The task to be run with the specified traits.
|
||||
* @return The result of the callable
|
||||
*/
|
||||
public static <T> T runSynchronously(@TaskTraits int taskTraits, Callable<T> c) {
|
||||
@ -143,15 +142,15 @@ public class PostTask {
|
||||
}
|
||||
|
||||
/**
|
||||
* This function executes the task immediately if the current thread is the
|
||||
* same as the one corresponding to the SingleThreadTaskRunner, otherwise it
|
||||
* posts it and blocks until the task finishes.
|
||||
* This function executes the task immediately if the current thread is the same as the one
|
||||
* corresponding to the SingleThreadTaskRunner, otherwise it posts it and blocks until the task
|
||||
* finishes.
|
||||
*
|
||||
* Usage outside of testing contexts is discouraged. Prefer callbacks in order
|
||||
* to avoid blocking.
|
||||
* <p>Usage outside of testing contexts is discouraged. Prefer callbacks in order to avoid
|
||||
* blocking.
|
||||
*
|
||||
* @param taskTraits The TaskTraits that describe the desired TaskRunner.
|
||||
* @param task The task to be run with the specified traits.
|
||||
* @param r The task to be run with the specified traits.
|
||||
*/
|
||||
public static void runSynchronously(@TaskTraits int taskTraits, Runnable r) {
|
||||
runSynchronouslyInternal(taskTraits, new FutureTask<Void>(r, null));
|
||||
@ -162,7 +161,10 @@ public class PostTask {
|
||||
try {
|
||||
return task.get();
|
||||
} catch (Exception e) {
|
||||
throw JavaUtils.throwUnchecked(e);
|
||||
// Use a RuntimeException rather than ExecutionException so that callers are not forced
|
||||
// to add try/catch.
|
||||
// Wrap the "caused by" rather than the ExecutionException to avoid excessive wrapping.
|
||||
throw new RuntimeException(e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,6 @@ import org.chromium.base.task.TaskTraits;
|
||||
import org.chromium.base.test.BaseRobolectricTestRunner;
|
||||
import org.chromium.build.BuildConfig;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/** Unit tests for ThreadUtils. */
|
||||
@RunWith(BaseRobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE)
|
||||
@ -33,9 +31,9 @@ public class ThreadUtilsTest {
|
||||
ThreadChecker checker = new ThreadChecker();
|
||||
checker.assertOnValidThread();
|
||||
|
||||
ExecutionException e =
|
||||
RuntimeException e =
|
||||
Assert.assertThrows(
|
||||
ExecutionException.class,
|
||||
RuntimeException.class,
|
||||
() ->
|
||||
PostTask.runSynchronously(
|
||||
TaskTraits.USER_BLOCKING, checker::assertOnValidThread));
|
||||
|
@ -10,7 +10,6 @@ import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import static org.chromium.chrome.browser.tasks.ReturnToChromeUtil.HOME_SURFACE_SHOWN_AT_STARTUP_UMA;
|
||||
import static org.chromium.chrome.browser.tasks.ReturnToChromeUtil.HOME_SURFACE_SHOWN_UMA;
|
||||
@ -69,7 +68,6 @@ import org.chromium.content_public.browser.test.util.JavaScriptUtils;
|
||||
import org.chromium.ui.test.util.UiRestriction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/** Integration tests of showing a NTP with Start surface UI at startup. */
|
||||
@ -394,12 +392,8 @@ public class ShowNtpAtStartupTest {
|
||||
cta, 2, UrlConstants.NTP_URL, /* expectHomeSurfaceUiShown= */ true);
|
||||
waitForNtpLoaded(cta.getActivityTab());
|
||||
|
||||
try {
|
||||
ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> cta.findViewById(R.id.single_tab_view).performClick());
|
||||
} catch (ExecutionException e) {
|
||||
Assert.fail("Failed to tap the single tab card " + e.toString());
|
||||
}
|
||||
ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> cta.findViewById(R.id.single_tab_view).performClick());
|
||||
|
||||
// Verifies that the last active Tab is showing, and NTP home surface is closed.
|
||||
verifyTabCountAndActiveTabUrl(cta, 1, TAB_URL, /* expectHomeSurfaceUiShown= */ null);
|
||||
@ -465,12 +459,8 @@ public class ShowNtpAtStartupTest {
|
||||
+ "snapshot for the NTP.",
|
||||
ntp.getSnapshotSingleTabCardChangedForTesting());
|
||||
|
||||
try {
|
||||
ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> cta.findViewById(R.id.tab_switcher_button).performClick());
|
||||
} catch (ExecutionException e) {
|
||||
fail("Failed to tap 'more tabs' " + e.toString());
|
||||
}
|
||||
ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> cta.findViewById(R.id.tab_switcher_button).performClick());
|
||||
LayoutTestUtils.waitForLayout(cta.getLayoutManager(), LayoutType.TAB_SWITCHER);
|
||||
ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
|
@ -77,7 +77,6 @@ import org.chromium.url.Origin;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -788,13 +787,8 @@ public class NavigateTest {
|
||||
}
|
||||
|
||||
private String getTabUrlOnUIThread(final Tab tab) {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> ChromeTabUtils.getUrlStringOnUiThread(tab));
|
||||
} catch (ExecutionException ex) {
|
||||
assert false : "Unexpected ExecutionException";
|
||||
}
|
||||
return null;
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> ChromeTabUtils.getUrlStringOnUiThread(tab));
|
||||
}
|
||||
|
||||
private String getTabBodyText(Tab tab) {
|
||||
|
14
chrome/android/javatests/src/org/chromium/chrome/browser/input/SelectPopupOtherContentViewTest.java
14
chrome/android/javatests/src/org/chromium/chrome/browser/input/SelectPopupOtherContentViewTest.java
@ -29,8 +29,6 @@ import org.chromium.content_public.browser.test.util.DOMUtils;
|
||||
import org.chromium.content_public.browser.test.util.WebContentsUtils;
|
||||
import org.chromium.ui.base.ViewAndroidDelegate;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/** Test the select popup and how it interacts with another WebContents. */
|
||||
@RunWith(ChromeJUnit4ClassRunner.class)
|
||||
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
|
||||
@ -54,14 +52,10 @@ public class SelectPopupOtherContentViewTest {
|
||||
+ "</body></html>");
|
||||
|
||||
private boolean isSelectPopupVisibleOnUiThread() {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() ->
|
||||
WebContentsUtils.isSelectPopupVisible(
|
||||
mActivityTestRule.getWebContents()));
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() ->
|
||||
WebContentsUtils.isSelectPopupVisible(
|
||||
mActivityTestRule.getWebContents()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,8 +64,6 @@ import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
@ -115,21 +113,12 @@ public class NotificationPlatformBridgeTest {
|
||||
}
|
||||
|
||||
private double getEngagementScoreBlocking() {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
new Callable<Double>() {
|
||||
@Override
|
||||
public Double call() {
|
||||
// TODO (https://crbug.com/1063807): Add incognito mode tests.
|
||||
return SiteEngagementService.getForBrowserContext(
|
||||
ProfileManager.getLastUsedRegularProfile())
|
||||
.getScore(mPermissionTestRule.getOrigin());
|
||||
}
|
||||
});
|
||||
} catch (ExecutionException ex) {
|
||||
assert false : "Unexpected ExecutionException";
|
||||
}
|
||||
return 0.0;
|
||||
// TODO (https://crbug.com/1063807): Add incognito mode tests.
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() ->
|
||||
SiteEngagementService.getForBrowserContext(
|
||||
ProfileManager.getLastUsedRegularProfile())
|
||||
.getScore(mPermissionTestRule.getOrigin()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,7 +58,6 @@ import org.chromium.ui.permissions.AndroidPermissionDelegate;
|
||||
import org.chromium.ui.test.util.UiRestriction;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/** Unit tests for {@link LocationBarLayout}. */
|
||||
@RunWith(ChromeJUnit4ClassRunner.class)
|
||||
@ -102,12 +101,7 @@ public class LocationBarLayoutTest {
|
||||
}
|
||||
|
||||
private String getUrlText(UrlBar urlBar) {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(() -> urlBar.getText().toString());
|
||||
} catch (ExecutionException ex) {
|
||||
throw new RuntimeException(
|
||||
"Failed to get the UrlBar's text! Exception below:\n" + ex.toString());
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(() -> urlBar.getText().toString());
|
||||
}
|
||||
|
||||
private UrlBar getUrlBar() {
|
||||
@ -145,24 +139,20 @@ public class LocationBarLayoutTest {
|
||||
});
|
||||
CriteriaHelper.pollUiThread(() -> urlBar.hasFocus());
|
||||
|
||||
try {
|
||||
ThreadUtils.runOnUiThreadBlocking(
|
||||
new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws InterruptedException {
|
||||
mActivityTestRule.typeInOmnibox(text, false);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException("Failed to type \"" + text + "\" into the omnibox!");
|
||||
}
|
||||
ThreadUtils.runOnUiThreadBlocking(
|
||||
new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws InterruptedException {
|
||||
mActivityTestRule.typeInOmnibox(text, false);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@SmallTest
|
||||
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
|
||||
public void testNotShowingVoiceSearchButtonIfUrlBarContainsText() throws ExecutionException {
|
||||
public void testNotShowingVoiceSearchButtonIfUrlBarContainsText() {
|
||||
// When there is text, the delete button should be visible.
|
||||
setUrlBarTextAndFocus("testing");
|
||||
|
||||
@ -173,7 +163,7 @@ public class LocationBarLayoutTest {
|
||||
@Test
|
||||
@SmallTest
|
||||
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
|
||||
public void testShowingVoiceSearchButtonIfUrlBarIsEmpty() throws ExecutionException {
|
||||
public void testShowingVoiceSearchButtonIfUrlBarIsEmpty() {
|
||||
// When there's no text, the mic button should be visible.
|
||||
setUrlBarTextAndFocus("");
|
||||
|
||||
@ -183,7 +173,7 @@ public class LocationBarLayoutTest {
|
||||
|
||||
@Test
|
||||
@SmallTest
|
||||
public void testDeleteButton() throws ExecutionException {
|
||||
public void testDeleteButton() {
|
||||
setUrlBarTextAndFocus("testing");
|
||||
CriteriaHelper.pollUiThread(
|
||||
() -> {
|
||||
|
@ -36,7 +36,6 @@ import org.chromium.components.search_engines.TemplateUrlService;
|
||||
import org.chromium.components.search_engines.TemplateUrlService.LoadListener;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/** Tests for Search Engine Settings. */
|
||||
@RunWith(ChromeJUnit4ClassRunner.class)
|
||||
@ -208,8 +207,7 @@ public class SearchEngineSettingsTest {
|
||||
}
|
||||
|
||||
private static Preference waitForPreference(
|
||||
final PreferenceFragmentCompat prefFragment, final String preferenceKey)
|
||||
throws ExecutionException {
|
||||
final PreferenceFragmentCompat prefFragment, final String preferenceKey) {
|
||||
CriteriaHelper.pollUiThread(
|
||||
() -> {
|
||||
Criteria.checkThat(
|
||||
|
@ -32,8 +32,6 @@ import org.chromium.chrome.test.batch.BlankCTATabInitialStateRule;
|
||||
import org.chromium.chrome.test.util.ChromeTabUtils;
|
||||
import org.chromium.net.test.util.TestWebServer;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/** Tests related to the sad tab logic. */
|
||||
@RunWith(ChromeJUnit4ClassRunner.class)
|
||||
@Batch(Batch.PER_CLASS)
|
||||
@ -52,11 +50,7 @@ public class SadTabTest {
|
||||
|
||||
private static boolean isShowingSadTab(Tab tab) {
|
||||
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(() -> SadTab.isShowing(tab));
|
||||
} catch (ExecutionException e) {
|
||||
return false;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(() -> SadTab.isShowing(tab));
|
||||
}
|
||||
|
||||
@After
|
||||
@ -217,11 +211,7 @@ public class SadTabTest {
|
||||
}
|
||||
|
||||
private static boolean showSendFeedbackView(final Tab tab) {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(() -> SadTab.from(tab).showSendFeedbackView());
|
||||
} catch (ExecutionException e) {
|
||||
return false; // Make tests fail when an exception is thrown.
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(() -> SadTab.from(tab).showSendFeedbackView());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,11 +222,7 @@ public class SadTabTest {
|
||||
*/
|
||||
private static Button getSadTabButton(Tab tab) {
|
||||
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> tab.getView().findViewById(R.id.sad_tab_button));
|
||||
} catch (ExecutionException e) {
|
||||
return null;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> tab.getView().findViewById(R.id.sad_tab_button));
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ import org.chromium.content_public.browser.LoadUrlParams;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/** Tests for the TabModelSelectorTabObserver. */
|
||||
@RunWith(BaseJUnit4ClassRunner.class)
|
||||
@ -211,11 +210,7 @@ public class TabModelSelectorTabObserverTest {
|
||||
}
|
||||
|
||||
private static void closeTab(TabModel tabModel, Tab tab) {
|
||||
try {
|
||||
ThreadUtils.runOnUiThreadBlocking(() -> tabModel.closeTab(tab));
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException("Error occurred waiting for runnable", e);
|
||||
}
|
||||
ThreadUtils.runOnUiThreadBlocking(() -> tabModel.closeTab(tab));
|
||||
}
|
||||
|
||||
private static void removeTab(TabModel tabModel, Tab tab) {
|
||||
|
@ -35,7 +35,6 @@ import org.chromium.content_public.browser.SelectionPopupController;
|
||||
import org.chromium.content_public.browser.test.util.DOMUtils;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/** Test that verifies back press will dismiss the selection popup. */
|
||||
@ -74,7 +73,7 @@ public class SelectionPopupBackPressTest {
|
||||
@MediumTest
|
||||
@Feature({"TextInput", "SmartSelection"})
|
||||
@EnableFeatures(ChromeFeatureList.BACK_GESTURE_REFACTOR)
|
||||
public void testBackPressHandlerOnTabSwitched() throws ExecutionException {
|
||||
public void testBackPressHandlerOnTabSwitched() {
|
||||
mActivityTestRule.startMainActivityOnBlankPage();
|
||||
final ChromeTabbedActivity activity = mActivityTestRule.getActivity();
|
||||
final BackPressHandler selectionPopupHandler =
|
||||
@ -104,7 +103,7 @@ public class SelectionPopupBackPressTest {
|
||||
@MediumTest
|
||||
@Feature({"TextInput", "SmartSelection"})
|
||||
@EnableFeatures(ChromeFeatureList.BACK_GESTURE_REFACTOR)
|
||||
public void testBackPressHandlerOnWebContentChanged() throws ExecutionException {
|
||||
public void testBackPressHandlerOnWebContentChanged() {
|
||||
mActivityTestRule.startMainActivityOnBlankPage();
|
||||
final ChromeTabbedActivity activity = mActivityTestRule.getActivity();
|
||||
final SelectionPopupBackPressHandler selectionPopupHandler =
|
||||
|
@ -25,7 +25,6 @@ import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
|
||||
import org.chromium.chrome.browser.profiles.Profile;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/** Util class for survey related testing. */
|
||||
public class TestSurveyUtils {
|
||||
@ -67,7 +66,7 @@ public class TestSurveyUtils {
|
||||
SurveyClientImpl.setForceShowSurveyForTesting(doForce);
|
||||
}
|
||||
|
||||
static TestSurveyFactory setUpTestSurveyFactory() throws ExecutionException {
|
||||
static TestSurveyFactory setUpTestSurveyFactory() {
|
||||
TestSurveyFactory factory = ThreadUtils.runOnUiThreadBlocking(TestSurveyFactory::new);
|
||||
SurveyClientFactory.setInstanceForTesting(factory);
|
||||
return factory;
|
||||
@ -109,12 +108,8 @@ public class TestSurveyUtils {
|
||||
CommandLine.getInstance()
|
||||
.appendSwitch(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE);
|
||||
|
||||
try {
|
||||
mTestSurveyFactory = setUpTestSurveyFactory();
|
||||
base.evaluate();
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
mTestSurveyFactory = setUpTestSurveyFactory();
|
||||
base.evaluate();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -7,8 +7,6 @@ package org.chromium.chrome.browser.ui.hats;
|
||||
import org.jni_zero.CalledByNative;
|
||||
import org.jni_zero.JNINamespace;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* Helper class that C++ can setup the survey testing environment. Java tests should instead use the
|
||||
* {@link TestSurveyUtils.TestSurveyComponentRule}.
|
||||
@ -16,7 +14,7 @@ import java.util.concurrent.ExecutionException;
|
||||
@JNINamespace("hats")
|
||||
public class TestSurveyUtilsBridge {
|
||||
@CalledByNative
|
||||
private static void setupTestSurveyFactory() throws ExecutionException {
|
||||
private static void setupTestSurveyFactory() {
|
||||
TestSurveyUtils.forceShowSurveyForTesting(true);
|
||||
TestSurveyUtils.setUpTestSurveyFactory();
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import static androidx.test.espresso.matcher.RootMatchers.isDialog;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
@ -22,9 +21,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.test.filters.MediumTest;
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@ -67,7 +64,6 @@ import org.chromium.ui.test.util.BlankUiTestActivity;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/** Instrumentation tests for {@link SignOutDialogCoordinator}. */
|
||||
@RunWith(ChromeJUnit4ClassRunner.class)
|
||||
@ -106,28 +102,6 @@ public class SignOutCoordinatorTest {
|
||||
mActivityTestRule.launchActivity(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SmallTest
|
||||
public void testNullOnSignOutCallback() {
|
||||
try {
|
||||
ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
SignOutCoordinator.startSignOutFlow(
|
||||
mActivityTestRule.getActivity(),
|
||||
mProfile,
|
||||
mFragmentManager,
|
||||
mActivityTestRule.getActivity().getModalDialogManager(),
|
||||
mSnackbarManager,
|
||||
SignoutReason.USER_CLICKED_SIGNOUT_SETTINGS,
|
||||
/* showConfirmDialog= */ false,
|
||||
null);
|
||||
return null;
|
||||
});
|
||||
} catch (ExecutionException ex) {
|
||||
MatcherAssert.assertThat(ex.getCause(), instanceOf(AssertionError.class));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@MediumTest
|
||||
@DisableFeatures(ChromeFeatureList.REPLACE_SYNC_PROMOS_WITH_SIGN_IN_PROMOS)
|
||||
|
@ -58,8 +58,6 @@ import org.chromium.components.user_prefs.UserPrefs;
|
||||
import org.chromium.components.user_prefs.UserPrefsJni;
|
||||
import org.chromium.ui.test.util.BlankUiTestActivity;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/** Instrumentation tests for {@link SignOutDialogCoordinator}. */
|
||||
@RunWith(ChromeJUnit4ClassRunner.class)
|
||||
@Batch(Batch.PER_CLASS)
|
||||
@ -101,9 +99,9 @@ public class SignOutDialogTest {
|
||||
public void testRegularAccountCanNotRevokeSyncConsent() {
|
||||
when(mProfile.isChild()).thenReturn(false);
|
||||
// ThreadUtils.runOnUiThreadBlocking() catches the IllegalArgumentException and throws it
|
||||
// wrapped inside a ExecutionException.
|
||||
// wrapped inside a RuntimeException.
|
||||
Assert.assertThrows(
|
||||
ExecutionException.class,
|
||||
RuntimeException.class,
|
||||
() -> showSignOutDialog(SignoutReason.USER_CLICKED_REVOKE_SYNC_CONSENT_SETTINGS));
|
||||
}
|
||||
|
||||
@ -112,9 +110,9 @@ public class SignOutDialogTest {
|
||||
public void testChildAccountCanOnlyRevokeSyncConsent() {
|
||||
when(mProfile.isChild()).thenReturn(true);
|
||||
// ThreadUtils.runOnUiThreadBlocking() catches the IllegalArgumentException and throws it
|
||||
// wrapped inside a ExecutionException.
|
||||
// wrapped inside a RuntimeException.
|
||||
Assert.assertThrows(
|
||||
ExecutionException.class,
|
||||
RuntimeException.class,
|
||||
() -> showSignOutDialog(SignoutReason.USER_CLICKED_SIGNOUT_SETTINGS));
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,6 @@ import org.chromium.url.GURL;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@ -342,21 +341,9 @@ public class ChromeActivityTestRule<T extends ChromeActivity> extends BaseActivi
|
||||
*/
|
||||
public Tab loadUrlInNewTab(
|
||||
final String url, final boolean incognito, final @TabLaunchType int launchType) {
|
||||
Tab tab;
|
||||
try {
|
||||
tab =
|
||||
ThreadUtils.runOnUiThreadBlocking(
|
||||
new Callable<Tab>() {
|
||||
@Override
|
||||
public Tab call() {
|
||||
return getActivity()
|
||||
.getTabCreator(incognito)
|
||||
.launchUrl(url, launchType);
|
||||
}
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
throw new AssertionError("Failed to create new tab", e);
|
||||
}
|
||||
Tab tab =
|
||||
ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> getActivity().getTabCreator(incognito).launchUrl(url, launchType));
|
||||
ChromeTabUtils.waitForTabPageLoaded(tab, url);
|
||||
ChromeTabUtils.waitForInteractable(tab);
|
||||
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
|
||||
|
@ -43,7 +43,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/** Integration tests for text input for Android L (or above) features. */
|
||||
@ -399,20 +398,8 @@ class ImeActivityTestRule extends ContentShellActivityTestRule {
|
||||
}
|
||||
|
||||
ChromiumBaseInputConnection getInputConnection() {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
new Callable<ChromiumBaseInputConnection>() {
|
||||
@Override
|
||||
public ChromiumBaseInputConnection call() {
|
||||
return (ChromiumBaseInputConnection)
|
||||
getImeAdapter().getInputConnectionForTest();
|
||||
}
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail();
|
||||
return null;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> (ChromiumBaseInputConnection) getImeAdapter().getInputConnectionForTest());
|
||||
}
|
||||
|
||||
void restartInput() {
|
||||
|
12
content/public/android/javatests/src/org/chromium/content/browser/webcontents/WebContentsTest.java
12
content/public/android/javatests/src/org/chromium/content/browser/webcontents/WebContentsTest.java
@ -36,7 +36,6 @@ import org.chromium.content_shell_apk.ContentShellActivityTestRule;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* Test various Java WebContents specific features.
|
||||
@ -56,12 +55,10 @@ public class WebContentsTest {
|
||||
* Check that {@link WebContents#isDestroyed()} works as expected.
|
||||
* TODO(dtrainor): Test this using {@link WebContents#destroy()} instead once it is possible to
|
||||
* build a {@link WebContents} directly in the content/ layer.
|
||||
*
|
||||
* @throws ExecutionException
|
||||
*/
|
||||
@Test
|
||||
@SmallTest
|
||||
public void testWebContentsIsDestroyedMethod() throws ExecutionException {
|
||||
public void testWebContentsIsDestroyedMethod() {
|
||||
final ContentShellActivity activity =
|
||||
mActivityTestRule.launchContentShellWithUrl(TEST_URL_1);
|
||||
mActivityTestRule.waitForActiveShellToBeDoneLoading();
|
||||
@ -227,11 +224,10 @@ public class WebContentsTest {
|
||||
/**
|
||||
* Check that serializing a destroyed WebContents always results in a null deserialized
|
||||
* WebContents.
|
||||
* @throws ExecutionException
|
||||
*/
|
||||
@Test
|
||||
@SmallTest
|
||||
public void testSerializingADestroyedWebContentsDoesNotDeserialize() throws ExecutionException {
|
||||
public void testSerializingADestroyedWebContentsDoesNotDeserialize() {
|
||||
ContentShellActivity activity = mActivityTestRule.launchContentShellWithUrl(TEST_URL_1);
|
||||
mActivityTestRule.waitForActiveShellToBeDoneLoading();
|
||||
WebContents webContents = activity.getActiveWebContents();
|
||||
@ -261,12 +257,10 @@ public class WebContentsTest {
|
||||
/**
|
||||
* Check that destroying a WebContents after serializing it always results in a null
|
||||
* deserialized WebContents.
|
||||
* @throws ExecutionException
|
||||
*/
|
||||
@Test
|
||||
@SmallTest
|
||||
public void testDestroyingAWebContentsAfterSerializingDoesNotDeserialize()
|
||||
throws ExecutionException {
|
||||
public void testDestroyingAWebContentsAfterSerializingDoesNotDeserialize() {
|
||||
ContentShellActivity activity = mActivityTestRule.launchContentShellWithUrl(TEST_URL_1);
|
||||
mActivityTestRule.waitForActiveShellToBeDoneLoading();
|
||||
WebContents webContents = activity.getActiveWebContents();
|
||||
|
@ -28,7 +28,6 @@ import org.chromium.content_public.browser.WebContents;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@ -659,12 +658,8 @@ public class DOMUtils {
|
||||
}
|
||||
|
||||
private static int getMaybeTopControlsHeight(final WebContents webContents) {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> DOMUtilsJni.get().getTopControlsShrinkBlinkHeight(webContents));
|
||||
} catch (ExecutionException e) {
|
||||
return 0;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> DOMUtilsJni.get().getTopControlsShrinkBlinkHeight(webContents));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,9 +12,6 @@ import android.view.ViewConfiguration;
|
||||
|
||||
import org.chromium.base.ThreadUtils;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* Touch-related functionality reused across test cases.
|
||||
*
|
||||
@ -493,21 +490,11 @@ public class TouchCommon {
|
||||
}
|
||||
|
||||
private static View getRootViewForActivity(final Activity activity) {
|
||||
try {
|
||||
View view =
|
||||
ThreadUtils.runOnUiThreadBlocking(
|
||||
new Callable<View>() {
|
||||
@Override
|
||||
public View call() {
|
||||
return activity.findViewById(android.R.id.content)
|
||||
.getRootView();
|
||||
}
|
||||
});
|
||||
assert view != null : "Failed to find root view for activity";
|
||||
return view;
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException("Dispatching touch event failed", e);
|
||||
}
|
||||
View view =
|
||||
ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> activity.findViewById(android.R.id.content).getRootView());
|
||||
assert view != null : "Failed to find root view for activity";
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -517,17 +504,7 @@ public class TouchCommon {
|
||||
* @param event The view to be dispatched.
|
||||
*/
|
||||
public static boolean dispatchTouchEvent(final View view, final MotionEvent event) {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() {
|
||||
return view.dispatchTouchEvent(event);
|
||||
}
|
||||
});
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Dispatching touch event failed", e);
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(() -> view.dispatchTouchEvent(event));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,6 @@ import org.chromium.content_public.browser.ViewEventSink;
|
||||
import org.chromium.content_public.browser.WebContents;
|
||||
import org.chromium.content_public.browser.WebContentsObserver;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/** Collection of test-only WebContents utilities. */
|
||||
@ -77,11 +76,7 @@ public class WebContentsUtils {
|
||||
* @param webContents The WebContents in use.
|
||||
*/
|
||||
public static ImeAdapter getImeAdapter(WebContents webContents) {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(() -> ImeAdapter.fromWebContents(webContents));
|
||||
} catch (ExecutionException e) {
|
||||
return null;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(() -> ImeAdapter.fromWebContents(webContents));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,12 +85,8 @@ public class WebContentsUtils {
|
||||
* @param webContents The WebContents in use.
|
||||
*/
|
||||
public static GestureListenerManager getGestureListenerManager(WebContents webContents) {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> GestureListenerManager.fromWebContents(webContents));
|
||||
} catch (ExecutionException e) {
|
||||
return null;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> GestureListenerManager.fromWebContents(webContents));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,11 +95,7 @@ public class WebContentsUtils {
|
||||
* @param webContents The WebContents in use.
|
||||
*/
|
||||
public static ViewEventSink getViewEventSink(WebContents webContents) {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(() -> ViewEventSink.from(webContents));
|
||||
} catch (ExecutionException e) {
|
||||
return null;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(() -> ViewEventSink.from(webContents));
|
||||
}
|
||||
|
||||
/**
|
||||
|
94
content/shell/android/javatests/src/org/chromium/content_shell_apk/ContentShellActivityTestRule.java
94
content/shell/android/javatests/src/org/chromium/content_shell_apk/ContentShellActivityTestRule.java
@ -16,7 +16,6 @@ import androidx.test.InstrumentationRegistry;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.chromium.base.Log;
|
||||
import org.chromium.base.ThreadUtils;
|
||||
import org.chromium.base.test.BaseActivityTestRule;
|
||||
import org.chromium.base.test.util.CallbackHelper;
|
||||
@ -43,7 +42,6 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@ -110,7 +108,7 @@ public class ContentShellActivityTestRule extends BaseActivityTestRule<ContentSh
|
||||
}
|
||||
|
||||
/** Returns the OnCursorUpdateHelper. */
|
||||
public OnCursorUpdateHelper getOnCursorUpdateHelper() throws ExecutionException {
|
||||
public OnCursorUpdateHelper getOnCursorUpdateHelper() {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
new Callable<OnCursorUpdateHelper>() {
|
||||
@Override
|
||||
@ -125,94 +123,61 @@ public class ContentShellActivityTestRule extends BaseActivityTestRule<ContentSh
|
||||
|
||||
/** Returns the current {@link ViewEventSink} or null if there is none; */
|
||||
public ViewEventSink getViewEventSink() {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
return ViewEventSink.from(getActivity().getActiveShell().getWebContents());
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
return null;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
return ViewEventSink.from(getActivity().getActiveShell().getWebContents());
|
||||
});
|
||||
}
|
||||
|
||||
/** Returns the WebContents of this Shell. */
|
||||
public WebContents getWebContents() {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
return getActivity().getActiveShell().getWebContents();
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
return null;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
return getActivity().getActiveShell().getWebContents();
|
||||
});
|
||||
}
|
||||
|
||||
/** Returns the {@link SelectionPopupControllerImpl} of the WebContents. */
|
||||
public SelectionPopupControllerImpl getSelectionPopupController() {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
return SelectionPopupControllerImpl.fromWebContents(
|
||||
getActivity().getActiveShell().getWebContents());
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
return null;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
return SelectionPopupControllerImpl.fromWebContents(
|
||||
getActivity().getActiveShell().getWebContents());
|
||||
});
|
||||
}
|
||||
|
||||
/** Returns the {@link ImeAdapterImpl} of the WebContents. */
|
||||
public ImeAdapterImpl getImeAdapter() {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> ImeAdapterImpl.fromWebContents(getWebContents()));
|
||||
} catch (ExecutionException e) {
|
||||
return null;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> ImeAdapterImpl.fromWebContents(getWebContents()));
|
||||
}
|
||||
|
||||
/** Returns the {@link SelectPopup} of the WebContents. */
|
||||
public SelectPopup getSelectPopup() {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> SelectPopup.fromWebContents(getWebContents()));
|
||||
} catch (ExecutionException e) {
|
||||
return null;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> SelectPopup.fromWebContents(getWebContents()));
|
||||
}
|
||||
|
||||
public WebContentsAccessibilityImpl getWebContentsAccessibility() {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> WebContentsAccessibilityImpl.fromWebContents(getWebContents()));
|
||||
} catch (ExecutionException e) {
|
||||
return null;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> WebContentsAccessibilityImpl.fromWebContents(getWebContents()));
|
||||
}
|
||||
|
||||
/** Returns the RenderCoordinates of the WebContents. */
|
||||
public RenderCoordinatesImpl getRenderCoordinates() {
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> ((WebContentsImpl) getWebContents()).getRenderCoordinates());
|
||||
} catch (ExecutionException e) {
|
||||
return null;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> ((WebContentsImpl) getWebContents()).getRenderCoordinates());
|
||||
}
|
||||
|
||||
/** Returns the current container view or null if there is no WebContents. */
|
||||
public View getContainerView() {
|
||||
final WebContents webContents = getWebContents();
|
||||
try {
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
return webContents != null
|
||||
? webContents.getViewAndroidDelegate().getContainerView()
|
||||
: null;
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
Log.w(TAG, "Getting container view failed. Returning null", e);
|
||||
return null;
|
||||
}
|
||||
return ThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
return webContents != null
|
||||
? webContents.getViewAndroidDelegate().getContainerView()
|
||||
: null;
|
||||
});
|
||||
}
|
||||
|
||||
public JavascriptInjector getJavascriptInjector() {
|
||||
@ -247,9 +212,8 @@ public class ContentShellActivityTestRule extends BaseActivityTestRule<ContentSh
|
||||
*
|
||||
* @param url The URL to create the new {@link Shell} with.
|
||||
* @return A new instance of a {@link Shell}.
|
||||
* @throws ExecutionException
|
||||
*/
|
||||
public Shell loadNewShell(String url) throws ExecutionException {
|
||||
public Shell loadNewShell(String url) {
|
||||
Shell shell =
|
||||
ThreadUtils.runOnUiThreadBlocking(
|
||||
new Callable<Shell>() {
|
||||
|
@ -17,8 +17,6 @@ import org.chromium.base.test.util.Feature;
|
||||
import org.chromium.base.test.util.UrlUtils;
|
||||
import org.chromium.content_shell.Shell;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/** Test suite to verify the behavior of the shell management logic. */
|
||||
@RunWith(BaseJUnit4ClassRunner.class)
|
||||
public class ContentShellShellManagementTest {
|
||||
@ -34,7 +32,7 @@ public class ContentShellShellManagementTest {
|
||||
@SmallTest
|
||||
@Feature({"Main"})
|
||||
@DisabledTest(message = "https://crbug.com/1371971")
|
||||
public void testMultipleShellsLaunched() throws ExecutionException {
|
||||
public void testMultipleShellsLaunched() {
|
||||
final ContentShellActivity activity =
|
||||
mActivityTestRule.launchContentShellWithUrl(TEST_PAGE_1);
|
||||
Assert.assertEquals(
|
||||
|
Reference in New Issue
Block a user