Index: chrome/android/javatests/src/org/chromium/chrome/browser/infobar/SearchGeolocationDisclosureInfoBarTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/SearchGeolocationDisclosureInfoBarTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/SearchGeolocationDisclosureInfoBarTest.java |
index 248e48d47494d1202da6f91d7aa8ec325b264271..6fafb5ebcab050063d4fdd91bb0954c68cb9430f 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/SearchGeolocationDisclosureInfoBarTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/SearchGeolocationDisclosureInfoBarTest.java |
@@ -4,16 +4,26 @@ |
package org.chromium.chrome.browser.infobar; |
+import android.support.test.InstrumentationRegistry; |
import android.support.test.filters.SmallTest; |
+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.metrics.RecordHistogram; |
import org.chromium.base.test.util.CommandLineFlags; |
import org.chromium.base.test.util.Feature; |
import org.chromium.chrome.browser.ChromeActivity; |
+import org.chromium.chrome.browser.ChromeSwitches; |
import org.chromium.chrome.browser.SearchGeolocationDisclosureTabHelper; |
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.net.test.EmbeddedTestServer; |
@@ -21,8 +31,10 @@ import org.chromium.net.test.EmbeddedTestServer; |
import java.util.concurrent.TimeoutException; |
/** Tests for the SearchGeolocationDisclosureInfobar. */ |
-public class SearchGeolocationDisclosureInfoBarTest |
- extends ChromeActivityTestCaseBase<ChromeActivity> { |
+@RunWith(ChromeJUnit4ClassRunner.class) |
+@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
+public class SearchGeolocationDisclosureInfoBarTest { |
private static final String SEARCH_PAGE = "/chrome/test/data/android/google.html"; |
private static final String ENABLE_NEW_DISCLOSURE_FEATURE = |
"enable-features=ConsistentOmniboxGeolocation"; |
@@ -31,19 +43,16 @@ public class SearchGeolocationDisclosureInfoBarTest |
private EmbeddedTestServer mTestServer; |
- public SearchGeolocationDisclosureInfoBarTest() { |
- super(ChromeActivity.class); |
- } |
+ @Rule |
+ public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
+ new ChromeActivityTestRule<>(ChromeActivity.class); |
- @Override |
- public void startMainActivity() throws InterruptedException { |
- startMainActivityOnBlankPage(); |
- } |
- @Override |
- protected void setUp() throws Exception { |
- super.setUp(); |
- mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext()); |
+ @Before |
+ public void setUp() throws Exception { |
+ mActivityTestRule.startMainActivityOnBlankPage(); |
+ mTestServer = EmbeddedTestServer.createAndStartServer( |
+ InstrumentationRegistry.getInstrumentation().getContext()); |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@Override |
public void run() { |
@@ -52,140 +61,164 @@ public class SearchGeolocationDisclosureInfoBarTest |
}); |
} |
- @Override |
- protected void tearDown() throws Exception { |
- mTestServer.stopAndDestroyServer(); |
- super.tearDown(); |
+ @After |
+ public void tearDown() throws Exception { |
+ if (mTestServer != null) mTestServer.stopAndDestroyServer(); |
} |
+ @Test |
@SmallTest |
@Feature({"Browser", "Main"}) |
@CommandLineFlags.Add(ENABLE_NEW_DISCLOSURE_FEATURE) |
public void testInfoBarAppears() throws InterruptedException, TimeoutException { |
SearchGeolocationDisclosureTabHelper.setIgnoreUrlChecksForTesting(); |
- assertEquals("Wrong starting infobar count", 0, getInfoBars().size()); |
+ Assert.assertEquals( |
+ "Wrong starting infobar count", 0, mActivityTestRule.getInfoBars().size()); |
// Infobar should appear when doing the first search. |
- InfoBarContainer container = getActivity().getActivityTab().getInfoBarContainer(); |
+ InfoBarContainer container = |
+ mActivityTestRule.getActivity().getActivityTab().getInfoBarContainer(); |
InfoBarTestAnimationListener listener = new InfoBarTestAnimationListener(); |
container.addAnimationListener(listener); |
- loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
+ mActivityTestRule.loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
// Note: the number of infobars is checked immediately after the URL is loaded, unlike in |
// other infobar tests where it is checked after animations have completed. This is because |
// (a) in this case it should work, as these infobars are added as part of the URL loading |
// process, and |
// (b) if this doesn't work, it is important to catch it as otherwise the checks that |
// infobars haven't being shown are invalid. |
- assertEquals("Wrong infobar count after search", 1, getInfoBars().size()); |
+ Assert.assertEquals( |
+ "Wrong infobar count after search", 1, mActivityTestRule.getInfoBars().size()); |
listener.addInfoBarAnimationFinished("InfoBar not added."); |
// Infobar should not appear again on the same day. |
- loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
+ mActivityTestRule.loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
// There can be a delay from infobars being removed in the native InfobarManager and them |
// being removed in the Java container, so wait until the infobar has really gone. |
- InfoBarUtil.waitUntilNoInfoBarsExist(getInfoBars()); |
- assertEquals("Wrong infobar count after search", 0, getInfoBars().size()); |
+ InfoBarUtil.waitUntilNoInfoBarsExist(mActivityTestRule.getInfoBars()); |
+ Assert.assertEquals( |
+ "Wrong infobar count after search", 0, mActivityTestRule.getInfoBars().size()); |
// Infobar should appear again the next day. |
SearchGeolocationDisclosureTabHelper.setDayOffsetForTesting(1); |
listener = new InfoBarTestAnimationListener(); |
container.addAnimationListener(listener); |
- loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
- assertEquals("Wrong infobar count after search", 1, getInfoBars().size()); |
+ mActivityTestRule.loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
+ Assert.assertEquals( |
+ "Wrong infobar count after search", 1, mActivityTestRule.getInfoBars().size()); |
listener.addInfoBarAnimationFinished("InfoBar not added."); |
// Infobar should not appear again on the same day. |
- loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
- InfoBarUtil.waitUntilNoInfoBarsExist(getInfoBars()); |
- assertEquals("Wrong infobar count after search", 0, getInfoBars().size()); |
+ mActivityTestRule.loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
+ InfoBarUtil.waitUntilNoInfoBarsExist(mActivityTestRule.getInfoBars()); |
+ Assert.assertEquals( |
+ "Wrong infobar count after search", 0, mActivityTestRule.getInfoBars().size()); |
// Infobar should appear again the next day. |
SearchGeolocationDisclosureTabHelper.setDayOffsetForTesting(2); |
listener = new InfoBarTestAnimationListener(); |
container.addAnimationListener(listener); |
- loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
- assertEquals("Wrong infobar count after search", 1, getInfoBars().size()); |
+ mActivityTestRule.loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
+ Assert.assertEquals( |
+ "Wrong infobar count after search", 1, mActivityTestRule.getInfoBars().size()); |
listener.addInfoBarAnimationFinished("InfoBar not added."); |
// Infobar should not appear again on the same day. |
- loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
- InfoBarUtil.waitUntilNoInfoBarsExist(getInfoBars()); |
- assertEquals("Wrong infobar count after search", 0, getInfoBars().size()); |
+ mActivityTestRule.loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
+ InfoBarUtil.waitUntilNoInfoBarsExist(mActivityTestRule.getInfoBars()); |
+ Assert.assertEquals( |
+ "Wrong infobar count after search", 0, mActivityTestRule.getInfoBars().size()); |
// Infobar has appeared three times now, it should not appear again. |
SearchGeolocationDisclosureTabHelper.setDayOffsetForTesting(3); |
- loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
- assertEquals("Wrong infobar count after search", 0, getInfoBars().size()); |
+ mActivityTestRule.loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
+ Assert.assertEquals( |
+ "Wrong infobar count after search", 0, mActivityTestRule.getInfoBars().size()); |
// Check histograms have been recorded. |
- assertEquals("Wrong pre-disclosure metric", 1, |
+ Assert.assertEquals("Wrong pre-disclosure metric", 1, |
RecordHistogram.getHistogramValueCountForTesting( |
"GeolocationDisclosure.PreDisclosureDSESetting", 1)); |
- assertEquals("Wrong post-disclosure metric", 1, |
+ Assert.assertEquals("Wrong post-disclosure metric", 1, |
RecordHistogram.getHistogramValueCountForTesting( |
"GeolocationDisclosure.PostDisclosureDSESetting", 1)); |
} |
+ @Test |
@SmallTest |
@Feature({"Browser", "Main"}) |
@CommandLineFlags.Add(ENABLE_NEW_DISCLOSURE_FEATURE) |
public void testInfoBarDismiss() throws InterruptedException, TimeoutException { |
SearchGeolocationDisclosureTabHelper.setIgnoreUrlChecksForTesting(); |
- assertEquals("Wrong starting infobar count", 0, getInfoBars().size()); |
+ Assert.assertEquals( |
+ "Wrong starting infobar count", 0, mActivityTestRule.getInfoBars().size()); |
// Infobar should appear when doing the first search. |
- InfoBarContainer container = getActivity().getActivityTab().getInfoBarContainer(); |
+ InfoBarContainer container = |
+ mActivityTestRule.getActivity().getActivityTab().getInfoBarContainer(); |
InfoBarTestAnimationListener listener = new InfoBarTestAnimationListener(); |
container.addAnimationListener(listener); |
- loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
- assertEquals("Wrong infobar count after search", 1, getInfoBars().size()); |
+ mActivityTestRule.loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
+ Assert.assertEquals( |
+ "Wrong infobar count after search", 1, mActivityTestRule.getInfoBars().size()); |
listener.addInfoBarAnimationFinished("InfoBar not added."); |
// Dismiss the infobar. |
- assertTrue(InfoBarUtil.clickCloseButton(getInfoBars().get(0))); |
+ Assert.assertTrue(InfoBarUtil.clickCloseButton(mActivityTestRule.getInfoBars().get(0))); |
// Infobar should not appear again on the same day. |
- loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
- InfoBarUtil.waitUntilNoInfoBarsExist(getInfoBars()); |
- assertEquals("Wrong infobar count after search", 0, getInfoBars().size()); |
+ mActivityTestRule.loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
+ InfoBarUtil.waitUntilNoInfoBarsExist(mActivityTestRule.getInfoBars()); |
+ Assert.assertEquals( |
+ "Wrong infobar count after search", 0, mActivityTestRule.getInfoBars().size()); |
// Infobar should not appear the next day either, as it has been dismissed. |
SearchGeolocationDisclosureTabHelper.setDayOffsetForTesting(1); |
- loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
- assertEquals("Wrong infobar count after search", 0, getInfoBars().size()); |
+ mActivityTestRule.loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
+ Assert.assertEquals( |
+ "Wrong infobar count after search", 0, mActivityTestRule.getInfoBars().size()); |
} |
+ @Test |
@SmallTest |
@Feature({"Browser", "Main"}) |
@CommandLineFlags.Add(ENABLE_NEW_DISCLOSURE_FEATURE) |
public void testNoInfoBarForRandomUrl() throws InterruptedException, TimeoutException { |
- assertEquals("Wrong starting infobar count", 0, getInfoBars().size()); |
+ Assert.assertEquals( |
+ "Wrong starting infobar count", 0, mActivityTestRule.getInfoBars().size()); |
- loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
- assertEquals("Wrong infobar count after search", 0, getInfoBars().size()); |
+ mActivityTestRule.loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
+ Assert.assertEquals( |
+ "Wrong infobar count after search", 0, mActivityTestRule.getInfoBars().size()); |
} |
+ @Test |
@SmallTest |
@Feature({"Browser", "Main"}) |
@CommandLineFlags.Add(ENABLE_NEW_DISCLOSURE_FEATURE) |
public void testNoInfoBarInIncognito() throws InterruptedException, TimeoutException { |
SearchGeolocationDisclosureTabHelper.setIgnoreUrlChecksForTesting(); |
- newIncognitoTabFromMenu(); |
- assertEquals("Wrong starting infobar count", 0, getInfoBars().size()); |
+ mActivityTestRule.newIncognitoTabFromMenu(); |
+ Assert.assertEquals( |
+ "Wrong starting infobar count", 0, mActivityTestRule.getInfoBars().size()); |
- loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
- assertEquals("Wrong infobar count after search", 0, getInfoBars().size()); |
+ mActivityTestRule.loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
+ Assert.assertEquals( |
+ "Wrong infobar count after search", 0, mActivityTestRule.getInfoBars().size()); |
} |
+ @Test |
@SmallTest |
@Feature({"Browser", "Main"}) |
@CommandLineFlags.Add(DISABLE_NEW_DISCLOSURE_FEATURE) |
public void testInfoBarAppearsDoesntAppearWithoutFeature() |
throws InterruptedException, TimeoutException { |
SearchGeolocationDisclosureTabHelper.setIgnoreUrlChecksForTesting(); |
- assertEquals("Wrong starting infobar count", 0, getInfoBars().size()); |
+ Assert.assertEquals( |
+ "Wrong starting infobar count", 0, mActivityTestRule.getInfoBars().size()); |
- loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
- assertEquals("Wrong infobar count after search", 0, getInfoBars().size()); |
+ mActivityTestRule.loadUrl(mTestServer.getURL(SEARCH_PAGE)); |
+ Assert.assertEquals( |
+ "Wrong infobar count after search", 0, mActivityTestRule.getInfoBars().size()); |
} |
} |