| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.android_webview.test; | 5 package org.chromium.android_webview.test; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.SharedPreferences; | 8 import android.content.SharedPreferences; |
| 9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
| 10 import android.graphics.Color; | 10 import android.graphics.Color; |
| 11 import android.support.test.filters.SmallTest; | 11 import android.support.test.filters.SmallTest; |
| 12 | 12 |
| 13 import org.chromium.android_webview.AwBrowserContext; | 13 import org.chromium.android_webview.AwBrowserContext; |
| 14 import org.chromium.android_webview.AwContents; | 14 import org.chromium.android_webview.AwContents; |
| 15 import org.chromium.android_webview.AwSwitches; | 15 import org.chromium.android_webview.AwSwitches; |
| 16 import org.chromium.android_webview.AwWebContentsObserver; | 16 import org.chromium.android_webview.AwWebContentsObserver; |
| 17 import org.chromium.android_webview.ErrorCodeConversionHelper; | 17 import org.chromium.android_webview.ErrorCodeConversionHelper; |
| 18 import org.chromium.android_webview.test.TestAwContentsClient.OnReceivedError2He
lper; | 18 import org.chromium.android_webview.test.TestAwContentsClient.OnReceivedError2He
lper; |
| 19 import org.chromium.android_webview.test.util.GraphicsTestUtils; | 19 import org.chromium.android_webview.test.util.GraphicsTestUtils; |
| 20 import org.chromium.base.ThreadUtils; | 20 import org.chromium.base.ThreadUtils; |
| 21 import org.chromium.base.test.util.CallbackHelper; | 21 import org.chromium.base.test.util.CallbackHelper; |
| 22 import org.chromium.base.test.util.CommandLineFlags; | 22 import org.chromium.base.test.util.CommandLineFlags; |
| 23 import org.chromium.base.test.util.Feature; | 23 import org.chromium.base.test.util.Feature; |
| 24 import org.chromium.base.test.util.InMemorySharedPreferences; | 24 import org.chromium.base.test.util.InMemorySharedPreferences; |
| 25 import org.chromium.components.safe_browsing.SafeBrowsingApiBridge; | 25 import org.chromium.components.safe_browsing.SafeBrowsingApiBridge; |
| 26 import org.chromium.components.safe_browsing.SafeBrowsingApiHandler; | 26 import org.chromium.components.safe_browsing.SafeBrowsingApiHandler; |
| 27 import org.chromium.content_public.browser.WebContents; | 27 import org.chromium.content_public.browser.WebContents; |
| 28 import org.chromium.net.test.EmbeddedTestServer; | 28 import org.chromium.net.test.EmbeddedTestServer; |
| 29 | 29 |
| 30 import java.util.concurrent.TimeUnit; | |
| 31 | |
| 32 /** | 30 /** |
| 33 * Test suite for SafeBrowsing. | 31 * Test suite for SafeBrowsing. |
| 34 * | 32 * |
| 35 * Ensures that interstitials can be successfully created for malicous pages. | 33 * Ensures that interstitials can be successfully created for malicous pages. |
| 36 */ | 34 */ |
| 37 public class SafeBrowsingTest extends AwTestBase { | 35 public class SafeBrowsingTest extends AwTestBase { |
| 38 private TestAwContentsClient mContentsClient; | 36 private TestAwContentsClient mContentsClient; |
| 39 private AwTestContainerView mContainerView; | 37 private AwTestContainerView mContainerView; |
| 40 private AwContents mAwContents; | 38 private AwContents mAwContents; |
| 41 private TestAwWebContentsObserver mWebContentsObserver; | 39 private TestAwWebContentsObserver mWebContentsObserver; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT) | 261 @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT) |
| 264 public void testSafeBrowsingBackToSafetyShowsNetworkError() throws Throwable
{ | 262 public void testSafeBrowsingBackToSafetyShowsNetworkError() throws Throwable
{ |
| 265 int interstitialCount = | 263 int interstitialCount = |
| 266 mWebContentsObserver.getAttachedInterstitialPageHelper().getCall
Count(); | 264 mWebContentsObserver.getAttachedInterstitialPageHelper().getCall
Count(); |
| 267 final String responseUrl = mTestServer.getURL(MALWARE_HTML_PATH); | 265 final String responseUrl = mTestServer.getURL(MALWARE_HTML_PATH); |
| 268 loadUrlAsync(mAwContents, responseUrl); | 266 loadUrlAsync(mAwContents, responseUrl); |
| 269 mWebContentsObserver.getAttachedInterstitialPageHelper().waitForCallback
(interstitialCount); | 267 mWebContentsObserver.getAttachedInterstitialPageHelper().waitForCallback
(interstitialCount); |
| 270 OnReceivedError2Helper errorHelper = mContentsClient.getOnReceivedError2
Helper(); | 268 OnReceivedError2Helper errorHelper = mContentsClient.getOnReceivedError2
Helper(); |
| 271 int errorCount = errorHelper.getCallCount(); | 269 int errorCount = errorHelper.getCallCount(); |
| 272 dontProceedThroughInterstitial(); | 270 dontProceedThroughInterstitial(); |
| 273 errorHelper.waitForCallback(errorCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MIL
LISECONDS); | 271 errorHelper.waitForCallback(errorCount); |
| 274 assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN, errorHelper.getErr
or().errorCode); | 272 assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN, errorHelper.getErr
or().errorCode); |
| 275 assertEquals(responseUrl, errorHelper.getRequest().url); | 273 assertEquals(responseUrl, errorHelper.getRequest().url); |
| 276 } | 274 } |
| 277 | 275 |
| 278 @SmallTest | 276 @SmallTest |
| 279 @Feature({"AndroidWebView"}) | 277 @Feature({"AndroidWebView"}) |
| 280 @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT) | 278 @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT) |
| 281 public void testSafeBrowsingBackToSafetyShowsNetworkErrorForMaliciousSubreso
urce() | 279 public void testSafeBrowsingBackToSafetyShowsNetworkErrorForMaliciousSubreso
urce() |
| 282 throws Throwable { | 280 throws Throwable { |
| 283 int interstitialCount = | 281 int interstitialCount = |
| 284 mWebContentsObserver.getAttachedInterstitialPageHelper().getCall
Count(); | 282 mWebContentsObserver.getAttachedInterstitialPageHelper().getCall
Count(); |
| 285 final String responseUrl = mTestServer.getURL(IFRAME_HTML_PATH); | 283 final String responseUrl = mTestServer.getURL(IFRAME_HTML_PATH); |
| 286 loadUrlAsync(mAwContents, responseUrl); | 284 loadUrlAsync(mAwContents, responseUrl); |
| 287 mWebContentsObserver.getAttachedInterstitialPageHelper().waitForCallback
(interstitialCount); | 285 mWebContentsObserver.getAttachedInterstitialPageHelper().waitForCallback
(interstitialCount); |
| 288 OnReceivedError2Helper errorHelper = mContentsClient.getOnReceivedError2
Helper(); | 286 OnReceivedError2Helper errorHelper = mContentsClient.getOnReceivedError2
Helper(); |
| 289 int errorCount = errorHelper.getCallCount(); | 287 int errorCount = errorHelper.getCallCount(); |
| 290 dontProceedThroughInterstitial(); | 288 dontProceedThroughInterstitial(); |
| 291 errorHelper.waitForCallback(errorCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MIL
LISECONDS); | 289 errorHelper.waitForCallback(errorCount); |
| 292 assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN, errorHelper.getErr
or().errorCode); | 290 assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN, errorHelper.getErr
or().errorCode); |
| 293 final String subresourceUrl = mTestServer.getURL(MALWARE_HTML_PATH); | 291 final String subresourceUrl = mTestServer.getURL(MALWARE_HTML_PATH); |
| 294 assertEquals(subresourceUrl, errorHelper.getRequest().url); | 292 assertEquals(subresourceUrl, errorHelper.getRequest().url); |
| 295 assertFalse(errorHelper.getRequest().isMainFrame); | 293 assertFalse(errorHelper.getRequest().isMainFrame); |
| 296 } | 294 } |
| 297 } | 295 } |
| OLD | NEW |