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

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

Issue 2762843002: WebView: rename SafeBrowsing tests to be more consistent (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 final String responseUrl = mTestServer.getURL(SAFE_HTML_PATH); 196 final String responseUrl = mTestServer.getURL(SAFE_HTML_PATH);
197 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), resp onseUrl); 197 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), resp onseUrl);
198 waitForVisualStateCallback(mAwContents); 198 waitForVisualStateCallback(mAwContents);
199 assertEquals("Target page should be visible", COLOR_BLUE, 199 assertEquals("Target page should be visible", COLOR_BLUE,
200 GraphicsTestUtils.getPixelColorAtCenterOfView(mAwContents, mCont ainerView)); 200 GraphicsTestUtils.getPixelColorAtCenterOfView(mAwContents, mCont ainerView));
201 } 201 }
202 202
203 @SmallTest 203 @SmallTest
204 @Feature({"AndroidWebView"}) 204 @Feature({"AndroidWebView"})
205 @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT) 205 @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT)
206 public void testSafeBrowsingShowsInterstitialForMalware() throws Throwable { 206 public void testSafeBrowsingShowsInterstitialForMainFrame() throws Throwable {
207 loadGreenPage(); 207 loadGreenPage();
208 int count = mWebContentsObserver.getAttachedInterstitialPageHelper().get CallCount(); 208 int count = mWebContentsObserver.getAttachedInterstitialPageHelper().get CallCount();
209 final String responseUrl = mTestServer.getURL(MALWARE_HTML_PATH); 209 final String responseUrl = mTestServer.getURL(MALWARE_HTML_PATH);
210 loadUrlAsync(mAwContents, responseUrl); 210 loadUrlAsync(mAwContents, responseUrl);
211 mWebContentsObserver.getAttachedInterstitialPageHelper().waitForCallback (count); 211 mWebContentsObserver.getAttachedInterstitialPageHelper().waitForCallback (count);
212 assertTrue("Original page should not be showing", COLOR_GREEN 212 assertTrue("Original page should not be showing", COLOR_GREEN
213 != GraphicsTestUtils.getPixelColorAtCenterOfView( 213 != GraphicsTestUtils.getPixelColorAtCenterOfView(
214 mAwContents, mContainerView)); 214 mAwContents, mContainerView));
215 assertTrue("Target page should not be visible", COLOR_BLUE 215 assertTrue("Target page should not be visible", COLOR_BLUE
216 != GraphicsTestUtils.getPixelColorAtCenterOfView( 216 != GraphicsTestUtils.getPixelColorAtCenterOfView(
217 mAwContents, mContainerView)); 217 mAwContents, mContainerView));
218 // Assume that we are rendering the interstitial, since we see neither t he previous page nor 218 // Assume that we are rendering the interstitial, since we see neither t he previous page nor
219 // the target page 219 // the target page
220 } 220 }
221 221
222 @SmallTest 222 @SmallTest
223 @Feature({"AndroidWebView"}) 223 @Feature({"AndroidWebView"})
224 @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT) 224 @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT)
225 public void testSafeBrowsingMaliciousSubresourceShowsInterstitial() throws T hrowable { 225 public void testSafeBrowsingShowsInterstitialForSubresource() throws Throwab le {
226 loadGreenPage(); 226 loadGreenPage();
227 int count = mWebContentsObserver.getAttachedInterstitialPageHelper().get CallCount(); 227 int count = mWebContentsObserver.getAttachedInterstitialPageHelper().get CallCount();
228 final String responseUrl = mTestServer.getURL(IFRAME_HTML_PATH); 228 final String responseUrl = mTestServer.getURL(IFRAME_HTML_PATH);
229 loadUrlAsync(mAwContents, responseUrl); 229 loadUrlAsync(mAwContents, responseUrl);
230 mWebContentsObserver.getAttachedInterstitialPageHelper().waitForCallback (count); 230 mWebContentsObserver.getAttachedInterstitialPageHelper().waitForCallback (count);
231 assertTrue("Original page should not be showing", COLOR_GREEN 231 assertTrue("Original page should not be showing", COLOR_GREEN
232 != GraphicsTestUtils.getPixelColorAtCenterOfView( 232 != GraphicsTestUtils.getPixelColorAtCenterOfView(
233 mAwContents, mContainerView)); 233 mAwContents, mContainerView));
234 assertTrue("Target page should not be visible", COLOR_GRAY 234 assertTrue("Target page should not be visible", COLOR_GRAY
235 != GraphicsTestUtils.getPixelColorAtCenterOfView( 235 != GraphicsTestUtils.getPixelColorAtCenterOfView(
236 mAwContents, mContainerView)); 236 mAwContents, mContainerView));
237 // Assume that we are rendering the interstitial, since we see neither t he previous page nor 237 // Assume that we are rendering the interstitial, since we see neither t he previous page nor
238 // the target page 238 // the target page
239 } 239 }
240 240
241 @SmallTest 241 @SmallTest
242 @Feature({"AndroidWebView"}) 242 @Feature({"AndroidWebView"})
243 @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT) 243 @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT)
244 public void testSafeBrowsingCanProceedThroughInterstitial() throws Throwable { 244 public void testSafeBrowsingProceedThroughInterstitialForMainFrame() throws Throwable {
245 int interstitialCount = 245 int interstitialCount =
246 mWebContentsObserver.getAttachedInterstitialPageHelper().getCall Count(); 246 mWebContentsObserver.getAttachedInterstitialPageHelper().getCall Count();
247 int pageFinishedCount = 247 int pageFinishedCount =
248 mContentsClient.getOnPageFinishedHelper().getCallCount(); 248 mContentsClient.getOnPageFinishedHelper().getCallCount();
249 final String responseUrl = mTestServer.getURL(MALWARE_HTML_PATH); 249 final String responseUrl = mTestServer.getURL(MALWARE_HTML_PATH);
250 loadUrlAsync(mAwContents, responseUrl); 250 loadUrlAsync(mAwContents, responseUrl);
251 mWebContentsObserver.getAttachedInterstitialPageHelper().waitForCallback (interstitialCount); 251 mWebContentsObserver.getAttachedInterstitialPageHelper().waitForCallback (interstitialCount);
252 proceedThroughInterstitial(); 252 proceedThroughInterstitial();
253 mContentsClient.getOnPageFinishedHelper().waitForCallback(pageFinishedCo unt); 253 mContentsClient.getOnPageFinishedHelper().waitForCallback(pageFinishedCo unt);
254 waitForVisualStateCallback(mAwContents); 254 waitForVisualStateCallback(mAwContents);
255 assertEquals("Target page should be visible", COLOR_BLUE, 255 assertEquals("Target page should be visible", COLOR_BLUE,
256 GraphicsTestUtils.getPixelColorAtCenterOfView(mAwContents, mCont ainerView)); 256 GraphicsTestUtils.getPixelColorAtCenterOfView(mAwContents, mCont ainerView));
257 } 257 }
258 258
259 @SmallTest 259 @SmallTest
260 @Feature({"AndroidWebView"}) 260 @Feature({"AndroidWebView"})
261 @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT) 261 @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT)
262 public void testSafeBrowsingBackToSafetyShowsNetworkError() throws Throwable { 262 public void testSafeBrowsingDontProceedCausesNetworkErrorForMainFrame() thro ws Throwable {
263 int interstitialCount = 263 int interstitialCount =
264 mWebContentsObserver.getAttachedInterstitialPageHelper().getCall Count(); 264 mWebContentsObserver.getAttachedInterstitialPageHelper().getCall Count();
265 final String responseUrl = mTestServer.getURL(MALWARE_HTML_PATH); 265 final String responseUrl = mTestServer.getURL(MALWARE_HTML_PATH);
266 loadUrlAsync(mAwContents, responseUrl); 266 loadUrlAsync(mAwContents, responseUrl);
267 mWebContentsObserver.getAttachedInterstitialPageHelper().waitForCallback (interstitialCount); 267 mWebContentsObserver.getAttachedInterstitialPageHelper().waitForCallback (interstitialCount);
268 OnReceivedError2Helper errorHelper = mContentsClient.getOnReceivedError2 Helper(); 268 OnReceivedError2Helper errorHelper = mContentsClient.getOnReceivedError2 Helper();
269 int errorCount = errorHelper.getCallCount(); 269 int errorCount = errorHelper.getCallCount();
270 dontProceedThroughInterstitial(); 270 dontProceedThroughInterstitial();
271 errorHelper.waitForCallback(errorCount); 271 errorHelper.waitForCallback(errorCount);
272 assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN, errorHelper.getErr or().errorCode); 272 assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN, errorHelper.getErr or().errorCode);
273 assertEquals(responseUrl, errorHelper.getRequest().url); 273 assertEquals("Network error is for the malicious page", responseUrl,
274 errorHelper.getRequest().url);
274 } 275 }
275 276
276 @SmallTest 277 @SmallTest
277 @Feature({"AndroidWebView"}) 278 @Feature({"AndroidWebView"})
278 @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT) 279 @CommandLineFlags.Add(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT)
279 public void testSafeBrowsingBackToSafetyShowsNetworkErrorForMaliciousSubreso urce() 280 public void testSafeBrowsingDontProceedCausesNetworkErrorForSubresource() th rows Throwable {
280 throws Throwable {
281 int interstitialCount = 281 int interstitialCount =
282 mWebContentsObserver.getAttachedInterstitialPageHelper().getCall Count(); 282 mWebContentsObserver.getAttachedInterstitialPageHelper().getCall Count();
283 final String responseUrl = mTestServer.getURL(IFRAME_HTML_PATH); 283 final String responseUrl = mTestServer.getURL(IFRAME_HTML_PATH);
284 loadUrlAsync(mAwContents, responseUrl); 284 loadUrlAsync(mAwContents, responseUrl);
285 mWebContentsObserver.getAttachedInterstitialPageHelper().waitForCallback (interstitialCount); 285 mWebContentsObserver.getAttachedInterstitialPageHelper().waitForCallback (interstitialCount);
286 OnReceivedError2Helper errorHelper = mContentsClient.getOnReceivedError2 Helper(); 286 OnReceivedError2Helper errorHelper = mContentsClient.getOnReceivedError2 Helper();
287 int errorCount = errorHelper.getCallCount(); 287 int errorCount = errorHelper.getCallCount();
288 dontProceedThroughInterstitial(); 288 dontProceedThroughInterstitial();
289 errorHelper.waitForCallback(errorCount); 289 errorHelper.waitForCallback(errorCount);
290 assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN, errorHelper.getErr or().errorCode); 290 assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN, errorHelper.getErr or().errorCode);
291 final String subresourceUrl = mTestServer.getURL(MALWARE_HTML_PATH); 291 final String subresourceUrl = mTestServer.getURL(MALWARE_HTML_PATH);
292 assertEquals(subresourceUrl, errorHelper.getRequest().url); 292 assertEquals(subresourceUrl, errorHelper.getRequest().url);
293 assertFalse(errorHelper.getRequest().isMainFrame); 293 assertFalse(errorHelper.getRequest().isMainFrame);
294 } 294 }
295 } 295 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698