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