| 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 081466bc41c2b7c096e933b97732b050293b88f8..502c78a939f165cae9700456da944b8a4e6e3f26 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,19 +6,30 @@ package org.chromium.chrome.browser.infobar;
|
|
|
| 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.ChromeActivityTestCaseBase;
|
| +import org.chromium.chrome.test.ChromeActivityTestRule;
|
| +import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| import org.chromium.chrome.test.util.InfoBarTestAnimationListener;
|
| import org.chromium.chrome.test.util.InfoBarUtil;
|
| import org.chromium.content.browser.test.util.Criteria;
|
| @@ -33,8 +44,15 @@ import java.util.concurrent.atomic.AtomicInteger;
|
| /**
|
| * Tests for the InfoBarContainer.
|
| */
|
| +@RunWith(ChromeJUnit4ClassRunner.class)
|
| @RetryOnFailure
|
| -public class InfoBarContainerTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| +@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| + ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
|
| +public class InfoBarContainerTest {
|
| + @Rule
|
| + public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
|
| + new ChromeActivityTestRule<>(ChromeActivity.class);
|
| +
|
| private static final String MESSAGE_TEXT = "Ding dong. Woof. Translate french? Bears!";
|
|
|
| private static final class TestListener implements SimpleConfirmInfoBarBuilder.Listener {
|
| @@ -61,51 +79,47 @@ public class InfoBarContainerTest extends ChromeActivityTestCaseBase<ChromeActiv
|
| private InfoBarTestAnimationListener mListener;
|
| private EmbeddedTestServer mTestServer;
|
|
|
| - public InfoBarContainerTest() {
|
| - super(ChromeActivity.class);
|
| - }
|
| -
|
| - @Override
|
| - protected void setUp() throws Exception {
|
| - super.setUp();
|
| + @Before
|
| + public void setUp() throws Exception {
|
| + mActivityTestRule.startMainActivityOnBlankPage();
|
|
|
| // Register for animation notifications
|
| InfoBarContainer container =
|
| - getActivity().getActivityTab().getInfoBarContainer();
|
| + mActivityTestRule.getActivity().getActivityTab().getInfoBarContainer();
|
| mListener = new InfoBarTestAnimationListener();
|
| container.setAnimationListener(mListener);
|
|
|
| - mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
|
| + mTestServer = EmbeddedTestServer.createAndStartServer(
|
| + InstrumentationRegistry.getInstrumentation().getContext());
|
| }
|
|
|
| - @Override
|
| - protected void tearDown() throws Exception {
|
| + @After
|
| + public 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 = getInfoBars();
|
| + List<InfoBar> infoBars = mActivityTestRule.getInfoBars();
|
| int previousCount = infoBars.size();
|
|
|
| final TestListener testListener = new TestListener();
|
| ThreadUtils.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| - SimpleConfirmInfoBarBuilder.create(getActivity().getActivityTab(),
|
| - testListener, InfoBarIdentifier.TEST_INFOBAR, 0,
|
| - MESSAGE_TEXT, null, null, expires);
|
| + SimpleConfirmInfoBarBuilder.create(mActivityTestRule.getActivity().getActivityTab(),
|
| + testListener, InfoBarIdentifier.TEST_INFOBAR, 0, MESSAGE_TEXT, null, null,
|
| + expires);
|
| }
|
| });
|
| mListener.addInfoBarAnimationFinished("InfoBar not added.");
|
|
|
| // Verify it's really there.
|
| - assertEquals(previousCount + 1, infoBars.size());
|
| + Assert.assertEquals(previousCount + 1, infoBars.size());
|
| TextView message =
|
| (TextView) infoBars.get(previousCount).getView().findViewById(R.id.infobar_message);
|
| - assertEquals(MESSAGE_TEXT, message.getText().toString());
|
| + Assert.assertEquals(MESSAGE_TEXT, message.getText().toString());
|
|
|
| return testListener;
|
| }
|
| @@ -116,8 +130,8 @@ public class InfoBarContainerTest extends ChromeActivityTestCaseBase<ChromeActiv
|
| */
|
| private void dismissInfoBar(final InfoBar infoBar, TestListener listener)
|
| throws Exception {
|
| - assertEquals(0, listener.dismissedCallback.getCallCount());
|
| - getInstrumentation().runOnMainSync(new Runnable() {
|
| + Assert.assertEquals(0, listener.dismissedCallback.getCallCount());
|
| + InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
|
| @Override
|
| public void run() {
|
| infoBar.onCloseButtonClicked();
|
| @@ -125,14 +139,15 @@ public class InfoBarContainerTest extends ChromeActivityTestCaseBase<ChromeActiv
|
| });
|
| mListener.removeInfoBarAnimationFinished("InfoBar not removed.");
|
| listener.dismissedCallback.waitForCallback(0, 1);
|
| - assertEquals(0, listener.primaryButtonCallback.getCallCount());
|
| - assertEquals(0, listener.secondaryButtonCallback.getCallCount());
|
| - getInstrumentation().waitForIdleSync();
|
| + Assert.assertEquals(0, listener.primaryButtonCallback.getCallCount());
|
| + Assert.assertEquals(0, listener.secondaryButtonCallback.getCallCount());
|
| + InstrumentationRegistry.getInstrumentation().waitForIdleSync();
|
| }
|
|
|
| /**
|
| * Verifies that infobars added from Java expire or not as expected.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"Browser"})
|
| public void testInfoBarExpiration() throws Exception {
|
| @@ -140,23 +155,23 @@ public class InfoBarContainerTest extends ChromeActivityTestCaseBase<ChromeActiv
|
| TestListener infobarListener = addInfoBarToCurrentTab(true);
|
|
|
| // Now navigate, it should expire.
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/google.html"));
|
| + mActivityTestRule.loadUrl(mTestServer.getURL("/chrome/test/data/android/google.html"));
|
| mListener.removeInfoBarAnimationFinished("InfoBar not removed.");
|
| - assertTrue(getInfoBars().isEmpty());
|
| - assertEquals(0, infobarListener.dismissedCallback.getCallCount());
|
| - assertEquals(0, infobarListener.primaryButtonCallback.getCallCount());
|
| - assertEquals(0, infobarListener.secondaryButtonCallback.getCallCount());
|
| + Assert.assertTrue(mActivityTestRule.getInfoBars().isEmpty());
|
| + Assert.assertEquals(0, infobarListener.dismissedCallback.getCallCount());
|
| + Assert.assertEquals(0, infobarListener.primaryButtonCallback.getCallCount());
|
| + Assert.assertEquals(0, infobarListener.secondaryButtonCallback.getCallCount());
|
|
|
| // Now test a non-expiring infobar.
|
| TestListener persistentListener = addInfoBarToCurrentTab(false);
|
|
|
| // Navigate, it should still be there.
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/about.html"));
|
| - List<InfoBar> infoBars = getInfoBars();
|
| - assertEquals(1, infoBars.size());
|
| + mActivityTestRule.loadUrl(mTestServer.getURL("/chrome/test/data/android/about.html"));
|
| + List<InfoBar> infoBars = mActivityTestRule.getInfoBars();
|
| + Assert.assertEquals(1, infoBars.size());
|
| TextView message =
|
| (TextView) infoBars.get(0).getView().findViewById(R.id.infobar_message);
|
| - assertEquals(MESSAGE_TEXT, message.getText().toString());
|
| + Assert.assertEquals(MESSAGE_TEXT, message.getText().toString());
|
|
|
| // Close the infobar.
|
| dismissInfoBar(infoBars.get(0), persistentListener);
|
| @@ -178,6 +193,7 @@ public class InfoBarContainerTest extends ChromeActivityTestCaseBase<ChromeActiv
|
| * 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 {
|
| @@ -203,80 +219,89 @@ public class InfoBarContainerTest extends ChromeActivityTestCaseBase<ChromeActiv
|
| * 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);
|
| - assertEquals(1, getInfoBars().size());
|
| - final InfoBar infoBar = getInfoBars().get(0);
|
| + Assert.assertEquals(1, mActivityTestRule.getInfoBars().size());
|
| + final InfoBar infoBar = mActivityTestRule.getInfoBars().get(0);
|
| dismissInfoBar(infoBar, infobarListener);
|
| - assertTrue(getInfoBars().isEmpty());
|
| + Assert.assertTrue(mActivityTestRule.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 {
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/google.html"));
|
| + mActivityTestRule.loadUrl(mTestServer.getURL("/chrome/test/data/android/google.html"));
|
|
|
| final TestListener infobarListener = addInfoBarToCurrentTab(false);
|
| - assertEquals(1, getInfoBars().size());
|
| - final InfoBar infoBar = getInfoBars().get(0);
|
| + Assert.assertEquals(1, mActivityTestRule.getInfoBars().size());
|
| + final InfoBar infoBar = mActivityTestRule.getInfoBars().get(0);
|
|
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - assertEquals(0, infobarListener.dismissedCallback.getCallCount());
|
| + Assert.assertEquals(0, infobarListener.dismissedCallback.getCallCount());
|
| infoBar.onCloseButtonClicked();
|
| - getActivity().getTabModelSelector().closeTab(getActivity().getActivityTab());
|
| + mActivityTestRule.getActivity().getTabModelSelector().closeTab(
|
| + mActivityTestRule.getActivity().getActivityTab());
|
| }
|
| });
|
|
|
| infobarListener.dismissedCallback.waitForCallback(0, 1);
|
| - assertEquals(0, infobarListener.primaryButtonCallback.getCallCount());
|
| - assertEquals(0, infobarListener.secondaryButtonCallback.getCallCount());
|
| + Assert.assertEquals(0, infobarListener.primaryButtonCallback.getCallCount());
|
| + Assert.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 {
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/click_listener.html"));
|
| + mActivityTestRule.loadUrl(
|
| + mTestServer.getURL("/chrome/test/data/android/click_listener.html"));
|
| TestListener infobarListener = addInfoBarToCurrentTab(false);
|
|
|
| // Now press the close button.
|
| - assertEquals(0, infobarListener.dismissedCallback.getCallCount());
|
| - assertTrue("Close button wasn't found", InfoBarUtil.clickCloseButton(getInfoBars().get(0)));
|
| + Assert.assertEquals(0, infobarListener.dismissedCallback.getCallCount());
|
| + Assert.assertTrue("Close button wasn't found",
|
| + InfoBarUtil.clickCloseButton(mActivityTestRule.getInfoBars().get(0)));
|
| mListener.removeInfoBarAnimationFinished("Infobar not removed.");
|
| infobarListener.dismissedCallback.waitForCallback(0, 1);
|
| - assertEquals(0, infobarListener.primaryButtonCallback.getCallCount());
|
| - assertEquals(0, infobarListener.secondaryButtonCallback.getCallCount());
|
| + Assert.assertEquals(0, infobarListener.primaryButtonCallback.getCallCount());
|
| + Assert.assertEquals(0, infobarListener.secondaryButtonCallback.getCallCount());
|
|
|
| // The page should not have received the click.
|
| - assertTrue("The page recieved the click.",
|
| - !Boolean.parseBoolean(runJavaScriptCodeInCurrentTab("wasClicked")));
|
| + Assert.assertTrue("The page recieved the click.",
|
| + !Boolean.parseBoolean(
|
| + mActivityTestRule.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) getActivity().getWindow().getDecorView();
|
| + final ViewGroup decorView =
|
| + (ViewGroup) mActivityTestRule.getActivity().getWindow().getDecorView();
|
| final InfoBarContainer infoBarContainer =
|
| - getActivity().getActivityTab().getInfoBarContainer();
|
| + mActivityTestRule.getActivity().getActivityTab().getInfoBarContainer();
|
|
|
| // Detect layouts. Note this doesn't actually need to be atomic (just final).
|
| final AtomicInteger layoutCount = new AtomicInteger();
|
| - getInstrumentation().runOnMainSync(new Runnable() {
|
| + InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
|
| @Override
|
| public void run() {
|
| decorView.getViewTreeObserver().addOnGlobalLayoutListener(
|
| @@ -291,8 +316,8 @@ public class InfoBarContainerTest extends ChromeActivityTestCaseBase<ChromeActiv
|
|
|
| // First add an infobar.
|
| TestListener infobarListener = addInfoBarToCurrentTab(false);
|
| - assertEquals(1, getInfoBars().size());
|
| - final InfoBar infoBar = getInfoBars().get(0);
|
| + Assert.assertEquals(1, mActivityTestRule.getInfoBars().size());
|
| + final InfoBar infoBar = mActivityTestRule.getInfoBars().get(0);
|
|
|
| // A layout must occur to recalculate the transparent region.
|
| CriteriaHelper.pollUiThread(
|
| @@ -307,7 +332,7 @@ public class InfoBarContainerTest extends ChromeActivityTestCaseBase<ChromeActiv
|
| final Rect fullDisplayFrameMinusContainer = new Rect();
|
| final Rect containerDisplayFrame = new Rect();
|
|
|
| - getInstrumentation().runOnMainSync(new Runnable() {
|
| + InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
|
| @Override
|
| public void run() {
|
| decorView.getWindowVisibleDisplayFrame(fullDisplayFrame);
|
| @@ -324,7 +349,7 @@ public class InfoBarContainerTest extends ChromeActivityTestCaseBase<ChromeActiv
|
| // The InfoBarContainer subtracts itself from the transparent region.
|
| Region transparentRegion = new Region(fullDisplayFrame);
|
| infoBarContainer.gatherTransparentRegion(transparentRegion);
|
| - assertEquals(transparentRegion.getBounds(), fullDisplayFrameMinusContainer);
|
| + Assert.assertEquals(transparentRegion.getBounds(), fullDisplayFrameMinusContainer);
|
| }
|
| });
|
|
|
| @@ -341,7 +366,7 @@ public class InfoBarContainerTest extends ChromeActivityTestCaseBase<ChromeActiv
|
| }
|
| });
|
|
|
| - getInstrumentation().runOnMainSync(new Runnable() {
|
| + InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
|
| @Override
|
| public void run() {
|
| // The InfoBarContainer should no longer be subtracted from the transparent region.
|
| @@ -352,7 +377,7 @@ public class InfoBarContainerTest extends ChromeActivityTestCaseBase<ChromeActiv
|
| decorView.gatherTransparentRegion(transparentRegion);
|
| Region opaqueRegion = new Region(fullDisplayFrame);
|
| opaqueRegion.op(transparentRegion, Region.Op.DIFFERENCE);
|
| - assertFalse(opaqueRegion.getBounds().intersect(containerDisplayFrame));
|
| + Assert.assertFalse(opaqueRegion.getBounds().intersect(containerDisplayFrame));
|
| }
|
| });
|
|
|
| @@ -360,9 +385,4 @@ public class InfoBarContainerTest extends ChromeActivityTestCaseBase<ChromeActiv
|
| // - 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();
|
| - }
|
| }
|
|
|