Commit 76b9c1f9 authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

TWA quality enforcement flag

This CL changes the how the TWA quality enforcement enabled with the
flag and enable the flag for now:
* If flag is not enabled:
    * Show a Toast if local build
* If flag is enabled:
    * if TWA client enabled quality enforcement:
        * crash
    * client not enabled, forced flag enabled:
        * crash
        * show a toast if local build
    * otherwise
        * show a Toast if local build

The NOTIFY callback is not needed and removed.

Bug: 1109609
Change-Id: I6959092f97d2c2f55cc3b57dbd152147527ae829
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2353171
Commit-Queue: Ella Ge <eirage@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799167}
parent 08ad5561
......@@ -47,8 +47,6 @@ import javax.inject.Inject;
*/
@ActivityScope
public class QualityEnforcer implements NativeInitObserver {
@VisibleForTesting
static final String NOTIFY = "quality_enforcement.notify";
@VisibleForTesting
static final String CRASH = "quality_enforcement.crash";
@VisibleForTesting
......@@ -138,18 +136,28 @@ public class QualityEnforcer implements NativeInitObserver {
private void trigger(@ViolationType int type, String url, int httpStatusCode) {
mUmaRecorder.recordQualityEnforcementViolation(type);
showErrorToast(getToastMessage(type, url, httpStatusCode));
if (!ChromeFeatureList.isEnabled(
ChromeFeatureList.TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT)) {
showErrorToast(getToastMessage(type, url, httpStatusCode));
return;
}
// Notify the client app.
Bundle args = new Bundle();
args.putString(KEY_CRASH_REASON, toTwaCrashMessage(type, url, httpStatusCode));
if (!ChromeFeatureList.isEnabled(
ChromeFeatureList.TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT)) {
mConnection.sendExtraCallbackWithResult(mSessionToken, NOTIFY, args);
} else {
Bundle result = mConnection.sendExtraCallbackWithResult(mSessionToken, CRASH, args);
boolean success = result != null && result.getBoolean(KEY_SUCCESS);
if (success) mActivity.finish();
Bundle result = mConnection.sendExtraCallbackWithResult(mSessionToken, CRASH, args);
boolean success = result != null && result.getBoolean(KEY_SUCCESS);
// Show the Toast if client app does not enable quality enforcement.
if (!success) {
showErrorToast(getToastMessage(type, url, httpStatusCode));
}
if (ChromeFeatureList.isEnabled(
ChromeFeatureList.TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT_FORCED)
|| success) {
mActivity.finish();
}
}
......
......@@ -48,7 +48,7 @@ import java.util.concurrent.TimeoutException;
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@DisableFeatures(ChromeFeatureList.TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT)
@DisableFeatures(ChromeFeatureList.TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT_FORCED)
public class QualityEnforcerTest {
private static final String TEST_PAGE = "/chrome/test/data/android/google.html";
// A not exist test page to triger 404.
......@@ -74,7 +74,7 @@ public class QualityEnforcerTest {
CustomTabsCallback mCallback = new CustomTabsCallback() {
@Override
public Bundle extraCallbackWithResult(String callbackName, Bundle args) {
if (callbackName.equals(QualityEnforcer.NOTIFY)) {
if (callbackName.equals(QualityEnforcer.CRASH)) {
mCallbackHelper.notifyCalled();
mErrorMessage = args.getString(QualityEnforcer.KEY_CRASH_REASON);
}
......
......@@ -40,12 +40,14 @@ import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabBrowserControlsConstraintsHelper;
import org.chromium.chrome.browser.tab.TabThemeColorHelper;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
import org.chromium.chrome.test.util.browser.ThemeTestUtils;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
......@@ -117,6 +119,7 @@ public class TrustedWebActivityTest {
@Test
@MediumTest
@DisableFeatures(ChromeFeatureList.TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT_FORCED)
public void leavesTwa_VerificationFailure() throws TimeoutException {
Intent intent = createTrustedWebActivityIntent(mTestPage);
createSession(intent, PACKAGE_NAME);
......
......@@ -27,6 +27,7 @@ import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabProvid
import org.chromium.chrome.browser.customtabs.content.TabCreationMode;
import org.chromium.chrome.browser.customtabs.dependency_injection.BaseCustomTabActivityComponent;
import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.lifecycle.InflationObserver;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
......@@ -37,6 +38,7 @@ import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorBase;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
import java.util.Arrays;
import java.util.List;
......@@ -148,6 +150,8 @@ public class CustomTabDeferredStartupTest {
@Test
@LargeTest
@DisableFeatures(ChromeFeatureList.TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT_FORCED)
// TODO(eirage): Make this test work with quality enforcement.
public void testPageIsLoadedOnDeferredStartup() throws Exception {
PageLoadFinishedTabObserver tabObserver = new PageLoadFinishedTabObserver();
NewTabObserver newTabObserver = new NewTabObserver(tabObserver);
......
......@@ -52,7 +52,8 @@ import org.chromium.net.NetError;
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@DisableFeatures(ChromeFeatureList.TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT)
@EnableFeatures(ChromeFeatureList.TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT)
@DisableFeatures(ChromeFeatureList.TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT_FORCED)
public class QualityEnforcerUnitTest {
private static final String TRUSTED_ORIGIN_PAGE = "https://www.origin1.com/page1";
private static final String UNTRUSTED_PAGE = "https://www.origin2.com/page1";
......@@ -135,7 +136,16 @@ public class QualityEnforcerUnitTest {
}
@Test
@EnableFeatures(ChromeFeatureList.TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT)
public void trigger_offline() {
navigateToUrlInternet(TRUSTED_ORIGIN_PAGE);
Assert.assertEquals(
ContextUtils.getApplicationContext().getString(
R.string.twa_quality_enforcement_violation_offline, TRUSTED_ORIGIN_PAGE),
ShadowToast.getTextOfLatestToast());
verifyNotifyClientApp();
}
@Test
public void triggerCrash_whenClientSupports() {
Bundle result = new Bundle();
result.putBoolean("success", true);
......@@ -148,8 +158,7 @@ public class QualityEnforcerUnitTest {
}
@Test
@EnableFeatures(ChromeFeatureList.TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT)
public void notTriggerCrash_whenClientDoesntSupport() {
public void notTriggerCrash_whenClientNotSupport() {
Bundle result = new Bundle();
result.putBoolean("success", false);
when(mCustomTabsConnection.sendExtraCallbackWithResult(
......@@ -160,16 +169,6 @@ public class QualityEnforcerUnitTest {
verify(mActivity, never()).finish();
}
@Test
public void trigger_offline() {
navigateToUrlInternet(TRUSTED_ORIGIN_PAGE);
Assert.assertEquals(
ContextUtils.getApplicationContext().getString(
R.string.twa_quality_enforcement_violation_offline, TRUSTED_ORIGIN_PAGE),
ShadowToast.getTextOfLatestToast());
verifyNotifyClientApp();
}
@Test
public void notTrigger_digitalAssertLinkPass() {
when(mIntentDataProvider.getUrlToLoad()).thenReturn(TRUSTED_ORIGIN_PAGE);
......@@ -189,6 +188,26 @@ public class QualityEnforcerUnitTest {
verifyNotifyClientApp();
}
@Test
@EnableFeatures(ChromeFeatureList.TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT_FORCED)
public void notTriggerCrash_whenClientNotSupportButForced() {
Bundle result = new Bundle();
result.putBoolean("success", false);
when(mCustomTabsConnection.sendExtraCallbackWithResult(
any(), eq(QualityEnforcer.CRASH), any()))
.thenReturn(result);
navigateToUrlNotFound(TRUSTED_ORIGIN_PAGE);
verify(mActivity).finish();
}
@Test
@DisableFeatures(ChromeFeatureList.TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT)
public void notTriggerCrash_whenFlagIsDisabled() {
navigateToUrlNotFound(TRUSTED_ORIGIN_PAGE);
verifyNotTriggered();
}
private void verifyTriggered404() {
Assert.assertEquals(ContextUtils.getApplicationContext().getString(
R.string.twa_quality_enforcement_violation_error,
......@@ -199,12 +218,14 @@ public class QualityEnforcerUnitTest {
private void verifyNotifyClientApp() {
verify(mCustomTabsConnection)
.sendExtraCallbackWithResult(any(), eq(QualityEnforcer.NOTIFY), any());
.sendExtraCallbackWithResult(any(), eq(QualityEnforcer.CRASH), any());
doNothing().when(mActivity).finish();
}
private void verifyNotTriggered() {
verify(mCustomTabsConnection, never())
.sendExtraCallbackWithResult(any(), eq(QualityEnforcer.NOTIFY), any());
.sendExtraCallbackWithResult(any(), eq(QualityEnforcer.CRASH), any());
verify(mActivity, never()).finish();
}
private void navigateToUrlNoError(String url) {
......
......@@ -210,10 +210,11 @@ const base::Feature* kFeaturesExposedToJava[] = {
&kTabToGTSAnimation,
&kTestDefaultDisabled,
&kTestDefaultEnabled,
&kTrustedWebActivityNewDisclosure,
&kTrustedWebActivityLocationDelegation,
&kTrustedWebActivityQualityEnforcement,
&kTrustedWebActivityNewDisclosure,
&kTrustedWebActivityPostMessage,
&kTrustedWebActivityQualityEnforcement,
&kTrustedWebActivityQualityEnforcementForced,
&kStartSurfaceAndroid,
&kUmaBackgroundSessions,
&kUpdateNotificationSchedulingIntegration,
......@@ -616,18 +617,22 @@ const base::Feature kTestDefaultDisabled{"TestDefaultDisabled",
const base::Feature kTestDefaultEnabled{"TestDefaultEnabled",
base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kTrustedWebActivityNewDisclosure{
"TrustedWebActivityNewDisclosure", base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kTrustedWebActivityQualityEnforcement{
"TrustedWebActivityQualityEnforcement", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kTrustedWebActivityLocationDelegation{
"TrustedWebActivityLocationDelegation", base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kTrustedWebActivityNewDisclosure{
"TrustedWebActivityNewDisclosure", base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kTrustedWebActivityPostMessage{
"TrustedWebActivityPostMessage", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kTrustedWebActivityQualityEnforcement{
"TrustedWebActivityQualityEnforcement", base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kTrustedWebActivityQualityEnforcementForced{
"TrustedWebActivityQualityEnforcementForced",
base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kStartSurfaceAndroid{"StartSurfaceAndroid",
base::FEATURE_DISABLED_BY_DEFAULT};
......
......@@ -123,10 +123,11 @@ extern const base::Feature kTabSwitcherOnReturn;
extern const base::Feature kTabToGTSAnimation;
extern const base::Feature kTestDefaultDisabled;
extern const base::Feature kTestDefaultEnabled;
extern const base::Feature kTrustedWebActivityQualityEnforcement;
extern const base::Feature kTrustedWebActivityNewDisclosure;
extern const base::Feature kTrustedWebActivityLocationDelegation;
extern const base::Feature kTrustedWebActivityNewDisclosure;
extern const base::Feature kTrustedWebActivityPostMessage;
extern const base::Feature kTrustedWebActivityQualityEnforcement;
extern const base::Feature kTrustedWebActivityQualityEnforcementForced;
extern const base::Feature kStartSurfaceAndroid;
extern const base::Feature kUmaBackgroundSessions;
extern const base::Feature kUpdateNotificationSchedulingIntegration;
......
......@@ -416,15 +416,17 @@ public abstract class ChromeFeatureList {
public static final String TEST_DEFAULT_ENABLED = "TestDefaultEnabled";
public static final String TOUCH_TO_FILL_ANDROID = "TouchToFillAndroid";
public static final String TRUSTED_WEB_ACTIVITY = "TrustedWebActivity";
public static final String TRUSTED_WEB_ACTIVITY_POST_MESSAGE = "TrustedWebActivityPostMessage";
public static final String TRUSTED_WEB_ACTIVITY_NOTIFICATION_DELEGATION_ENROLMENT =
"TrustedWebActivityNotificationDelegationAutoEnrolment";
public static final String TRUSTED_WEB_ACTIVITY_LOCATION_DELEGATION =
"TrustedWebActivityLocationDelegation";
public static final String TRUSTED_WEB_ACTIVITY_NEW_DISCLOSURE =
"TrustedWebActivityNewDisclosure";
public static final String TRUSTED_WEB_ACTIVITY_NOTIFICATION_DELEGATION_ENROLMENT =
"TrustedWebActivityNotificationDelegationAutoEnrolment";
public static final String TRUSTED_WEB_ACTIVITY_POST_MESSAGE = "TrustedWebActivityPostMessage";
public static final String TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT =
"TrustedWebActivityQualityEnforcement";
public static final String TRUSTED_WEB_ACTIVITY_LOCATION_DELEGATION =
"TrustedWebActivityLocationDelegation";
public static final String TRUSTED_WEB_ACTIVITY_QUALITY_ENFORCEMENT_FORCED =
"TrustedWebActivityQualityEnforcementForced";
public static final String VIDEO_PERSISTENCE = "VideoPersistence";
public static final String VIDEO_TUTORIALS = "VideoTutorials";
public static final String USAGE_STATS = "UsageStats";
......
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