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; ...@@ -6,6 +6,7 @@ package org.chromium.android_webview;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import org.chromium.base.BuildInfo;
import org.chromium.components.safe_browsing.SBThreatType; import org.chromium.components.safe_browsing.SBThreatType;
/** /**
...@@ -26,12 +27,16 @@ public final class AwSafeBrowsingConversionHelper { ...@@ -26,12 +27,16 @@ public final class AwSafeBrowsingConversionHelper {
public static final int SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE = public static final int SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE =
WebViewClient.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. */ /** The resource was blocked because it may trick the user into a billing agreement. */
// TODO(ntfschr): add a new int to the SDK. // TODO(ntfschr): replace this with the named constant when we roll the Q SDK
public static final int SAFE_BROWSING_THREAT_BILLING = // (http://crbug.com/887186).
WebViewClient.SAFE_BROWSING_THREAT_UNKNOWN; public static final int SAFE_BROWSING_THREAT_BILLING = 4;
/** /**
* Converts the threat type value from SafeBrowsing code to the WebViewClient constant. * 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) { public static int convertThreatType(int chromiumThreatType) {
switch (chromiumThreatType) { switch (chromiumThreatType) {
...@@ -42,7 +47,8 @@ public final class AwSafeBrowsingConversionHelper { ...@@ -42,7 +47,8 @@ public final class AwSafeBrowsingConversionHelper {
case SBThreatType.URL_UNWANTED: case SBThreatType.URL_UNWANTED:
return SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE; return SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE;
case SBThreatType.BILLING: case SBThreatType.BILLING:
return SAFE_BROWSING_THREAT_BILLING; return BuildInfo.targetsAtLeastQ() ? SAFE_BROWSING_THREAT_BILLING
: SAFE_BROWSING_THREAT_UNKNOWN;
default: default:
return SAFE_BROWSING_THREAT_UNKNOWN; return SAFE_BROWSING_THREAT_UNKNOWN;
} }
......
...@@ -40,6 +40,7 @@ import org.chromium.android_webview.ErrorCodeConversionHelper; ...@@ -40,6 +40,7 @@ import org.chromium.android_webview.ErrorCodeConversionHelper;
import org.chromium.android_webview.SafeBrowsingAction; import org.chromium.android_webview.SafeBrowsingAction;
import org.chromium.android_webview.test.TestAwContentsClient.OnReceivedError2Helper; import org.chromium.android_webview.test.TestAwContentsClient.OnReceivedError2Helper;
import org.chromium.android_webview.test.util.GraphicsTestUtils; import org.chromium.android_webview.test.util.GraphicsTestUtils;
import org.chromium.base.BuildInfo;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CallbackHelper; import org.chromium.base.test.util.CallbackHelper;
...@@ -532,8 +533,12 @@ public class SafeBrowsingTest { ...@@ -532,8 +533,12 @@ public class SafeBrowsingTest {
// Check onSafeBrowsingHit arguments // Check onSafeBrowsingHit arguments
final String responseUrl = mTestServer.getURL(BILLING_HTML_PATH); final String responseUrl = mTestServer.getURL(BILLING_HTML_PATH);
Assert.assertEquals(responseUrl, mContentsClient.getLastRequest().url); Assert.assertEquals(responseUrl, mContentsClient.getLastRequest().url);
Assert.assertEquals(AwSafeBrowsingConversionHelper.SAFE_BROWSING_THREAT_BILLING, // The expectedCode intentionally depends on targetSdk (and is disconnected from SDK_INT).
mContentsClient.getLastThreatType()); // 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 @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