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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappModeTest.java

Issue 2847933002: Convert MultiActivityTestBase children to JUnit4 (Closed)
Patch Set: Add imports and rebase Created 3 years, 8 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/webapps/WebappModeTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappModeTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappModeTest.java
index 540f792afc623822f79d235c824173519c6837a9..a105310bfa3d8405fbf8012937788266ce394da7 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappModeTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappModeTest.java
@@ -8,23 +8,34 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.view.View;
+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.ApplicationStatus;
import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils;
+import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.base.test.util.UrlUtils;
import org.chromium.blink_public.platform.WebDisplayMode;
import org.chromium.chrome.browser.ChromeActivity;
+import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.ShortcutSource;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabIdManager;
-import org.chromium.chrome.test.MultiActivityTestBase;
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
+import org.chromium.chrome.test.MultiActivityTestRule;
import org.chromium.chrome.test.util.ActivityUtils;
import org.chromium.chrome.test.util.ApplicationTestUtils;
import org.chromium.chrome.test.util.browser.TabLoadObserver;
@@ -44,8 +55,13 @@ import org.chromium.net.test.EmbeddedTestServer;
* FLAG_ACTIVITY_NEW_DOCUMENT mechanism. Moreover, we don't have access to the task list pre-L so
* we have to assume that any non-running WebappActivities are not listed in Android's Overview.
*/
+@RunWith(ChromeJUnit4ClassRunner.class)
+@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@RetryOnFailure
-public class WebappModeTest extends MultiActivityTestBase {
+public class WebappModeTest {
+ @Rule
+ public MultiActivityTestRule mTestRule = new MultiActivityTestRule();
+
private static final String WEBAPP_1_ID = "webapp_id_1";
private static final String WEBAPP_1_URL = UrlUtils.encodeHtmlDataUri(
"<html><head><title>Web app #1</title><meta name='viewport' "
@@ -67,12 +83,14 @@ public class WebappModeTest extends MultiActivityTestBase {
private Intent createIntent(String id, String url, String title, String icon, boolean addMac) {
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.setPackage(getInstrumentation().getTargetContext().getPackageName());
+ intent.setPackage(
+ InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName());
intent.setAction(WebappLauncherActivity.ACTION_START_WEBAPP);
if (addMac) {
// Needed for security reasons. If the MAC is excluded, the URL of the webapp is opened
// in a browser window, instead.
- String mac = ShortcutHelper.getEncodedMac(getInstrumentation().getTargetContext(), url);
+ String mac = ShortcutHelper.getEncodedMac(
+ InstrumentationRegistry.getInstrumentation().getTargetContext(), url);
intent.putExtra(ShortcutHelper.EXTRA_MAC, mac);
}
@@ -89,14 +107,13 @@ public class WebappModeTest extends MultiActivityTestBase {
boolean addMac) {
Intent intent = createIntent(id, url, title, icon, addMac);
- getInstrumentation().getTargetContext().startActivity(intent);
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().getTargetContext().startActivity(intent);
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
ApplicationTestUtils.waitUntilChromeInForeground();
}
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
WebappRegistry.refreshSharedPrefsForTesting();
// Register the webapps so when the data storage is opened, the test doesn't crash. There is
@@ -119,18 +136,19 @@ public class WebappModeTest extends MultiActivityTestBase {
}
});
- mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
+ mTestServer = EmbeddedTestServer.createAndStartServer(
+ InstrumentationRegistry.getInstrumentation().getContext());
}
- @Override
+ @After
public void tearDown() throws Exception {
mTestServer.stopAndDestroyServer();
- super.tearDown();
}
/**
* Tests that WebappActivities are started properly.
*/
+ @Test
@MediumTest
@Feature({"Webapps"})
public void testWebappLaunches() {
@@ -169,6 +187,7 @@ public class WebappModeTest extends MultiActivityTestBase {
/**
* Tests that the WebappActivity gets the next available Tab ID instead of 0.
*/
+ @Test
@MediumTest
@Feature({"Webapps"})
public void testWebappTabIdsProperlyAssigned() {
@@ -179,13 +198,15 @@ public class WebappModeTest extends MultiActivityTestBase {
final WebappActivity webappActivity =
startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAPP_ICON);
- assertEquals("Wrong Tab ID was used", 11684, webappActivity.getActivityTab().getId());
+ Assert.assertEquals(
+ "Wrong Tab ID was used", 11684, webappActivity.getActivityTab().getId());
}
/**
* Tests that a WebappActivity can be brought forward by firing an Intent with
* TabOpenType.BRING_TAB_TO_FRONT.
*/
+ @Test
@MediumTest
@Feature({"Webapps"})
public void testBringTabToFront() throws Exception {
@@ -195,9 +216,9 @@ public class WebappModeTest extends MultiActivityTestBase {
final int webappTabId = firstActivity.getActivityTab().getId();
// Return home.
- final Context context = getInstrumentation().getTargetContext();
+ final Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
ApplicationTestUtils.fireHomeScreenIntent(context);
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
// Bring the WebappActivity back via an Intent.
Intent intent = Tab.createBringTabToFrontIntent(webappTabId);
@@ -207,7 +228,7 @@ public class WebappModeTest extends MultiActivityTestBase {
// When Chrome is back in the foreground, confirm that the correct Activity was restored.
// Because of Android killing Activities willy-nilly, it may not be the same Activity, but
// it should have the same Tab ID.
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
ApplicationTestUtils.waitUntilChromeInForeground();
CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override
@@ -224,6 +245,7 @@ public class WebappModeTest extends MultiActivityTestBase {
/**
* Ensure WebappActivities can't be launched without proper security checks.
*/
+ @Test
@MediumTest
@Feature({"Webapps"})
public void testWebappRequiresValidMac() {
@@ -238,7 +260,7 @@ public class WebappModeTest extends MultiActivityTestBase {
});
ChromeActivity chromeActivity =
(ChromeActivity) ApplicationStatus.getLastTrackedFocusedActivity();
- waitForFullLoad(chromeActivity, WEBAPP_1_TITLE);
+ mTestRule.waitForFullLoad(chromeActivity, WEBAPP_1_TITLE);
// Firing a correct Intent should start a WebappActivity instance instead of the browser.
fireWebappIntent(WEBAPP_2_ID, WEBAPP_2_URL, WEBAPP_2_TITLE, WEBAPP_ICON, true);
@@ -253,6 +275,7 @@ public class WebappModeTest extends MultiActivityTestBase {
/**
* Tests that WebappActivities handle window.open() properly in tabbed mode.
*/
+ @Test
@MediumTest
@Feature({"Webapps"})
public void testWebappHandlesWindowOpenInTabbedMode() throws Exception {
@@ -262,6 +285,7 @@ public class WebappModeTest extends MultiActivityTestBase {
/**
* Tests that WebappActivities handle suppressed window.open() properly in tabbed mode.
*/
+ @Test
@MediumTest
@Feature({"Webapps"})
public void testWebappHandlesSuppressedWindowOpenInTabbedMode() throws Exception {
@@ -294,14 +318,14 @@ public class WebappModeTest extends MultiActivityTestBase {
}
};
ChromeActivity secondActivity = ActivityUtils.waitForActivity(
- getInstrumentation(), classToWaitFor, fgTrigger);
- waitForFullLoad(secondActivity, "The Google");
+ InstrumentationRegistry.getInstrumentation(), classToWaitFor, fgTrigger);
+ mTestRule.waitForFullLoad(secondActivity, "The Google");
if (checkContents) {
- assertEquals("New WebContents was not created", "SUCCESS",
+ Assert.assertEquals("New WebContents was not created", "SUCCESS",
firstActivity.getActivityTab().getTitle());
}
- assertNotSame("Wrong Activity in foreground",
- firstActivity, ApplicationStatus.getLastTrackedFocusedActivity());
+ Assert.assertNotSame("Wrong Activity in foreground", firstActivity,
+ ApplicationStatus.getLastTrackedFocusedActivity());
// Close the child window to kick the user back to the WebappActivity.
JavaScriptUtils.executeJavaScript(

Powered by Google App Engine
This is Rietveld 408576698