Commit 64b2a76c authored by Rohit Agarwal's avatar Rohit Agarwal Committed by Commit Bot

Restrict Incognito CCT to Chrome and 1P apps only.

This CL:

a) Restricts Incognito CCT to non-3P apps.

b) Modifies the existing tests in order for them to launch the
Incognito CCT with this change.

c) Adds a new IncongitoCustomTabActivityTestRule that adds module
overrides to help with the mocking 1P apps.

Bug: 1139293
Change-Id: Ie230858361c915470b4d5ff6042b4d6e1784fe8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536455
Commit-Queue: Rohit Agarwal <roagarwal@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828202}
parent 78876189
......@@ -142,6 +142,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java",
"javatests/src/org/chromium/chrome/browser/customtabs/DetachedResourceRequestTest.java",
"javatests/src/org/chromium/chrome/browser/customtabs/IncognitoCustomTabActivityRenderTest.java",
"javatests/src/org/chromium/chrome/browser/customtabs/IncognitoCustomTabActivityTestRule.java",
"javatests/src/org/chromium/chrome/browser/customtabs/RequestThrottlerTest.java",
"javatests/src/org/chromium/chrome/browser/customtabs/TrustedCdnPublisherUrlTest.java",
"javatests/src/org/chromium/chrome/browser/customtabs/content/CustomTabActivityTabControllerTest.java",
......
......@@ -25,6 +25,7 @@ import androidx.browser.customtabs.CustomTabsSessionToken;
import org.chromium.base.IntentUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeApplication;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.flags.ActivityType;
......@@ -117,11 +118,19 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD
return (isTrustedIntent(intent) && (requestedUiType == CustomTabsUiType.READER_MODE));
}
private static boolean isVerifiedFirstPartyIntent(Intent intent) {
CustomTabsSessionToken sessionToken =
CustomTabsSessionToken.getSessionTokenFromIntent(intent);
String sendersPackageName =
CustomTabsConnection.getInstance().getClientPackageNameForSession(sessionToken);
return !TextUtils.isEmpty(sendersPackageName)
&& ChromeApplication.getComponent().resolveExternalAuthUtils().isGoogleSigned(
sendersPackageName);
}
private static boolean isTrustedIntent(Intent intent) {
CustomTabsSessionToken session = CustomTabsSessionToken.getSessionTokenFromIntent(intent);
boolean isOpenedByChrome =
IntentUtils.safeGetBooleanExtra(intent, EXTRA_IS_OPENED_BY_CHROME, false);
return isTrustedCustomTab(intent, session) && isOpenedByChrome;
if (IntentHandler.wasIntentSenderChrome(intent)) return true;
return isVerifiedFirstPartyIntent(intent);
}
private static boolean isAllowedToAddCustomMenuItem(Intent intent) {
......@@ -150,6 +159,7 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD
// incognito CCT request for all apps.
public static boolean isValidIncognitoIntent(Intent intent) {
if (!isIncognitoRequested(intent)) return false;
if (!isTrustedIntent(intent)) return false;
// Incognito requests for payments flow are supported without
// INCOGNITO_CCT flag as an exceptional case that can use Chrome
// incognito profile.
......
......@@ -72,13 +72,15 @@ import java.util.concurrent.TimeoutException;
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.FORCE_FIRST_RUN_FLOW_COMPLETE_FOR_TESTING})
public class CustomTabActivityIncognitoTest {
private String mTestPage;
private static final String TEST_PAGE = "/chrome/test/data/android/google.html";
private static final String TEST_MENU_TITLE = "testMenuTitle";
private static int sIdToIncrement = 1;
private String mTestPage;
@Rule
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule();
public IncognitoCustomTabActivityTestRule mCustomTabActivityTestRule =
new IncognitoCustomTabActivityTestRule();
@Rule
public TestRule mProcessor = new Features.InstrumentationProcessor();
......@@ -89,7 +91,6 @@ public class CustomTabActivityIncognitoTest {
@Before
public void setUp() throws TimeoutException {
mTestPage = mEmbeddedTestServerRule.getServer().getURL(TEST_PAGE);
// Ensuring native is initialized before we access the CCT_INCOGNITO feature flag.
IncognitoDataTestUtils.fireAndWaitForCctWarmup();
}
......
......@@ -56,8 +56,8 @@ public class IncognitoCustomTabActivityRenderTest {
private Intent mIntent;
@Rule
public final CustomTabActivityTestRule mCustomTabActivityTestRule =
new CustomTabActivityTestRule();
public final IncognitoCustomTabActivityTestRule mCustomTabActivityTestRule =
new IncognitoCustomTabActivityTestRule();
@Rule
public final EmbeddedTestServerRule mEmbeddedTestServerRule = new EmbeddedTestServerRule();
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.customtabs;
import android.content.Intent;
import androidx.browser.customtabs.CustomTabsSessionToken;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.chromium.chrome.browser.AppHooksModule;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.dependency_injection.ModuleOverridesRule;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import java.util.concurrent.TimeoutException;
/**
* Custom ActivityTestRule for all instrumentation tests that require a regular or Incognito {@link
* CustomTabActivity}.
*/
public class IncognitoCustomTabActivityTestRule extends CustomTabActivityTestRule {
@Rule
private final TestRule mModuleOverridesRule = new ModuleOverridesRule().setOverride(
AppHooksModule.Factory.class, AppHooksModuleForTest::new);
/**
* To load a fake module in tests we need to bypass a check if package name of module
* is Google-signed. This class overrides this check for testing.
*/
class AppHooksModuleForTest extends AppHooksModule {
@Override
public ExternalAuthUtils provideExternalAuthUtils() {
return new ExternalAuthUtils() {
@Override
public boolean isGoogleSigned(String packageName) {
return true;
}
};
}
}
private static void createNewCustomTabSessionForIntent(Intent intent) throws TimeoutException {
// To emulate first party we create a new session with the session token provided by the
// |intent|. The session is needed in order to verify if the embedder is 1P or not.
CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait();
CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFromIntent(intent);
connection.newSession(token);
}
private static boolean isIntentIncognito(Intent intent) {
return intent.getBooleanExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false);
}
@Override
public void startCustomTabActivityWithIntent(Intent intent) {
if (isIntentIncognito(intent)) {
try {
createNewCustomTabSessionForIntent(intent);
} catch (TimeoutException e) {
Assert.fail();
}
}
super.startCustomTabActivityWithIntent(intent);
}
@Override
public Statement apply(Statement base, Description description) {
// ModuleOverridesRule must be an outer rule.
Statement moduleOverridesStatement = mModuleOverridesRule.apply(base, description);
return super.apply(moduleOverridesStatement, description);
}
}
\ No newline at end of file
......@@ -26,7 +26,7 @@ import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Criteria;
import org.chromium.base.test.util.CriteriaHelper;
import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule;
import org.chromium.chrome.browser.customtabs.IncognitoCustomTabActivityTestRule;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.incognito.IncognitoDataTestUtils.ActivityType;
......@@ -53,17 +53,17 @@ import java.util.concurrent.TimeoutException;
@EnableFeatures({ChromeFeatureList.CCT_INCOGNITO})
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class IncognitoCookieLeakageTest {
private static final String COOKIES_SETTING_PATH = "/chrome/test/data/android/cookie.html";
private String mCookiesTestPage;
private EmbeddedTestServer mTestServer;
private static final String COOKIES_SETTING_PATH = "/chrome/test/data/android/cookie.html";
@Rule
public ChromeTabbedActivityTestRule mChromeActivityTestRule =
new ChromeTabbedActivityTestRule();
@Rule
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule();
public IncognitoCustomTabActivityTestRule mCustomTabActivityTestRule =
new IncognitoCustomTabActivityTestRule();
@Before
public void setUp() throws TimeoutException {
......
......@@ -6,7 +6,11 @@ package org.chromium.chrome.browser.incognito;
import static org.junit.Assert.assertEquals;
import static org.chromium.chrome.browser.customtabs.CustomTabsTestUtils.createMinimalCustomTabIntent;
import static org.chromium.chrome.browser.customtabs.CustomTabsTestUtils.createMinimalIncognitoCustomTabIntent;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
......@@ -19,11 +23,9 @@ import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.Criteria;
import org.chromium.base.test.util.CriteriaHelper;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule;
import org.chromium.chrome.browser.customtabs.CustomTabsConnection;
import org.chromium.chrome.browser.customtabs.CustomTabsTestUtils;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
......@@ -157,15 +159,11 @@ public class IncognitoDataTestUtils {
private static Tab launchUrlInCCT(
CustomTabActivityTestRule testRule, String url, boolean incognito) {
Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getContext(), url);
if (incognito) {
intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
}
Context context = InstrumentationRegistry.getContext();
Intent intent = incognito ? createMinimalIncognitoCustomTabIntent(context, url)
: createMinimalCustomTabIntent(context, url);
testRule.startCustomTabActivityWithIntent(intent);
Tab tab = testRule.getActivity().getActivityTab();
// Giving time to the WebContents to be ready.
......
......@@ -27,7 +27,7 @@ import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule;
import org.chromium.chrome.browser.customtabs.IncognitoCustomTabActivityTestRule;
import org.chromium.chrome.browser.download.DownloadItem;
import org.chromium.chrome.browser.download.DownloadManagerService;
import org.chromium.chrome.browser.download.DownloadPromptStatus;
......@@ -129,7 +129,8 @@ public class IncognitoDownloadLeakageTest {
new ChromeTabbedActivityTestRule();
@Rule
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule();
public IncognitoCustomTabActivityTestRule mCustomTabActivityTestRule =
new IncognitoCustomTabActivityTestRule();
@Before
public void setUp() throws Exception {
......
......@@ -27,7 +27,7 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Criteria;
import org.chromium.base.test.util.CriteriaHelper;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule;
import org.chromium.chrome.browser.customtabs.IncognitoCustomTabActivityTestRule;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.history.BrowsingHistoryBridge;
......@@ -58,19 +58,20 @@ import java.util.concurrent.TimeoutException;
@EnableFeatures({ChromeFeatureList.CCT_INCOGNITO})
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class IncognitoHistoryLeakageTest {
private static final String TEST_PAGE_1 = "/chrome/test/data/android/google.html";
private static final String TEST_PAGE_2 = "/chrome/test/data/android/test.html";
private EmbeddedTestServer mTestServer;
private String mTestPage1;
private String mTestPage2;
private static final String TEST_PAGE_1 = "/chrome/test/data/android/google.html";
private static final String TEST_PAGE_2 = "/chrome/test/data/android/test.html";
@Rule
public ChromeTabbedActivityTestRule mChromeActivityTestRule =
new ChromeTabbedActivityTestRule();
@Rule
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule();
public IncognitoCustomTabActivityTestRule mCustomTabActivityTestRule =
new IncognitoCustomTabActivityTestRule();
@Before
public void setUp() throws TimeoutException {
......
......@@ -37,7 +37,7 @@ import org.chromium.base.test.util.CriteriaHelper;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.FlakyTest;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule;
import org.chromium.chrome.browser.customtabs.IncognitoCustomTabActivityTestRule;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.incognito.IncognitoDataTestUtils.ActivityType;
......@@ -68,18 +68,19 @@ import java.util.concurrent.TimeoutException;
@EnableFeatures({ChromeFeatureList.CCT_INCOGNITO})
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class IncognitoPermissionLeakageTest {
private String mPermissionTestPage;
private EmbeddedTestServer mTestServer;
private static final String PERMISSION_HTML_PATH =
"/content/test/data/android/geolocation.html";
private String mPermissionTestPage;
private EmbeddedTestServer mTestServer;
@Rule
public ChromeTabbedActivityTestRule mChromeActivityTestRule =
new ChromeTabbedActivityTestRule();
@Rule
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule();
public IncognitoCustomTabActivityTestRule mCustomTabActivityTestRule =
new IncognitoCustomTabActivityTestRule();
@Before
public void setUp() throws TimeoutException {
......
......@@ -25,7 +25,7 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Criteria;
import org.chromium.base.test.util.CriteriaHelper;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule;
import org.chromium.chrome.browser.customtabs.IncognitoCustomTabActivityTestRule;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.incognito.IncognitoDataTestUtils.ActivityType;
......@@ -53,21 +53,22 @@ import java.util.concurrent.TimeoutException;
@EnableFeatures({ChromeFeatureList.CCT_INCOGNITO})
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class IncognitoStorageLeakageTest {
private String mSiteDataTestPage;
private EmbeddedTestServer mTestServer;
private static final String SITE_DATA_HTML_PATH =
"/content/test/data/browsing_data/site_data.html";
private static final List<String> sSiteData = Arrays.asList(
"LocalStorage", "ServiceWorker", "CacheStorage", "IndexedDb", "FileSystem", "WebSql");
private String mSiteDataTestPage;
private EmbeddedTestServer mTestServer;
@Rule
public ChromeTabbedActivityTestRule mChromeActivityTestRule =
new ChromeTabbedActivityTestRule();
@Rule
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule();
public IncognitoCustomTabActivityTestRule mCustomTabActivityTestRule =
new IncognitoCustomTabActivityTestRule();
@Before
public void setUp() throws TimeoutException {
......
......@@ -23,8 +23,8 @@ import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule;
import org.chromium.chrome.browser.customtabs.CustomTabsTestUtils;
import org.chromium.chrome.browser.customtabs.IncognitoCustomTabActivityTestRule;
import org.chromium.chrome.browser.customtabs.features.toolbar.CustomTabToolbar;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
......@@ -56,7 +56,8 @@ public class ToolbarDataProviderTest {
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
@Rule
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule();
public IncognitoCustomTabActivityTestRule mCustomTabActivityTestRule =
new IncognitoCustomTabActivityTestRule();
@Rule
public BlankCTATabInitialStateRule mBlankCTATabInitialStateRule =
......
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