Commit 1e100475 authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: Trick to Bill constant for targetsAtLeastQ

When the app targets at least Q, we should return a dedicated integer
constant. Otherwise, we should return UNKNOWN for backwards
compatibility.

Bug: 887186
Test: run_run_webview_instrumentation_test_apk -f=SafeBrowsingTest#*Billing*
Change-Id: Ifcab24c33469d3c5ce31dafa3b947a60cf6a82ed
Reviewed-on: https://chromium-review.googlesource.com/c/1406317Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#622117}
parent cb5b610f
......@@ -6,6 +6,7 @@ package org.chromium.android_webview;
import android.webkit.WebViewClient;
import org.chromium.base.BuildInfo;
import org.chromium.components.safe_browsing.SBThreatType;
/**
......@@ -26,12 +27,16 @@ public final class AwSafeBrowsingConversionHelper {
public static final int SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE =
WebViewClient.SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE;
/** The resource was blocked because it may trick the user into a billing agreement. */
// TODO(ntfschr): add a new int to the SDK.
public static final int SAFE_BROWSING_THREAT_BILLING =
WebViewClient.SAFE_BROWSING_THREAT_UNKNOWN;
// TODO(ntfschr): replace this with the named constant when we roll the Q SDK
// (http://crbug.com/887186).
public static final int SAFE_BROWSING_THREAT_BILLING = 4;
/**
* Converts the threat type value from SafeBrowsing code to the WebViewClient constant.
*
* <p class="note"><b>Note:</b> this output may depend upon the embedding application's {@code
* targetSdk} value if {@code chromiumThreatType} refers to a threat type added after {@link
* Build.VERSION_CODES#O_MR1} (when we added the original Safe Browisng threat type constants).
*/
public static int convertThreatType(int chromiumThreatType) {
switch (chromiumThreatType) {
......@@ -42,7 +47,8 @@ public final class AwSafeBrowsingConversionHelper {
case SBThreatType.URL_UNWANTED:
return SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE;
case SBThreatType.BILLING:
return SAFE_BROWSING_THREAT_BILLING;
return BuildInfo.targetsAtLeastQ() ? SAFE_BROWSING_THREAT_BILLING
: SAFE_BROWSING_THREAT_UNKNOWN;
default:
return SAFE_BROWSING_THREAT_UNKNOWN;
}
......
......@@ -40,6 +40,7 @@ import org.chromium.android_webview.ErrorCodeConversionHelper;
import org.chromium.android_webview.SafeBrowsingAction;
import org.chromium.android_webview.test.TestAwContentsClient.OnReceivedError2Helper;
import org.chromium.android_webview.test.util.GraphicsTestUtils;
import org.chromium.base.BuildInfo;
import org.chromium.base.Callback;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CallbackHelper;
......@@ -532,8 +533,12 @@ public class SafeBrowsingTest {
// Check onSafeBrowsingHit arguments
final String responseUrl = mTestServer.getURL(BILLING_HTML_PATH);
Assert.assertEquals(responseUrl, mContentsClient.getLastRequest().url);
Assert.assertEquals(AwSafeBrowsingConversionHelper.SAFE_BROWSING_THREAT_BILLING,
mContentsClient.getLastThreatType());
// The expectedCode intentionally depends on targetSdk (and is disconnected from SDK_INT).
// This is for backwards compatibility with apps with a lower targetSdk.
int expectedCode = BuildInfo.targetsAtLeastQ()
? AwSafeBrowsingConversionHelper.SAFE_BROWSING_THREAT_BILLING
: AwSafeBrowsingConversionHelper.SAFE_BROWSING_THREAT_UNKNOWN;
Assert.assertEquals(expectedCode, mContentsClient.getLastThreatType());
}
@Test
......
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