Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/ntp/NewTabPageNavigationTest.java

Issue 2853573002: Convert ChromeTabbedActivityTestCaseBase children to JUnit4 (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/ntp/NewTabPageNavigationTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/NewTabPageNavigationTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/NewTabPageNavigationTest.java
index 4c24d2b31f69aae2932cb7342562f57415817fc5..3cde542bb85b92e61145d1d74145fc43c968e5ee 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/NewTabPageNavigationTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/NewTabPageNavigationTest.java
@@ -4,86 +4,101 @@
package org.chromium.chrome.browser.ntp;
+import android.support.test.InstrumentationRegistry;
import android.support.test.filters.LargeTest;
import android.support.test.filters.MediumTest;
+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.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.RetryOnFailure;
+import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.tab.Tab;
-import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
+import org.chromium.chrome.test.ChromeActivityTestRule;
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
+import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.net.test.EmbeddedTestServer;
/**
* Tests loading the NTP and navigating between it and other pages.
*/
+@RunWith(ChromeJUnit4ClassRunner.class)
+@CommandLineFlags.Add({
+ ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
+})
@RetryOnFailure
-public class NewTabPageNavigationTest extends ChromeTabbedActivityTestBase {
+public class NewTabPageNavigationTest {
+ @Rule
+ public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
private EmbeddedTestServer mTestServer;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
+ @Before
+ public void setUp() throws Exception {
+ mActivityTestRule.startMainActivityWithURL(null);
+ mTestServer = EmbeddedTestServer.createAndStartServer(
+ InstrumentationRegistry.getInstrumentation().getContext());
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
mTestServer.stopAndDestroyServer();
- super.tearDown();
}
/**
* Sanity check that we do start on the NTP by default.
*/
+ @Test
@MediumTest
@Feature({"NewTabPage", "Main"})
public void testNTPIsDefault() {
- Tab tab = getActivity().getActivityTab();
- assertNotNull(tab);
+ Tab tab = mActivityTestRule.getActivity().getActivityTab();
+ Assert.assertNotNull(tab);
String url = tab.getUrl();
- assertTrue("Unexpected url: " + url,
+ Assert.assertTrue("Unexpected url: " + url,
url.startsWith("chrome-native://newtab/")
- || url.startsWith("chrome-native://bookmarks/")
- || url.startsWith("chrome-native://recent-tabs/"));
+ || url.startsWith("chrome-native://bookmarks/")
+ || url.startsWith("chrome-native://recent-tabs/"));
}
/**
* Check that navigating away from the NTP does work.
*/
+ @Test
@LargeTest
@Feature({"NewTabPage"})
public void testNavigatingFromNTP() throws InterruptedException {
String url = mTestServer.getURL("/chrome/test/data/android/google.html");
- loadUrl(url);
- assertEquals(url, getActivity().getActivityTab().getUrl());
+ mActivityTestRule.loadUrl(url);
+ Assert.assertEquals(url, mActivityTestRule.getActivity().getActivityTab().getUrl());
}
/**
* Tests navigating back to the NTP after loading another page.
*/
+ @Test
@MediumTest
@Feature({"NewTabPage"})
public void testNavigateBackToNTPViaUrl() throws InterruptedException {
String url = mTestServer.getURL("/chrome/test/data/android/google.html");
- loadUrl(url);
- assertEquals(url, getActivity().getActivityTab().getUrl());
+ mActivityTestRule.loadUrl(url);
+ Assert.assertEquals(url, mActivityTestRule.getActivity().getActivityTab().getUrl());
- loadUrl(UrlConstants.NTP_URL);
- Tab tab = getActivity().getActivityTab();
- assertNotNull(tab);
+ mActivityTestRule.loadUrl(UrlConstants.NTP_URL);
+ Tab tab = mActivityTestRule.getActivity().getActivityTab();
+ Assert.assertNotNull(tab);
url = tab.getUrl();
- assertEquals(UrlConstants.NTP_URL, url);
+ Assert.assertEquals(UrlConstants.NTP_URL, url);
// Check that the NTP is actually displayed.
- assertNotNull(tab.getNativePage() instanceof NewTabPage);
- }
-
- @Override
- public void startMainActivity() throws InterruptedException {
- // Passing null below starts the activity on its default page, which is the NTP on a clean
- // profile.
- startMainActivityWithURL(null);
+ Assert.assertNotNull(tab.getNativePage() instanceof NewTabPage);
}
}

Powered by Google App Engine
This is Rietveld 408576698