Commit 06f433ae authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

Re-enable TrustedWebActivityTests

This CL re-enables
TrustedWebActivityTest#testStatusBarColorCertificateError()
TrustedWebActivityTest#testToolbarVisibleCertificateError()

- It modifies the tests to use different origins for "pages without a
certificate error" and "pages with a certificate error". This is now
necessary due to http://crrev.com/c/1872423
- Uses host-resolver-rules command line flag in order to use multiple
origins in tests. The command line flag has the side effect of causing
"redirected-urls" to throw a certificate error when navigated to
- It also fixes a bug with the testStatusBarColorCertificateError()
test on Lollipop

BUG=1016743,1016746

Change-Id: I20bbfdd7828c243af991e62f9c7d9a173d326c59
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1876872Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709975}
parent d7eb78dc
...@@ -15,11 +15,13 @@ import static org.chromium.chrome.browser.browserservices.TrustedWebActivityTest ...@@ -15,11 +15,13 @@ import static org.chromium.chrome.browser.browserservices.TrustedWebActivityTest
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import androidx.browser.customtabs.CustomTabsIntent; import androidx.browser.customtabs.CustomTabsIntent;
import androidx.browser.customtabs.TrustedWebUtils; import androidx.browser.customtabs.TrustedWebUtils;
import androidx.browser.trusted.TrustedWebActivityIntentBuilder;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
...@@ -27,12 +29,12 @@ import org.junit.Test; ...@@ -27,12 +29,12 @@ import org.junit.Test;
import org.junit.rules.RuleChain; import org.junit.rules.RuleChain;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.library_loader.LibraryProcessType; import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.base.test.util.CallbackHelper; import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.MinAndroidSdkLevel; import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.base.test.util.Restriction; import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
...@@ -42,18 +44,17 @@ import org.chromium.chrome.browser.tab.EmptyTabObserver; ...@@ -42,18 +44,17 @@ import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabBrowserControlsState; import org.chromium.chrome.browser.tab.TabBrowserControlsState;
import org.chromium.chrome.browser.tab.TabThemeColorHelper; import org.chromium.chrome.browser.tab.TabThemeColorHelper;
import org.chromium.chrome.browser.test.MockCertVerifierRuleAndroid;
import org.chromium.chrome.browser.util.ColorUtils; import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ChromeTabUtils; import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.content_public.browser.test.NativeLibraryTestRule;
import org.chromium.content_public.browser.test.util.Criteria; import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.NetError; import org.chromium.content_public.common.ContentSwitches;
import org.chromium.net.test.EmbeddedTestServerRule; import org.chromium.net.test.EmbeddedTestServerRule;
import org.chromium.ui.test.util.UiRestriction; import org.chromium.ui.test.util.UiRestriction;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
...@@ -69,15 +70,10 @@ public class TrustedWebActivityTest { ...@@ -69,15 +70,10 @@ public class TrustedWebActivityTest {
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule(); public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule();
public EmbeddedTestServerRule mEmbeddedTestServerRule = new EmbeddedTestServerRule(); public EmbeddedTestServerRule mEmbeddedTestServerRule = new EmbeddedTestServerRule();
public final NativeLibraryTestRule mNativeLibraryTestRule = new NativeLibraryTestRule();
public MockCertVerifierRuleAndroid mCertVerifierRule =
new MockCertVerifierRuleAndroid(mNativeLibraryTestRule, 0 /* net::OK */);
@Rule @Rule
public RuleChain mRuleChain = RuleChain.emptyRuleChain() public RuleChain mRuleChain = RuleChain.emptyRuleChain()
.around(mCustomTabActivityTestRule) .around(mCustomTabActivityTestRule)
.around(mNativeLibraryTestRule)
.around(mCertVerifierRule)
.around(mEmbeddedTestServerRule); .around(mEmbeddedTestServerRule);
private static final String TEST_PAGE = "/chrome/test/data/android/google.html"; private static final String TEST_PAGE = "/chrome/test/data/android/google.html";
...@@ -93,6 +89,12 @@ public class TrustedWebActivityTest { ...@@ -93,6 +89,12 @@ public class TrustedWebActivityTest {
mEmbeddedTestServerRule.setServerUsesHttps(true); // TWAs only work with HTTPS. mEmbeddedTestServerRule.setServerUsesHttps(true); // TWAs only work with HTTPS.
mTestPage = mEmbeddedTestServerRule.getServer().getURL(TEST_PAGE); mTestPage = mEmbeddedTestServerRule.getServer().getURL(TEST_PAGE);
// Map non-localhost-URLs to localhost. Navigations to non-localhost URLs will throw a
// certificate error.
Uri mapToUri = Uri.parse(mEmbeddedTestServerRule.getServer().getURL("/"));
CommandLine.getInstance().appendSwitchWithValue(
ContentSwitches.HOST_RESOLVER_RULES, "MAP * " + mapToUri.getAuthority());
} }
@Test @Test
...@@ -180,36 +182,33 @@ public class TrustedWebActivityTest { ...@@ -180,36 +182,33 @@ public class TrustedWebActivityTest {
* in the intent). * in the intent).
*/ */
@Test @Test
@DisabledTest(message = "crbug.com/1016743") @MediumTest
//@MediumTest
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP_MR1) @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP_MR1)
@Restriction({UiRestriction.RESTRICTION_TYPE_PHONE}) @Restriction({UiRestriction.RESTRICTION_TYPE_PHONE})
public void testStatusBarColorCertificateError() throws ExecutionException, TimeoutException { public void testStatusBarColorCertificateError() throws ExecutionException, TimeoutException {
final String pageWithThemeColor = mEmbeddedTestServerRule.getServer().getURL( final String pageWithThemeColor = mEmbeddedTestServerRule.getServer().getURL(
"/chrome/test/data/android/theme_color_test.html"); "/chrome/test/data/android/theme_color_test.html");
final String pageWithThemeColorCertError = mEmbeddedTestServerRule.getServer().getURL( final String pageWithThemeColorCertError =
"/chrome/test/data/android/theme_color_test2.html"); "https://certificateerror.com/chrome/test/data/android/theme_color_test2.html";
// Initially don't set certificate error so that we can later wait for the status bar color // Initially don't set certificate error so that we can later wait for the status bar color
// to change back to the default color. // to change back to the default color.
Intent intent = createTrustedWebActivityIntent(pageWithThemeColor); Intent intent = createTrustedWebActivityIntent(pageWithThemeColor);
intent.putExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, Color.GREEN); intent.putExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, Color.GREEN);
addTrustedOriginToIntent(intent, pageWithThemeColorCertError);
launchCustomTabActivity(intent); launchCustomTabActivity(intent);
CustomTabActivity activity = mCustomTabActivityTestRule.getActivity(); CustomTabActivity activity = mCustomTabActivityTestRule.getActivity();
waitForThemeColor(activity, Color.RED); waitForThemeColor(activity, Color.RED);
assertStatusBarColor(activity, Color.RED); assertStatusBarColor(activity, Color.RED);
mCertVerifierRule.setResult(NetError.ERR_CERT_INVALID); spoofVerification(PACKAGE_NAME, pageWithThemeColorCertError);
ChromeTabUtils.loadUrlOnUiThread(activity.getActivityTab(), pageWithThemeColorCertError); ChromeTabUtils.loadUrlOnUiThread(activity.getActivityTab(), pageWithThemeColorCertError);
int expectedColor = Color.BLACK; int defaultColor = TestThreadUtils.runOnUiThreadBlocking(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { () -> { return TabThemeColorHelper.getDefaultColor(activity.getActivityTab()); });
expectedColor = TestThreadUtils.runOnUiThreadBlocking(() -> { int expectedColor =
return TabThemeColorHelper.getDefaultColor(activity.getActivityTab()); Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? defaultColor : Color.BLACK;
}); waitForThemeColor(activity, defaultColor);
}
waitForThemeColor(activity, expectedColor);
assertStatusBarColor(activity, expectedColor); assertStatusBarColor(activity, expectedColor);
} }
...@@ -258,20 +257,21 @@ public class TrustedWebActivityTest { ...@@ -258,20 +257,21 @@ public class TrustedWebActivityTest {
* (and origin verification succeeds). * (and origin verification succeeds).
*/ */
@Test @Test
@DisabledTest(message = "crbug.com/1016743") @MediumTest
//@MediumTest
public void testToolbarVisibleCertificateError() throws ExecutionException, TimeoutException { public void testToolbarVisibleCertificateError() throws ExecutionException, TimeoutException {
final String pageWithoutCertError = final String pageWithoutCertError =
mEmbeddedTestServerRule.getServer().getURL("/chrome/test/data/android/about.html"); mEmbeddedTestServerRule.getServer().getURL("/chrome/test/data/android/about.html");
final String pageWithCertError = mEmbeddedTestServerRule.getServer().getURL( final String pageWithCertError =
"/chrome/test/data/android/theme_color_test.html"); "https://certificateerror.com/chrome/test/data/android/theme_color_test.html";
// Initially don't set certificate error so that we can later wait for the toolbar to hide. // Initially don't set certificate error so that we can later wait for the toolbar to hide.
Intent intent = createTrustedWebActivityIntent(pageWithoutCertError);
addTrustedOriginToIntent(intent, pageWithCertError);
launchCustomTabActivity(createTrustedWebActivityIntent(pageWithoutCertError)); launchCustomTabActivity(createTrustedWebActivityIntent(pageWithoutCertError));
Tab tab = mCustomTabActivityTestRule.getActivity().getActivityTab(); Tab tab = mCustomTabActivityTestRule.getActivity().getActivityTab();
assertFalse(getCanShowToolbarState(tab)); assertFalse(getCanShowToolbarState(tab));
mCertVerifierRule.setResult(NetError.ERR_CERT_INVALID); spoofVerification(PACKAGE_NAME, pageWithCertError);
ChromeTabUtils.loadUrlOnUiThread(tab, pageWithCertError); ChromeTabUtils.loadUrlOnUiThread(tab, pageWithCertError);
CriteriaHelper.pollUiThread(new Criteria() { CriteriaHelper.pollUiThread(new Criteria() {
...@@ -282,6 +282,13 @@ public class TrustedWebActivityTest { ...@@ -282,6 +282,13 @@ public class TrustedWebActivityTest {
}, 10000, CriteriaHelper.DEFAULT_POLLING_INTERVAL); }, 10000, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
} }
public void addTrustedOriginToIntent(Intent intent, String trustedOrigin) {
ArrayList<String> additionalTrustedOrigins = new ArrayList<>();
additionalTrustedOrigins.add(trustedOrigin);
intent.putExtra(TrustedWebActivityIntentBuilder.EXTRA_ADDITIONAL_TRUSTED_ORIGINS,
additionalTrustedOrigins);
}
public boolean getCanShowToolbarState(Tab tab) { public boolean getCanShowToolbarState(Tab tab) {
return TestThreadUtils.runOnUiThreadBlockingNoException( return TestThreadUtils.runOnUiThreadBlockingNoException(
() -> TabBrowserControlsState.get(tab).canShow()); () -> TabBrowserControlsState.get(tab).canShow());
......
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