| Index: chrome/android/javatests/src/org/chromium/chrome/browser/ChromeActivityTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/ChromeActivityTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/ChromeActivityTest.java
|
| index 075956f7a8c75d9e4cd34f41c278d1821427c4af..90962a2fe3bfb34a570cffa91a3aa889b418f09d 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/ChromeActivityTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ChromeActivityTest.java
|
| @@ -4,16 +4,27 @@
|
|
|
| package org.chromium.chrome.browser;
|
|
|
| +import android.support.test.InstrumentationRegistry;
|
| import android.support.test.filters.MediumTest;
|
| 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.test.util.CommandLineFlags;
|
| import org.chromium.base.test.util.RetryOnFailure;
|
| import org.chromium.chrome.browser.device.DeviceClassManager;
|
| import org.chromium.chrome.browser.tab.Tab;
|
| import org.chromium.chrome.browser.tabmodel.ChromeTabCreator;
|
| import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
|
| -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.content_public.browser.LoadUrlParams;
|
| import org.chromium.net.test.EmbeddedTestServer;
|
|
|
| @@ -22,21 +33,27 @@ import java.util.concurrent.Callable;
|
| /**
|
| * Instrumentation tests for ChromeActivity.
|
| */
|
| -public class ChromeActivityTest extends ChromeTabbedActivityTestBase {
|
| +@RunWith(ChromeJUnit4ClassRunner.class)
|
| +@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| + ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
|
| +public class ChromeActivityTest {
|
| + @Rule
|
| + public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
|
| +
|
| private static final String FILE_PATH = "/chrome/test/data/android/test.html";
|
|
|
| private EmbeddedTestServer mTestServer;
|
|
|
| - @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());
|
| }
|
|
|
| - @Override
|
| - protected void tearDown() throws Exception {
|
| - mTestServer.stopAndDestroyServer();
|
| - super.tearDown();
|
| + @After
|
| + public void tearDown() throws Exception {
|
| + if (mTestServer != null) mTestServer.stopAndDestroyServer();
|
| }
|
|
|
| /**
|
| @@ -44,6 +61,7 @@ public class ChromeActivityTest extends ChromeTabbedActivityTestBase {
|
| * and that it receives the show() call when the activity is started again. This is a regression
|
| * test for http://crbug.com/319804 .
|
| */
|
| + @Test
|
| @MediumTest
|
| @RetryOnFailure
|
| public void testTabVisibility() {
|
| @@ -53,7 +71,8 @@ public class ChromeActivityTest extends ChromeTabbedActivityTestBase {
|
| @Override
|
| public void run() {
|
| // Foreground tab.
|
| - ChromeTabCreator tabCreator = getActivity().getCurrentTabCreator();
|
| + ChromeTabCreator tabCreator =
|
| + mActivityTestRule.getActivity().getCurrentTabCreator();
|
| tabs[0] = tabCreator.createNewTab(
|
| new LoadUrlParams(mTestServer.getURL(FILE_PATH)),
|
| TabLaunchType.FROM_CHROME_UI, null);
|
| @@ -65,70 +84,68 @@ public class ChromeActivityTest extends ChromeTabbedActivityTestBase {
|
| });
|
|
|
| // Verify that the front tab is in the 'visible' state.
|
| - assertFalse(tabs[0].isHidden());
|
| - assertTrue(tabs[1].isHidden());
|
| + Assert.assertFalse(tabs[0].isHidden());
|
| + Assert.assertTrue(tabs[1].isHidden());
|
|
|
| // Fake sending the activity to background.
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getActivity().onPause();
|
| + mActivityTestRule.getActivity().onPause();
|
| }
|
| });
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getActivity().onStop();
|
| + mActivityTestRule.getActivity().onStop();
|
| }
|
| });
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getActivity().onWindowFocusChanged(false);
|
| + mActivityTestRule.getActivity().onWindowFocusChanged(false);
|
| }
|
| });
|
| // Verify that both Tabs are hidden.
|
| - assertTrue(tabs[0].isHidden());
|
| - assertTrue(tabs[1].isHidden());
|
| + Assert.assertTrue(tabs[0].isHidden());
|
| + Assert.assertTrue(tabs[1].isHidden());
|
|
|
| // Fake bringing the activity back to foreground.
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getActivity().onWindowFocusChanged(true);
|
| + mActivityTestRule.getActivity().onWindowFocusChanged(true);
|
| }
|
| });
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getActivity().onStart();
|
| + mActivityTestRule.getActivity().onStart();
|
| }
|
| });
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getActivity().onResume();
|
| + mActivityTestRule.getActivity().onResume();
|
| }
|
| });
|
| // Verify that the front tab is in the 'visible' state.
|
| - assertFalse(tabs[0].isHidden());
|
| - assertTrue(tabs[1].isHidden());
|
| + Assert.assertFalse(tabs[0].isHidden());
|
| + Assert.assertTrue(tabs[1].isHidden());
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testTabAnimationsCorrectlyEnabled() {
|
| boolean animationsEnabled = ThreadUtils.runOnUiThreadBlockingNoException(
|
| new Callable<Boolean>() {
|
| @Override
|
| public Boolean call() throws Exception {
|
| - return getActivity().getLayoutManager().animationsEnabled();
|
| + return mActivityTestRule.getActivity()
|
| + .getLayoutManager()
|
| + .animationsEnabled();
|
| }
|
| });
|
| - assertEquals(animationsEnabled, DeviceClassManager.enableAnimations());
|
| - }
|
| -
|
| - @Override
|
| - public void startMainActivity() throws InterruptedException {
|
| - startMainActivityOnBlankPage();
|
| + Assert.assertEquals(animationsEnabled, DeviceClassManager.enableAnimations());
|
| }
|
| }
|
|
|