Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2147)

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/SafeBrowsingTest.java

Issue 2833923002: WebView: carefully check size for SafeBrowsing interstitial (Closed)
Patch Set: Also check if attached, add @VisibleForTesting Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/javatests/src/org/chromium/android_webview/test/SafeBrowsingTest.java
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/SafeBrowsingTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/SafeBrowsingTest.java
index fc4b69a68be54d4082956a35949cfacd8f623256..4672eaa302b1ddd750368b2375c225bdb5e2cad8 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/SafeBrowsingTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/SafeBrowsingTest.java
@@ -9,9 +9,15 @@ import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.support.test.filters.SmallTest;
+import android.view.ViewGroup;
import org.chromium.android_webview.AwBrowserContext;
import org.chromium.android_webview.AwContents;
+import org.chromium.android_webview.AwContents.DependencyFactory;
+import org.chromium.android_webview.AwContents.InternalAccessDelegate;
+import org.chromium.android_webview.AwContents.NativeDrawGLFunctorFactory;
+import org.chromium.android_webview.AwContentsClient;
+import org.chromium.android_webview.AwSettings;
import org.chromium.android_webview.AwSwitches;
import org.chromium.android_webview.AwWebContentsObserver;
import org.chromium.android_webview.ErrorCodeConversionHelper;
@@ -35,7 +41,7 @@ import org.chromium.net.test.EmbeddedTestServer;
public class SafeBrowsingTest extends AwTestBase {
private TestAwContentsClient mContentsClient;
private AwTestContainerView mContainerView;
- private AwContents mAwContents;
+ private MockAwContents mAwContents;
private TestAwWebContentsObserver mWebContentsObserver;
private EmbeddedTestServer mTestServer;
@@ -122,12 +128,59 @@ public class SafeBrowsingTest extends AwTestBase {
}
}
+ private static class MockAwContents extends AwContents {
+ private boolean mCanShowInterstitial;
+ private boolean mCanShowBigInterstitial;
+
+ public MockAwContents(AwBrowserContext browserContext, ViewGroup containerView,
+ Context context, InternalAccessDelegate internalAccessAdapter,
+ NativeDrawGLFunctorFactory nativeDrawGLFunctorFactory,
+ AwContentsClient contentsClient, AwSettings settings,
+ DependencyFactory dependencyFactory) {
+ super(browserContext, containerView, context, internalAccessAdapter,
+ nativeDrawGLFunctorFactory, contentsClient, settings, dependencyFactory);
+ mCanShowInterstitial = true;
+ mCanShowBigInterstitial = true;
+ }
+
+ public void setCanShowInterstitial(boolean able) {
+ mCanShowInterstitial = able;
+ }
+
+ public void setCanShowBigInterstitial(boolean able) {
+ mCanShowBigInterstitial = able;
+ }
+
+ @Override
+ protected boolean canShowInterstitial() {
+ return mCanShowInterstitial;
+ }
+
+ @Override
+ protected boolean canShowBigInterstitial() {
+ return mCanShowBigInterstitial;
+ }
+ }
+
+ private static class SafeBrowsingDependencyFactory extends AwTestBase.TestDependencyFactory {
+ @Override
+ public AwContents createAwContents(AwBrowserContext browserContext, ViewGroup containerView,
+ Context context, InternalAccessDelegate internalAccessAdapter,
+ NativeDrawGLFunctorFactory nativeDrawGLFunctorFactory,
+ AwContentsClient contentsClient, AwSettings settings,
+ DependencyFactory dependencyFactory) {
+ return new MockAwContents(browserContext, containerView, context, internalAccessAdapter,
+ nativeDrawGLFunctorFactory, contentsClient, settings, dependencyFactory);
+ }
+ }
+
@Override
public void setUp() throws Exception {
super.setUp();
mContentsClient = new TestAwContentsClient();
- mContainerView = createAwTestContainerViewOnMainSync(mContentsClient);
- mAwContents = mContainerView.getAwContents();
+ mContainerView = createAwTestContainerViewOnMainSync(
+ mContentsClient, false, new SafeBrowsingDependencyFactory());
+ mAwContents = (MockAwContents) mContainerView.getAwContents();
mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
getInstrumentation().runOnMainSync(new Runnable() {
@@ -351,4 +404,35 @@ public class SafeBrowsingTest extends AwTestBase {
!= GraphicsTestUtils.getPixelColorAtCenterOfView(
mAwContents, mContainerView));
}
+
+ @SmallTest
+ @Feature({"AndroidWebView"})
+ @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT)
+ public void testSafeBrowsingShowsNetworkErrorForInvisibleViews() throws Throwable {
+ mAwContents.setCanShowInterstitial(false);
+ mAwContents.setCanShowBigInterstitial(false);
+ final String responseUrl = mTestServer.getURL(MALWARE_HTML_PATH);
+ OnReceivedError2Helper errorHelper = mContentsClient.getOnReceivedError2Helper();
+ int errorCount = errorHelper.getCallCount();
+ loadUrlAsync(mAwContents, responseUrl);
+ errorHelper.waitForCallback(errorCount);
+ assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN, errorHelper.getError().errorCode);
+ assertEquals("Network error is for the malicious page", responseUrl,
+ errorHelper.getRequest().url);
+ }
+
+ @SmallTest
+ @Feature({"AndroidWebView"})
+ @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT)
+ public void testSafeBrowsingShowsNetworkErrorForOddSizedViews() throws Throwable {
+ mAwContents.setCanShowBigInterstitial(false);
+ final String responseUrl = mTestServer.getURL(MALWARE_HTML_PATH);
+ OnReceivedError2Helper errorHelper = mContentsClient.getOnReceivedError2Helper();
+ int errorCount = errorHelper.getCallCount();
+ loadUrlAsync(mAwContents, responseUrl);
+ errorHelper.waitForCallback(errorCount);
+ assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN, errorHelper.getError().errorCode);
+ assertEquals("Network error is for the malicious page", responseUrl,
+ errorHelper.getRequest().url);
+ }
}
« no previous file with comments | « android_webview/java/src/org/chromium/android_webview/AwContents.java ('k') | android_webview/native/aw_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698