Commit 617af2a7 authored by piotrs's avatar piotrs Committed by Commit bot

Converts WebApkIntegrationTest to JUnit4.

This will allow me to increase code reuse with a nice custom @Rule.

BUG=640116

Review-Url: https://codereview.chromium.org/2854943005
Cr-Commit-Position: refs/heads/master@{#469559}
parent 60b4d8b2
...@@ -5,13 +5,23 @@ ...@@ -5,13 +5,23 @@
package org.chromium.chrome.browser.webapps; package org.chromium.chrome.browser.webapps;
import android.content.Intent; import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.LargeTest; import android.support.test.filters.LargeTest;
import org.junit.After;
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.Feature;
import org.chromium.base.test.util.RetryOnFailure; import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.base.test.util.ScalableTimeout; import org.chromium.base.test.util.ScalableTimeout;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ShortcutHelper; import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.test.ChromeActivityTestCaseBase; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ChromeTabUtils; import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
...@@ -19,32 +29,39 @@ import org.chromium.net.test.EmbeddedTestServer; ...@@ -19,32 +29,39 @@ import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.webapk.lib.common.WebApkConstants; import org.chromium.webapk.lib.common.WebApkConstants;
/** Integration tests for WebAPK feature. */ /** Integration tests for WebAPK feature. */
public class WebApkIntegrationTest extends ChromeActivityTestCaseBase<WebApkActivity> { @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
public class WebApkIntegrationTest {
@Rule
public final ChromeActivityTestRule<WebApkActivity> mActivityTestRule =
new ChromeActivityTestRule<>(WebApkActivity.class);
private static final long STARTUP_TIMEOUT = ScalableTimeout.scaleTimeout(10000); private static final long STARTUP_TIMEOUT = ScalableTimeout.scaleTimeout(10000);
private EmbeddedTestServer mTestServer; private EmbeddedTestServer mTestServer;
public WebApkIntegrationTest() {
super(WebApkActivity.class);
}
public void startWebApkActivity(String webApkPackageName, final String startUrl) public void startWebApkActivity(String webApkPackageName, final String startUrl)
throws InterruptedException { throws InterruptedException {
Intent intent = new Intent(getInstrumentation().getTargetContext(), WebApkActivity.class); Intent intent =
new Intent(InstrumentationRegistry.getTargetContext(), WebApkActivity.class);
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackageName); intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackageName);
intent.putExtra(ShortcutHelper.EXTRA_URL, startUrl); intent.putExtra(ShortcutHelper.EXTRA_URL, startUrl);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
setActivity(getInstrumentation().startActivitySync(intent)); mActivityTestRule.setActivity(
getInstrumentation().waitForIdleSync(); (WebApkActivity) InstrumentationRegistry.getInstrumentation().startActivitySync(
intent));
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
CriteriaHelper.pollInstrumentationThread(new Criteria() { CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
return getActivity().getActivityTab() != null; return mActivityTestRule.getActivity().getActivityTab() != null;
} }
}, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL); }, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
ChromeTabUtils.waitForTabPageLoaded(getActivity().getActivityTab(), startUrl); ChromeTabUtils.waitForTabPageLoaded(
mActivityTestRule.getActivity().getActivityTab(), startUrl);
} }
/** Waits for the splash screen to be hidden. */ /** Waits for the splash screen to be hidden. */
...@@ -52,33 +69,28 @@ public class WebApkIntegrationTest extends ChromeActivityTestCaseBase<WebApkActi ...@@ -52,33 +69,28 @@ public class WebApkIntegrationTest extends ChromeActivityTestCaseBase<WebApkActi
CriteriaHelper.pollInstrumentationThread(new Criteria() { CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
return !getActivity().isSplashScreenVisibleForTests(); return !mActivityTestRule.getActivity().isSplashScreenVisibleForTests();
} }
}); });
} }
@Override @Before
public final void startMainActivity() throws InterruptedException { public void setUp() throws Exception {
// Do nothing mTestServer = EmbeddedTestServer.createAndStartServer(
} InstrumentationRegistry.getInstrumentation().getContext());
@Override
protected void setUp() throws Exception {
super.setUp();
mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
WebApkUpdateManager.setUpdatesEnabledForTesting(false); WebApkUpdateManager.setUpdatesEnabledForTesting(false);
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
mTestServer.stopAndDestroyServer(); mTestServer.stopAndDestroyServer();
super.tearDown();
} }
/** /**
* Test launching a WebAPK. Test that loading the start page works and that the splashscreen * Test launching a WebAPK. Test that loading the start page works and that the splashscreen
* eventually hides. * eventually hides.
*/ */
@Test
@LargeTest @LargeTest
@Feature({"WebApk"}) @Feature({"WebApk"})
@RetryOnFailure @RetryOnFailure
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment