| Index: chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarContainerTest.java
 | 
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarContainerTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarContainerTest.java
 | 
| index 66dccb5178ca325413a3ff472c1c174a2a08284c..b02ac03aca1163be553f22a7246c15f7bc12bc03 100644
 | 
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarContainerTest.java
 | 
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarContainerTest.java
 | 
| @@ -6,30 +6,19 @@
 | 
|  
 | 
|  import android.graphics.Rect;
 | 
|  import android.graphics.Region;
 | 
| -import android.support.test.InstrumentationRegistry;
 | 
|  import android.support.test.filters.MediumTest;
 | 
|  import android.view.ViewGroup;
 | 
|  import android.view.ViewTreeObserver;
 | 
|  import android.widget.TextView;
 | 
|  
 | 
| -import org.junit.After;
 | 
| -import org.junit.Assert;
 | 
| -import org.junit.Before;
 | 
| -import org.junit.Rule;
 | 
| -import org.junit.Test;
 | 
| -import org.junit.runner.RunWith;
 | 
| -
 | 
|  import org.chromium.base.ThreadUtils;
 | 
|  import org.chromium.base.test.util.CallbackHelper;
 | 
| -import org.chromium.base.test.util.CommandLineFlags;
 | 
|  import org.chromium.base.test.util.Feature;
 | 
|  import org.chromium.base.test.util.RetryOnFailure;
 | 
|  import org.chromium.chrome.R;
 | 
|  import org.chromium.chrome.browser.ChromeActivity;
 | 
| -import org.chromium.chrome.browser.ChromeSwitches;
 | 
|  import org.chromium.chrome.browser.preferences.PrefServiceBridge;
 | 
| -import org.chromium.chrome.test.ChromeActivityTestRule;
 | 
| -import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
 | 
| +import org.chromium.chrome.test.ChromeActivityTestCaseBase;
 | 
|  import org.chromium.chrome.test.util.InfoBarTestAnimationListener;
 | 
|  import org.chromium.chrome.test.util.InfoBarUtil;
 | 
|  import org.chromium.content.browser.test.util.Criteria;
 | 
| @@ -44,15 +33,8 @@
 | 
|  /**
 | 
|   * Tests for the InfoBarContainer.
 | 
|   */
 | 
| -@RunWith(ChromeJUnit4ClassRunner.class)
 | 
|  @RetryOnFailure
 | 
| -@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
 | 
| -        ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
 | 
| -public class InfoBarContainerTest {
 | 
| -    @Rule
 | 
| -    public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
 | 
| -            new ChromeActivityTestRule<>(ChromeActivity.class);
 | 
| -
 | 
| +public class InfoBarContainerTest extends ChromeActivityTestCaseBase<ChromeActivity> {
 | 
|      private static final String MESSAGE_TEXT = "Ding dong. Woof. Translate french? Bears!";
 | 
|  
 | 
|      private static final class TestListener implements SimpleConfirmInfoBarBuilder.Listener {
 | 
| @@ -79,47 +61,51 @@
 | 
|      private InfoBarTestAnimationListener mListener;
 | 
|      private EmbeddedTestServer mTestServer;
 | 
|  
 | 
| -    @Before
 | 
| -    public void setUp() throws Exception {
 | 
| -        mActivityTestRule.startMainActivityOnBlankPage();
 | 
| +    public InfoBarContainerTest() {
 | 
| +        super(ChromeActivity.class);
 | 
| +    }
 | 
| +
 | 
| +    @Override
 | 
| +    protected void setUp() throws Exception {
 | 
| +        super.setUp();
 | 
|  
 | 
|          // Register for animation notifications
 | 
|          InfoBarContainer container =
 | 
| -                mActivityTestRule.getActivity().getActivityTab().getInfoBarContainer();
 | 
| +                getActivity().getActivityTab().getInfoBarContainer();
 | 
|          mListener =  new InfoBarTestAnimationListener();
 | 
|          container.addAnimationListener(mListener);
 | 
|  
 | 
| -        mTestServer = EmbeddedTestServer.createAndStartServer(
 | 
| -                InstrumentationRegistry.getInstrumentation().getContext());
 | 
| -    }
 | 
| -
 | 
| -    @After
 | 
| -    public void tearDown() throws Exception {
 | 
| +        mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
 | 
| +    }
 | 
| +
 | 
| +    @Override
 | 
| +    protected void tearDown() throws Exception {
 | 
|          mTestServer.stopAndDestroyServer();
 | 
| +        super.tearDown();
 | 
|      }
 | 
|  
 | 
|      // Adds an infobar to the currrent tab. Blocks until the infobar has been added.
 | 
|      private TestListener addInfoBarToCurrentTab(final boolean expires)
 | 
|              throws InterruptedException, TimeoutException {
 | 
| -        List<InfoBar> infoBars = mActivityTestRule.getInfoBars();
 | 
| +        List<InfoBar> infoBars = getInfoBars();
 | 
|          int previousCount = infoBars.size();
 | 
|  
 | 
|          final TestListener testListener = new TestListener();
 | 
|          ThreadUtils.runOnUiThread(new Runnable() {
 | 
|              @Override
 | 
|              public void run() {
 | 
| -                SimpleConfirmInfoBarBuilder.create(mActivityTestRule.getActivity().getActivityTab(),
 | 
| -                        testListener, InfoBarIdentifier.TEST_INFOBAR, 0, MESSAGE_TEXT, null, null,
 | 
| -                        expires);
 | 
| +                SimpleConfirmInfoBarBuilder.create(getActivity().getActivityTab(),
 | 
| +                        testListener, InfoBarIdentifier.TEST_INFOBAR, 0,
 | 
| +                        MESSAGE_TEXT, null, null, expires);
 | 
|              }
 | 
|          });
 | 
|          mListener.addInfoBarAnimationFinished("InfoBar not added.");
 | 
|  
 | 
|          // Verify it's really there.
 | 
| -        Assert.assertEquals(previousCount + 1, infoBars.size());
 | 
| +        assertEquals(previousCount + 1, infoBars.size());
 | 
|          TextView message =
 | 
|                  (TextView) infoBars.get(previousCount).getView().findViewById(R.id.infobar_message);
 | 
| -        Assert.assertEquals(MESSAGE_TEXT, message.getText().toString());
 | 
| +        assertEquals(MESSAGE_TEXT, message.getText().toString());
 | 
|  
 | 
|          return testListener;
 | 
|      }
 | 
| @@ -130,8 +116,8 @@
 | 
|       */
 | 
|      private void dismissInfoBar(final InfoBar infoBar, TestListener listener)
 | 
|              throws Exception {
 | 
| -        Assert.assertEquals(0, listener.dismissedCallback.getCallCount());
 | 
| -        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
 | 
| +        assertEquals(0, listener.dismissedCallback.getCallCount());
 | 
| +        getInstrumentation().runOnMainSync(new Runnable() {
 | 
|              @Override
 | 
|              public void run() {
 | 
|                  infoBar.onCloseButtonClicked();
 | 
| @@ -139,15 +125,14 @@
 | 
|          });
 | 
|          mListener.removeInfoBarAnimationFinished("InfoBar not removed.");
 | 
|          listener.dismissedCallback.waitForCallback(0, 1);
 | 
| -        Assert.assertEquals(0, listener.primaryButtonCallback.getCallCount());
 | 
| -        Assert.assertEquals(0, listener.secondaryButtonCallback.getCallCount());
 | 
| -        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
 | 
| +        assertEquals(0, listener.primaryButtonCallback.getCallCount());
 | 
| +        assertEquals(0, listener.secondaryButtonCallback.getCallCount());
 | 
| +        getInstrumentation().waitForIdleSync();
 | 
|      }
 | 
|  
 | 
|      /**
 | 
|       * Verifies that infobars added from Java expire or not as expected.
 | 
|       */
 | 
| -    @Test
 | 
|      @MediumTest
 | 
|      @Feature({"Browser"})
 | 
|      public void testInfoBarExpiration() throws Exception {
 | 
| @@ -155,23 +140,23 @@
 | 
|          TestListener infobarListener = addInfoBarToCurrentTab(true);
 | 
|  
 | 
|          // Now navigate, it should expire.
 | 
| -        mActivityTestRule.loadUrl(mTestServer.getURL("/chrome/test/data/android/google.html"));
 | 
| +        loadUrl(mTestServer.getURL("/chrome/test/data/android/google.html"));
 | 
|          mListener.removeInfoBarAnimationFinished("InfoBar not removed.");
 | 
| -        Assert.assertTrue(mActivityTestRule.getInfoBars().isEmpty());
 | 
| -        Assert.assertEquals(0, infobarListener.dismissedCallback.getCallCount());
 | 
| -        Assert.assertEquals(0, infobarListener.primaryButtonCallback.getCallCount());
 | 
| -        Assert.assertEquals(0, infobarListener.secondaryButtonCallback.getCallCount());
 | 
| +        assertTrue(getInfoBars().isEmpty());
 | 
| +        assertEquals(0, infobarListener.dismissedCallback.getCallCount());
 | 
| +        assertEquals(0, infobarListener.primaryButtonCallback.getCallCount());
 | 
| +        assertEquals(0, infobarListener.secondaryButtonCallback.getCallCount());
 | 
|  
 | 
|          // Now test a non-expiring infobar.
 | 
|          TestListener persistentListener = addInfoBarToCurrentTab(false);
 | 
|  
 | 
|          // Navigate, it should still be there.
 | 
| -        mActivityTestRule.loadUrl(mTestServer.getURL("/chrome/test/data/android/about.html"));
 | 
| -        List<InfoBar> infoBars = mActivityTestRule.getInfoBars();
 | 
| -        Assert.assertEquals(1, infoBars.size());
 | 
| +        loadUrl(mTestServer.getURL("/chrome/test/data/android/about.html"));
 | 
| +        List<InfoBar> infoBars = getInfoBars();
 | 
| +        assertEquals(1, infoBars.size());
 | 
|          TextView message =
 | 
|                  (TextView) infoBars.get(0).getView().findViewById(R.id.infobar_message);
 | 
| -        Assert.assertEquals(MESSAGE_TEXT, message.getText().toString());
 | 
| +        assertEquals(MESSAGE_TEXT, message.getText().toString());
 | 
|  
 | 
|          // Close the infobar.
 | 
|          dismissInfoBar(infoBars.get(0), persistentListener);
 | 
| @@ -193,7 +178,6 @@
 | 
|       * The behavior when prerender is on/off is different as in the prerender case the infobars are
 | 
|       * added when we swap tabs.
 | 
|       */
 | 
| -    @Test
 | 
|      @MediumTest
 | 
|      @Feature({"Browser"})
 | 
|      public void testInfoBarExpirationNoPrerender() throws Exception {
 | 
| @@ -219,89 +203,80 @@
 | 
|       * Tests that adding and then immediately dismissing an infobar works as expected (and does not
 | 
|       * assert).
 | 
|       */
 | 
| -    @Test
 | 
|      @MediumTest
 | 
|      @Feature({"Browser"})
 | 
|      public void testQuickAddOneAndDismiss() throws Exception {
 | 
|          final TestListener infobarListener = addInfoBarToCurrentTab(false);
 | 
| -        Assert.assertEquals(1, mActivityTestRule.getInfoBars().size());
 | 
| -        final InfoBar infoBar = mActivityTestRule.getInfoBars().get(0);
 | 
| +        assertEquals(1, getInfoBars().size());
 | 
| +        final InfoBar infoBar = getInfoBars().get(0);
 | 
|          dismissInfoBar(infoBar, infobarListener);
 | 
| -        Assert.assertTrue(mActivityTestRule.getInfoBars().isEmpty());
 | 
| +        assertTrue(getInfoBars().isEmpty());
 | 
|      }
 | 
|  
 | 
|      /**
 | 
|       * Tests that we don't assert when a tab is getting closed while an infobar is being shown and
 | 
|       * had been removed.
 | 
|       */
 | 
| -    @Test
 | 
|      @MediumTest
 | 
|      @Feature({"Browser"})
 | 
|      public void testCloseTabOnAdd() throws Exception {
 | 
| -        mActivityTestRule.loadUrl(mTestServer.getURL("/chrome/test/data/android/google.html"));
 | 
| +        loadUrl(mTestServer.getURL("/chrome/test/data/android/google.html"));
 | 
|  
 | 
|          final TestListener infobarListener = addInfoBarToCurrentTab(false);
 | 
| -        Assert.assertEquals(1, mActivityTestRule.getInfoBars().size());
 | 
| -        final InfoBar infoBar = mActivityTestRule.getInfoBars().get(0);
 | 
| +        assertEquals(1, getInfoBars().size());
 | 
| +        final InfoBar infoBar = getInfoBars().get(0);
 | 
|  
 | 
|          ThreadUtils.runOnUiThreadBlocking(new Runnable() {
 | 
|              @Override
 | 
|              public void run() {
 | 
| -                Assert.assertEquals(0, infobarListener.dismissedCallback.getCallCount());
 | 
| +                assertEquals(0, infobarListener.dismissedCallback.getCallCount());
 | 
|                  infoBar.onCloseButtonClicked();
 | 
| -                mActivityTestRule.getActivity().getTabModelSelector().closeTab(
 | 
| -                        mActivityTestRule.getActivity().getActivityTab());
 | 
| +                getActivity().getTabModelSelector().closeTab(getActivity().getActivityTab());
 | 
|              }
 | 
|          });
 | 
|  
 | 
|          infobarListener.dismissedCallback.waitForCallback(0, 1);
 | 
| -        Assert.assertEquals(0, infobarListener.primaryButtonCallback.getCallCount());
 | 
| -        Assert.assertEquals(0, infobarListener.secondaryButtonCallback.getCallCount());
 | 
| +        assertEquals(0, infobarListener.primaryButtonCallback.getCallCount());
 | 
| +        assertEquals(0, infobarListener.secondaryButtonCallback.getCallCount());
 | 
|      }
 | 
|  
 | 
|      /**
 | 
|       * Tests that the x button in the infobar does close the infobar and that the event is not
 | 
|       * propagated to the ContentView.
 | 
|       */
 | 
| -    @Test
 | 
|      @MediumTest
 | 
|      @Feature({"Browser"})
 | 
|      public void testCloseButton() throws Exception {
 | 
| -        mActivityTestRule.loadUrl(
 | 
| -                mTestServer.getURL("/chrome/test/data/android/click_listener.html"));
 | 
| +        loadUrl(mTestServer.getURL("/chrome/test/data/android/click_listener.html"));
 | 
|          TestListener infobarListener = addInfoBarToCurrentTab(false);
 | 
|  
 | 
|          // Now press the close button.
 | 
| -        Assert.assertEquals(0, infobarListener.dismissedCallback.getCallCount());
 | 
| -        Assert.assertTrue("Close button wasn't found",
 | 
| -                InfoBarUtil.clickCloseButton(mActivityTestRule.getInfoBars().get(0)));
 | 
| +        assertEquals(0, infobarListener.dismissedCallback.getCallCount());
 | 
| +        assertTrue("Close button wasn't found", InfoBarUtil.clickCloseButton(getInfoBars().get(0)));
 | 
|          mListener.removeInfoBarAnimationFinished("Infobar not removed.");
 | 
|          infobarListener.dismissedCallback.waitForCallback(0, 1);
 | 
| -        Assert.assertEquals(0, infobarListener.primaryButtonCallback.getCallCount());
 | 
| -        Assert.assertEquals(0, infobarListener.secondaryButtonCallback.getCallCount());
 | 
| +        assertEquals(0, infobarListener.primaryButtonCallback.getCallCount());
 | 
| +        assertEquals(0, infobarListener.secondaryButtonCallback.getCallCount());
 | 
|  
 | 
|          // The page should not have received the click.
 | 
| -        Assert.assertTrue("The page recieved the click.",
 | 
| -                !Boolean.parseBoolean(
 | 
| -                        mActivityTestRule.runJavaScriptCodeInCurrentTab("wasClicked")));
 | 
| +        assertTrue("The page recieved the click.",
 | 
| +                !Boolean.parseBoolean(runJavaScriptCodeInCurrentTab("wasClicked")));
 | 
|      }
 | 
|  
 | 
|      /**
 | 
|       * Tests that adding and removing correctly manages the transparent region, which allows for
 | 
|       * optimizations in SurfaceFlinger (less overlays).
 | 
|       */
 | 
| -    @Test
 | 
|      @MediumTest
 | 
|      @Feature({"Browser"})
 | 
|      public void testAddAndDismissSurfaceFlingerOverlays() throws Exception {
 | 
| -        final ViewGroup decorView =
 | 
| -                (ViewGroup) mActivityTestRule.getActivity().getWindow().getDecorView();
 | 
| +        final ViewGroup decorView = (ViewGroup)  getActivity().getWindow().getDecorView();
 | 
|          final InfoBarContainer infoBarContainer =
 | 
| -                mActivityTestRule.getActivity().getActivityTab().getInfoBarContainer();
 | 
| +                getActivity().getActivityTab().getInfoBarContainer();
 | 
|  
 | 
|          // Detect layouts. Note this doesn't actually need to be atomic (just final).
 | 
|          final AtomicInteger layoutCount = new AtomicInteger();
 | 
| -        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
 | 
| +        getInstrumentation().runOnMainSync(new Runnable() {
 | 
|              @Override
 | 
|              public void run() {
 | 
|                  decorView.getViewTreeObserver().addOnGlobalLayoutListener(
 | 
| @@ -316,8 +291,8 @@
 | 
|  
 | 
|          // First add an infobar.
 | 
|          TestListener infobarListener = addInfoBarToCurrentTab(false);
 | 
| -        Assert.assertEquals(1, mActivityTestRule.getInfoBars().size());
 | 
| -        final InfoBar infoBar = mActivityTestRule.getInfoBars().get(0);
 | 
| +        assertEquals(1, getInfoBars().size());
 | 
| +        final InfoBar infoBar = getInfoBars().get(0);
 | 
|  
 | 
|          // A layout must occur to recalculate the transparent region.
 | 
|          CriteriaHelper.pollUiThread(
 | 
| @@ -332,7 +307,7 @@
 | 
|          final Rect fullDisplayFrameMinusContainer = new Rect();
 | 
|          final Rect containerDisplayFrame = new Rect();
 | 
|  
 | 
| -        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
 | 
| +        getInstrumentation().runOnMainSync(new Runnable() {
 | 
|              @Override
 | 
|              public void run() {
 | 
|                  decorView.getWindowVisibleDisplayFrame(fullDisplayFrame);
 | 
| @@ -349,7 +324,7 @@
 | 
|                  // The InfoBarContainer subtracts itself from the transparent region.
 | 
|                  Region transparentRegion = new Region(fullDisplayFrame);
 | 
|                  infoBarContainer.gatherTransparentRegion(transparentRegion);
 | 
| -                Assert.assertEquals(transparentRegion.getBounds(), fullDisplayFrameMinusContainer);
 | 
| +                assertEquals(transparentRegion.getBounds(), fullDisplayFrameMinusContainer);
 | 
|              }
 | 
|          });
 | 
|  
 | 
| @@ -366,7 +341,7 @@
 | 
|                      }
 | 
|                  });
 | 
|  
 | 
| -        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
 | 
| +        getInstrumentation().runOnMainSync(new Runnable() {
 | 
|              @Override
 | 
|              public void run() {
 | 
|                  // The InfoBarContainer should no longer be subtracted from the transparent region.
 | 
| @@ -377,7 +352,7 @@
 | 
|                  decorView.gatherTransparentRegion(transparentRegion);
 | 
|                  Region opaqueRegion = new Region(fullDisplayFrame);
 | 
|                  opaqueRegion.op(transparentRegion, Region.Op.DIFFERENCE);
 | 
| -                Assert.assertFalse(opaqueRegion.getBounds().intersect(containerDisplayFrame));
 | 
| +                assertFalse(opaqueRegion.getBounds().intersect(containerDisplayFrame));
 | 
|              }
 | 
|          });
 | 
|  
 | 
| @@ -385,4 +360,9 @@
 | 
|          // - adb shell dumpsys SurfaceFlinger
 | 
|          // - Observe that Clank's overlay size changes (or disappears if URLbar is also gone).
 | 
|      }
 | 
| +
 | 
| +    @Override
 | 
| +    public void startMainActivity() throws InterruptedException {
 | 
| +        startMainActivityOnBlankPage();
 | 
| +    }
 | 
|  }
 | 
| 
 |