| Index: chrome/android/javatests/src/org/chromium/chrome/browser/toolbar/BrandColorTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/toolbar/BrandColorTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/toolbar/BrandColorTest.java
|
| index c1b7667e75f76fe404de69aea40a6d39cadb4d0a..7f3eeaf986d74906d40290e0a2bcf212a5553a46 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/toolbar/BrandColorTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/toolbar/BrandColorTest.java
|
| @@ -10,21 +10,29 @@ import android.os.Build;
|
| import android.support.test.filters.SmallTest;
|
| import android.text.TextUtils;
|
|
|
| +import org.junit.Assert;
|
| +import org.junit.Rule;
|
| +import org.junit.Test;
|
| +import org.junit.runner.RunWith;
|
| +
|
| import org.chromium.base.ApiCompatibilityUtils;
|
| import org.chromium.base.ObserverList.RewindableIterator;
|
| import org.chromium.base.SysUtils;
|
| 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.Restriction;
|
| 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.tab.Tab;
|
| import org.chromium.chrome.browser.tab.TabObserver;
|
| import org.chromium.chrome.browser.tab.TabTestUtils;
|
| import org.chromium.chrome.browser.util.ColorUtils;
|
| -import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| +import org.chromium.chrome.test.ChromeActivityTestRule;
|
| +import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| import org.chromium.chrome.test.util.ChromeRestriction;
|
| import org.chromium.chrome.test.util.DisableInTabbedMode;
|
| import org.chromium.content.browser.InterstitialPageDelegateAndroid;
|
| @@ -36,12 +44,14 @@ import java.util.concurrent.Callable;
|
| /**
|
| * Contains tests for the brand color feature.
|
| */
|
| +@RunWith(ChromeJUnit4ClassRunner.class)
|
| @RetryOnFailure
|
| -public class BrandColorTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| -
|
| - public BrandColorTest() {
|
| - super(ChromeActivity.class);
|
| - }
|
| +@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| + ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
|
| +public class BrandColorTest {
|
| + @Rule
|
| + public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
|
| + new ChromeActivityTestRule<>(ChromeActivity.class);
|
|
|
| private static final String BRAND_COLOR_1 = "#482329";
|
| private static final String BRAND_COLOR_2 = "#505050";
|
| @@ -65,11 +75,6 @@ public class BrandColorTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| + "</html>");
|
| }
|
|
|
| - @Override
|
| - public void startMainActivity() {
|
| - // Don't launch activity automatically.
|
| - }
|
| -
|
| @TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
| private void checkForBrandColor(final int brandColor) {
|
| CriteriaHelper.pollUiThread(new Criteria(
|
| @@ -97,24 +102,24 @@ public class BrandColorTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| Criteria.equals(expectedStatusBarColor, new Callable<Integer>() {
|
| @Override
|
| public Integer call() {
|
| - return getActivity().getWindow().getStatusBarColor();
|
| + return mActivityTestRule.getActivity().getWindow().getStatusBarColor();
|
| }
|
| }));
|
| }
|
| }
|
|
|
| - @Override
|
| protected void startMainActivityWithURL(String url) throws InterruptedException {
|
| - super.startMainActivityWithURL(url);
|
| - mToolbar = (ToolbarPhone) getActivity().findViewById(R.id.toolbar);
|
| + mActivityTestRule.startMainActivityWithURL(url);
|
| + mToolbar = (ToolbarPhone) mActivityTestRule.getActivity().findViewById(R.id.toolbar);
|
| mToolbarDataProvider = mToolbar.getToolbarDataProvider();
|
| - mDefaultColor = ApiCompatibilityUtils.getColor(getActivity().getResources(),
|
| - R.color.default_primary_color);
|
| + mDefaultColor = ApiCompatibilityUtils.getColor(
|
| + mActivityTestRule.getActivity().getResources(), R.color.default_primary_color);
|
| }
|
|
|
| /**
|
| * Test for having default primary color working correctly.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE)
|
| @Feature({"Omnibox"})
|
| @@ -126,6 +131,7 @@ public class BrandColorTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| /**
|
| * Test for adding a brand color for a url.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE)
|
| @Feature({"Omnibox"})
|
| @@ -137,6 +143,7 @@ public class BrandColorTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| /**
|
| * Test for immediately setting the brand color.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE)
|
| @Feature({"Omnibox"})
|
| @@ -147,10 +154,11 @@ public class BrandColorTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getActivity().getToolbarManager().updatePrimaryColor(mDefaultColor, false);
|
| + mActivityTestRule.getActivity().getToolbarManager().updatePrimaryColor(
|
| + mDefaultColor, false);
|
| // Since the color should change instantly, there is no need to use the criteria
|
| // helper.
|
| - assertEquals(mToolbarDataProvider.getPrimaryColor(),
|
| + Assert.assertEquals(mToolbarDataProvider.getPrimaryColor(),
|
| mToolbar.getBackgroundDrawable().getColor());
|
| }
|
| });
|
| @@ -159,6 +167,7 @@ public class BrandColorTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| /**
|
| * Test to make sure onLoadStarted doesn't reset the brand color.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE)
|
| @Feature({"Omnibox"})
|
| @@ -167,7 +176,7 @@ public class BrandColorTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| ThreadUtils.postOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| - Tab tab = getActivity().getActivityTab();
|
| + Tab tab = mActivityTestRule.getActivity().getActivityTab();
|
| RewindableIterator<TabObserver> observers = TabTestUtils.getTabObservers(tab);
|
| while (observers.hasNext()) {
|
| observers.next().onLoadStarted(tab, true);
|
| @@ -180,13 +189,14 @@ public class BrandColorTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| /**
|
| * Test for checking navigating to new brand color updates correctly.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE)
|
| @Feature({"Omnibox"})
|
| public void testNavigatingToNewBrandColor() throws InterruptedException {
|
| startMainActivityWithURL(getUrlWithBrandColor(BRAND_COLOR_1));
|
| checkForBrandColor(Color.parseColor(BRAND_COLOR_1));
|
| - loadUrl(getUrlWithBrandColor(BRAND_COLOR_2));
|
| + mActivityTestRule.loadUrl(getUrlWithBrandColor(BRAND_COLOR_2));
|
| checkForBrandColor(Color.parseColor(BRAND_COLOR_2));
|
| }
|
|
|
| @@ -194,27 +204,28 @@ public class BrandColorTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| * Test for checking navigating to a brand color site from a site with no brand color and then
|
| * back again.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE)
|
| @Feature({"Omnibox"})
|
| public void testNavigatingToBrandColorAndBack() throws InterruptedException {
|
| startMainActivityWithURL("about:blank");
|
| checkForBrandColor(mDefaultColor);
|
| - loadUrl(getUrlWithBrandColor(BRAND_COLOR_1));
|
| + mActivityTestRule.loadUrl(getUrlWithBrandColor(BRAND_COLOR_1));
|
| checkForBrandColor(Color.parseColor(BRAND_COLOR_1));
|
| - loadUrl("about:blank");
|
| + mActivityTestRule.loadUrl("about:blank");
|
| checkForBrandColor(mDefaultColor);
|
| ThreadUtils.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getActivity().onBackPressed();
|
| + mActivityTestRule.getActivity().onBackPressed();
|
| }
|
| });
|
| checkForBrandColor(Color.parseColor(BRAND_COLOR_1));
|
| ThreadUtils.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getActivity().onBackPressed();
|
| + mActivityTestRule.getActivity().onBackPressed();
|
| }
|
| });
|
| checkForBrandColor(mDefaultColor);
|
| @@ -225,6 +236,7 @@ public class BrandColorTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| *
|
| * TODO(aurimas): investigate why this test is crasing in tabbed mode.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE)
|
| @DisableInTabbedMode
|
| @@ -238,17 +250,19 @@ public class BrandColorTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getActivity().getActivityTab().getWebContents().showInterstitialPage(
|
| - brandColorUrl, delegate.getNative());
|
| + mActivityTestRule.getActivity()
|
| + .getActivityTab()
|
| + .getWebContents()
|
| + .showInterstitialPage(brandColorUrl, delegate.getNative());
|
| }
|
| });
|
| CriteriaHelper.pollUiThread(new Criteria() {
|
| @Override
|
| public boolean isSatisfied() {
|
| - return getActivity().getActivityTab().isShowingInterstitialPage();
|
| + return mActivityTestRule.getActivity().getActivityTab().isShowingInterstitialPage();
|
| }
|
| });
|
| checkForBrandColor(ApiCompatibilityUtils.getColor(
|
| - getActivity().getResources(), R.color.default_primary_color));
|
| + mActivityTestRule.getActivity().getResources(), R.color.default_primary_color));
|
| }
|
| }
|
|
|