| Index: chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java
|
| index 9c9a0f77164cd9bd60b6b3a4ee9aae0f11270f57..211100f19fb5d2a5a426ce9d68f1792e43da034f 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java
|
| @@ -15,8 +15,14 @@ import android.os.Bundle;
|
| import android.os.Process;
|
| import android.support.customtabs.CustomTabsService;
|
| import android.support.customtabs.CustomTabsSessionToken;
|
| +import android.support.test.InstrumentationRegistry;
|
| import android.support.test.filters.SmallTest;
|
| -import android.test.InstrumentationTestCase;
|
| +
|
| +import org.junit.After;
|
| +import org.junit.Assert;
|
| +import org.junit.Before;
|
| +import org.junit.Test;
|
| +import org.junit.runner.RunWith;
|
|
|
| import org.chromium.base.PathUtils;
|
| import org.chromium.base.ThreadUtils;
|
| @@ -26,6 +32,7 @@ import org.chromium.base.test.util.Restriction;
|
| import org.chromium.base.test.util.RetryOnFailure;
|
| import org.chromium.chrome.browser.WarmupManager;
|
| import org.chromium.chrome.browser.preferences.PrefServiceBridge;
|
| +import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| import org.chromium.content_public.browser.WebContents;
|
|
|
| import java.util.ArrayList;
|
| @@ -34,7 +41,8 @@ import java.util.concurrent.Callable;
|
| import java.util.concurrent.FutureTask;
|
|
|
| /** Tests for CustomTabsConnection. */
|
| -public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| +@RunWith(ChromeJUnit4ClassRunner.class)
|
| +public class CustomTabsConnectionTest {
|
| private CustomTabsConnection mCustomTabsConnection;
|
| private static final String URL = "http://www.google.com";
|
| private static final String URL2 = "https://www.android.com";
|
| @@ -43,19 +51,19 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
|
|
| private Context mAppContext;
|
|
|
| - @Override
|
| - protected void setUp() throws Exception {
|
| - super.setUp();
|
| - mAppContext = getInstrumentation().getTargetContext().getApplicationContext();
|
| + @Before
|
| + public void setUp() throws Exception {
|
| + mAppContext = InstrumentationRegistry.getInstrumentation()
|
| + .getTargetContext()
|
| + .getApplicationContext();
|
| PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
|
| LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized();
|
| mCustomTabsConnection = CustomTabsTestUtils.setUpConnection((Application) mAppContext);
|
| mCustomTabsConnection.resetThrottling(mAppContext, Process.myUid());
|
| }
|
|
|
| - @Override
|
| - protected void tearDown() throws Exception {
|
| - super.tearDown();
|
| + @After
|
| + public void tearDown() throws Exception {
|
| CustomTabsTestUtils.cleanupSessions(mCustomTabsConnection);
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| @@ -69,39 +77,43 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| * Tests that we can create a new session. Registering with a null callback
|
| * fails, as well as multiple sessions with the same callback.
|
| */
|
| + @Test
|
| @SmallTest
|
| public void testNewSession() {
|
| - assertEquals(false, mCustomTabsConnection.newSession(null));
|
| + Assert.assertEquals(false, mCustomTabsConnection.newSession(null));
|
| CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
|
| - assertEquals(true, mCustomTabsConnection.newSession(token));
|
| - assertEquals(false, mCustomTabsConnection.newSession(token));
|
| + Assert.assertEquals(true, mCustomTabsConnection.newSession(token));
|
| + Assert.assertEquals(false, mCustomTabsConnection.newSession(token));
|
| }
|
|
|
| /**
|
| * Tests that we can create several sessions.
|
| */
|
| + @Test
|
| @SmallTest
|
| public void testSeveralSessions() {
|
| CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
|
| - assertEquals(true, mCustomTabsConnection.newSession(token));
|
| + Assert.assertEquals(true, mCustomTabsConnection.newSession(token));
|
| CustomTabsSessionToken token2 = CustomTabsSessionToken.createDummySessionTokenForTesting();
|
| - assertEquals(true, mCustomTabsConnection.newSession(token2));
|
| + Assert.assertEquals(true, mCustomTabsConnection.newSession(token2));
|
| }
|
|
|
| /**
|
| * Tests that {@link CustomTabsConnection#warmup(long)} succeeds and can
|
| * be issued multiple times.
|
| */
|
| + @Test
|
| @SmallTest
|
| public void testCanWarmup() {
|
| - assertEquals(true, mCustomTabsConnection.warmup(0));
|
| - assertEquals(true, mCustomTabsConnection.warmup(0));
|
| + Assert.assertEquals(true, mCustomTabsConnection.warmup(0));
|
| + Assert.assertEquals(true, mCustomTabsConnection.warmup(0));
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| public void testCreateSpareRenderer() {
|
| - assertTrue(mCustomTabsConnection.warmup(0));
|
| + Assert.assertTrue(mCustomTabsConnection.warmup(0));
|
| // On UI thread because:
|
| // 1. takeSpareWebContents needs to be called from the UI thread.
|
| // 2. warmup() is non-blocking and posts tasks to the UI thread, it ensures proper ordering.
|
| @@ -109,27 +121,28 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| @Override
|
| public void run() {
|
| WarmupManager warmupManager = WarmupManager.getInstance();
|
| - assertTrue(warmupManager.hasSpareWebContents());
|
| + Assert.assertTrue(warmupManager.hasSpareWebContents());
|
| WebContents webContents = warmupManager.takeSpareWebContents(false, false);
|
| - assertNotNull(webContents);
|
| - assertFalse(warmupManager.hasSpareWebContents());
|
| + Assert.assertNotNull(webContents);
|
| + Assert.assertFalse(warmupManager.hasSpareWebContents());
|
| webContents.destroy();
|
| }
|
| });
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| public void testCreateSpareRendererCanBeRecreated() {
|
| - assertTrue(mCustomTabsConnection.warmup(0));
|
| + Assert.assertTrue(mCustomTabsConnection.warmup(0));
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| assertSpareWebContentsNotNullAndDestroy();
|
| - assertFalse(WarmupManager.getInstance().hasSpareWebContents());
|
| + Assert.assertFalse(WarmupManager.getInstance().hasSpareWebContents());
|
| }
|
| });
|
| - assertTrue(mCustomTabsConnection.warmup(0));
|
| + Assert.assertTrue(mCustomTabsConnection.warmup(0));
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| @@ -138,6 +151,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| });
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| public void testPrerenderDestroysSpareRenderer() {
|
| @@ -145,12 +159,12 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - assertFalse(WarmupManager.getInstance().hasSpareWebContents());
|
| + Assert.assertFalse(WarmupManager.getInstance().hasSpareWebContents());
|
| String referrer =
|
| mCustomTabsConnection.getReferrerForSession(token).getUrl();
|
| WebContents webContents =
|
| mCustomTabsConnection.takePrerenderedUrl(token, URL, referrer);
|
| - assertNotNull(webContents);
|
| + Assert.assertNotNull(webContents);
|
| webContents.destroy();
|
| }
|
| });
|
| @@ -160,6 +174,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| * Tests that when the disconnection notification comes from a non-UI thread, Chrome doesn't
|
| * crash. Non-regression test for crbug.com/623128.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| public void testPrerenderAndDisconnectOnOtherThread() {
|
| @@ -180,18 +195,19 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| // Should not crash, hence no assertions below.
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| public void testMayLaunchUrlKeepsSpareRendererWithoutPrerendering() {
|
| - assertTrue(mCustomTabsConnection.warmup(0));
|
| + Assert.assertTrue(mCustomTabsConnection.warmup(0));
|
| final CustomTabsSessionToken token =
|
| CustomTabsSessionToken.createDummySessionTokenForTesting();
|
| - assertTrue(mCustomTabsConnection.newSession(token));
|
| + Assert.assertTrue(mCustomTabsConnection.newSession(token));
|
|
|
| Bundle extras = new Bundle();
|
| extras.putInt(
|
| CustomTabsConnection.DEBUG_OVERRIDE_KEY, CustomTabsConnection.NO_PRERENDERING);
|
| - assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), extras, null));
|
| + Assert.assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), extras, null));
|
|
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| @@ -201,6 +217,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| });
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testMayLaunchUrlNullOrEmptyUrl() {
|
| assertWarmupAndMayLaunchUrl(null, null, true);
|
| @@ -208,12 +225,13 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| assertWarmupAndMayLaunchUrl(null, "", true);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| public void testUnderstandsLowConfidenceMayLaunchUrl() {
|
| final CustomTabsSessionToken token =
|
| CustomTabsSessionToken.createDummySessionTokenForTesting();
|
| - assertTrue(mCustomTabsConnection.newSession(token));
|
| + Assert.assertTrue(mCustomTabsConnection.newSession(token));
|
| List<Bundle> urls = new ArrayList<>();
|
| Bundle urlBundle = new Bundle();
|
| urlBundle.putParcelable(CustomTabsService.KEY_URL, Uri.parse(URL));
|
| @@ -225,17 +243,18 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| public void run() {
|
| assertSpareWebContentsNotNullAndDestroy();
|
| String referrer = mCustomTabsConnection.getReferrerForSession(token).getUrl();
|
| - assertNull(mCustomTabsConnection.takePrerenderedUrl(token, URL, referrer));
|
| + Assert.assertNull(mCustomTabsConnection.takePrerenderedUrl(token, URL, referrer));
|
| }
|
| });
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testLowConfidenceMayLaunchUrlOnlyAcceptUris() {
|
| final CustomTabsSessionToken token =
|
| CustomTabsSessionToken.createDummySessionTokenForTesting();
|
| - assertTrue(mCustomTabsConnection.newSession(token));
|
| - assertTrue(mCustomTabsConnection.warmup(0));
|
| + Assert.assertTrue(mCustomTabsConnection.newSession(token));
|
| + Assert.assertTrue(mCustomTabsConnection.warmup(0));
|
|
|
| final List<Bundle> urlsAsString = new ArrayList<>();
|
| Bundle urlStringBundle = new Bundle();
|
| @@ -250,18 +269,19 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - assertFalse(mCustomTabsConnection.lowConfidenceMayLaunchUrl(urlsAsString));
|
| - assertTrue(mCustomTabsConnection.lowConfidenceMayLaunchUrl(urlsAsUri));
|
| + Assert.assertFalse(mCustomTabsConnection.lowConfidenceMayLaunchUrl(urlsAsString));
|
| + Assert.assertTrue(mCustomTabsConnection.lowConfidenceMayLaunchUrl(urlsAsUri));
|
| }
|
| });
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testLowConfidenceMayLaunchUrlDoesntCrash() {
|
| final CustomTabsSessionToken token =
|
| CustomTabsSessionToken.createDummySessionTokenForTesting();
|
| - assertTrue(mCustomTabsConnection.newSession(token));
|
| - assertTrue(mCustomTabsConnection.warmup(0));
|
| + Assert.assertTrue(mCustomTabsConnection.newSession(token));
|
| + Assert.assertTrue(mCustomTabsConnection.warmup(0));
|
|
|
| final List<Bundle> invalidBundles = new ArrayList<>();
|
| Bundle invalidBundle = new Bundle();
|
| @@ -274,18 +294,19 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| try {
|
| mCustomTabsConnection.lowConfidenceMayLaunchUrl(invalidBundles);
|
| } catch (ClassCastException e) {
|
| - fail();
|
| + Assert.fail();
|
| }
|
| }
|
| });
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| public void testStillHighConfidenceMayLaunchUrlWithSeveralUrls() {
|
| final CustomTabsSessionToken token =
|
| CustomTabsSessionToken.createDummySessionTokenForTesting();
|
| - assertTrue(mCustomTabsConnection.newSession(token));
|
| + Assert.assertTrue(mCustomTabsConnection.newSession(token));
|
| List<Bundle> urls = new ArrayList<>();
|
| Bundle urlBundle = new Bundle();
|
| urlBundle.putParcelable(CustomTabsService.KEY_URL, Uri.parse(URL));
|
| @@ -295,24 +316,26 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - assertNull(WarmupManager.getInstance().takeSpareWebContents(false, false));
|
| + Assert.assertNull(WarmupManager.getInstance().takeSpareWebContents(false, false));
|
| String referrer = mCustomTabsConnection.getReferrerForSession(token).getUrl();
|
| - assertNotNull(mCustomTabsConnection.takePrerenderedUrl(token, URL, referrer));
|
| + Assert.assertNotNull(
|
| + mCustomTabsConnection.takePrerenderedUrl(token, URL, referrer));
|
| }
|
| });
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| public void testPrefetchOnlyNoPrerenderHasSpareWebContents() {
|
| - assertTrue(mCustomTabsConnection.warmup(0));
|
| + Assert.assertTrue(mCustomTabsConnection.warmup(0));
|
| final CustomTabsSessionToken token =
|
| CustomTabsSessionToken.createDummySessionTokenForTesting();
|
| - assertTrue(mCustomTabsConnection.newSession(token));
|
| + Assert.assertTrue(mCustomTabsConnection.newSession(token));
|
|
|
| Bundle extras = new Bundle();
|
| extras.putInt(CustomTabsConnection.DEBUG_OVERRIDE_KEY, CustomTabsConnection.PREFETCH_ONLY);
|
| - assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), extras, null));
|
| + Assert.assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), extras, null));
|
|
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| @@ -322,6 +345,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| });
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| @RetryOnFailure
|
| @@ -330,23 +354,23 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - assertNull(WarmupManager.getInstance().takeSpareWebContents(false, false));
|
| + Assert.assertNull(WarmupManager.getInstance().takeSpareWebContents(false, false));
|
| }
|
| });
|
| - assertTrue(mCustomTabsConnection.mayLaunchUrl(token, null, null, null));
|
| + Assert.assertTrue(mCustomTabsConnection.mayLaunchUrl(token, null, null, null));
|
| // mayLaunchUrl() posts a task, the following has to run after it.
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| String referrer = mCustomTabsConnection.getReferrerForSession(token).getUrl();
|
| - assertNull(mCustomTabsConnection.takePrerenderedUrl(token, URL, referrer));
|
| + Assert.assertNull(mCustomTabsConnection.takePrerenderedUrl(token, URL, referrer));
|
| }
|
| });
|
| }
|
|
|
| private void assertSpareWebContentsNotNullAndDestroy() {
|
| WebContents webContents = WarmupManager.getInstance().takeSpareWebContents(false, false);
|
| - assertNotNull(webContents);
|
| + Assert.assertNotNull(webContents);
|
| webContents.destroy();
|
| }
|
|
|
| @@ -363,7 +387,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| }
|
| Uri uri = url == null ? null : Uri.parse(url);
|
| boolean succeeded = mCustomTabsConnection.mayLaunchUrl(token, uri, null, null);
|
| - assertEquals(shouldSucceed, succeeded);
|
| + Assert.assertEquals(shouldSucceed, succeeded);
|
| return shouldSucceed ? token : null;
|
| }
|
|
|
| @@ -373,6 +397,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| * CustomTabsSessionToken, Uri, android.os.Bundle, java.util.List)}
|
| * returns an error when called with an invalid session ID.
|
| */
|
| + @Test
|
| @SmallTest
|
| public void testNoMayLaunchUrlWithInvalidSessionId() {
|
| assertWarmupAndMayLaunchUrl(
|
| @@ -384,6 +409,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| * {@link CustomTabsConnection#mayLaunchUrl(CustomTabsSessionToken, Uri, Bundle, List)}
|
| * rejects invalid URL schemes.
|
| */
|
| + @Test
|
| @SmallTest
|
| public void testNoMayLaunchUrlWithInvalidScheme() {
|
| assertWarmupAndMayLaunchUrl(null, INVALID_SCHEME_URL, false);
|
| @@ -394,6 +420,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| * {@link CustomTabsConnection#mayLaunchUrl(CustomTabsSessionToken, Uri, Bundle, List)}
|
| * succeeds.
|
| */
|
| + @Test
|
| @SmallTest
|
| public void testMayLaunchUrl() {
|
| assertWarmupAndMayLaunchUrl(null, URL, true);
|
| @@ -404,6 +431,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| * {@link CustomTabsConnection#mayLaunchUrl(CustomTabsSessionToken, Uri, Bundle, List)}
|
| * can be called several times with the same, and different URLs.
|
| */
|
| + @Test
|
| @SmallTest
|
| public void testMultipleMayLaunchUrl() {
|
| CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, true);
|
| @@ -416,6 +444,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| /**
|
| * Tests that sessions are forgotten properly.
|
| */
|
| + @Test
|
| @SmallTest
|
| public void testForgetsSession() {
|
| CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, true);
|
| @@ -430,13 +459,14 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| * the same cgroup for background processes and background _threads_, which
|
| * has been the case through LOLLIPOP_MR1.
|
| */
|
| + @Test
|
| @SmallTest
|
| public void testGetSchedulerGroup() {
|
| if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
|
| - assertNotNull(CustomTabsConnection.getSchedulerGroup(Process.myPid()));
|
| + Assert.assertNotNull(CustomTabsConnection.getSchedulerGroup(Process.myPid()));
|
| String cgroup = CustomTabsConnection.getSchedulerGroup(Process.myPid());
|
| // Tests run in the foreground.
|
| - assertTrue(cgroup.equals("/") || cgroup.equals("/apps"));
|
| + Assert.assertTrue(cgroup.equals("/") || cgroup.equals("/apps"));
|
|
|
| final String[] backgroundThreadCgroup = {null};
|
| Thread backgroundThread = new Thread(new Runnable() {
|
| @@ -451,18 +481,19 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| try {
|
| backgroundThread.join();
|
| } catch (InterruptedException e) {
|
| - fail();
|
| + Assert.fail();
|
| return;
|
| }
|
| String threadCgroup = backgroundThreadCgroup[0];
|
| - assertNotNull(threadCgroup);
|
| - assertTrue(threadCgroup.equals("/bg_non_interactive")
|
| + Assert.assertNotNull(threadCgroup);
|
| + Assert.assertTrue(threadCgroup.equals("/bg_non_interactive")
|
| || threadCgroup.equals("/apps/bg_non_interactive"));
|
| }
|
|
|
| /**
|
| * Tests that predictions are throttled.
|
| */
|
| + @Test
|
| @SmallTest
|
| public void testThrottleMayLaunchUrl() {
|
| CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, true);
|
| @@ -472,12 +503,13 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| if (!mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null)) break;
|
| successfulRequests++;
|
| }
|
| - assertTrue("10 requests in a row should not all succeed.", successfulRequests < 10);
|
| + Assert.assertTrue("10 requests in a row should not all succeed.", successfulRequests < 10);
|
| }
|
|
|
| /**
|
| * Tests that the mayLaunchUrl() throttling is reset after a long enough wait.
|
| */
|
| + @Test
|
| @SmallTest
|
| public void testThrottlingIsReset() {
|
| CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, true);
|
| @@ -488,7 +520,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| try {
|
| Thread.sleep(450); // 2 * MAX_POSSIBLE_DELAY + 50ms
|
| } catch (InterruptedException e) {
|
| - fail();
|
| + Assert.fail();
|
| return;
|
| }
|
| assertWarmupAndMayLaunchUrl(token, URL, true);
|
| @@ -496,7 +528,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| try {
|
| Thread.sleep(150); // MIN_DELAY + 50ms margin
|
| } catch (InterruptedException e) {
|
| - fail();
|
| + Assert.fail();
|
| return;
|
| }
|
| assertWarmupAndMayLaunchUrl(token, URL, true);
|
| @@ -505,6 +537,7 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| /**
|
| * Tests that throttling applies across sessions.
|
| */
|
| + @Test
|
| @SmallTest
|
| public void testThrottlingAcrossSessions() {
|
| CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, true);
|
| @@ -517,53 +550,56 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| assertWarmupAndMayLaunchUrl(token2, URL, false);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| public void testBanningWorks() {
|
| mCustomTabsConnection.ban(mAppContext, Process.myUid());
|
| final CustomTabsSessionToken token =
|
| CustomTabsSessionToken.createDummySessionTokenForTesting();
|
| - assertTrue(mCustomTabsConnection.newSession(token));
|
| + Assert.assertTrue(mCustomTabsConnection.newSession(token));
|
|
|
| - assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null));
|
| + Assert.assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null));
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| assertSpareWebContentsNotNullAndDestroy();
|
| String referrer = mCustomTabsConnection.getReferrerForSession(token).getUrl();
|
| - assertNull(mCustomTabsConnection.takePrerenderedUrl(token, URL, referrer));
|
| + Assert.assertNull(mCustomTabsConnection.takePrerenderedUrl(token, URL, referrer));
|
| }
|
| });
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| public void testBanningDisabledForCellular() {
|
| mCustomTabsConnection.ban(mAppContext, Process.myUid());
|
| final CustomTabsSessionToken token =
|
| CustomTabsSessionToken.createDummySessionTokenForTesting();
|
| - assertTrue(mCustomTabsConnection.newSession(token));
|
| + Assert.assertTrue(mCustomTabsConnection.newSession(token));
|
| mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true);
|
|
|
| - assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null));
|
| + Assert.assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null));
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - assertNull(WarmupManager.getInstance().takeSpareWebContents(false, false));
|
| + Assert.assertNull(WarmupManager.getInstance().takeSpareWebContents(false, false));
|
| String referrer = mCustomTabsConnection.getReferrerForSession(token).getUrl();
|
| WebContents prerender = mCustomTabsConnection.takePrerenderedUrl(
|
| token, URL, referrer);
|
| - assertNotNull(prerender);
|
| + Assert.assertNotNull(prerender);
|
| prerender.destroy();
|
| }
|
| });
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| public void testCellularPrerenderingDoesntOverrideSettings() throws Exception {
|
| CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
|
| - assertTrue(mCustomTabsConnection.newSession(token));
|
| + Assert.assertTrue(mCustomTabsConnection.newSession(token));
|
| mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true);
|
| mCustomTabsConnection.warmup(0);
|
|
|
| @@ -579,7 +615,8 @@ public class CustomTabsConnectionTest extends InstrumentationTestCase {
|
| final boolean enabled = result.get();
|
|
|
| try {
|
| - assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null));
|
| + Assert.assertTrue(
|
| + mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null));
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
|
|