Index: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/AddToHomescreenManagerTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/AddToHomescreenManagerTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/AddToHomescreenManagerTest.java |
index d7a9d740d703f635bb6ba30d9f3e8dcb484946e4..8678d77e5568b5c70e0f3fb9a57361620b9b6c53 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/AddToHomescreenManagerTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/AddToHomescreenManagerTest.java |
@@ -7,14 +7,7 @@ |
import android.app.Activity; |
import android.content.Intent; |
import android.graphics.Bitmap; |
-import android.support.test.InstrumentationRegistry; |
import android.support.test.filters.SmallTest; |
- |
-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; |
@@ -24,12 +17,10 @@ |
import org.chromium.base.test.util.UrlUtils; |
import org.chromium.chrome.R; |
import org.chromium.chrome.browser.ChromeActivity; |
-import org.chromium.chrome.browser.ChromeSwitches; |
import org.chromium.chrome.browser.ShortcutHelper; |
import org.chromium.chrome.browser.tab.Tab; |
import org.chromium.chrome.browser.tabmodel.TabModel; |
-import org.chromium.chrome.test.ChromeActivityTestRule; |
-import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
+import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
import org.chromium.chrome.test.util.browser.TabLoadObserver; |
import org.chromium.chrome.test.util.browser.TabTitleObserver; |
import org.chromium.content.browser.test.util.Criteria; |
@@ -42,15 +33,8 @@ |
/** |
* Tests org.chromium.chrome.browser.webapps.AddToHomescreenManager and its C++ counterpart. |
*/ |
-@RunWith(ChromeJUnit4ClassRunner.class) |
@RetryOnFailure |
-@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
- ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
-public class AddToHomescreenManagerTest { |
- @Rule |
- public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
- new ChromeActivityTestRule<>(ChromeActivity.class); |
- |
+public class AddToHomescreenManagerTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
private static final String WEBAPP_ACTION_NAME = "WEBAPP_ACTION"; |
private static final String WEBAPP_TITLE = "Webapp shortcut"; |
@@ -127,7 +111,7 @@ |
@Override |
public void updateSplashScreenImage(String splashScreenImage) { |
- Assert.assertNull(mSplashImage); |
+ assertNull(mSplashImage); |
mSplashImage = splashScreenImage; |
} |
} |
@@ -169,46 +153,51 @@ |
private Tab mTab; |
private TestShortcutHelperDelegate mShortcutHelperDelegate; |
- @Before |
+ public AddToHomescreenManagerTest() { |
+ super(ChromeActivity.class); |
+ } |
+ |
+ @Override |
+ public void startMainActivity() throws InterruptedException { |
+ startMainActivityOnBlankPage(); |
+ } |
+ |
+ @Override |
public void setUp() throws Exception { |
- mActivityTestRule.startMainActivityOnBlankPage(); |
+ super.setUp(); |
ChromeWebApkHost.initForTesting(false); |
- mTestServer = EmbeddedTestServer.createAndStartServer( |
- InstrumentationRegistry.getInstrumentation().getContext()); |
+ mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext()); |
mShortcutHelperDelegate = new TestShortcutHelperDelegate(); |
ShortcutHelper.setDelegateForTests(mShortcutHelperDelegate); |
- mActivity = mActivityTestRule.getActivity(); |
+ mActivity = getActivity(); |
mTab = mActivity.getActivityTab(); |
} |
- @Test |
@SmallTest |
@Feature("{Webapp}") |
public void testAddWebappShortcuts() throws Exception { |
// Add a webapp shortcut and make sure the intent's parameters make sense. |
loadUrl(WEBAPP_HTML, WEBAPP_TITLE); |
addShortcutToTab(mTab, ""); |
- Assert.assertEquals(WEBAPP_TITLE, mShortcutHelperDelegate.mRequestedShortcutTitle); |
+ assertEquals(WEBAPP_TITLE, mShortcutHelperDelegate.mRequestedShortcutTitle); |
Intent launchIntent = mShortcutHelperDelegate.mRequestedShortcutIntent; |
- Assert.assertEquals(WEBAPP_HTML, launchIntent.getStringExtra(ShortcutHelper.EXTRA_URL)); |
- Assert.assertEquals(WEBAPP_ACTION_NAME, launchIntent.getAction()); |
- Assert.assertEquals(mActivity.getPackageName(), launchIntent.getPackage()); |
+ assertEquals(WEBAPP_HTML, launchIntent.getStringExtra(ShortcutHelper.EXTRA_URL)); |
+ assertEquals(WEBAPP_ACTION_NAME, launchIntent.getAction()); |
+ assertEquals(mActivity.getPackageName(), launchIntent.getPackage()); |
// Add a second shortcut and make sure it matches the second webapp's parameters. |
mShortcutHelperDelegate.clearRequestedShortcutData(); |
loadUrl(SECOND_WEBAPP_HTML, SECOND_WEBAPP_TITLE); |
addShortcutToTab(mTab, ""); |
- Assert.assertEquals(SECOND_WEBAPP_TITLE, mShortcutHelperDelegate.mRequestedShortcutTitle); |
+ assertEquals(SECOND_WEBAPP_TITLE, mShortcutHelperDelegate.mRequestedShortcutTitle); |
Intent newLaunchIntent = mShortcutHelperDelegate.mRequestedShortcutIntent; |
- Assert.assertEquals( |
- SECOND_WEBAPP_HTML, newLaunchIntent.getStringExtra(ShortcutHelper.EXTRA_URL)); |
- Assert.assertEquals(WEBAPP_ACTION_NAME, newLaunchIntent.getAction()); |
- Assert.assertEquals(mActivity.getPackageName(), newLaunchIntent.getPackage()); |
- } |
- |
- @Test |
+ assertEquals(SECOND_WEBAPP_HTML, newLaunchIntent.getStringExtra(ShortcutHelper.EXTRA_URL)); |
+ assertEquals(WEBAPP_ACTION_NAME, newLaunchIntent.getAction()); |
+ assertEquals(mActivity.getPackageName(), newLaunchIntent.getPackage()); |
+ } |
+ |
@SmallTest |
@Feature("{Webapp}") |
public void testAddBookmarkShortcut() throws Exception { |
@@ -216,44 +205,40 @@ |
addShortcutToTab(mTab, ""); |
// Make sure the intent's parameters make sense. |
- Assert.assertEquals(NORMAL_TITLE, mShortcutHelperDelegate.mRequestedShortcutTitle); |
+ assertEquals(NORMAL_TITLE, mShortcutHelperDelegate.mRequestedShortcutTitle); |
Intent launchIntent = mShortcutHelperDelegate.mRequestedShortcutIntent; |
- Assert.assertEquals(mActivity.getPackageName(), launchIntent.getPackage()); |
- Assert.assertEquals(Intent.ACTION_VIEW, launchIntent.getAction()); |
- Assert.assertEquals(NORMAL_HTML, launchIntent.getDataString()); |
- } |
- |
- @Test |
+ assertEquals(mActivity.getPackageName(), launchIntent.getPackage()); |
+ assertEquals(Intent.ACTION_VIEW, launchIntent.getAction()); |
+ assertEquals(NORMAL_HTML, launchIntent.getDataString()); |
+ } |
+ |
@SmallTest |
@Feature("{Webapp}") |
public void testAddWebappShortcutsWithoutTitleEdit() throws Exception { |
// Add a webapp shortcut using the page's title. |
loadUrl(WEBAPP_HTML, WEBAPP_TITLE); |
addShortcutToTab(mTab, ""); |
- Assert.assertEquals(WEBAPP_TITLE, mShortcutHelperDelegate.mRequestedShortcutTitle); |
- } |
- |
- @Test |
+ assertEquals(WEBAPP_TITLE, mShortcutHelperDelegate.mRequestedShortcutTitle); |
+ } |
+ |
@SmallTest |
@Feature("{Webapp}") |
public void testAddWebappShortcutsWithTitleEdit() throws Exception { |
// Add a webapp shortcut with a custom title. |
loadUrl(WEBAPP_HTML, WEBAPP_TITLE); |
addShortcutToTab(mTab, EDITED_WEBAPP_TITLE); |
- Assert.assertEquals(EDITED_WEBAPP_TITLE, mShortcutHelperDelegate.mRequestedShortcutTitle); |
- } |
- |
- @Test |
+ assertEquals(EDITED_WEBAPP_TITLE, mShortcutHelperDelegate.mRequestedShortcutTitle); |
+ } |
+ |
@SmallTest |
@Feature("{Webapp}") |
public void testAddWebappShortcutsWithApplicationName() throws Exception { |
loadUrl(META_APP_NAME_HTML, META_APP_NAME_PAGE_TITLE); |
addShortcutToTab(mTab, ""); |
- Assert.assertEquals(META_APP_NAME_TITLE, mShortcutHelperDelegate.mRequestedShortcutTitle); |
- } |
- |
- @Test |
+ assertEquals(META_APP_NAME_TITLE, mShortcutHelperDelegate.mRequestedShortcutTitle); |
+ } |
+ |
@SmallTest |
@Feature("{Webapp}") |
@Restriction(Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
@@ -263,7 +248,6 @@ |
addShortcutToTab(spawnedPopup, ""); |
} |
- @Test |
@SmallTest |
@Feature("{Webapp}") |
public void testAddWebappShortcutSplashScreenIcon() throws Exception { |
@@ -288,8 +272,8 @@ |
R.dimen.webapp_splash_image_size_ideal); |
Bitmap splashImage = |
ShortcutHelper.decodeBitmapFromString(dataStorageFactory.mSplashImage); |
- Assert.assertEquals(idealSize, splashImage.getWidth()); |
- Assert.assertEquals(idealSize, splashImage.getHeight()); |
+ assertEquals(idealSize, splashImage.getWidth()); |
+ assertEquals(idealSize, splashImage.getHeight()); |
} finally { |
mTestServer.stopAndDestroyServer(); |
} |
@@ -297,7 +281,6 @@ |
/** Tests that the appinstalled event is fired when an app is installed. |
*/ |
- @Test |
@SmallTest |
@Feature("{Webapp}") |
public void testAddWebappShortcutAppInstalledEvent() throws Exception { |
@@ -369,15 +352,12 @@ |
CriteriaHelper.pollUiThread(Criteria.equals(2, new Callable<Integer>() { |
@Override |
public Integer call() { |
- return mActivityTestRule.getActivity() |
- .getTabModelSelector() |
- .getModel(false) |
- .getCount(); |
+ return getActivity().getTabModelSelector().getModel(false).getCount(); |
} |
})); |
- TabModel tabModel = mActivityTestRule.getActivity().getTabModelSelector().getModel(false); |
- Assert.assertEquals(0, tabModel.indexOf(mTab)); |
- return mActivityTestRule.getActivity().getTabModelSelector().getModel(false).getTabAt(1); |
+ TabModel tabModel = getActivity().getTabModelSelector().getModel(false); |
+ assertEquals(0, tabModel.indexOf(mTab)); |
+ return getActivity().getTabModelSelector().getModel(false).getTabAt(1); |
} |
} |